changeset 236:3dbeacf42e9e

BUGFIX missing deko init in reboot code. + Typo in ppN2 name.
author JeanDo
date Sat, 19 Mar 2011 15:15:17 +0100
parents ade0848c8b8b
children 55178aa1f972
files code_part1/OSTC_code_asm_part1/divemode_menu.asm code_part1/OSTC_code_asm_part1/simulator.asm code_part1/OSTC_code_asm_part1/start.asm code_part1/OSTC_code_asm_part1/surfmode.asm code_part1/OSTC_code_c_part2/p2_deco.c code_part1/OSTC_code_c_part2/p2_deco.o
diffstat 6 files changed, 46 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/code_part1/OSTC_code_asm_part1/divemode_menu.asm	Sat Mar 19 11:34:32 2011 +0100
+++ b/code_part1/OSTC_code_asm_part1/divemode_menu.asm	Sat Mar 19 15:15:17 2011 +0100
@@ -334,15 +334,12 @@
 	call	PLED_divemode_simulator_mask		; Redraw Simualtor mask
 
 	; Check limits (130m and 0m)
-	movlw	LOW		d'14000'
-	movwf	sub_a+0
+	movlw	LOW		d'14000'            ; Compare to 14bar=14000mbar (130m).
+	subwf   sim_pressure+0,W
 	movlw	HIGH	d'14000'
-	movwf	sub_a+1
-	movff	sim_pressure+0,sub_b+0
-	movff	sim_pressure+1,sub_b+1
-	call	sub16				; sub_c = sub_a - sub_b
-	btfss	neg_flag	
-	bra		divemode_menu_simulator_common2
+	subwfb  sim_pressure+1,W
+	bnc     divemode_menu_simulator_common2 ; No-carry = borrow = not deeper
+
 	; Too deep, limit to 130m
 	movlw	LOW		d'14000'
 	movwf	sim_pressure+0
@@ -351,15 +348,13 @@
 	return
 
 divemode_menu_simulator_common2:
-	movlw	LOW		d'1000'
-	movwf	sub_a+0
+	movlw	LOW		d'1000'             ; Compare to 1bar == 0m == 1000 mbar.
+	subwf   sim_pressure+0,W
 	movlw	HIGH	d'1000'
-	movwf	sub_a+1
-	movff	sim_pressure+0,sub_b+0
-	movff	sim_pressure+1,sub_b+1
-	call	sub16				; sub_c = sub_a - sub_b
-	btfsc	neg_flag	
-	return
+	subwfb  sim_pressure+1,W
+	btfsc   STATUS,C                    ; No-carry = borrow = not deeper.
+	return                              ; Deeper than 0m == Ok.
+
 	; Too shallow, limit to 1m
 	movlw	LOW		d'1000'
 	movwf	sim_pressure+0
@@ -381,6 +376,7 @@
 	addwf	sim_pressure+0,F
 	movlw	HIGH	d'1000'
 	addwfc	sim_pressure+1,F
+
 	movlw	d'4'
 	movwf	menupos						; reset cursor
 	bra		divemode_menu_simulator_common
--- a/code_part1/OSTC_code_asm_part1/simulator.asm	Sat Mar 19 11:34:32 2011 +0100
+++ b/code_part1/OSTC_code_asm_part1/simulator.asm	Sat Mar 19 15:15:17 2011 +0100
@@ -130,11 +130,6 @@
 	movlw	HIGH	d'1000'
 	addwfc	xC+1,F							; add 1000mBar
 
-;	movf	amb_pressure+0,W
-;	addwf	xC+0,F
-;	movf	amb_pressure+1,W
-;	addwfc	xC+1,F							; Add ambient pressure
-;	
 	movff	xC+0,sim_pressure+0
 	movff	xC+1,sim_pressure+1
 	
--- a/code_part1/OSTC_code_asm_part1/start.asm	Sat Mar 19 11:34:32 2011 +0100
+++ b/code_part1/OSTC_code_asm_part1/start.asm	Sat Mar 19 15:15:17 2011 +0100
@@ -73,15 +73,22 @@
 	endif
 
 ; reset deco data
-	clrf	WREG                            ; Use as buffer
-	movff	WREG,char_I_He_ratio            ; No He at the Surface
+	ostc_debug	'0'		; Sends debug-information to screen if debugmode active
+
 	movlw	d'79'							; 79% N2
 	movff	WREG,char_I_N2_ratio            ; No He at the Surface
