changeset 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 cb77d1fa4535
children 2144f19fa1eb
files code_part1/OSTC_code_asm_part1/definitions.asm code_part1/OSTC_code_asm_part1/isr.asm code_part1/OSTC_code_asm_part1/ms5535.asm code_part1/OSTC_code_asm_part1/pled_outputs.asm code_part1/OSTC_code_c_part2/p2_deco.c
diffstat 5 files changed, 108 insertions(+), 78 deletions(-) [+]
line wrap: on
line diff
--- a/code_part1/OSTC_code_asm_part1/definitions.asm	Wed May 18 02:01:52 2011 +0200
+++ b/code_part1/OSTC_code_asm_part1/definitions.asm	Fri May 20 00:39:05 2011 +0200
@@ -188,7 +188,6 @@
 ext_ee_temp2    res 1           ; External EEPROM Temp 2		used in I2C EEPROM
 
 isr1_temp       res 1           ; ISR temp variables
-isr3_temp       res 2
 
 timer1int_counter1  res 1       ;Timer 1 counter
 timer1int_counter2  res 1       ;Timer 1 counter
@@ -235,15 +234,16 @@
 OFF             res 2
 SENS            res 2
 
+amb_pressure_avg res 2          ; ambient pressure summing buffer[mBar]
 amb_pressure    res 2           ; ambient pressure [mBar]
 rel_pressure    res 2		    ; amb_pressure - surface pressure [mBar]
 max_pressure    res 2           ; Max. pressure for the dive [mBar]
 avr_rel_pressure res 2          ; Average rel. pressure (Average depth) for the dive [mBar], Resettable
 avr_rel_pressure_total res 2    ; Average rel. pressure (Average depth) for the dive [mBar], Non-Resettable
 last_pressure   res 2
+temperature_avg res 2           ; Temperature summing buffer.
 temperature     res 2
 last_temperature res 2
-temperature_temp res 2
 Dx              res 2
 
 last_surfpressure       res 2   ; Divemode
@@ -387,7 +387,7 @@
 #DEFINE win_flip_screen     win_flags,0 ; 180° rotation of the OLED screen.
 
 ; Flags
-#DEFINE	tts_extra_time		flag1,0	; unused
+#DEFINE	tts_extra_time		flag1,0	; Show Futur TTS in customview
 #DEFINE	FLAG_2      		flag1,1	; unused
 #DEFINE	pre_zero_flag		flag1,2	; leading zeros
 #DEFINE neg_flag			flag1,3	; e.g. Sub_16 (sub_c = sub_a - sub_b)
@@ -440,7 +440,7 @@
 #DEFINE	switch_left			flag6,3	;=1: left switch pressed
 #DEFINE	switch_right		flag6,4	;=1: right switch pressed
 #DEFINE	uart_settime		flag6,5	;=1: enter time sync routine
-#DEFINE	neg_temp			flag6,6	;=1: temperature below zero
+#DEFINE	FLAG_1              flag6,6	;=1: unused
 #DEFINE	twosecupdate		flag6,7	;=1: after any two seconds
 
 #DEFINE	dekostop_active			flag7,0	;=1: in deocompression mode
--- 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)
--- a/code_part1/OSTC_code_asm_part1/ms5535.asm	Wed May 18 02:01:52 2011 +0200
+++ b/code_part1/OSTC_code_asm_part1/ms5535.asm	Fri May 20 00:39:05 2011 +0200
@@ -27,7 +27,7 @@
 ; Expose internal variables, to ease debug:
     global D1, D2
     global C1, C2, C3, C4, C5, C6
-    global xdT, xdT2, OFF, SENS, amb_pressure, temperature
+    global xdT, xdT2, OFF, SENS, amb_pressure_avg, temperature_avg
 
 ;=============================================================================
 calculate_compensation:
@@ -151,20 +151,23 @@
     movlw   .12-.8                      ; a 12bit shift = 1 byte + 4 bits.
     call    isr_shift_C31
 
-    movlw   LOW(.1000)                  ; add 1000, and save into amb_pressure
-    addwf   isr_xC+1,W
-    movwf   amb_pressure+0
+    movlw   LOW(.1000)                  ; add 1000
+    addwf   isr_xC+1,F
     movlw   HIGH(.1000)
-    addwfc  isr_xC+2,W
-    movwf   amb_pressure+1
+    addwfc  isr_xC+2,F
 
 	btfss	simulatormode_active		; are we in simulator mode?
-	bra		calc_pressure_done			; no
+	bra		calc_compensation_2			; no
 
-	movff	sim_pressure+0,amb_pressure+0	; override readings with simulator values
-	movff	sim_pressure+1,amb_pressure+1
+	movff	sim_pressure+0,isr_xC+1	    ; override readings with simulator values
+	movff	sim_pressure+1,isr_xC+2
 	
