summaryrefslogtreecommitdiff
path: root/software/ihu/solar.inc
blob: 3848f4445dad93c0d84f9de0dcb96d859b4736b2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
  ;;
  ;;  mur.sat
  ;;
  ;;  Somewhen in the year 2012, mur.at will have a nano satellite launched
  ;;  into a low earth orbit (310 km above the surface of our planet). The
  ;;  satellite itself is a TubeSat personal satellite kit, developed and
  ;;  launched by interorbital systems. mur.sat is a joint venture of mur.at,
  ;;  ESC im Labor and realraum.
  ;;
  ;;  Please visit the project hompage at sat.mur.at for further information.
  ;;
  ;;
  ;;  Copyright (C) 2011 Christian Pointner <equinox@mur.at>
  ;;
  ;;  This file is part of mur.sat.
  ;;
  ;;  mur.sat is free software: you can redistribute it and/or modify
  ;;  it under the terms of the GNU General Public License as published by
  ;;  the Free Software Foundation, either version 3 of the License, or
  ;;  any later version.
  ;;
  ;;  mur.sat is distributed in the hope that it will be useful,
  ;;  but WITHOUT ANY WARRANTY; without even the implied warranty of
  ;;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  ;;  GNU General Public License for more details.
  ;;
  ;;  You should have received a copy of the GNU General Public License
  ;;  along with mur.sat. If not, see <http://www.gnu.org/licenses/>.
  ;;
  ;; -------------------------------------
  ;; DEFINES
  ;;   constants
sol_calc_power_single
  clrf      SOL_CALC_0
  clrf      SOL_CALC_1
  clrf      SOL_CALC_2
  movlw     .4
  movwf     SOL_CALC_CNT

  ;; sum up all currents -> SOL_CALC_0:2
sol_sum_current
  movf      INDF,w
  bcf       STATUS,C
  addwf     SOL_CALC_0,f
  btfsc     STATUS,C
  incf      SOL_CALC_1,f
  incf      FSR,f
  decfsz    SOL_CALC_CNT,f
  goto      sol_sum_current

  movf      INDF,w
  movwf     SOL_CALC_9
  clrf      SOL_CALC_3
  clrf      SOL_CALC_4
  clrf      SOL_CALC_5

  ;; multiply SOL_CALC_0:2 with SOL_CALC_9 -> SOL_CALC_3:5
  movlw     .8
  movwf     SOL_CALC_CNT
sol_mula_vc
  btfss     SOL_CALC_9,0
  goto      sol_mula_rotate

  bcf       STATUS,C
  movf      SOL_CALC_0,w
  addwf     SOL_CALC_3,f
  btfss     STATUS,C
  goto      sol_mula_vc1
  bcf       STATUS,C
  movlw     .1
  addwf     SOL_CALC_4,f
  btfsc     STATUS,C
  incf      SOL_CALC_5,f

sol_mula_vc1
  bcf       STATUS,C
  movf      SOL_CALC_1,w
  addwf     SOL_CALC_4,f
  btfsc     STATUS,C
  incf      SOL_CALC_5,f

  movf      SOL_CALC_2,w
  addwf     SOL_CALC_5,f

sol_mula_rotate
  rrf       SOL_CALC_9,f
  bcf       STATUS,C
  rlf       SOL_CALC_0,f
  rlf       SOL_CALC_1,f
  rlf       SOL_CALC_2,f

  decfsz    SOL_CALC_CNT,f
  goto      sol_mula_vc

  return

  ;; -------------------------------------
solar_calc_power
  ;; calc power of power line 1
  movlw     ADC_SOLAR_C0
  movwf     FSR
  call      sol_calc_power_single

  ;; move SOL_CALC_3:5 -> SOL_CALC_6:8
  movf      SOL_CALC_3,w
  movwf     SOL_CALC_6
  movf      SOL_CALC_4,w
  movwf     SOL_CALC_7
  movf      SOL_CALC_5,w
  movwf     SOL_CALC_8

  ;; calc power of power line 2
  movlw     ADC_SOLAR_C4
  movwf     FSR
  call      sol_calc_power_single

  ;; add SOL_CALC_3:5 to SOL_CALC_6:8 -> SOL_CALC_6:8
  bcf       STATUS,C
  movf      SOL_CALC_3,w
  addwf     SOL_CALC_6,f
  btfss     STATUS,C
  goto      solar_calc_power1
  bcf       STATUS,C
  movlw     .1
  addwf     SOL_CALC_7,f
  btfsc     STATUS,C
  incf      SOL_CALC_8,f

solar_calc_power1
  movf      SOL_CALC_4,w
  addwf     SOL_CALC_7,f
  btfsc     STATUS,C
  incf      SOL_CALC_8,f

  movf      SOL_CALC_5,w
  addwf     SOL_CALC_8,f

  ;; SOL_CALC_6:8 << 1   ->   SOL_CALC_6:8
  rlf       SOL_CALC_6,f
  rlf       SOL_CALC_7,f
  rlf       SOL_CALC_8,f

  ;; if(SOL_CALC_6 & 0x80) SOL_CALC_7:8+=1
  bcf       STATUS,C
  movlw     .1
  btfsc     SOL_CALC_6,7
  addwf     SOL_CALC_7,f
  btfsc     STATUS,C
  incf      SOL_CALC_8,f

  ;; SOL_CALC_7 -> SOL_POWERL, SOL_CALC_8 -> SOL_POWERH
  movf      SOL_CALC_7,w
  movwf     SOL_POWERL
  movf      SOL_CALC_8,w
  movwf     SOL_POWERH

  return
  ;; -------------------------------------