comparison code_part1/OSTC_code_asm_part1/isr.asm @ 238:9581e48a914f

Some cleanup in the ISR
author heinrichsweikamp
date Sun, 20 Mar 2011 17:55:21 +0100
parents ed7826c740a0
children dee88c962653
comparison
equal deleted inserted replaced
237:55178aa1f972 238:9581e48a914f
79 mullw d'100' ; result will be mbar 79 mullw d'100' ; result will be mbar
80 movff PRODL,sim_pressure+0 ; stored for pressure overwrite 80 movff PRODL,sim_pressure+0 ; stored for pressure overwrite
81 movff PRODH,sim_pressure+1 81 movff PRODH,sim_pressure+1
82 bra uartint1 ; exit uart int 82 bra uartint1 ; exit uart int
83 83
84 schalter_links: ; 84 switch_left_int:
85 bcf INTCON,INT0IF ; Clear flag 85 bcf INTCON,INT0IF ; Clear flag
86 86
87 btfsc T0CON,TMR0ON ; Timer0 running? 87 btfsc T0CON,TMR0ON ; Timer0 running?
88 bra timer0_restart ; Yes, restart 88 bra timer0_restart ; Yes, restart
89 89
91 91
92 bsf T0CON,TMR0ON ; Start Timer 0 92 bsf T0CON,TMR0ON ; Start Timer 0
93 return 93 return
94 94
95 95
96 schalter_rechts: ; 96 switch_right_int:
97 bcf INTCON3,INT1IF ; Clear flag 97 bcf INTCON3,INT1IF ; Clear flag
98 98
99 btfsc T0CON,TMR0ON ; Timer0 running? 99 btfsc T0CON,TMR0ON ; Timer0 running?
100 bra timer0_restart ; Yes, restart 100 bra timer0_restart ; Yes, restart
101 101
104 bsf T0CON,TMR0ON ; Start Timer 0 104 bsf T0CON,TMR0ON ; Start Timer 0
105 return 105 return
106 106
107 timer0_restart: 107 timer0_restart:
108 bcf INTCON,TMR0IF ; Clear flag 108 bcf INTCON,TMR0IF ; Clear flag
109
110 clrf T0CON ; Timer0 109 clrf T0CON ; Timer0
111 clrf TMR0H 110 clrf TMR0H
112 clrf TMR0L 111 clrf TMR0L
113 bsf T0CON,TMR0ON ; Start Timer 0 112 bsf T0CON,TMR0ON ; Start Timer 0
114 return 113 return
118 bcf T0CON,TMR0ON ; Stop Timer 0 117 bcf T0CON,TMR0ON ; Stop Timer 0
119 clrf TMR0H 118 clrf TMR0H
120 clrf TMR0L 119 clrf TMR0L
121 return 120 return
122 121
123
124 timer0int_left_reset: 122 timer0int_left_reset:
125 bcf INTCON2, INTEDG0 ; Interrupt on faling edge again 123 bcf INTCON2, INTEDG0 ; Interrupt on faling edge again
126 bcf switch_left_isr ; Clear flag, button press is done 124 bcf switch_left_isr ; Clear flag, button press is done
127 125
128 movlw T0CON_debounce ; Timer0 126 movlw T0CON_debounce ; Timer0
147 145
148 timer0int_right: 146 timer0int_right:
149 bsf INTCON2, INTEDG1 ; Interrupt on rising edge again 147 bsf INTCON2, INTEDG1 ; Interrupt on rising edge again
150 return 148 return
151 149
152 timer3int:
153 bcf PIR2,TMR3IF ; Clear flag
154 bcf T3CON,TMR0ON ; Stop Timer 3
155 bcf T2CON,2 ; stop Timer 2
156 return
157
158 timer1int: 150 timer1int:
159 bcf PIR1,TMR1IF ; Clear flag 151 bcf PIR1,TMR1IF ; Clear flag
160 152
161 timer1int_debug: 153 timer1int_debug:
162 bcf LED_red ; LEDr off (For charge indicator) 154 bcf LED_red ; LEDr off (For charge indicator)
166 incf timer1int_counter1,F ; Yes, add extra 1/16 second 158 incf timer1int_counter1,F ; Yes, add extra 1/16 second
167 159
168 movlw 0x08 ; Timer1 int after 62.5ms (=16/second) 160 movlw 0x08 ; Timer1 int after 62.5ms (=16/second)
169 subwf TMR1H,F 161 subwf TMR1H,F
170 162
171 incf timer1int_counter1,F 163 incf timer1int_counter1,F ; Increase timer1 counter
164
172 movlw d'15' ; One second 16 165 movlw d'15' ; One second 16
173 cpfsgt timer1int_counter1 166 cpfsgt timer1int_counter1
174 bra sensor_int_pre ; only pressure sensor 167 bra sensor_int_pre ; only pressure sensor
175 call RTCisr ; adjust time, then query pressure sensor 168 rcall RTCisr ; adjust time, then query pressure sensor
176 169
177 sensor_int_pre: 170 sensor_int_pre:
178 btfss sleepmode ; In sleepmode? 171 btfsc sleepmode ; In sleepmode?
179 bra sensor_int ; No 172 return ; Yes
180 return
181 173
182 sensor_int: 174 sensor_int:
183 btfsc no_sensor_int ; No sensor interrupt (because it's addressed during sleep) 175 btfsc no_sensor_int ; No sensor interrupt (because it's addressed during sleep)
184 return 176 return
185 177
186 incf timer1int_counter2,F ; counts to eight for state maschine 178 incf timer1int_counter2,F ; counts to eight for state maschine
187 179
188 movlw d'1' 180 ; State 1: Clear flags and average registers, get temperature (51us) and start pressure integration (73,5us)
189 cpfseq timer1int_counter2 ; State 1? 181 ; State 2: Get pressure (51us), start temperature integration (73,5us) and calculate temperature compensated pressure (233us)
190 bra sensor_int1 ; No 182 ; State 3: Get temperature (51us) and start pressure integration (73,5us)
191 183 ; State 4: Get pressure (51us), start temperature integration (73,5us) and calculate temperature compensated pressure (233us)
192 bcf pressure_refresh ; clear flags 184 ; State 5: Get temperature (51us) and start pressure integration (73,5us)
185 ; State 6: Get pressure (51us), start temperature integration (73,5us) and calculate temperature compensated pressure (233us)
186 ; State 7: Get temperature (51us) and start pressure integration (73,5us)
187 ; State 8: Get pressure (51us), start temperature integration (73,5us), calculate temperature compensated pressure (233us) and build average for half-second update of tempperature and pressure
188
189 movff timer1int_counter2,isr_divB ; isr_divB used as temp here...
190 dcfsnz isr_divB,F
191 bra sensor_int_state1_plus_restart ; Do State 1
192 dcfsnz isr_divB,F
193 bra sensor_int_state2 ; Do State 2
194 dcfsnz isr_divB,F
195 bra sensor_int_state1 ; Do State 3
196 dcfsnz isr_divB,F
197 bra sensor_int_state2 ; Do State 4
198 dcfsnz isr_divB,F
199 bra sensor_int_state1 ; Do State 5
200 dcfsnz isr_divB,F
201 bra sensor_int_state2 ; Do State 6
202 dcfsnz isr_divB,F
203 bra sensor_int_state1 ; Do State 7
204 ; bra sensor_int2_plus_average ; Do State 8
205
206 ;sensor_int2_plus_average:
207 rcall sensor_int_state2
208 sensor_int2_plus_average2:
209 bcf STATUS,C
210 rrcf isr3_temp+1 ; isr3_temp / 2
211 rrcf isr3_temp+0
212 bcf STATUS,C
213 rrcf temperature_temp+1 ; temperature_temp /2
214 rrcf temperature_temp+0
215
216 bcf STATUS,C
217 rrcf isr3_temp+1 ; isr3_temp / 4
218 rrcf isr3_temp+0
219 bcf STATUS,C
220 rrcf temperature_temp+1 ; temperature_temp /4
221 rrcf temperature_temp+0
222
223 movff isr3_temp+1,amb_pressure+1 ; copy into actual register
224 movff isr3_temp+0,amb_pressure+0
225
226 movff temperature_temp+1,temperature+1
227 movff temperature_temp+0,temperature+0
228
229 bsf pressure_refresh ; Set flag! Temp and pressure were updated!
230 clrf timer1int_counter2 ; Then reset State counter
231
232 btfss simulatormode_active ; are we in simulator mode?
233 bra comp_air_pressure ; no
234
235 comp_air_pressure0:
236 movlw LOW d'1000' ; yes, so simulate 1Bar surface pressure
237 movwf last_surfpressure+0
238 movlw HIGH d'1000'
239 movwf last_surfpressure+1
240
241 comp_air_pressure:
242 bcf neg_flag
243 movf last_surfpressure+0,W ; compensate airpressure
244 subwf amb_pressure+0,W
245 movwf rel_pressure+0 ; rel_pressure stores depth!
246
247 movf last_surfpressure+1,W
248 subwfb amb_pressure+1,W
249 movwf rel_pressure+1
250 btfss STATUS,N ; result is below zero?
251 return
252 clrf rel_pressure+0 ; Yes, do not display negative depths
253 clrf rel_pressure+1 ; e.g. when surface air pressure dropped during the dive
254 return
255
256
257 sensor_int_state1_plus_restart:
258 bcf pressure_refresh ; clear flags
193 clrf isr3_temp+0 ; pressure average registers 259 clrf isr3_temp+0 ; pressure average registers
194 clrf isr3_temp+1 260 clrf isr3_temp+1
195 clrf temperature_temp+0 261 clrf temperature_temp+0
196 clrf temperature_temp+1 262 clrf temperature_temp+1
197 sensor_int0: 263
198 call get_temperature_value ; State 1: Get temperature 264 sensor_int_state1:
265 call get_temperature_value ; State 1: Get temperature
199 call get_pressure_start ; and start pressure integration. 266 call get_pressure_start ; and start pressure integration.
200 return ; Done. 267 return ; Done.
201 sensor_int1: 268
202 movlw d'2' 269 sensor_int_state2:
203 cpfseq timer1int_counter2 ; State 2?
204 bra sensor_int2 ; No
205
206 sensor_int1_1:
207 call get_pressure_value ; State2: Get pressure (51us) 270 call get_pressure_value ; State2: Get pressure (51us)
208 call get_temperature_start ; and start temperature integration (73,5us) 271 call get_temperature_start ; and start temperature integration (73,5us)
209 call calculate_compensation ; calculate temperature compensated pressure (233us) 272 call calculate_compensation ; calculate temperature compensated pressure (233us)
210 movf amb_pressure+0,W 273 movf amb_pressure+0,W
211 addwf isr3_temp+0 ; average pressure 274 addwf isr3_temp+0 ; average pressure
212 movf amb_pressure+1,W 275 movf amb_pressure+1,W
213 addwfc isr3_temp+1 276 addwfc isr3_temp+1
214 movf temperature+0,W 277 movf temperature+0,W
215 addwf temperature_temp+0 ; average temperature 278 addwf temperature_temp+0 ; average temperature
216 movf temperature+1,W 279 movf temperature+1,W
217 addwfc temperature_temp+1 280 addwfc temperature_temp+1
218 return 281 return
219 sensor_int2: 282
220 movlw d'3'
221 cpfseq timer1int_counter2 ; State 3?
222 bra sensor_int3 ; No
223 bra sensor_int0 ; Yes, but same as State 1!
224 sensor_int3:
225 movlw d'4'
226 cpfseq timer1int_counter2 ; State 4?
227 bra sensor_int4 ; No
228 bra sensor_int1_1 ; Yes, but same as State 2!
229 sensor_int4:
230 movlw d'5'
231 cpfseq timer1int_counter2 ; State 5?
232 bra sensor_int5 ; No
233 bra sensor_int0 ; Yes, but same as State 1!
234 sensor_int5:
235 movlw d'6'
236 cpfseq timer1int_counter2 ; State 6?
237 bra sensor_int6 ; No
238 bra sensor_int1_1 ; Yes, but same as State 2!
239 sensor_int6:
240 movlw d'7'
241 cpfseq timer1int_counter2 ; State 7?
242 bra sensor_int7 ; No
243 bra sensor_int0 ; Yes, but same as State 1!
244 sensor_int7:
245 rcall sensor_int1_1 ; Do State 2...
246 clrf timer1int_counter2 ; ..then reset State counter...
247 movlw d'2' ; and calculate average!
248 movwf isr2_temp
249 sensor_int8:
250 bcf STATUS,C
251 rrcf isr3_temp+1 ; isr3_temp / 2
252 rrcf isr3_temp+0
253 bcf STATUS,C
254 rrcf temperature_temp+1 ; temperature_temp /2
255 rrcf temperature_temp+0
256 decfsz isr2_temp,F
257 bra sensor_int8 ; once more
258
259 movff isr3_temp+1,amb_pressure+1 ; copy into actual register
260 movff isr3_temp+0,amb_pressure+0
261
262 movff temperature_temp+1,temperature+1
263 movff temperature_temp+0,temperature+0
264
265 bsf pressure_refresh ; Set flag! Temp and pressure were updated!
266
267 btfss simulatormode_active ; are we in simulator mode?
268 bra comp_air_pressure ; no
269
270 comp_air_pressure0:
271 movlw LOW d'1000' ; yes, so simulate 1Bar surface pressure
272 movwf last_surfpressure+0
273 movlw HIGH d'1000'
274 movwf last_surfpressure+1
275
276 comp_air_pressure:
277 bcf neg_flag
278 movf last_surfpressure+0,W ; compensate airpressure
279 subwf amb_pressure+0,W
280 movwf rel_pressure+0 ; rel_pressure stores depth!
281
282 movf last_surfpressure+1,W
283 subwfb amb_pressure+1,W
284 movwf rel_pressure+1
285 btfss STATUS,N ; result is below zero?
286 return
287 clrf rel_pressure+0 ; Yes, do not display negative depths
288 clrf rel_pressure+1 ; e.g. when surface air pressure dropped during the dive
289 return
290 283
291 RTCisr: 284 RTCisr:
292 clrf timer1int_counter1 ; counts to 16 (one second / 62.5ms) 285 clrf timer1int_counter1 ; counts to 16 (one second / 62.5ms)
293 bsf onesecupdate ; we have a new second! 286 bsf onesecupdate ; we have a new second!
294 287
295 bcf STATUS,Z ; are we in dive mode? 288 bcf STATUS,Z ; are we in dive mode?
296 btfss divemode 289 btfss divemode
297 bra RTCisr2 ; No, must be surface or sleepmode 290 bra RTCisr2 ; No, must be surface or sleepmode
298 291
299 incf samplesecs,F ; CF20 diving seconds done 292 incf samplesecs,F ; CF20 diving seconds done
300 decf samplesecs_value,W ; holds CF20 value (minus 1 into WREG) 293 decf samplesecs_value,W ; holds CF20 value (minus 1 into WREG)
301 cpfsgt samplesecs 294 cpfsgt samplesecs
302 bra RTCisr1 ; no 295 bra RTCisr1 ; no
303 296
304 clrf samplesecs ; clear counter... 297 clrf samplesecs ; clear counter...
305 bsf store_sample ; ...and set bit for profile storage 298 bsf store_sample ; ...and set bit for profile storage
299
306 RTCisr1: 300 RTCisr1:
307 ; Increase re-setable average depth divetime counter 301 ; Increase re-setable average depth divetime counter
308 incf average_divesecs+0,F ; increase stopwatch registers 302 incf average_divesecs+0,F ; increase stopwatch registers
309 btfsc STATUS,Z 303 btfsc STATUS,Z
310 incf average_divesecs+1,F ; increase stopwatch registers 304 incf average_divesecs+1,F ; increase stopwatch registers
314 308
315 incf divesecs,F ; increase divetime registers 309 incf divesecs,F ; increase divetime registers
316 movlw d'59' 310 movlw d'59'
317 cpfsgt divesecs 311 cpfsgt divesecs
318 bra RTCisr1a 312 bra RTCisr1a
313
319 clrf divesecs 314 clrf divesecs
320 bsf realdive ; this bit is always set (again) if the dive is longer then one minute 315 bsf realdive ; this bit is always set (again) if the dive is longer then one minute
321 316
322 incf divemins+0,F ; increase divemins 317 incf divemins+0,F ; increase divemins
323 btfsc STATUS,Z 318 btfsc STATUS,Z