# HG changeset patch # User JeanDo # Date 1303753364 -7200 # Node ID 21a0f7393468b8684155636c0e522f4df8522dc6 # Parent 916df3161d52e05aaa5005ca819e854c9577fd11 New CNS calculation in decoplan. BUGFIX set current gas in decoplan. diff -r 916df3161d52 -r 21a0f7393468 code_part1/OSTC_code_asm_part1/changelog.txt --- a/code_part1/OSTC_code_asm_part1/changelog.txt Fri Apr 22 10:02:18 2011 +0200 +++ b/code_part1/OSTC_code_asm_part1/changelog.txt Mon Apr 25 19:42:44 2011 +0200 @@ -2,7 +2,10 @@ BETA Version - Do NOT use for diving! CHANGE: Runtime simulator faster BUGFIX: "Active?" list in Divemode - +NEW: Display CNS in decoplan +NEW: Colored stops in decoplan (CF55 > 0) +NEW: 115kbauds bootloader. +NEW: Colored battery sign when charging (yellow) or charged (green). New in 1.86 beta: BETA Version - Do NOT use for diving! diff -r 916df3161d52 -r 21a0f7393468 code_part1/OSTC_code_asm_part1/divemode.asm --- a/code_part1/OSTC_code_asm_part1/divemode.asm Fri Apr 22 10:02:18 2011 +0200 +++ b/code_part1/OSTC_code_asm_part1/divemode.asm Mon Apr 25 19:42:44 2011 +0200 @@ -290,34 +290,11 @@ call calc_average_depth ; calculate average depth call calc_velocity ; calculate vertical velocity and display if > threshold (every two seconds) - ; calculate ppO2 in 0.01Bar (e.g. 150 = 1.50 Bar ppO2) - movff amb_pressure+0,xA+0 ; P_amb in milibar (1000 = 1.000 bar). - movff amb_pressure+1,xA+1 - movlw d'10' - movwf xB+0 - clrf xB+1 - call div16x16 ; xC=p_amb/10 (100 = 1.00 bar). - movff xC+0,xA+0 - movff xC+1,xA+1 - movff char_I_O2_ratio,xB+0 - clrf xB+1 - call mult16x16 ; char_I_O2_ratio * (p_amb/10) - movff xC+0,xA+0 - movff xC+1,xA+1 - movlw d'100' - movwf xB+0 - clrf xB+1 - call div16x16 ; xC=(char_I_O2_ratio * p_amb/10)/100 +; Calculate CNS + rcall set_actual_ppo2 ; Set char_I_actual_ppO2 + clrf WREG + movff WREG,char_I_step_is_1min ; Make sure to be in 2sec mode. -; Copy ppO2 for CNS calculation - tstfsz xC+1 ; Is ppO2 > 2.55bar ? - setf xC+0 ; yes: bound to 2.55... better than wrap around. - - movff xC+0, char_I_actual_ppO2 ; copy last ppO2 to buffer register - btfsc FLAG_const_ppO2_mode ; do in const_ppO2_mode - movff char_I_const_ppO2, char_I_actual_ppO2 ; copy last ppO2 to buffer register - -; Calculate CNS call deco_calc_CNS_fraction ; calculate CNS movlb b'00000001' ; rambank 1 selected @@ -451,6 +428,36 @@ return +;----------------------------------------------------------------------------- +; calculate ppO2 in 0.01Bar (e.g. 150 = 1.50 Bar ppO2) +set_actual_ppo2: + movff amb_pressure+0,xA+0 ; P_amb in milibar (1000 = 1.000 bar). + movff amb_pressure+1,xA+1 + movlw d'10' + movwf xB+0 + clrf xB+1 + call div16x16 ; xC=p_amb/10 (100 = 1.00 bar). + movff xC+0,xA+0 + movff xC+1,xA+1 + movff char_I_O2_ratio,xB+0 + clrf xB+1 + call mult16x16 ; char_I_O2_ratio * (p_amb/10) + movff xC+0,xA+0 + movff xC+1,xA+1 + movlw d'100' + movwf xB+0 + clrf xB+1 + call div16x16 ; xC=(char_I_O2_ratio * p_amb/10)/100 + +; Copy ppO2 for CNS calculation + tstfsz xC+1 ; Is ppO2 > 2.55bar ? + setf xC+0 ; yes: bound to 2.55... better than wrap around. + + movff xC+0, char_I_actual_ppO2 ; copy last ppO2 to buffer register + btfsc FLAG_const_ppO2_mode ; do in const_ppO2_mode + movff char_I_const_ppO2, char_I_actual_ppO2 ; copy last ppO2 to buffer register + return + reset_decompression_gases: ; reset the deco gas while in NDL ostc_debug 'F' ; Sends debug-information to screen if debugmode active lfsr FSR2,char_I_deco_gas_change @@ -471,8 +478,8 @@ ostc_debug 'B' ; Sends debug-information to screen if debugmode active call divemode_prepare_flags_for_deco - movlw d'0' - movff WREG,char_I_step_is_1min ; 2 second deco mode + clrf WREG + movff WREG,char_I_step_is_1min ; Force 2 second deco mode clrf TMR3L clrf TMR3H ; Reset Timer3 @@ -1746,8 +1753,8 @@ divemode1: read_int_eeprom d'36' ; Read mix 1 ppO2 btfsc FLAG_const_ppO2_mode - movff EEDATA,char_I_const_ppO2 ; Set ppO2 setpoint if in ppO2 mode - movff EEDATA, ppO2_setpoint_store ; Store also in this byte... + movff EEDATA,char_I_const_ppO2 ; Set ppO2 setpoint if in ppO2 mode + movff EEDATA,ppO2_setpoint_store ; Store also in this byte... bcf LED_blue bcf low_battery_state ; clear flag for battery warning mode @@ -1758,10 +1765,11 @@ btfss simulatormode_active ; do not disable in simulator mode! call disable_rs232 ; Disable RS232 +; Read Start Gas and configure char_I_He_ratio, char_I_O2_ratio and char_I_N2_ratio +set_first_gas: read_int_eeprom d'33' ; Read byte (stored in EEDATA) movff EEDATA,active_gas ; Read start gas (1-5) -; Read Start Gas and configure char_I_He_ratio, char_I_O2_ratio and char_I_N2_ratio decf active_gas,W ; Gas 0-4 mullw d'4' movf PRODL,W @@ -1769,13 +1777,11 @@ movwf EEADR call read_eeprom ; Read He ratio movff EEDATA,char_I_He_ratio ; And copy into hold register - decf active_gas,W ; Gas 0-4 - mullw d'4' - movf PRODL,W - addlw d'6' ; = address for O2 ratio - movwf EEADR + + decf EEADR,F call read_eeprom ; Read O2 ratio movff EEDATA, char_I_O2_ratio ; O2 ratio + movff char_I_He_ratio, wait_temp ; copy into bank1 register bsf STATUS,C ; Borrow bit movlw d'100' ; 100% diff -r 916df3161d52 -r 21a0f7393468 code_part1/OSTC_code_asm_part1/pled_outputs.asm --- a/code_part1/OSTC_code_asm_part1/pled_outputs.asm Fri Apr 22 10:02:18 2011 +0200 +++ b/code_part1/OSTC_code_asm_part1/pled_outputs.asm Mon Apr 25 19:42:44 2011 +0200 @@ -2426,8 +2426,8 @@ sublw .240 ; No: bottom row in planning movff WREG,win_height - WIN_LEFT .82 ; Full divemenu width - movlw .160-.82+1 + WIN_LEFT .85 ; Full divemenu width + movlw .160-.85+1 movff WREG,win_width clrf WREG ; Fill with black @@ -2715,7 +2715,7 @@ return ; no, return PLED_clear_divemode_menu: - WIN_BOX_BLACK .0, .168, .82, .160 ;top, bottom, left, right + WIN_BOX_BLACK .0, .168, .85, .160 ;top, bottom, left, right return PLED_divemenu_cursor: diff -r 916df3161d52 -r 21a0f7393468 code_part1/OSTC_code_asm_part1/simulator.asm --- a/code_part1/OSTC_code_asm_part1/simulator.asm Fri Apr 22 10:02:18 2011 +0200 +++ b/code_part1/OSTC_code_asm_part1/simulator.asm Mon Apr 25 19:42:44 2011 +0200 @@ -169,7 +169,7 @@ iorwf hi,W bz simulator_decoplan_notts - WIN_TOP .160 + WIN_TOP .162 lfsr FSR2, letter OUTPUTTEXT .85 ; TTS STRCAT ": " @@ -178,19 +178,15 @@ STRCAT_PRINT "'" simulator_decoplan_notts: - ; Print ambient pressure in DEBUG compile, because if might - ; be usefull to calibrate decompression algorithm. -#ifdef __DEBUG - movff int_I_pres_surface+0,lo - movff int_I_pres_surface+1,hi + WIN_TOP .190 ; Print calculated CNS before and after dive + STRCPY "CNS:" + movff char_O_CNS_fraction,lo ; Current CNS, before dive. + output_8 - WIN_TOP .190 - lfsr FSR2, letter - bsf leftbind - output_16 - bcf leftbind - STRCAT_PRINT " mbar" -#endif + STRCAT "%\x92" ; Right-arrow + movff logbook_temp3,lo ; Get back CNS value. + output_8 ; CNS after dive. + STRCAT_PRINT "%" WIN_INVERT .1 ; Init new Wordprocessor DISPLAYTEXT .188 ; Sim. Results: @@ -253,7 +249,7 @@ movlb 1 ; Clear the complete stop result column: - WIN_BOX_BLACK .0, .239, .82, .160 ;top, bottom, left, right + WIN_BOX_BLACK .0, .239, .85, .160 ;top, bottom, left, right movlw d'10' movwf waitms_temp ; Row for gas list is .10+.25 @@ -316,37 +312,37 @@ simulator_calc_deco: call simulator_save_tissue_data ; Stores 32 floats "pre_tissue" into bank3 - bsf simulatormode_active ; normal simulator mode - bsf standalone_simulator ; Standalone Simulator active - bsf no_sensor_int ; Disable sensor interrupt - clrf T3CON ; Restart time3 counter, - clrf TMR3L ; so the simu won't stop right away. + bsf simulatormode_active ; normal simulator mode + bsf standalone_simulator ; Standalone Simulator active + bsf no_sensor_int ; Disable sensor interrupt + clrf T3CON ; Restart time3 counter, + clrf TMR3L ; so the simu won't stop right away. clrf TMR3H - call diveloop_boot ; configure gases, etc. + call diveloop_boot ; configure gases, etc. ; Save dive parameters for gas volume estimation: movff logbook_temp2,char_I_bottom_depth movff logbook_temp1,char_I_bottom_time - movff logbook_temp2,xA+0 ; Bottom depth. + movff logbook_temp2,xA+0 ; Bottom depth. clrf xA+1 movlw d'100' movwf xB+0 clrf xB+1 - call mult16x16 ;xA*xB=xC ; Depth in m*100 + call mult16x16 ;xA*xB=xC, Depth in m*100 movlw LOW d'1000' addwf xC+0,F movlw HIGH d'1000' - addwfc xC+1,F ; add 1000mBar + addwfc xC+1,F ; add 1000mBar movff xC+0,sim_pressure+0 movff xC+1,sim_pressure+1 call PLED_topline_box WIN_INVERT .1 - DISPLAYTEXT .12 ; "Wait..." + DISPLAYTEXT .12 ; "Wait..." WIN_INVERT .0 movff sim_pressure+0,amb_pressure+0 ; override readings with simulator values @@ -354,6 +350,8 @@ call divemode_check_decogases ; Checks for decogases and sets the gases call divemode_prepare_flags_for_deco + call set_first_gas ; Set current N2/He/O2 ratios. + call set_actual_ppo2 ; Then configure char_I_actual_ppO2 ; First minute is special: init everything. movlw d'3' ; Begin of deco cycle (reset table). @@ -363,17 +361,19 @@ movff WREG,char_I_step_is_1min ; 1 minute mode. call deco_calc_hauptroutine ; Reset table + sim one minute for descent. + call deco_calc_CNS_fraction ; Also calculate CNS (in 1min loop) movlb b'00000001' ; rambank 1 selected decf logbook_temp1,F ; One minute done. ; Loop for bottom time duration simulator_calc_deco_loop2: - call PLED_simulator_data ; Update display of bottom time. + call PLED_simulator_data ; Update display of bottom time. - call deco_calc_tissue ; JUST calc tissue (faster). - movlb b'00000001' ; rambank 1 selected - ostc_debug 'C' ; Sends debug-information to screen if debugmode active + call deco_calc_tissue ; JUST calc tissue (faster). + call deco_calc_CNS_fraction ; Also calculate CNS (in 1min loop) + movlb b'00000001' ; rambank 1 selected + ostc_debug 'C' ; Sends debug-information to screen if debugmode active decfsz logbook_temp1,F ; Decrement bottom time, bra simulator_calc_deco_loop2 ; and loop while not finished. @@ -399,9 +399,10 @@ iorwf WREG ; deco_status=0 if decompression calculation done bnz simulator_calc_deco2 ; Not finished +; Finished simulator_calc_deco3: - ; Finished - rcall simulator_restore_tissue_data ; Restore 32 floats "pre_tissue" from bank3 + movff char_O_CNS_fraction,logbook_temp3 ; Save calculated CNS. + rcall simulator_restore_tissue_data ; Restore CNS & 32 floats "pre_tissue" from vault bcf simulatormode_active ; normal simulator mode bcf standalone_simulator ; Standalone Simulator active @@ -428,7 +429,7 @@ simulator_restore_tissue_data: bcf restore_deco_data ; clear restore flag ostc_debug 'S' ; Sends debug-information to screen if debugmode active - call deco_pull_tissues_from_vault + call deco_pull_tissues_from_vault ; Restore CNS too... movlb 0x01 ; Back to RAM Bank1 ostc_debug 'T' ; Sends debug-information to screen if debugmode active @@ -440,8 +441,4 @@ ; during simulation, which is the right thing to do... ostc_debug 'H' ; Sends debug-information to screen if debugmode active - ; Calculate CNS - call deco_calc_CNS_fraction ; calculate CNS - movlb b'00000001' ; rambank 1 selected - return diff -r 916df3161d52 -r 21a0f7393468 code_part1/OSTC_code_c_part2/p2_deco.c --- a/code_part1/OSTC_code_c_part2/p2_deco.c Fri Apr 22 10:02:18 2011 +0200 +++ b/code_part1/OSTC_code_c_part2/p2_deco.c Mon Apr 25 19:42:44 2011 +0200 @@ -2197,6 +2197,7 @@ // optimized in v.102 : with new variables char_I_actual_ppO2 and actual_ppO2 // // Input: char_I_actual_ppO2 +// char_I_step_is_1min : use 1min steps instead of 2sec. // Output: char_O_CNS_fraction // Uses and Updates: CNS_fraction // Uses: acutal_ppO2 @@ -2204,49 +2205,52 @@ void deco_calc_CNS_fraction(void) { overlay float actual_ppO2; + overlay float time_factor = 1.0f; RESET_C_STACK assert( 0.0 <= CNS_fraction && CNS_fraction <= 2.5 ); assert( char_I_actual_ppO2 > 15 ); actual_ppO2 = (float)char_I_actual_ppO2 / 100.0; + if( char_I_step_is_1min ) + time_factor = 30.0f; if (char_I_actual_ppO2 < 50) - CNS_fraction = CNS_fraction;// no changes + ; // no changes else if (char_I_actual_ppO2 < 60) - CNS_fraction = 1/(-54000.0 * actual_ppO2 + 54000.0) + CNS_fraction; + CNS_fraction += time_factor/(-54000.0 * actual_ppO2 + 54000.0); else if (char_I_actual_ppO2 < 70) - CNS_fraction = 1/(-45000.0 * actual_ppO2 + 48600.0) + CNS_fraction; + CNS_fraction += time_factor/(-45000.0 * actual_ppO2 + 48600.0); else if (char_I_actual_ppO2 < 80) - CNS_fraction = 1/(-36000.0 * actual_ppO2 + 42300.0) + CNS_fraction; + CNS_fraction += time_factor/(-36000.0 * actual_ppO2 + 42300.0); else if (char_I_actual_ppO2 < 90) - CNS_fraction = 1/(-27000.0 * actual_ppO2 + 35100.0) + CNS_fraction; + CNS_fraction += time_factor/(-27000.0 * actual_ppO2 + 35100.0); else if (char_I_actual_ppO2 < 110) - CNS_fraction = 1/(-18000.0 * actual_ppO2 + 27000.0) + CNS_fraction; + CNS_fraction += time_factor/(-18000.0 * actual_ppO2 + 27000.0); else if (char_I_actual_ppO2 < 150) - CNS_fraction = 1/(-9000.0 * actual_ppO2 + 17100.0) + CNS_fraction; + CNS_fraction += time_factor/(-9000.0 * actual_ppO2 + 17100.0); else if (char_I_actual_ppO2 < 160) - CNS_fraction = 1/(-22500.0 * actual_ppO2 + 37350.0) + CNS_fraction; + CNS_fraction += time_factor/(-22500.0 * actual_ppO2 + 37350.0); else if (char_I_actual_ppO2 < 165) - CNS_fraction = 0.000755 + CNS_fraction; // Arieli et all.(2002): Modeling pulmonary and CNS O2 toxicity... Formula (A1) based on value for 1.55 and c=20 + CNS_fraction += time_factor*0.000755; // Arieli et all.(2002): Modeling pulmonary and CNS O2 toxicity... Formula (A1) based on value for 1.55 and c=20 else if (char_I_actual_ppO2 < 170) - CNS_fraction = 0.00102 + CNS_fraction; // example calculation: Sqrt((1.7/1.55)^20)*0.000404 + CNS_fraction += time_factor*0.00102; // example calculation: Sqrt((1.7/1.55)^20)*0.000404 else if (char_I_actual_ppO2 < 175) - CNS_fraction = 0.00136 + CNS_fraction; + CNS_fraction += time_factor*0.00136; else if (char_I_actual_ppO2 < 180) - CNS_fraction = 0.00180 + CNS_fraction; + CNS_fraction += time_factor*0.00180; else if (char_I_actual_ppO2 < 185) - CNS_fraction = 0.00237 + CNS_fraction; + CNS_fraction += time_factor*0.00237; else if (char_I_actual_ppO2 < 190) - CNS_fraction = 0.00310 + CNS_fraction; + CNS_fraction += time_factor*0.00310; else if (char_I_actual_ppO2 < 195) - CNS_fraction = 0.00401 + CNS_fraction; + CNS_fraction += time_factor*0.00401; else if (char_I_actual_ppO2 < 200) - CNS_fraction = 0.00517 + CNS_fraction; + CNS_fraction += time_factor*0.00517; else if (char_I_actual_ppO2 < 230) - CNS_fraction = 0.0209 + CNS_fraction; + CNS_fraction += time_factor*0.0209; else - CNS_fraction = 0.0482 + CNS_fraction; // value for 2.5 + CNS_fraction += time_factor*0.0482; // value for 2.5 if (CNS_fraction > 2.5) CNS_fraction = 2.5; @@ -2429,9 +2433,12 @@ overlay unsigned char x; RESET_C_STACK - CNS_fraction = cns_vault; for (x=0;x<32;x++) pres_tissue[x] = pres_tissue_vault[x]; + + // Restore both CNS variable, too. + CNS_fraction = cns_vault; + char_O_CNS_fraction = (char)(CNS_fraction * 100.0 + 0.5); } ////////////////////////////////////////////////////////////////////////////// diff -r 916df3161d52 -r 21a0f7393468 code_part1/OSTC_code_c_part2/p2_deco.o Binary file code_part1/OSTC_code_c_part2/p2_deco.o has changed diff -r 916df3161d52 -r 21a0f7393468 code_part1/OSTC_code_c_part2/shared_definitions.h --- a/code_part1/OSTC_code_c_part2/shared_definitions.h Fri Apr 22 10:02:18 2011 +0200 +++ b/code_part1/OSTC_code_c_part2/shared_definitions.h Mon Apr 25 19:42:44 2011 +0200 @@ -114,7 +114,7 @@ bank3 udata_ovr 0x300 #endif -VAR_UCHAR (char_I_step_is_1min); +VAR_UCHAR (char_I_step_is_1min); // Use 1min integration for tissue and CNS. VAR_UINT (int_I_pres_respiration); // VAR_UINT (int_I_pres_surface); //