-calc_pressure_done:
+calc_compensation_2:
+    movf    isr_xC+1,W                  ; Then sum_up to pressure averaging buffer.
+    addwf   amb_pressure_avg+0,F
+    movf    isr_xC+2,W
+    addwfc  amb_pressure_avg+1,F
+
     ; calculate temp = 200 + dT*(C6+100)/2^11
     movlw   LOW(.100)                   ; C6 + 100 --> A
     addwf   C6+0,W
@@ -179,23 +182,16 @@
     movlw   .11-.8                      ; A 12bit shift = 1 byte + 3 bits.
     call    isr_shift_C31
 
-    movlw   LOW(.200)                   ; Add 200, and save into temperature
-    addwf   isr_xC+1,W
-    movwf   temperature+0
+    movlw   LOW(.200)                   ; Add 200
+    addwf   isr_xC+1,F
     movlw   HIGH(.200)
-    addwfc  isr_xC+2,W
-    movwf   temperature+1
+    addwfc  isr_xC+2,F
 
-    bcf     neg_temp
-    bnn     calc_pos_temp               ; Is Temp° negativ ?
-    
-    bsf     neg_temp                    ; Yes: set flag and store -temp
-    comf    temperature+1
-    negf    temperature+0
-    btfsc   STATUS,C
-    incf    temperature+1
+    movf    isr_xC+1,W
+    addwf   temperature_avg+0,F
+    movf    isr_xC+2,W
+    addwfc  temperature_avg+1,F
 
-calc_pos_temp:
 	return			                    ; Fertig mit allem
 
 ;=============================================================================
--- a/code_part1/OSTC_code_asm_part1/pled_outputs.asm	Wed May 18 02:01:52 2011 +0200
+++ b/code_part1/OSTC_code_asm_part1/pled_outputs.asm	Fri May 20 00:39:05 2011 +0200
@@ -953,15 +953,24 @@
 	WIN_TOP		.100
 	WIN_LEFT	.1
 	WIN_FONT 	FT_SMALL
-	WIN_INVERT	.0					; Init new Wordprocessor
+	WIN_INVERT	.0                      ; Init new Wordprocessor
 	call	PLED_standard_color
 
+	movff	temperature+1,hi
+	movff	temperature+0,lo
 	lfsr	FSR2,letter
-	movlw	'-'
-	btfsc	neg_temp			; Show "-"?
-	movwf	POSTINC2			; Yes
-	movff	temperature+0,lo
-	movff	temperature+1,hi
+
+    btfss   hi,7                        ; Negative temperature ?
+    bra     PLED_temp_surfmode_1        ; No: continue
+
+	PUTC	'-'                         ; Display "-"
+
+    comf    hi                          ; Then, 16bit sign changes.
+    negf    lo
+    btfsc   STATUS,C
+    incf    hi
+
+PLED_temp_surfmode_1:
 	movlw	d'3'
 	movwf	ignore_digits
 	bsf		leftbind			; left orientated output
@@ -983,12 +992,21 @@
 	WIN_INVERT	.0					; Init new Wordprocessor
 	call	PLED_standard_color
 
+	movff	temperature+1,hi
+	movff	temperature+0,lo
 	lfsr	FSR2,letter
-	movlw	'-'
-	btfsc	neg_temp			; Show "-"?
-	movwf	POSTINC2			; Yes
-	movff	temperature+0,lo
-	movff	temperature+1,hi
+
+    btfss   hi,7                        ; Negative temperature ?
+    bra     PLED_temp_divemode_1        ; No: continue
+
+	PUTC	'-'                         ; Display "-"
+
+    comf    hi                          ; Then, 16bit sign changes.
+    negf    lo
+    btfsc   STATUS,C
+    incf    hi
+
+PLED_temp_divemode_1:
 	movlw	d'3'
 	movwf	ignore_digits
 	bsf		leftbind			; left orientated output
--- a/code_part1/OSTC_code_c_part2/p2_deco.c	Wed May 18 02:01:52 2011 +0200
+++ b/code_part1/OSTC_code_c_part2/p2_deco.c	Fri May 20 00:39:05 2011 +0200
@@ -671,7 +671,7 @@
 }
 
 //////////////////////////////////////////////////////////////////////////////
-// calc_next_decodepth_GF
+// calc_nextdecodepth
 //
 // new in v.102
 //
@@ -1056,7 +1056,7 @@
         overlay unsigned char j;
 
         // Loop over all enabled gas, to find the deepest one,
-        // above las gas, but below temp_depth_limit.
+        // above last used gas, but below temp_depth_limit.
         for(j=0; j<NUM_GAS; ++j)
         {
             // Gas not (yet) allowed ? Skip !