comparison code_part1/OSTC_code_asm_part1/isr.asm @ 340:ecbbbd423e86

BUGFIX save negativ temperatures in logbook (bbbug #6) BUGFIX temperature & amb_pressure averaging done in private variable. BUGFIX Signed averaging of temperature.
author JeanDo
date Fri, 20 May 2011 00:39:05 +0200
parents ceedf078b2d8
children 2144f19fa1eb
comparison
equal deleted inserted replaced
339:cb77d1fa4535 340:ecbbbd423e86
24 24
25 ; the timer1 module interrupts every 62.5ms (16x/second) 25 ; the timer1 module interrupts every 62.5ms (16x/second)
26 ; temperature and pressure is averaged over 4 measurements 26 ; temperature and pressure is averaged over 4 measurements
27 ; flag pressure_refresh is set every 500ms 27 ; flag pressure_refresh is set every 500ms
28 ; and provides accurate pressure (+/-1mBar stable) and temperature (0.1C stable) 28 ; and provides accurate pressure (+/-1mBar stable) and temperature (0.1C stable)
29
30 ;=============================================================================
29 31
30 uartint: 32 uartint:
31 btfsc simulatormode_active ; are we in simulatormode? 33 btfsc simulatormode_active ; are we in simulatormode?
32 bra simulator_int ; Yes, reading is depth in m! 34 bra simulator_int ; Yes, reading is depth in m!
33 35
54 bsf internal_eeprom_write2 ; set flag 56 bsf internal_eeprom_write2 ; set flag
55 dcfsnz uart1_temp,F ; "j" 57 dcfsnz uart1_temp,F ; "j"
56 bsf uart_send_int_eeprom2 ; set flag 58 bsf uart_send_int_eeprom2 ; set flag
57 dcfsnz uart1_temp,F ; "k" 59 dcfsnz uart1_temp,F ; "k"
58 bsf uart_store_tissue_data ; set flag 60 bsf uart_store_tissue_data ; set flag
59 61
60 movlw 0xC1 62 movlw 0xC1
61 cpfseq RCREG ; 115200Baud Bootloader request? 63 cpfseq RCREG ; 115200Baud Bootloader request?
62 bra uartint1 ; No 64 bra uartint1 ; No
63 bsf uart_115200_bootloader ; Yes, set Flag 65 bsf uart_115200_bootloader ; Yes, set Flag
64
65 66
66 uartint1: 67 uartint1:
67 movf RCREG,w ; unload RCREG in stand-alone simulator mode 68 movf RCREG,w ; unload RCREG in stand-alone simulator mode
68 bcf PIR1,RCIF ; Clear flag 69 bcf PIR1,RCIF ; Clear flag
69 bcf RCSTA,CREN ; Clear receiver status 70 bcf RCSTA,CREN ; Clear receiver status
84 mullw d'100' ; result will be mbar 85 mullw d'100' ; result will be mbar
85 movff PRODL,sim_pressure+0 ; stored for pressure overwrite 86 movff PRODL,sim_pressure+0 ; stored for pressure overwrite
86 movff PRODH,sim_pressure+1 87 movff PRODH,sim_pressure+1
87 bra uartint1 ; exit uart int 88 bra uartint1 ; exit uart int
88 89
90 ;=============================================================================
91
89 switch_left_int: 92 switch_left_int:
90 bcf INTCON,INT0IF ; Clear flag 93 bcf INTCON,INT0IF ; Clear flag
91 94
92 btfsc T0CON,TMR0ON ; Timer0 running? 95 btfsc T0CON,TMR0ON ; Timer0 running?
93 bra timer0_restart ; Yes, restart 96 bra timer0_restart ; Yes, restart
131 bcf INTCON,TMR0IF ; Clear flag 134 bcf INTCON,TMR0IF ; Clear flag
132 bcf T0CON,TMR0ON ; Stop Timer 0 135 bcf T0CON,TMR0ON ; Stop Timer 0
133 clrf TMR0H 136 clrf TMR0H
134 clrf TMR0L 137 clrf TMR0L
135 return 138 return
136 139
140 ;=============================================================================
141 ;
142
137 timer1int: 143 timer1int:
138 bcf PIR1,TMR1IF ; Clear flag 144 bcf PIR1,TMR1IF ; Clear flag
139 145
140 timer1int_debug: 146 timer1int_debug:
141 bcf LED_red ; LEDr off (For charge indicator) 147 bcf LED_red ; LEDr off (For charge indicator)
156 162
157 sensor_int_pre: 163 sensor_int_pre:
158 btfsc sleepmode ; In sleepmode? 164 btfsc sleepmode ; In sleepmode?
159 return ; Yes 165 return ; Yes
160 166
167 ; Sensor interput do poll the presure/temperature sensor, download results,
168 ; compute compensations, and store results in various shared variables.
169 ;
170 ; Input: interupt (every 62.5msec == 16Hz), sensor,
171 ; last_surfpressure:2.
172 ;
173 ; Output: amb_pressure:2,
174 ; temperature:2,
175 ; rel_pressure:2,
176 ; and the pressure_refresh flag.
177 ;
178 ; NOTE: averaging (4 successive value, as recommended in the MS5535 datasheet)
179 ; is done on private variables, to avoid trashing data while reading it
180 ; from the main code.
181 ;
161 sensor_int: 182 sensor_int:
162 btfsc no_sensor_int ; No sensor interrupt (because it's addressed during sleep) 183 btfsc no_sensor_int ; No sensor interrupt (because it's addressed during sleep)
163 return 184 return
164 185
165 incf timer1int_counter2,F ; counts to eight for state maschine 186 incf timer1int_counter2,F ; counts to eight for state maschine
191 ; bra sensor_int2_plus_average ; Do State 8 212 ; bra sensor_int2_plus_average ; Do State 8
192 213
193 ;sensor_int2_plus_average: 214 ;sensor_int2_plus_average:
194 rcall sensor_int_state2 215 rcall sensor_int_state2
195 sensor_int2_plus_average2: 216 sensor_int2_plus_average2:
196 bcf STATUS,C 217 bcf STATUS,C ; clear carry bit.
197 rrcf isr3_temp+1 ; isr3_temp / 2 218 rrcf amb_pressure_avg+1 ; amb_pressure sum / 2
198 rrcf isr3_temp+0 219 rrcf amb_pressure_avg+0
199 bcf STATUS,C 220 bcf STATUS,C ; clear carry bit, twice.
200 rrcf temperature_temp+1 ; temperature_temp /2 221 rrcf amb_pressure_avg+1 ; amb_pressure sum / 4
201 rrcf temperature_temp+0 222 rrcf amb_pressure_avg+0
202 223
203 bcf STATUS,C 224 movff amb_pressure_avg+1,amb_pressure+1 ; copy into actual register
204 rrcf isr3_temp+1 ; isr3_temp / 4 225 movff amb_pressure_avg+0,amb_pressure+0
205 rrcf isr3_temp+0 226
206 bcf STATUS,C 227 bcf STATUS,C
207 rrcf temperature_temp+1 ; temperature_temp /4 228 btfsc temperature_avg+1,7 ; Copy sign bit to carry
208 rrcf temperature_temp+0 229 bsf STATUS,C
209 230 rrcf temperature_avg+1 ; Signed temperature /2
210 movff isr3_temp+1,amb_pressure+1 ; copy into actual register 231 rrcf temperature_avg+0
211 movff isr3_temp+0,amb_pressure+0 232
212 233 bcf STATUS,C
213 movff temperature_temp+1,temperature+1 234 btfsc temperature_avg+1,7 ; Copy sign bit to carry
214 movff temperature_temp+0,temperature+0 235 bsf STATUS,C
236 rrcf temperature_avg+1 ; Signed temperature /4
237 rrcf temperature_avg+0
238
239 movff temperature_avg+1,temperature+1
240 movff temperature_avg+0,temperature+0
215 241
216 bsf pressure_refresh ; Set flag! Temp and pressure were updated! 242 bsf pressure_refresh ; Set flag! Temp and pressure were updated!
217 clrf timer1int_counter2 ; Then reset State counter 243 clrf timer1int_counter2 ; Then reset State counter
218 244
219 btfss simulatormode_active ; are we in simulator mode? 245 btfss simulatormode_active ; are we in simulator mode?
224 movwf last_surfpressure+0 250 movwf last_surfpressure+0
225 movlw HIGH d'1000' 251 movlw HIGH d'1000'
226 movwf last_surfpressure+1 252 movwf last_surfpressure+1
227 253
228 comp_air_pressure: 254 comp_air_pressure:
229 bcf neg_flag
230 movf last_surfpressure+0,W ; compensate airpressure 255 movf last_surfpressure+0,W ; compensate airpressure
231 subwf amb_pressure+0,W 256 subwf amb_pressure+0,W
232 movwf rel_pressure+0 ; rel_pressure stores depth! 257 movwf rel_pressure+0 ; rel_pressure stores depth!
233 258
234 movf last_surfpressure+1,W 259 movf last_surfpressure+1,W
238 return 263 return
239 clrf rel_pressure+0 ; Yes, do not display negative depths 264 clrf rel_pressure+0 ; Yes, do not display negative depths
240 clrf rel_pressure+1 ; e.g. when surface air pressure dropped during the dive 265 clrf rel_pressure+1 ; e.g. when surface air pressure dropped during the dive
241 return 266 return
242 267
243
244 sensor_int_state1_plus_restart: 268 sensor_int_state1_plus_restart:
245 bcf pressure_refresh ; clear flags 269 ;;; bcf pressure_refresh ; clear flags
246 clrf isr3_temp+0 ; pressure average registers 270 clrf amb_pressure_avg+0 ; pressure average registers
247 clrf isr3_temp+1 271 clrf amb_pressure_avg+1
248 clrf temperature_temp+0 272 clrf temperature_avg+0
249 clrf temperature_temp+1 273 clrf temperature_avg+1
250 274
251 sensor_int_state1: 275 sensor_int_state1:
252 call get_temperature_value ; State 1: Get temperature 276 call get_temperature_value ; State 1: Get temperature
253 call get_pressure_start ; and start pressure integration. 277 call get_pressure_start ; and start pressure integration.
254 return ; Done. 278 return ; Done.
255 279
256 sensor_int_state2: 280 sensor_int_state2:
257 call get_pressure_value ; State2: Get pressure (51us) 281 call get_pressure_value ; State2: Get pressure (51us)
258 call get_temperature_start ; and start temperature integration (73,5us) 282 call get_temperature_start ; and start temperature integration (73,5us)
259 call calculate_compensation ; calculate temperature compensated pressure (233us) 283 goto calculate_compensation ; calculate temperature compensated pressure (233us)
260 movf amb_pressure+0,W 284
261 addwf isr3_temp+0 ; average pressure 285 ;=============================================================================
262 movf amb_pressure+1,W
263 addwfc isr3_temp+1
264 movf temperature+0,W
265 addwf temperature_temp+0 ; average temperature
266 movf temperature+1,W
267 addwfc temperature_temp+1
268 return
269
270 286
271 RTCisr: 287 RTCisr:
272 clrf timer1int_counter1 ; counts to 16 (one second / 62.5ms) 288 clrf timer1int_counter1 ; counts to 16 (one second / 62.5ms)
273 bsf onesecupdate ; we have a new second! 289 bsf onesecupdate ; we have a new second!
274 290