diff 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
line wrap: on
line diff
--- a/code_part1/OSTC_code_asm_part1/isr.asm	Wed May 18 02:01:52 2011 +0200
+++ b/code_part1/OSTC_code_asm_part1/isr.asm	Fri May 20 00:39:05 2011 +0200
@@ -27,6 +27,8 @@
 ; flag pressure_refresh is set every 500ms 
 ; and provides accurate pressure (+/-1mBar stable) and temperature (0.1C stable)
 
+;=============================================================================
+
 uartint:
 		btfsc	simulatormode_active		; are we in simulatormode?
 		bra		simulator_int				; Yes, reading is depth in m!
@@ -56,13 +58,12 @@
 		bsf		uart_send_int_eeprom2		; set flag
 		dcfsnz	uart1_temp,F				; "k"
 		bsf		uart_store_tissue_data		; set flag
-	
+
 		movlw	0xC1
 		cpfseq	RCREG						; 115200Baud Bootloader request?
 		bra		uartint1					; No
 		bsf		uart_115200_bootloader		; Yes, set Flag
 
-
 uartint1:
 		movf	RCREG,w						; unload RCREG in stand-alone simulator mode
 		bcf		PIR1,RCIF					; Clear flag
@@ -86,6 +87,8 @@
 		movff	PRODH,sim_pressure+1
 		bra		uartint1					; exit uart int
 
+;=============================================================================
+
 switch_left_int:
 		bcf		INTCON,INT0IF				; Clear flag
 
@@ -133,7 +136,10 @@
 		clrf	TMR0H
 		clrf	TMR0L
 		return
-		
+
+;=============================================================================
+;
+
 timer1int:
 		bcf		PIR1,TMR1IF					; Clear flag
 
@@ -158,6 +164,21 @@
 		btfsc	sleepmode					; In sleepmode?
 		return								; Yes
 
+; Sensor interput do poll the presure/temperature sensor, download results,
+; compute compensations, and store results in various shared variables.
+;
+; Input:    interupt (every 62.5msec == 16Hz), sensor,
+;           last_surfpressure:2.
+;
+; Output:   amb_pressure:2,
+;           temperature:2,
+;           rel_pressure:2,
+;           and the pressure_refresh flag.
+;
+; NOTE: averaging (4 successive value, as recommended in the MS5535 datasheet)
+;       is done on private variables, to avoid trashing data while reading it
+;       from the main code.
+;
 sensor_int:
 		btfsc		no_sensor_int			; No sensor interrupt (because it's addressed during sleep)
 		return						
@@ -193,25 +214,30 @@
 ;sensor_int2_plus_average:
 		rcall		sensor_int_state2
 sensor_int2_plus_average2:		
-		bcf			STATUS,C
-		rrcf		isr3_temp+1				; isr3_temp / 2
-		rrcf		isr3_temp+0
-		bcf			STATUS,C
-		rrcf		temperature_temp+1		; temperature_temp /2
-		rrcf		temperature_temp+0
+		bcf			STATUS,C            ; clear carry bit.
+		rrcf		amb_pressure_avg+1  ; amb_pressure sum / 2
+		rrcf		amb_pressure_avg+0
+		bcf			STATUS,C            ; clear carry bit, twice.
+		rrcf		amb_pressure_avg+1  ; amb_pressure sum / 4
+		rrcf		amb_pressure_avg+0
+
+		movff		amb_pressure_avg+1,amb_pressure+1	; copy into actual register
+		movff		amb_pressure_avg+0,amb_pressure+0
 
-		bcf			STATUS,C
-		rrcf		isr3_temp+1				; isr3_temp / 4
-		rrcf		isr3_temp+0
-		bcf			STATUS,C
-		rrcf		temperature_temp+1		; temperature_temp /4
-		rrcf		temperature_temp+0
-	
-		movff		isr3_temp+1,amb_pressure+1	; copy into actual register
-		movff		isr3_temp+0,amb_pressure+0
+        bcf			STATUS,C
+        btfsc       temperature_avg+1,7 ; Copy sign bit to carry
+        bsf         STATUS,C
+		rrcf		temperature_avg+1   ; Signed temperature /2
+		rrcf		temperature_avg+0
 
-		movff		temperature_temp+1,temperature+1
-		movff		temperature_temp+0,temperature+0
+        bcf			STATUS,C
+        btfsc       temperature_avg+1,7 ; Copy sign bit to carry
+        bsf         STATUS,C
+		rrcf		temperature_avg+1   ; Signed temperature /4
+		rrcf		temperature_avg+0
+
+		movff		temperature_avg+1,temperature+1
+		movff		temperature_avg+0,temperature+0
 
 		bsf			pressure_refresh 			; Set flag! Temp and pressure were updated!
 		clrf		timer1int_counter2			; Then reset State counter
@@ -226,7 +252,6 @@
 		movwf		last_surfpressure+1
 
 comp_air_pressure:
-		bcf			neg_flag				
 		movf		last_surfpressure+0,W		; compensate airpressure
 		subwf   	amb_pressure+0,W             
 		movwf   	rel_pressure+0				; rel_pressure stores depth!
@@ -240,13 +265,12 @@
 		clrf		rel_pressure+1				; e.g. when surface air pressure dropped during the dive
 		return
 
-
 sensor_int_state1_plus_restart:
-		bcf			pressure_refresh		; clear flags
-		clrf		isr3_temp+0				; pressure average registers
-		clrf		isr3_temp+1
-		clrf		temperature_temp+0
-		clrf		temperature_temp+1
+;;;		bcf			pressure_refresh    ; clear flags
+		clrf		amb_pressure_avg+0  ; pressure average registers
+		clrf		amb_pressure_avg+1
+		clrf		temperature_avg+0
+		clrf		temperature_avg+1
 
 sensor_int_state1:
 		call		get_temperature_value	; State 1: Get temperature
@@ -256,17 +280,9 @@
 sensor_int_state2:
 		call		get_pressure_value		; State2: Get pressure (51us)
 		call		get_temperature_start	; and start temperature integration (73,5us)
-		call		calculate_compensation	; calculate temperature compensated pressure (233us)
-		movf		amb_pressure+0,W
-		addwf		isr3_temp+0				; average pressure
-		movf		amb_pressure+1,W
-		addwfc		isr3_temp+1
-		movf		temperature+0,W
-		addwf		temperature_temp+0		; average temperature
-		movf		temperature+1,W
-		addwfc		temperature_temp+1
-		return		
+		goto		calculate_compensation	; calculate temperature compensated pressure (233us)
 
+;=============================================================================
 
 RTCisr:			
 		clrf		timer1int_counter1		; counts to 16 (one second / 62.5ms)