annotate src/rx_ops.asm @ 632:0347acdf6d8e

changelog updates
author heinrichsweikamp
date Sat, 29 Feb 2020 16:57:45 +0100
parents 185ba2f91f59
children 4050675965ea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
1 ;=============================================================================
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
2 ;
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
3 ; File rx_ops.asm combined next generation V3.03.8
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
4 ;
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
5 ; RX (Tank Pressure Transmitter) Routines.
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
6 ;
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
7 ; Copyright (c) 2018, heinrichs weikamp, all right reserved.
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
8 ;=============================================================================
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
9
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
10 #include "hwos.inc" ; mandatory header
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
11 #include "shared_definitions.h" ; mailbox to p2_deco.c
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
12 #include "i2c.inc"
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
13 #include "math.inc"
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
14 #include "wait.inc"
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
15
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
16 ;=============================================================================
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
17
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
18 IFDEF _rx_functions
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
19
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
20
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
21 extern get_first_gas_to_WREG
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
22 extern I2C_probe_OSTC_rx
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
23
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
24 IFDEF _rx_update
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
25 extern I2C_update_OSTC_rx
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
26 extern rx_firmware_storage
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
27 ENDIF
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
28
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
29 IFDEF _ccr_pscr
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
30 extern get_first_dil_to_WREG
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
31 ENDIF
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
32
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
33
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
34 ; SAC calculation averaging settings
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
35 #DEFINE time_accu_target_OC .60 ; [s] target time accumulator filling level in OC modes
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
36 #DEFINE time_accu_target_CCR .180; [s] target time accumulator filling level in CCR mode
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
37
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
38
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
39 rx_ops CODE
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
40
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
41 ;=============================================================================
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
42
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
43
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
44 ;-----------------------------------------------------------------------------
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
45 ; Get configured pressure readings
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
46 ;
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
47 ; input : opt_TR_1st_pres - selector for first pressure reading, in normal mode
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
48 ; opt_TR_Bail_pres - selector for first pressure reading, in bailout mode
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
49 ; opt_TR_2nd_pres - selector for second pressure reading, all modes
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
50 ;
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
51 ; output: int_IO_pressure_value+0/+2 - pressure in 0.1 bar, low byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
52 ; int_IO_pressure_value+1/+3 - pressure in 0.1 bar, high byte, including data not available flag
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
53 ; char_I_pressure_gas +0/+1 - associated gas (1-5) / diluent (6-10)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
54 ; char_I_pressure_age +0/+1 - age of data in seconds (max 60)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
55 ; char_I_pressure_stat +0/+1 - status data
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
56 ;
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
57 global get_pressure_readings
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
58 get_pressure_readings:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
59 call I2C_get_tankdata ; get raw pressure data
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
60 get_pressure_readings_1:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
61 movff opt_TR_1st_pres,ul ; 1st pressure to read
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
62 btfsc bailout_mode ; in bailout mode?
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
63 movff opt_TR_Bail_pres,ul ; YES - replace with assigned bailout selection
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
64 tstfsz ul ; disabled?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
65 bra get_pressure_readings_1a ; NO - get received pressure data
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
66 rcall get_pressure_readings_H1 ; YES - set pressure data to not available
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
67 bra get_pressure_readings_1c ; - continue with copying to result vars
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
68 get_pressure_readings_1a:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
69 IFDEF _ccr_pscr
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
70 movlw .11 ; first code for "special" pressures
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
71 cpfslt ul ; opt_TR_1st_pres < 11 ?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
72 rcall get_pressure_readings_H2 ; NO - pre-process measurement selection
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
73 ENDIF
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
74 rcall get_pressure_readings_H3 ; get transmitter ID
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
75 rcall get_pres_by_transmitter_id ; get data from transmitter with ID in hi:lo into hi:lo (pressure) and up (status)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
76 get_pressure_readings_1c:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
77 movff lo,int_IO_pressure_value+0 ; copy pressure, low byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
78 movff hi,int_IO_pressure_value+1 ; copy pressure, high byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
79 movff ul,char_I_pressure_gas+0 ; copy associated gas number
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
80 movff up,char_I_pressure_age+0 ; copy age of data
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
81 movff ex,char_I_pressure_stat+0 ; copy status data
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
82 get_pressure_readings_2:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
83 movff opt_TR_2nd_pres,ul ; 2nd pressure to read
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
84 tstfsz ul ; disabled?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
85 bra get_pressure_readings_2a ; NO - get received pressure data
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
86 rcall get_pressure_readings_H1 ; YES - set pressure data to not available
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
87 bra get_pressure_readings_2c ; - continue with copying to result vars
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
88 get_pressure_readings_2a:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
89 IFDEF _ccr_pscr
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
90 movlw .11 ; first code for "special" pressures
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
91 cpfslt ul ; opt_TR_2nd_pres < 11 ?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
92 rcall get_pressure_readings_H2 ; NO - pre-process measurement selection
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
93 ENDIF
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
94 btfss ul,7 ; gas selector >= 127 (special treatment)?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
95 bra get_pressure_readings_2b ; NO - proceed reading a pressure
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
96 rcall get_pressure_readings_H1 ; YES - set pressure data to not available
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
97 bra get_pressure_readings_2c ; - continue wit copying to output data
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
98 get_pressure_readings_2b:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
99 rcall get_pressure_readings_H3 ; get transmitter ID
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
100 rcall get_pres_by_transmitter_id ; get data from transmitter with ID in hi:lo into hi:lo (pressure) and up (status)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
101 get_pressure_readings_2c:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
102 movff lo,int_IO_pressure_value+2 ; copy pressure, low byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
103 movff hi,int_IO_pressure_value+3 ; copy pressure, high byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
104 movff ul,char_I_pressure_gas+1 ; copy associated gas number
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
105 movff up,char_I_pressure_age+1 ; copy age of data
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
106 movff ex,char_I_pressure_stat+1 ; copy status data
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
107 return
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
108
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
109 get_pressure_readings_H1:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
110 clrf lo ; set pressure to 0 (low byte)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
111 clrf hi ; set pressure to 0 (high byte)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
112 clrf up ; set age to 0
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
113 clrf ex ; set status to 0
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
114 bsf hi,int_not_avail_flag ; set flag for data not available
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
115 return
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
116
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
117
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
118 IFDEF _ccr_pscr
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
119 get_pressure_readings_H2:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
120 movlw .11
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
121 subwf ul,F
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
122 bnz get_pressure_readings_H2a
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
123 call get_first_gas_to_WREG ; ul = 11 -> ul = (get_first_gas_to_WREG)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
124 movwf ul
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
125 return
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
126 get_pressure_readings_H2a:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
127 decfsz ul,F
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
128 bra get_pressure_readings_H2b
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
129 movff active_gas,ul ; ul = 12 -> ul = active_gas
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
130 return
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
131 get_pressure_readings_H2b:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
132 decfsz ul,F
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
133 bra get_pressure_readings_H2c
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
134 call get_first_dil_to_WREG ; ul = 13 -> ul = (get_first_dil_to_WREG) + 5
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
135 movwf ul
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
136 movlw .5
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
137 addwf ul,F
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
138 return
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
139 get_pressure_readings_H2c:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
140 decfsz ul,F
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
141 bra get_pressure_readings_H2d
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
142 movff active_dil,ul ; ul = 14 -> ul = active_dil + 5
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
143 movlw .5
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
144 addwf ul,F
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
145 return
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
146 get_pressure_readings_H2d:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
147 movlw .1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
148 movwf ul ; ul >= 15 -> should not happen, default to ul = 1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
149 return
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
150 ENDIF ; _ccr_pscr
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
151
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
152
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
153 get_pressure_readings_H3:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
154 lfsr FSR1,opt_transmitter_id_1 ; load base address of transmitter ID array
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
155 decf ul,W ; (1-10) -> (0-9)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
156 mullw .2 ; IDs are 2 byte in size
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
157 movf PRODL,W ; WREG is index now
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
158 movff PLUSW1,lo ; get transmitter ID (low byte)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
159 incf WREG,W ; increment index
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
160 movff PLUSW1,hi ; get transmitter ID (high byte)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
161 return
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
162
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
163
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
164 ;-----------------------------------------------------------------------------
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
165 ; Get data from transmitter with ID in (hi:lo)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
166 ;
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
167 ; input: hi:lo = transmitter ID
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
168 ;
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
169 ; output: hi:lo = pressure in 0.1 bar if return code = 0, else 0 + int_not_avail_flag
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
170 ; up = packet age if return code = 0, else 0
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
171 ; ex = status data if return code = 0, else 0
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
172 ;
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
173 ; return code: 0 transmitter found
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
174 ; 254 illegal transmitter ID
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
175 ; 255 transmitter not found
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
176 ;
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
177 ; RX slot data: Byte 0 : transmitter ID high byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
178 ; 1 : transmitter ID low byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
179 ; 2 (-> hi) : pressure in 0.1 bar, high byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
180 ; 3 (-> lo) : pressure in 0.1 bar, low byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
181 ; 4 (-> ex) : status data:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
182 ; bit 2..0: battery status
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
183 ; 5..3: sequence counter
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
184 ; 6: =1 if pressure changed (usage in RX slot data)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
185 ; =1 if transmitter not found (usage in output data)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
186 ; 7: =1 if pressure sensed (usage in RX slot data)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
187 ; =1 if low battery (< 3.0V) (usage in output data)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
188 ; 5 (-> up) : age of data in seconds, 0 if slot is unused
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
189 ;
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
190 global get_pres_by_transmitter_id
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
191 get_pres_by_transmitter_id:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
192 ; hi:lo zero?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
193 tstfsz hi ; hi <> zero ?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
194 bra output_pressure_1 ; YES - search transmitter
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
195 tstfsz lo ; lo <> zero ?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
196 bra output_pressure_1 ; YES - search transmitter
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
197 movlw .254 ; NO to both - set return code for invalid transmitter ID
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
198 bra output_pressure_6 ; - clear result vars, set data as not available and return
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
199 output_pressure_1:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
200 lfsr FSR1,rx_buffer ; load base address of RX buffer
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
201 movlw .8 ; 8 RX slots to look at
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
202 movwf up ; up will be the loop counter
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
203 output_pressure_2:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
204 movf POSTINC1,W ; get high byte of received transmitter ID
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
205 cpfseq hi ; match?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
206 bra output_pressure_3 ; NO - check next slot
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
207 movf POSTINC1,W ; get low byte byte received transmitter ID
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
208 cpfseq lo ; match?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
209 bra output_pressure_4 ; NO - check next slot
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
210 ; transmitter found, gather data ; YES - transmitter found, copy:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
211 movff POSTINC1,hi ; - pressure high byte,
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
212 movff POSTINC1,lo ; - pressure low byte,
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
213 movff POSTINC1,ex ; - status byte, and
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
214 movff POSTINC1,up ; - packet age.
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
215 movlw rx_packet_overdue_timeout ; - load overdue time
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
216 subwf up,W ; - subtract overdue time from packet age
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
217 btfss STATUS,N ; - result negative (packet younger than overdue time)?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
218 bsf hi,int_outdated_flag ; NO - set outdated flag
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
219 bcf ex,char_transmitter_lost ; - clear transmitter lost flag
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
220 bsf ex,char_transmitter_low_bat ; - set low battery warning by default
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
221 btfsc ex,1 ; - bit 1 of battery voltage set?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
222 bcf ex,char_transmitter_low_bat ; - YES - revoke low battery warning
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
223 btfsc ex,2 ; - bit 2 of battery voltage set?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
224 bcf ex,char_transmitter_low_bat ; - YES - revoke low battery warning
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
225 ;bsf ex,char_transmitter_low_bat ; DEBUG CODE TO FAKE A LOW BAT WARNING
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
226 retlw .0 ; - return with success code 0
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
227 output_pressure_3:
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
228 movf POSTINC1,W ; dummy read to advance FSR1 to byte 2 position
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
229 output_pressure_4:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
230 dcfsnz up,F ; decrement loop counter, last slot searched?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
231 bra output_pressure_5 ; YES - return with error code
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 628
diff changeset
232 movf POSTINC1,W ; NO - dummy reads to advance FSR1 to byte 3 (any other code would not be more compact...)
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
233 movf POSTINC1,W ; - ... byte 4
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
234 movf POSTINC1,W ; - ... byte 5
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
235 movf POSTINC1,W ; - ... byte 6 = first byte of next slot
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
236 bra output_pressure_2 ; - loop
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
237 output_pressure_5:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
238 movlw .255 ; return code for transmitter not found
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
239 clrf ex ; clear ex (status data)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
240 bsf ex,char_transmitter_lost ; set transmitter status to lost
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
241 bra output_pressure_7
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
242 output_pressure_6:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
243 clrf ex ; clear ex (status data)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
244 output_pressure_7:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
245 clrf lo ; clear lo (pressure, low byte)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
246 clrf hi ; clear hi (pressure, high byte)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
247 clrf up ; clear up (age of data)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
248 bsf hi,int_not_avail_flag ; set flag for data not available
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
249 return ; done
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
250
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
251
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
252 ;-----------------------------------------------------------------------------
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
253 ; Get transmitter ID in given slot
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
254 ;
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
255 ; input : WREG = slot (0-7)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
256 ; output : hi:lo = transmitter ID
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
257 ;
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
258 global get_transmitter_id_by_slot
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
259 get_transmitter_id_by_slot:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
260 lfsr FSR1,rx_buffer ; load base address of RX buffer
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
261 mullw .6 ; multiply WREG with 6 because each slot is 6 bytes in size
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
262 movf PRODL,W ; get result into WREG to be used as index (product is 42 at max)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
263 movff PLUSW1,hi ; read transmitter ID high byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
264 incf WREG,W ; increment index
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
265 movff PLUSW1,lo ; read transmitter ID low byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
266 return
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
267
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
268
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
269 ;-----------------------------------------------------------------------------
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
270 ; Compute average pressure drop from 1st / 2nd reading
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
271 ;
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
272 ; Memory Map:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
273 ; ------------------------------------------------------------------------------------
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
274 ;
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
275 ; pres_accu_1st res 4 ; accumulator for pressure drop in 1/(160 * 2^16) bar
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
276 ; pres_accu_2nd res 4 ; accumulator for pressure drop in 1/(160 * 2^16) bar
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
277 ; time_accu_1st res 2 ; accumulator for reading periods in seconds
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
278 ; gas__last_1st res 1 ; last gas assignment
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
279 ; time_accu_2nd res 2 ; accumulator for reading periods in seconds
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
280 ; gas__last_2nd res 1 ; last gas assignment
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
281 ; pres_last_1st res 2 ; last pressure reading pressure in 1/160 bar
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
282 ; pres_last_2nd res 2 ; last pressure reading pressure in 1/160 bar
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
283 ; time_last_1st res 2 ; last pressure reading time in seconds
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
284 ; time_last_2nd res 2 ; last pressure reading time in seconds
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
285 ;
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
286 ; int_IO_pressure_value [1] res 2 ; current pressure reading in 1/10 bar
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
287 ; int_IO_pressure_value [2] res 2 ; current pressure reading in 1/10 bar
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
288 ; int_I_pressure_drop [1] res 2 ; calculated average pressure drop in 1/5120 bar/sec
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
289 ; int_I_pressure_drop [2] res 2 ; calculated average pressure drop in 1/5120 bar/sec
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
290
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
291 ; relative positioning of 16 bit ASM variables
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
292 #DEFINE offset_FSR1_time_accu .0 ; offset 0 == base address of 1st/2nd
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
293 #DEFINE offset_FSR1_gas__last .2 ; offset 1 to base address of 1st/2nd
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
294 #DEFINE offset_FSR1_pres_last .6 ; offset 6 ...
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
295 #DEFINE offset_FSR1_time_last .10 ; offset 10 ...
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
296
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
297 ; relative positioning of shared integer variables
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
298 #DEFINE offset_FSR2_press_curr .0 ; offset 0 == base address of 1st/2nd
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
299 #DEFINE offset_FSR2_press_drop .4 ; offset 4 to base address of 1st/2nd
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
300
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
301
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
302 calc_pres_drop_1st:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
303 ; set up base addresses
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
304 lfsr FSR0,pres_accu_1st ; load base address of pressure accumulator
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
305 lfsr FSR1,time_accu_1st ; load base address of other ASM variables
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
306 lfsr FSR2,int_IO_pressure_value+0; load base address of the shared variables
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
307
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
308 ; get the currently assigned gas into lo
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
309 movff char_I_pressure_gas+0,lo
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
310
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
311 ; get the age of the current reading into hi
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
312 movff char_I_pressure_age+0,hi
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
313
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
314 ; continue with common part
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
315 bra calc_pres_drop_common
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
316
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
317 calc_pres_drop_2nd:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
318 ; set up base addresses
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
319 lfsr FSR0,pres_accu_2nd-1 ; load base address - 1 of pressure accumulator
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
320 lfsr FSR1,time_accu_2nd ; load base address of other ASM variables
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
321 lfsr FSR2,int_IO_pressure_value+2; load base address of the shared variables
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
322
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
323 ; get the currently assigned gas into lo
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
324 movff char_I_pressure_gas+1,lo
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
325
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
326 ; get the age of the current reading into hi
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
327 movff char_I_pressure_age+1,hi
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
328
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
329 calc_pres_drop_common:
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
330 ; load the pressure accumulator into xC - after copying, FSR0 stays on highest byte
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
331 movff POSTINC0,xC+0 ; copy pressure accumulator to xC, lowest byte
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
332 movff POSTINC0,xC+1 ; copy pressure accumulator to xC, second byte
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
333 movff POSTINC0,xC+2 ; copy pressure accumulator to xC, third byte
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
334 movff INDF0, xC+3 ; copy pressure accumulator to xC, highest byte
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
335
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
336 ; check if the assigned gas has changed
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
337 movlw offset_FSR1_gas__last ; load index of last assigned gas
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
338 movf PLUSW1,W ; copy last gas to WREG
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
339 cpfseq lo ; is current gas = last gas ?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
340 bra calc_pres_drop_reset ; NO - reset everything
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
341
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
342 ; check if the pressure reading is activated at all
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
343 tstfsz lo ; is there no gas (0=off) assigned to the reading?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
344 bra calc_pres_drop_common_1 ; NO - continue
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
345 bra calc_pres_drop_reset ; YES - reset everything
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
346
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
347 calc_pres_drop_common_1:
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
348 ; load the time accumulator into xB - after copying, FSR1 will have been restored to initial address
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
349 movff POSTINC1,xB+0 ; load time accumulator, low byte
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
350 movff POSTDEC1,xB+1 ; load time accumulator, high byte
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
351
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
352 ; get the current pressure value into divA - after copying, FSR2 will have been restored to initial address
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
353 movff POSTINC2,divA+0 ; copy current pressure value to divA, low byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
354 movff POSTDEC2,divA+1 ; copy current pressure value to divA, high byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
355
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
356 ; check if the current pressure value is available and not outdated
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
357 bsf aux_flag ; set the current pressure value as not available or outdated by default
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
358 btfsc divA+1,int_not_avail_flag ; current pressure value not available?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
359 bra calc_pres_drop_common_2 ; YES - skip updating the accumulators with new data
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
360 btfsc divA+1,int_outdated_flag ; current pressure outdated?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
361 bra calc_pres_drop_common_2 ; YES - skip updating the accumulators with new data
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
362 bcf aux_flag ; NO to both - set current pressure value as available and up-to-date
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
363
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
364 ; check if a new reading has been received
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
365 movlw .2 ; capture new reading at an age of 2 (age 1 sometimes slips through...)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
366 subwf hi,W ; subtract capture-age from reading age, dump result to WREG
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
367 bnz calc_pres_drop_common_2 ; result <> 0 ? YES - skip updating the accumulators
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
368
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
369 ; multiply the current pressure with 16 (pre-scaling), this will also remove the flags
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
370 movlw .4 ; multiply with 16 = 2^4
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
371 call mult16 ; divA = divA * 2^WREG
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
372
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
373 ; get the last pressure value and store the current pressure as the new last pressure value
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
374 movlw offset_FSR1_pres_last+0 ; load index of last pressure value, low byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
375 movff PLUSW1,sub_b+0 ; copy last pressure value to sub_b, low byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
376 movff divA+0,PLUSW1 ; store current pressure value as new last pressure value, low byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
377 movlw offset_FSR1_pres_last+1 ; load index of last pressure value, high byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
378 movff PLUSW1,sub_b+1 ; copy last pressure value to sub_b, high byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
379 movff divA+1,PLUSW1 ; store current pressure value as new last pressure value, high byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
380
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
381 ; add the last pressure value to the pressure accumulator: pres_accu (xC) += pres_last (sub_b) * 2^16
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
382 movf sub_b+0,W ; copy pres_last (sub_b) to WREG, low byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
383 addwf xC+2,F ; add to pres_accu (xC), third byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
384 movf sub_b+1,W ; copy pres_last (sub_b) to WREG, high byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
385 addwfc xC+3,F ; add to pres_accu (xC), highest byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
386
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
387 ; subtract the current pressure from the pressure accumulator: pres_accu (xC) -= pres_curr (divA) * 2^16
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
388 ; -> effectively, the pressure drop during the last measurement period has been added now
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
389 bcf neg_flag ; clear neg_flag by default
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
390 movf divA+0,W ; copy pres_curr (divA) to WREG, low byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
391 subwf xC+2,F ; subtract from pres_accu (xC), third byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
392 movf divA+1,W ; copy pres_curr (divA) to WREG, high byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
393 subwfb xC+3,F ; subtract from pres_accu (xC), highest byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
394 btfss STATUS,C ; did the accumulator under-run (result negative)?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
395 bsf neg_flag ; YES - memorize this
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
396
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
397 ; get the current time into the multi-purpose register
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
398 SMOVII total_divetime_secs,mpr ; ISR-safe 2 byte copy of current total dive time into hi:lo
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
399
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
400 ; get the last pressure time and store the current time as the new last pressure time
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
401 movlw offset_FSR1_time_last+0 ; load index of last pressure time, low byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
402 movff PLUSW1,sub_b+0 ; copy last pressure time to sub_b, low byte
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
403 movff lo,PLUSW1 ; store current time as new last pressure time, low byte
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
404 movlw offset_FSR1_time_last+1 ; load index of last pressure time, high byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
405 movff PLUSW1,sub_b+1 ; copy last pressure time to sub_b, high byte
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
406 movff hi,PLUSW1 ; store current time as new last pressure time, high byte
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
407
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
408 ; did the pressure accumulator under-run before because the current pressure is higher than the accumulator value was?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
409 ; we can not check & abort earlier because the current time needs to be stored along with the current pressure
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
410 btfsc neg_flag ; did the pressure accumulator under-run?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
411 bra calc_pres_drop_restart ; YES - reset both accumulators and set average pressure drop to not available
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
412
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
413 ; add the current time to the time accumulator: time_accu (xB) += time_curr (mpr)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
414 movf lo,W ; copy time_curr (mpr) to WREG, low byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
415 addwf xB+0,F ; add to time_accu (xB), low byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
416 movf hi,W ; copy time_curr (mpr) to WREG, high byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
417 addwfc xB+1,F ; add to time_accu (xB), high_byte
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
418 btfsc STATUS,C ; did the accumulator over-run ?
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
419 bra calc_pres_drop_restart ; YES - reset both accumulators and set average pressure drop to not available
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
420
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
421 ; subtract the last pressure time from time accumulator: time_accu (xB) -= time_last (sub_b)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
422 movf sub_b+0,W ; copy time_last (sub_b) to WREG, low byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
423 subwf xB+0,F ; subtract from time_accu (xB), low byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
424 movf sub_b+1,W ; copy time_last (sub_b) to WREG, high byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
425 subwfb xB+1,F ; subtract from time_accu (xB), high byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
426 btfss STATUS,C ; did the accumulator under-run (result negative) because of a wrap-around of the current time?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
427 bra calc_pres_drop_restart ; YES - reset both accumulators and set average pressure drop to not available
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
428
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
429 calc_pres_drop_common_2:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
430 ; check if the time accumulator is or has become zero to avoid a div/0
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
431 ; as long as no valid pressure value is available, the time accumulator will stay at 0 and the pressure drop calculation kept in reset
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
432 movf xB+0,W ; copy time accumulator low byte to WREG
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
433 iorwf xB+1,W ; inclusive-or time accumulator high byte into WREG, is result = zero ?
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
434 bz calc_pres_drop_restart ; YES - reset both accumulators and set average pressure drop to not available
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
435
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
436 ; duplicate pressure and time accumulators to other variables because xC and xB will get destroyed in div32x16 operation
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
437 movff xC+0,mpr+0 ; duplicate pres_accu to mpr, lowest byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
438 movff xC+1,mpr+1 ; duplicate pres_accu to mpr, second byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
439 movff xC+2,mpr+3 ; duplicate pres_accu to mpr, third byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
440 movff xC+3,mpr+4 ; duplicate pres_accu to mpr, highest byte
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
441 movff xB+0,divA+0 ; duplicate time_accu to divA, low byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
442 movff xB+1,divA+1 ; duplicate time_accu to divA, high byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
443
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
444 ; calculate average pressure drop: pres_drop (xC) = pres_accu (xC) / time_accu (xB)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
445 call div32x16 ; xC = xC / xB, xC is average pressure drop in 1/(160 * 2^16) bar/sec
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
446
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
447 ; is the time accumulator above target level? (only the low byte needs to be evaluated)?
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
448 tstfsz divA+1 ; is the time accumulator > 255 seconds?
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
449 bra calc_pres_drop_common_2a ; YES - do an accumulator reduction
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
450 incf ul,W ; NO - load the target threshold, +1 (incf) transforms cpfslt from < to <= operation
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
451 cpfslt divA+0 ; - is the time accumulator > target threshold ?
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
452 calc_pres_drop_common_2a:
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
453 rcall calc_pres_drop_reduce_accus ; YES - do an accumulator reduction
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
454
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
455 ; do an additional half-rate (every 2nd second) accumulator reduction
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
456 btfsc timebase_1sec ; are we on an even second?
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
457 rcall calc_pres_drop_reduce_accus ; YES - do an additional accumulator reduction
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
458
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
459 ; store pressure accumulator (mpr:4) - FSR0 was left pointing to address of highest byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
460 movff mpr+3,POSTDEC0 ; store pressure accumulator, highest byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
461 movff mpr+2,POSTDEC0 ; store pressure accumulator, third byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
462 movff mpr+1,POSTDEC0 ; store pressure accumulator, second byte
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
463 movff mpr+0,INDF0 ; store pressure accumulator, lowest byte
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
464
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
465 ; store the time accumulator - after copying, FSR1 will have been restored to initial address
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
466 movff divA+0,POSTINC1 ; store time accumulator, low byte
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
467 movff divA+1,POSTDEC1 ; store time accumulator, high byte
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
468
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
469 ; check if the average pressure drop for transfer to p2deco needs to be limited
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
470 tstfsz xC+3 ; check if the highest byte is all zero
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
471 bra calc_pres_drop_limit ; NO - limit output
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
472 btfsc xC+2,7 ; check if the highest bit of the third byte is zero
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
473 bra calc_pres_drop_limit ; NO - limit output
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
474
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
475 ; pick and adjust the bytes from pres_drop for transfer to p2deco
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
476 movff xC+1,divA+0 ; pick second byte of average pressure drop for transfer to p2deco as low byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
477 movff xC+2,divA+1 ; pick third byte of average pressure drop for transfer to p2deco as high byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
478 movlw .3 ; divide by 8 = 2^3
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
479 call div16 ; divA = divA / 2^WREG
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
480 bra calc_pres_drop_common_3
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
481
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
482 calc_pres_drop_limit:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
483 ; limit output to 0x0FFF
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
484 MOVLI 0x0FFF,divA ; set output to 0x0FFF
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
485 bsf divA+1,int_warning_flag ; set warning flag indicating out-of-range
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
486
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
487 calc_pres_drop_common_3:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
488 ; set the average pressure drop as not available if the last pressure reading is outdated or not available
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
489 btfsc aux_flag ; is the last pressure reading outdated or not available?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
490 bsf divA+1,int_not_avail_flag ; YES - set pressure drop to not available, too
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
491
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
492 ; set the average pressure drop as outdated if time_accu (divA) < (target threshold / 2)
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
493 movlw offset_FSR1_time_accu+1 ; address high byte of time accumulator
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
494 tstfsz PLUSW1 ; time accumulator > 255 ?
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
495 bra calc_pres_drop_common_3a ; YES - can not be outdated then
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
496 rrncf ul,W ; NO - load time accumulator target value / 2 into WREG
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
497 decf WREG,W ; subtract 1 to transform cpfsgt from > into >= operation
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
498 cpfsgt INDF1 ; time accumulator < (target threshold / 2) ?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
499 bsf divA+1,int_outdated_flag ; YES - set outdated flag
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
500
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
501 calc_pres_drop_common_3a:
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
502 ; write average pressure drop to p2deco interface
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
503 movlw offset_FSR2_press_drop+0 ; load index of average pressure drop, low byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
504 movff divA+0,PLUSW2 ; store average pressure drop, low byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
505 movlw offset_FSR2_press_drop+1 ; load index of average pressure drop, high byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
506 movff divA+1,PLUSW2 ; store average pressure drop, high byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
507
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
508 ; done
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
509 return
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
510
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
511
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
512 calc_pres_drop_reduce_accus:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
513 ; subtract 1 second from the time accumulator: time_accu (divA) -= 1 (only the low byte needs to be processed)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
514 decf divA+0,F ; decrement low byte of time_accu
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
515
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
516 ; subtract average pressure drop per second from pressure accumulator: press_accu (mpr) -= press_drop (xC)
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
517 movf xC+0,W ; copy press_drop(xC) to WREG, lowest byte
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
518 subwf mpr+0,F ; subtract from pres_accu, lowest byte
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
519 movf xC+1,W ; copy press_drop(xC) to WREG, second byte
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
520 subwfb mpr+1,F ; subtract from pres_accu, second byte
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
521 movf xC+2,W ; copy press_drop(xC) to WREG, third byte
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
522 subwfb mpr+2,F ; subtract from pres_accu, third byte
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
523 movf xC+3,W ; copy press_drop(xC) to WREG, highest byte
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
524 subwfb mpr+3,F ; subtract from pres_accu, highest byte
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
525 btfsc STATUS,C ; did the buffer under-run (result negative)?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
526 return ; NO - done
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
527 clrf mpr+0 ; YES - clear pressure accumulator, lowest byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
528 clrf mpr+1 ; - clear pressure accumulator, second byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
529 clrf mpr+2 ; - clear pressure accumulator, third byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
530 clrf mpr+3 ; - clear pressure accumulator, highest byte
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
531 return ; - done
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
532
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
533 calc_pres_drop_reset:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
534 ; store the current gas as the last gas
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
535 movlw offset_FSR1_gas__last ; load index of last gas
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
536 movff lo,PLUSW1 ; store current gas as new last gas
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
537
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
538 ; clear last pressure value
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
539 movlw offset_FSR1_pres_last+0 ; load index of last pressure value, low byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
540 clrf PLUSW1 ; clear last pressure value, low byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
541 movlw offset_FSR1_pres_last+1 ; load index of last pressure value, high byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
542 clrf PLUSW1 ; clear last pressure value, high byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
543
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
544 ; clear last pressure time
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
545 movlw offset_FSR1_time_last+0 ; load index of last pressure time, low byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
546 clrf PLUSW1 ; clear last pressure time, low byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
547 movlw offset_FSR1_time_last+1 ; load index of last pressure time, high byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
548 clrf PLUSW1 ; clear last pressure time, high byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
549
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
550 calc_pres_drop_restart:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
551 ; clear pressure accumulator - FSR0 was left pointing to address of highest byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
552 clrf POSTDEC0 ; clear pressure accumulator, highest byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
553 clrf POSTDEC0 ; clear pressure accumulator, third byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
554 clrf POSTDEC0 ; clear pressure accumulator, second byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
555 clrf POSTDEC0 ; clear pressure accumulator, lowest byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
556
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
557 ; clear time accumulator - after clearing, FSR1 will have been restored to initial address
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
558 clrf POSTINC1 ; clear time accumulator, low byte
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
559 clrf POSTDEC1 ; clear time accumulator, high byte
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
560
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
561 ; clear pressure drop and set it to not available
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
562 movlw offset_FSR2_press_drop+0 ; load index of average pressure drop, low byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
563 clrf PLUSW2 ; clear average pressure drop, low byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
564 movlw offset_FSR2_press_drop+1 ; load index of average pressure drop, high byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
565 clrf PLUSW2 ; clear average pressure drop, high byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
566 bsf PLUSW2,int_not_avail_flag ; set flag for data not available
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
567
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
568 return ; done
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
569
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
570
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
571 ;-----------------------------------------------------------------------------
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
572 ; set up SAC calculation dependent on TR mode
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
573 ;
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
574 global configure_sac_calculation
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
575 configure_sac_calculation:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
576 movlw time_accu_target_OC ; load time accumulator target value for OC as default
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
577 movwf ul ; store it in ul
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
578 movff opt_TR_mode,WREG ; get TR mode
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
579 dcfsnz WREG,W ; TR mode = 1 (on)?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
580 bra configure_sac_calculation_1 ; YES
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
581 dcfsnz WREG,W ; TR mode = 2 (ind.double)?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
582 bra configure_sac_calculation_2 ; YES
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
583 dcfsnz WREG,W ; TR mode = 3 (CCR Dil+O2)?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
584 bra configure_sac_calculation_3 ; YES
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
585 bra configure_sac_calculation_4 ; NO to all - was disabled then (or invalid)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
586
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
587 configure_sac_calculation_1: ; TR mode 1: calculate SAC on 1st reading
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
588 rcall calc_pres_drop_1st ; calculate pressure drop on 1st reading
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
589 movlw .1 ; select SAC mode 1: SAC on 1st reading
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
590 bra configure_sac_calculation_5 ; goto exit
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
591
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
592 configure_sac_calculation_2: ; TR mode 2: independent double
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
593 rcall calc_pres_drop_1st ; calculate pressure drop on 1st reading
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
594 rcall calc_pres_drop_2nd ; calculate pressure drop on 2nd reading
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
595 movlw .3 ; select SAC mode 3: SAC on higher of both readings
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
596 bra configure_sac_calculation_5 ; goto exit
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
597
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
598 configure_sac_calculation_3: ; TR mode 3: CCR Dil+O2
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
599 btfsc bailout_mode ; in bailout?
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
600 bra configure_sac_calculation_1 ; YES - handle alike TR mode 1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
601 movlw time_accu_target_CCR ; load time accumulator target value for CCR mode
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
602 movwf ul ; store it in ul
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
603 rcall calc_pres_drop_2nd ; calculate pressure drop on 2nd reading
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
604 movlw .4 ; select SAC mode 4: SAC on 2nd reading, O2 usage
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
605 bra configure_sac_calculation_5 ; goto exit
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
606
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
607 configure_sac_calculation_4:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
608 clrf WREG ; select SAC mode 0 (disabled)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
609
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
610 configure_sac_calculation_5:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
611 movff WREG,char_I_SAC_mode ; write SAC mode selection
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
612 return
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
613
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
614
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
615 ;-----------------------------------------------------------------------------
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
616 ; Update TR module
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
617 ;
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
618
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
619 IFDEF _rx_update
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
620
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
621 global update_tr_module
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
622 update_tr_module:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
623 movlw LOW rx_firmware_storage ; setup program memory read for embedded TR firmware
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
624 movwf TBLPTRL
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
625 movlw HIGH rx_firmware_storage
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
626 movwf TBLPTRH
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
627 movlw UPPER rx_firmware_storage
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
628 movwf TBLPTRU
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
629
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
630 bsf active_reset_ostc_rx ; apply a reset to the RX co-processor
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
631 WAITMS .200 ; wait 200 ms
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
632 bcf active_reset_ostc_rx ; release reset
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
633 WAITMS .100 ; wait 100 ms, the RX co-processor will be in bootloader stage by then
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
634
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
635 bcf INTCON,GIE ; halt all interrupts
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
636
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
637 movlw .64 ; load loop counter
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
638 movwf lo ; ...
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
639
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
640 update_tr_module_loop: ; (loop 64 times)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
641 call I2C_update_OSTC_rx ; send a batch of 64 bytes to the RX co-processor
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
642 tstfsz WREG ; WREG = 0, i.e. data sent successfully?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
643 bra update_tr_module_fail ; NO - transfer error, abort
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
644 decfsz lo,F ; YES - decrement loop counter, became zero?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
645 bra update_tr_module_loop ; NO - loop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
646 bra update_tr_module_done ; YES - transfer complete & successful
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
647
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
648 update_tr_module_fail:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
649 bsf INTCON,GIE ; re-enable interrupts
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
650 bcf ostc_rx_present ; flag TR module as unserviceable
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
651 return ; done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
652
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
653 update_tr_module_done:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
654 bsf INTCON,GIE ; re-enable interrupts
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
655
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
656 call wait_1s ; wait (up to) 1 second
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
657 call wait_1s ; wait (another full) 1 second
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
658
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
659 bsf active_reset_ostc_rx ; apply a reset to the RX co-processor
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
660 WAITMS .200 ; wait 200 ms
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
661 bcf active_reset_ostc_rx ; release reset
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
662 call wait_1s ; wait (up to) 1 second
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
663 call wait_1s ; wait (another full) 1 second
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
664 call wait_1s ; wait (another full) 1 second
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
665
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
666 call I2C_probe_OSTC_rx ; check if RX co-processor is alive, will set ostc_rx_present if so (1st try)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
667 btfsc ostc_rx_present ; RX co-processor up & running?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
668 return ; YES
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
669 call wait_1s ; NO - wait (up to) 1 second
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
670 call I2C_probe_OSTC_rx ; - give it a 2nd try
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
671 return ; - finally done (whatever result on 2nd tray)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
672
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
673 ENDIF ; _rx_update
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
674
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
675 ;=============================================================================
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
676
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
677 ENDIF ; _rx_functions
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents:
diff changeset
678
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
679 END