-	movff	amb_pressure+0,int_I_pres_respiration+0		; copy surface air pressure to deco routine
+	clrf	WREG                            ; Use as buffer
+	movff	WREG,char_I_He_ratio            ; No He at the Surface
+	movff	WREG,char_I_step_is_1min		; 2 second deco mode
+	GETCUSTOM8	d'11'					    ; Saturation multiplier %
+	movff	WREG,char_I_saturation_multiplier
+	GETCUSTOM8	d'12'					    ; Desaturation multiplier %
+	movff	WREG,char_I_desaturation_multiplier
+	movff	amb_pressure+0,int_I_pres_respiration+0 ; copy for deco routine
 	movff	amb_pressure+1,int_I_pres_respiration+1		
+	movff	amb_pressure+0,int_I_pres_surface+0     ; copy for desat routine
+	movff	amb_pressure+1,int_I_pres_surface+1		
 
-	clrf    WREG
-	movff	WREG,char_I_step_is_1min		; 2 second deco mode
 	call	deco_clear_tissue			    ;
 	call	deco_calc_desaturation_time     ; calculate desaturation time
 	call	deco_clear_CNS_fraction			; clear CNS
--- a/code_part1/OSTC_code_asm_part1/surfmode.asm	Sat Mar 19 11:34:32 2011 +0100
+++ b/code_part1/OSTC_code_asm_part1/surfmode.asm	Sat Mar 19 15:15:17 2011 +0100
@@ -281,11 +281,9 @@
 	movff	amb_pressure+0,int_I_pres_respiration+0		; copy surface air pressure to deco routine
 	movff	amb_pressure+1,int_I_pres_respiration+1		
 	GETCUSTOM8	d'11'									; Saturation multiplier %
-	movwf	wait_temp
-	movff	wait_temp,char_I_saturation_multiplier
+	movff	WREG,char_I_saturation_multiplier
 	GETCUSTOM8	d'12'									; Desaturation multiplier %
-	movwf	wait_temp
-	movff	wait_temp,char_I_desaturation_multiplier
+	movff	WREG,char_I_desaturation_multiplier
 
 	call	deco_calc_wo_deco_step_1_min    ; calculate deco in surface mode 
 	movlb	b'00000001'									; select ram bank 1
--- a/code_part1/OSTC_code_c_part2/p2_deco.c	Sat Mar 19 11:34:32 2011 +0100
+++ b/code_part1/OSTC_code_c_part2/p2_deco.c	Sat Mar 19 15:15:17 2011 +0100
@@ -166,7 +166,7 @@
 static float 			pres_respiration;
 static float			pres_surface;
 static float			temp_deco;
-static float			ppO2;
+static float			ppN2;
 static float			ppHe;
 static float			temp_tissue;
 static float			N2_ratio;       // Breathed gas nitrogen ratio.
@@ -646,7 +646,7 @@
 	{
         // Recompute leading gas limit, at current depth:
         overlay float depth = (temp_deco - pres_surface) / 0.09995;
-        assert( depth >= 0.0 );
+        assert( depth >= -0.01 );       // -epsilon tolerance.
         assert( low_depth < 255 );
 
         if( depth > low_depth )
@@ -1006,7 +1006,7 @@
 //        temp_deco : simulated respiration pressure + security offset (deco_distance)
 //        Water-vapor pressure inside lumbs (ppWVapour).
 //
-// Output: ppO2, ppHe.
+// Output: ppN2, ppHe.
 //
 static void sim_alveolar_presures(void)
 {
@@ -1031,15 +1031,15 @@
 
     if( deco_diluent > ppWVapour )
     {
-        ppO2 = calc_N2_ratio * (deco_diluent - ppWVapour);
+        ppN2 = calc_N2_ratio * (deco_diluent - ppWVapour);
         ppHe = calc_He_ratio * (deco_diluent - ppWVapour);
     }
     else
     {
-        ppO2 = 0.0;
+        ppN2 = 0.0;
         ppHe = 0.0;
     }
-    assert( 0.0 <= ppO2 && ppO2 < 14.0 );
+    assert( 0.0 <= ppN2 && ppN2 < 14.0 );
     assert( 0.0 <= ppHe && ppHe < 14.0 );
 }
 
@@ -1273,13 +1273,13 @@
     }
  	if (pres_diluent > ppWVapour)                                               // new in v.101
  	{
- 		ppO2 = N2_ratio * (pres_diluent - ppWVapour);                           // changed in v.101
+ 		ppN2 = N2_ratio * (pres_diluent - ppWVapour);                           // changed in v.101
  		ppHe = He_ratio * (pres_diluent - ppWVapour);                           // changed in v.101
  		char_O_diluent = (char)(pres_diluent/pres_respiration*100.0);
  	}
  	else																		// new in v.101
  	{
- 		ppO2 = 0.0;                                                             // new in v.101
+ 		ppN2 = 0.0;                                                             // new in v.101
  		ppHe = 0.0;                                                             // new in v.101
  		char_O_diluent = 0;
  	}
