forked from KentuckySolarCar/Drivetek_MPPT
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcharge.asm
More file actions
237 lines (202 loc) · 6.05 KB
/
charge.asm
File metadata and controls
237 lines (202 loc) · 6.05 KB
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
;**********************************************************************
; P R O G R A M M MPPTnG *
; *
; Traking program for MPPT new generation *
;**********************************************************************
; *
; Filename: charge.asm *
; Date: 16.2.05 *
; Last Update: 16.2.05 *
; File Version: V1.0 *
; *
; Author: Christoph Raible *
; *
; Company: drivetek ag *
; *
; Changes: program part which charges the output capacitor *
; *
;**********************************************************************
; *
; Notes: *
; *
; *
;**********************************************************************
PreCharge
clrwdt ; reset watchdog
bsf REDLED
bsf NOC
movlw 0x01
movwf Waitboost ;Init Boost-Timer
movlw INITDUTY ; PWM2 duty cycle (Sm')
movwf DUTY2_H ; init duty variable
movwf CCPR2L
MeasStableUs
call GetFilteredUin
jmpFltL UIF0H,MINUINH,CV_UVState1 ; jmp, if minimal voltage not reached
jmpFgtL UIF0H,MINUINH,CV_MeasUout1 ; go on, if minimal reached
jmpFleL UIF0L,MINUINL,CV_UVState1 ; consider L-Byte
goto CV_MeasUout1
CV_UVState1 call UnderVoltage
CV_MeasUout1
; call UpdateCAN
clrwdt ; reset watchdog
call GetFilteredUout
movlw MINUBATH ;get 3/4 of MINUBAT
movwf Temp0
movlw MINUBATL
movwf Temp1
bcf _C ;divide by 2
rrf Temp0,F
rrf Temp1,F
bcf _C ;divide by 2 (now 4)
rrf Temp0,W
movwf Temp2
rrf Temp1,W
addwf Temp1,F ;times tree
btfsc _C
incf Temp2,F
movf Temp2,W
addwf Temp0,F
jmpFltF UOFH,Temp0,BoostALittle ; jmp, if output voltage within limits
movf UOFH,W
jmpWgtF Temp0,Wait4Connect ; go on, if ouput voltage exceeded
jmpFleF UOFL,Temp1,BoostALittle ; consider L-Byte
goto Wait4Connect
BoostALittle
call PWMon ; Precharge the output C during 300us
movlw 0xFF
call wait
call PWMoff
call wait20ms
goto MeasStableUs
Wait4Connect
clrwdt ; reset watchdog
call UpdateCAN
call GetFilteredUout ;MINUBAT<=UOUT<=MAXUOUT
movlw MINUBATH
subwf UOFH,w
btfsc _Z
goto CheckLsb
btfss _C ;c set if w=UOFH-MINUBATH >=0
goto PreCharge
goto CheckMaxuout
CheckLsb
movlw MINUBATL
subwf UOFL,W
btfss _C ;c set if w=UOFL-MINUBATL >=0
goto PreCharge
CheckMaxuout
movlw MAXUOH
movwf Temp1
movf UOFH,w
subwf Temp1,w
btfsc _Z
goto CheckLsb2
btfss _C ;c set if w=MAXUOH-UOFH >=0
goto PreCharge
goto BatConn
CheckLsb2
movlw MAXUOL
movwf Temp1
movfw UOFL
subwf Temp1,W
btfss _C ;c set if w=MAXUOL-UOFL >=0
goto PreCharge
BatConn
clrwdt
call GetFilteredUin
jmpFltL UIF0H,MINUINH,CV_UVState2 ; jmp, if minimal voltage not reached
jmpFgtL UIF0H,MINUINH,CV_MeasUout2 ; go on, if minimal reached
jmpFleL UIF0L,MINUINL,CV_UVState2 ; consider L-Byte
goto CV_MeasUout2
CV_UVState2 call UnderVoltage
CV_MeasUout2
call GetFilteredUin ;check Uin and transform in to 8bit value
rrf UIF0H,F
rrf UIF0L,F
rrf UIF0H,F
rrf UIF0L,F
movlw 0x53 ;50V @ 8bit ADC
subwf UIF0L,w ;UIFOL-50V<0?
btfss STATUS,C ; c set if UIF0L-50V>0
goto BigPWM
movlw 0x74 ;70V @ 8bit ADC
subwf UIF0L,w ;UIFOL-70V<0?
btfss STATUS,C ; c set if UIF0L-70V>0
goto MedPWM
movlw 0x25 ;small duty cycle
movwf CCPR2L
goto StartPWM
MedPWM
movlw 0x5b
movwf CCPR2L ;medium duty cycle
goto StartPWM
BigPWM
movlw 0x89 ;big duty cycle
movwf CCPR2L
StartPWM
clrwdt
call PWMon
call waittoboost
call PWMoff
call wait20ms
clrwdt
movfw UOFH ;Save old values of UOFH,OUFL
movwf Temp0
movfw UOFL
movwf Temp1
call GetFilteredUout ;check delta of Uout and dedect Bat. connection
movlw 0xFF ;Twocomplement
xorwf UOFL,F
xorwf UOFH,F
movlw 0x01
addwf UOFL,F
btfsc STATUS,C
Incf UOFH
movfw UOFL
addwf Temp1,F ; compare Uout_old Low Byte to Uout Low Byte Temp1=Temp1-UOFL
btfsc STATUS, C ; is result of subtraction negative?
goto Overflow
CheckMSB
movfw UOFH ; compare Uout_old High Byte to Uout High Byte Temp0=Temp0-UOFH
addwf Temp0,F
btfss STATUS,C ;is result of subtraction negativ?
goto Twocomplement
Checkdelta
movlw 0x06 ; max. allowed difference ca. 0.6V
movwf Temp2
movfw Temp1
subwf Temp2,w ;w=Temp2-Temp1 (max. allowed difference-real difference)
btfss STATUS, C ; jump back if difference too big
goto ResetBoosttime
movlw 0x05 ;longer boost-time
addwf Waitboost,F
btfss STATUS,C
goto Wait4Connect
goto RetFromPreCha ; Bat. connected?
ResetBoosttime
movlw 0x01
movwf Waitboost
goto Wait4Connect
Overflow
Incf Temp0
goto CheckMSB
Twocomplement
movlw 0xFF ;invert bits (two's complement)
xorwf Temp1,f
xorwf Temp0,f
movlw 0x01
addwf Temp1,f
btfsc STATUS,C
Incf Temp0
goto Checkdelta
RetFromPreCha
clrwdt
bcf REDLED
bcf NOC
call UpdateCAN
movlw INITDUTY ; PWM2 duty cycle (Sm')
movwf DUTY2_H ; init duty variable
movwf CCPR2L
call wait1s
RETURN