comparison code_part1/OSTC_code_asm_part1/divemode.asm @ 292:21a0f7393468

New CNS calculation in decoplan. BUGFIX set current gas in decoplan.
author JeanDo
date Mon, 25 Apr 2011 19:42:44 +0200
parents 916df3161d52
children a5fd8777a598
comparison
equal deleted inserted replaced
291:916df3161d52 292:21a0f7393468
288 bsf twosecupdate ; No, but next second! 288 bsf twosecupdate ; No, but next second!
289 ; Routines used in the "other second" 289 ; Routines used in the "other second"
290 call calc_average_depth ; calculate average depth 290 call calc_average_depth ; calculate average depth
291 call calc_velocity ; calculate vertical velocity and display if > threshold (every two seconds) 291 call calc_velocity ; calculate vertical velocity and display if > threshold (every two seconds)
292 292
293 ; calculate ppO2 in 0.01Bar (e.g. 150 = 1.50 Bar ppO2)
294 movff amb_pressure+0,xA+0 ; P_amb in milibar (1000 = 1.000 bar).
295 movff amb_pressure+1,xA+1
296 movlw d'10'
297 movwf xB+0
298 clrf xB+1
299 call div16x16 ; xC=p_amb/10 (100 = 1.00 bar).
300 movff xC+0,xA+0
301 movff xC+1,xA+1
302 movff char_I_O2_ratio,xB+0
303 clrf xB+1
304 call mult16x16 ; char_I_O2_ratio * (p_amb/10)
305 movff xC+0,xA+0
306 movff xC+1,xA+1
307 movlw d'100'
308 movwf xB+0
309 clrf xB+1
310 call div16x16 ; xC=(char_I_O2_ratio * p_amb/10)/100
311
312 ; Copy ppO2 for CNS calculation
313 tstfsz xC+1 ; Is ppO2 > 2.55bar ?
314 setf xC+0 ; yes: bound to 2.55... better than wrap around.
315
316 movff xC+0, char_I_actual_ppO2 ; copy last ppO2 to buffer register
317 btfsc FLAG_const_ppO2_mode ; do in const_ppO2_mode
318 movff char_I_const_ppO2, char_I_actual_ppO2 ; copy last ppO2 to buffer register
319
320 ; Calculate CNS 293 ; Calculate CNS
294 rcall set_actual_ppo2 ; Set char_I_actual_ppO2
295 clrf WREG
296 movff WREG,char_I_step_is_1min ; Make sure to be in 2sec mode.
297
321 call deco_calc_CNS_fraction ; calculate CNS 298 call deco_calc_CNS_fraction ; calculate CNS
322 movlb b'00000001' ; rambank 1 selected 299 movlb b'00000001' ; rambank 1 selected
323 300
324 ; Check if CNS should be displayed 301 ; Check if CNS should be displayed
325 movff char_O_CNS_fraction,lo ; copy into bank1 302 movff char_O_CNS_fraction,lo ; copy into bank1
449 ; movff char_I_deco_gas_change,TXREG 426 ; movff char_I_deco_gas_change,TXREG
450 ; call rs232_wait_tx ; wait for UART 427 ; call rs232_wait_tx ; wait for UART
451 428
452 return 429 return
453 430
431 ;-----------------------------------------------------------------------------
432 ; calculate ppO2 in 0.01Bar (e.g. 150 = 1.50 Bar ppO2)
433 set_actual_ppo2:
434 movff amb_pressure+0,xA+0 ; P_amb in milibar (1000 = 1.000 bar).
435 movff amb_pressure+1,xA+1
436 movlw d'10'
437 movwf xB+0
438 clrf xB+1
439 call div16x16 ; xC=p_amb/10 (100 = 1.00 bar).
440 movff xC+0,xA+0
441 movff xC+1,xA+1
442 movff char_I_O2_ratio,xB+0
443 clrf xB+1
444 call mult16x16 ; char_I_O2_ratio * (p_amb/10)
445 movff xC+0,xA+0
446 movff xC+1,xA+1
447 movlw d'100'
448 movwf xB+0
449 clrf xB+1
450 call div16x16 ; xC=(char_I_O2_ratio * p_amb/10)/100
451
452 ; Copy ppO2 for CNS calculation
453 tstfsz xC+1 ; Is ppO2 > 2.55bar ?
454 setf xC+0 ; yes: bound to 2.55... better than wrap around.
455
456 movff xC+0, char_I_actual_ppO2 ; copy last ppO2 to buffer register
457 btfsc FLAG_const_ppO2_mode ; do in const_ppO2_mode
458 movff char_I_const_ppO2, char_I_actual_ppO2 ; copy last ppO2 to buffer register
459 return
460
454 reset_decompression_gases: ; reset the deco gas while in NDL 461 reset_decompression_gases: ; reset the deco gas while in NDL
455 ostc_debug 'F' ; Sends debug-information to screen if debugmode active 462 ostc_debug 'F' ; Sends debug-information to screen if debugmode active
456 lfsr FSR2,char_I_deco_gas_change 463 lfsr FSR2,char_I_deco_gas_change
457 clrf POSTINC2 ; Clear Gas1 464 clrf POSTINC2 ; Clear Gas1
458 clrf POSTINC2 465 clrf POSTINC2
469 btfsc FLAG_apnoe_mode ; ignore decompression calculation in apnoe mode 476 btfsc FLAG_apnoe_mode ; ignore decompression calculation in apnoe mode
470 return 477 return
471 478
472 ostc_debug 'B' ; Sends debug-information to screen if debugmode active 479 ostc_debug 'B' ; Sends debug-information to screen if debugmode active
473 call divemode_prepare_flags_for_deco 480 call divemode_prepare_flags_for_deco
474 movlw d'0' 481 clrf WREG
475 movff WREG,char_I_step_is_1min ; 2 second deco mode 482 movff WREG,char_I_step_is_1min ; Force 2 second deco mode
476 483
477 clrf TMR3L 484 clrf TMR3L
478 clrf TMR3H ; Reset Timer3 485 clrf TMR3H ; Reset Timer3
479 486
480 call deco_calc_hauptroutine ; calc_tissue 487 call deco_calc_hauptroutine ; calc_tissue
1744 movwf samplesecs_value ; to avoid EEPROM access in the ISR 1751 movwf samplesecs_value ; to avoid EEPROM access in the ISR
1745 1752
1746 divemode1: 1753 divemode1:
1747 read_int_eeprom d'36' ; Read mix 1 ppO2 1754 read_int_eeprom d'36' ; Read mix 1 ppO2
1748 btfsc FLAG_const_ppO2_mode 1755 btfsc FLAG_const_ppO2_mode
1749 movff EEDATA,char_I_const_ppO2 ; Set ppO2 setpoint if in ppO2 mode 1756 movff EEDATA,char_I_const_ppO2 ; Set ppO2 setpoint if in ppO2 mode
1750 movff EEDATA, ppO2_setpoint_store ; Store also in this byte... 1757 movff EEDATA,ppO2_setpoint_store ; Store also in this byte...
1751 1758
1752 bcf LED_blue 1759 bcf LED_blue
1753 bcf low_battery_state ; clear flag for battery warning mode 1760 bcf low_battery_state ; clear flag for battery warning mode
1754 bcf header_stored 1761 bcf header_stored
1755 bcf premenu 1762 bcf premenu
1756 bcf realdive 1763 bcf realdive
1757 bsf update_divetime ; set flag 1764 bsf update_divetime ; set flag
1758 btfss simulatormode_active ; do not disable in simulator mode! 1765 btfss simulatormode_active ; do not disable in simulator mode!
1759 call disable_rs232 ; Disable RS232 1766 call disable_rs232 ; Disable RS232
1760 1767
1768 ; Read Start Gas and configure char_I_He_ratio, char_I_O2_ratio and char_I_N2_ratio
1769 set_first_gas:
1761 read_int_eeprom d'33' ; Read byte (stored in EEDATA) 1770 read_int_eeprom d'33' ; Read byte (stored in EEDATA)
1762 movff EEDATA,active_gas ; Read start gas (1-5) 1771 movff EEDATA,active_gas ; Read start gas (1-5)
1763 1772
1764 ; Read Start Gas and configure char_I_He_ratio, char_I_O2_ratio and char_I_N2_ratio
1765 decf active_gas,W ; Gas 0-4 1773 decf active_gas,W ; Gas 0-4
1766 mullw d'4' 1774 mullw d'4'
1767 movf PRODL,W 1775 movf PRODL,W
1768 addlw d'7' ; = address for He ratio 1776 addlw d'7' ; = address for He ratio
1769 movwf EEADR 1777 movwf EEADR
1770 call read_eeprom ; Read He ratio 1778 call read_eeprom ; Read He ratio
1771 movff EEDATA,char_I_He_ratio ; And copy into hold register 1779 movff EEDATA,char_I_He_ratio ; And copy into hold register
1772 decf active_gas,W ; Gas 0-4 1780
1773 mullw d'4' 1781 decf EEADR,F
1774 movf PRODL,W
1775 addlw d'6' ; = address for O2 ratio
1776 movwf EEADR
1777 call read_eeprom ; Read O2 ratio 1782 call read_eeprom ; Read O2 ratio
1778 movff EEDATA, char_I_O2_ratio ; O2 ratio 1783 movff EEDATA, char_I_O2_ratio ; O2 ratio
1784
1779 movff char_I_He_ratio, wait_temp ; copy into bank1 register 1785 movff char_I_He_ratio, wait_temp ; copy into bank1 register
1780 bsf STATUS,C ; Borrow bit 1786 bsf STATUS,C ; Borrow bit
1781 movlw d'100' ; 100% 1787 movlw d'100' ; 100%
1782 subfwb wait_temp,W ; minus He 1788 subfwb wait_temp,W ; minus He
1783 bsf STATUS,C ; Borrow bit 1789 bsf STATUS,C ; Borrow bit