@@ -1422,12 +1422,15 @@
 //
 static void calc_tissue(PARAMETER unsigned char period)
 {
+    assert( 0.00 <= ppN2 && ppN2 < 6.40 );  // 80% N2 at 70m
+    assert( 0.00 <= ppHe && ppHe < 18.9 );  // 90% He at 200m
+
     for (ci=0;ci<16;ci++)
     {
         read_buhlmann_coefficients(period);   // 2 sec or 1 min period.
 
         // N2
-        temp_tissue = (ppO2 - pres_tissue[ci]) * var_N2_e;
+        temp_tissue = (ppN2 - pres_tissue[ci]) * var_N2_e;
         temp_tissue_safety();
         pres_tissue[ci] += temp_tissue;
 
@@ -1602,12 +1605,15 @@
 //   + Do it on sim_pres_tissue, instead of pres_tissue.
 static void sim_tissue(PARAMETER unsigned char period)
 {
+    assert( 0.00 <= ppN2 && ppN2 < 6.40 );  // 80% N2 at 70m
+    assert( 0.00 <= ppHe && ppHe < 18.9 );  // 90% He at 200m
+
     for(ci=0; ci<16; ci++)
     {
         read_buhlmann_coefficients(period);  // 1 or 10 minute(s) interval
 
         // N2
-        temp_tissue = (ppO2 - sim_pres_tissue[ci]) * var_N2_e;
+        temp_tissue = (ppN2 - sim_pres_tissue[ci]) * var_N2_e;
         temp_tissue_safety();
         sim_pres_tissue[ci] += temp_tissue;
         
@@ -1809,7 +1815,7 @@
 
     N2_ratio = 0.7902; // FIXED sum as stated in b"uhlmann
     pres_surface = int_I_pres_surface * 0.001;
-    ppO2 = N2_ratio * (pres_surface - ppWVapour);
+    ppN2 = N2_ratio * (pres_surface - ppWVapour);
     int_O_desaturation_time = 0;
     float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101	(70,42%/100.=142)
 
@@ -1823,9 +1829,9 @@
         // new in version v.101: 1.07 = 7 percent distance to totally clean (totally clean is not possible, would take infinite time )
         // changes in v.101: 1.05 = 5 percent dist to totally clean is new desaturation point for display and noFly calculations
         // N2
-        temp1 = 1.05 * ppO2;
+        temp1 = 1.05 * ppN2;
         temp1 = temp1 - pres_tissue[ci];
-        temp2 = ppO2 - pres_tissue[ci];
+        temp2 = ppN2 - pres_tissue[ci];
         if (temp2 >= 0.0)
         {
             temp1 = 0.0;
@@ -1916,7 +1922,7 @@
     N2_ratio = 0.7902; // FIXED, sum lt. buehlmann
     pres_respiration = int_I_pres_respiration * 0.001;  // assembler code uses different digit system
     pres_surface = int_I_pres_surface * 0.001;          // the b"uhlmann formula using pres_surface does not use the N2_ratio
-    ppO2 = N2_ratio * (pres_respiration - ppWVapour);   // ppWVapour is the extra pressure in the body
+    ppN2 = N2_ratio * (pres_respiration - ppWVapour);   // ppWVapour is the extra pressure in the body
     ppHe = 0.0;
     float_desaturation_multiplier = char_I_desaturation_multiplier / 142.0; // new in v.101	(70,42%/100.=142)
     float_saturation_multiplier   = char_I_saturation_multiplier   * 0.01;
Binary file code_part1/OSTC_code_c_part2/p2_deco.o has changed