comparison src/divemode.asm @ 480:ad8acade5567

NEW: PSCR mode (Passive semi-closed rebreather)
author heinrichsweikamp
date Mon, 06 Feb 2017 16:26:36 +0100
parents c6f36c55b4f6
children c0ee33f1f399
comparison
equal deleted inserted replaced
479:34e73dc68799 480:ad8acade5567
224 return 224 return
225 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode 225 btfsc FLAG_gauge_mode ; Done for Apnoe or Gauge mode
226 return 226 return
227 227
228 ; Calculate CNS 228 ; Calculate CNS
229 rcall set_actual_ppo2 ; Set char_I_actual_ppO2 229 btfss FLAG_pscr_mode ; in PSCR mode?
230 rcall set_actual_ppo2 ; No, set char_I_actual_ppO2
230 clrf WREG 231 clrf WREG
231 movff WREG,char_I_step_is_1min ; Make sure to be in 2sec mode. 232 movff WREG,char_I_step_is_1min ; Make sure to be in 2sec mode.
232 call deco_calc_CNS_fraction ; calculate CNS 233 call deco_calc_CNS_fraction ; calculate CNS
233 movlb b'00000001' ; rambank 1 selected 234 movlb b'00000001' ; rambank 1 selected
234 ; Check for a gas change 235 ; Check for a gas change
313 314
314 SAFE_2BYTE_COPY amb_pressure,int_I_pres_respiration ; C-code needs the ambient pressure 315 SAFE_2BYTE_COPY amb_pressure,int_I_pres_respiration ; C-code needs the ambient pressure
315 clrf WREG 316 clrf WREG
316 movff WREG,char_I_step_is_1min ; Force 2 second deco mode 317 movff WREG,char_I_step_is_1min ; Force 2 second deco mode
317 318
319 movff char_I_O2_ratio,lo_temp ; Backup original value for everything
320 movff char_I_N2_ratio,hi_temp ; Backup original value for everything
321
322 btfss FLAG_pscr_mode
323 bra calc_deko_divemode2a ; Non-PSCR modes...
324
325 ; in PSCR mode, compute fO2 into char_I_O2_ratio
326 call compute_pscr_ppo2 ; pSCR ppO2 into sub_c:2
327 movff sub_c+0,xA+0
328 movff sub_c+1,xA+1
329 movlw LOW .10
330 movwf xB+0
331 movlw HIGH .10
332 movwf xB+1
333 call mult16x16 ;xA*xB=xC -> xC:4 = ppO2*10
334 SAFE_2BYTE_COPY amb_pressure, xB
335 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
336 ; xC+0 has O2 in percent
337 movff xC+0,char_I_O2_ratio
338
339 movff char_I_He_ratio, wait_temp ; copy into bank1 register
340 bsf STATUS,C ; Borrow bit
341 movlw d'100' ; 100%
342 subfwb wait_temp,W ; minus He
343 bsf STATUS,C ; Borrow bit
344 subfwb xC+0,W ; minus O2
345 movff WREG, char_I_N2_ratio ; = N2!
346
347 calc_deko_divemode2a:
318 clrf TMR5L 348 clrf TMR5L
319 clrf TMR5H ; 30,51757813µs/bit in TMR5L:TMR5H 349 clrf TMR5H ; 30,51757813µs/bit in TMR5L:TMR5H
320 call deco_calc_hauptroutine ; calc_tissue 350 call deco_calc_hauptroutine ; calc_tissue
321 movlb .1 351 movlb .1
352
353 movff lo_temp,char_I_O2_ratio ; Restore original value for everything
354 movff hi_temp,char_I_N2_ratio ; Restore original value for everything
355
322 356
323 movff char_O_deco_status,WREG ; Is a compute cycle finished ? 357 movff char_O_deco_status,WREG ; Is a compute cycle finished ?
324 iorwf WREG,F 358 iorwf WREG,F
325 btfss STATUS,Z 359 btfss STATUS,Z
326 return ; Return is status <> 0 360 return ; Return is status <> 0
1675 incf warning_counter,F ; increase counter 1709 incf warning_counter,F ; increase counter
1676 goto TFT_divetimeout ; Show timeout counter (and return) 1710 goto TFT_divetimeout ; Show timeout counter (and return)
1677 1711
1678 1712
1679 check_ppO2: ; check current ppO2 and display warning if required 1713 check_ppO2: ; check current ppO2 and display warning if required
1714 btfss FLAG_pscr_mode
1715 bra check_ppO2_non_pscr ; Non-PSCR modes...
1716 ; in PSCR mode
1717 call compute_pscr_ppo2 ; pSCR ppO2 into sub_c:2
1718 movff sub_c+0,xA+0
1719 movff sub_c+1,xA+1
1720 movlw d'100'
1721 movwf xB+0
1722 clrf xB+1
1723 call div16x16 ; /100
1724 tstfsz xC+1 ; Is ppO2 > 2.55bar ?
1725 setf xC+0 ; yes: bound to 2.55... better than wrap around.
1726 movff xC+0,char_I_actual_ppO2 ; copy last ppO2 to buffer register (for pSCR CNS)
1727 clrf xC+2
1728 clrf xC+3
1729 movff sub_c+0,xC+0
1730 movff sub_c+1,xC+1 ; copy for comptibility
1731 bra check_ppO2_check
1732
1733 check_ppO2_non_pscr:
1680 SAFE_2BYTE_COPY amb_pressure, xA 1734 SAFE_2BYTE_COPY amb_pressure, xA
1681 movlw d'10' 1735 movlw d'10'
1682 movwf xB+0 1736 movwf xB+0
1683 clrf xB+1 1737 clrf xB+1
1684 call div16x16 ; xC=p_amb/10 1738 call div16x16 ; xC=p_amb/10
1685 1739
1686 movff xC+0,xA+0 1740 movff xC+0,xA+0
1687 movff xC+1,xA+1 1741 movff xC+1,xA+1
1688 movff char_I_O2_ratio,xB+0 ; =O2 ratio 1742 movff char_I_O2_ratio,xB+0 ; =O2 ratio
1689 clrf xB+1 1743 clrf xB+1
1690 call mult16x16 ; char_I_O2_ratio * p_amb/10 1744 call mult16x16 ; char_I_O2_ratio * p_amb/10
1691 1745
1746 check_ppO2_check:
1692 ; Check very high ppO2 manually 1747 ; Check very high ppO2 manually
1693 tstfsz xC+2 ; char_I_O2_ratio * p_amb/10 > 65536, ppO2>6,55bar? 1748 tstfsz xC+2 ; char_I_O2_ratio * p_amb/10 > 65536, ppO2>6,55bar?
1694 bra check_ppO2_1 ; Yes, display Value! 1749 bra check_ppO2_1 ; Yes, display Value!
1695 ; Check if ppO2>3,30bar 1750 ; Check if ppO2>3,30bar
1696 btfsc xC+1,7 1751 btfsc xC+1,7