Mercurial > public > hwos_code
annotate src/calibrate.asm @ 563:f4faff954816
minor
author | heinrichsweikamp |
---|---|
date | Sat, 03 Feb 2018 17:02:23 +0100 |
parents | b7eb98dbd800 |
children | 54346c651b6a |
rev | line source |
---|---|
113 | 1 ;============================================================================= |
2 ; | |
560 | 3 ; File calibration.asm REFACTORED VERSION V2.91 |
113 | 4 ; |
5 ; o2 sensor calibration subroutines | |
6 ; | |
7 ; Copyright (c) 2014, Heinrichs Weikamp, all right reserved. | |
8 ;============================================================================= | |
9 | |
448 | 10 #include "hwos.inc" |
11 #include "shared_definitions.h" ; Mailbox between c and asm | |
12 #include "math.inc" | |
113 | 13 #include "adc_lightsensor.inc" |
14 #include "eeprom_rs232.inc" | |
15 | |
16 calibrate CODE | |
17 | |
560 | 18 global check_sensors ; Check O2 sensor thresholds for fallback and voting logic |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
19 check_sensors: |
560 | 20 ; Check min_mv |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
21 movff o2_mv_sensor1+0, sub_a+0 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
22 movff o2_mv_sensor1+1, sub_a+1 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
23 movlw LOW min_mv |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
24 movwf sub_b+0 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
25 movlw HIGH min_mv |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
26 movwf sub_b+1 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
27 call sub16 ; sub_c = sub_a - sub_b |
192 | 28 bsf use_O2_sensor1 ;=1: Use this sensor for deco |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
29 btfsc neg_flag |
192 | 30 bcf use_O2_sensor1 ;=1: Use this sensor for deco |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
31 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
32 movff o2_mv_sensor2+0, sub_a+0 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
33 movff o2_mv_sensor2+1, sub_a+1 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
34 movlw LOW min_mv |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
35 movwf sub_b+0 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
36 movlw HIGH min_mv |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
37 movwf sub_b+1 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
38 call sub16 ; sub_c = sub_a - sub_b |
192 | 39 bsf use_O2_sensor2 ;=1: Use this sensor for deco |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
40 btfsc neg_flag |
192 | 41 bcf use_O2_sensor2 ;=1: Use this sensor for deco |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
42 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
43 movff o2_mv_sensor3+0, sub_a+0 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
44 movff o2_mv_sensor3+1, sub_a+1 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
45 movlw LOW min_mv |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
46 movwf sub_b+0 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
47 movlw HIGH min_mv |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
48 movwf sub_b+1 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
49 call sub16 ; sub_c = sub_a - sub_b |
192 | 50 bsf use_O2_sensor3 ;=1: Use this sensor for deco |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
51 btfsc neg_flag |
192 | 52 bcf use_O2_sensor3 ;=1: Use this sensor for deco |
560 | 53 |
54 ; Check max_mv | |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
55 movff o2_mv_sensor1+0, sub_a+0 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
56 movff o2_mv_sensor1+1, sub_a+1 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
57 movlw LOW max_mv |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
58 movwf sub_b+0 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
59 movlw HIGH max_mv |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
60 movwf sub_b+1 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
61 call sub16 ; sub_c = sub_a - sub_b |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
62 btfss neg_flag |
192 | 63 bcf use_O2_sensor1 ;=1: Use this sensor for deco |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
64 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
65 movff o2_mv_sensor2+0, sub_a+0 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
66 movff o2_mv_sensor2+1, sub_a+1 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
67 movlw LOW max_mv |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
68 movwf sub_b+0 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
69 movlw HIGH max_mv |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
70 movwf sub_b+1 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
71 call sub16 ; sub_c = sub_a - sub_b |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
72 btfss neg_flag |
192 | 73 bcf use_O2_sensor2 ;=1: Use this sensor for deco |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
74 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
75 movff o2_mv_sensor3+0, sub_a+0 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
76 movff o2_mv_sensor3+1, sub_a+1 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
77 movlw LOW max_mv |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
78 movwf sub_b+0 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
79 movlw HIGH max_mv |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
80 movwf sub_b+1 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
81 call sub16 ; sub_c = sub_a - sub_b |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
82 btfss neg_flag |
192 | 83 bcf use_O2_sensor3 ;=1: Use this sensor for deco |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
84 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
85 btfss hud_connection_ok ;=1: HUD connection ok |
189
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
86 bra check_sensor2 ; No HUD/Digital data |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
87 |
147 | 88 ; Copy disable flags from digital input |
227
03946aa48fa5
NEW: Support for hwHUD without the LED module
heinrichsweikamp
parents:
224
diff
changeset
|
89 btfss sensor1_active |
03946aa48fa5
NEW: Support for hwHUD without the LED module
heinrichsweikamp
parents:
224
diff
changeset
|
90 bcf use_O2_sensor1 |
03946aa48fa5
NEW: Support for hwHUD without the LED module
heinrichsweikamp
parents:
224
diff
changeset
|
91 btfss sensor2_active |
03946aa48fa5
NEW: Support for hwHUD without the LED module
heinrichsweikamp
parents:
224
diff
changeset
|
92 bcf use_O2_sensor2 |
03946aa48fa5
NEW: Support for hwHUD without the LED module
heinrichsweikamp
parents:
224
diff
changeset
|
93 btfss sensor3_active |
03946aa48fa5
NEW: Support for hwHUD without the LED module
heinrichsweikamp
parents:
224
diff
changeset
|
94 bcf use_O2_sensor3 |
192 | 95 bra check_sensor3 ; Check for voting logic |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
96 |
189
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
97 check_sensor2: |
560 | 98 ; Copy disable flags from internal calibration routine |
189
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
99 btfss sensor1_calibrated_ok |
192 | 100 bcf use_O2_sensor1 |
189
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
101 btfss sensor2_calibrated_ok |
192 | 102 bcf use_O2_sensor2 |
189
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
103 btfss sensor3_calibrated_ok |
192 | 104 bcf use_O2_sensor3 |
105 check_sensor3: ; Check for voting logic | |
560 | 106 ; DELETE - voting is done in calc_deko_divemode_sensor ## voting logic |
107 ; bsf voting_logic_sensor1 | |
108 ; movff o2_ppo2_sensor1,temp1 | |
109 ; rcall check_sensor_voting_common | |
110 ; incfsz WREG ; Was Wreg=255? | |
111 ; bcf voting_logic_sensor1 ; Yes, ignore this sensor | |
112 ; bsf voting_logic_sensor2 | |
113 ; movff o2_ppo2_sensor2,temp1 | |
114 ; rcall check_sensor_voting_common | |
115 ; incfsz WREG ; Was Wreg=255? | |
116 ; bcf voting_logic_sensor2 ; Yes, ignore this sensor | |
117 ; bsf voting_logic_sensor3 | |
118 ; movff o2_ppo2_sensor3,temp1 | |
119 ; ;rcall check_sensor_voting_common | |
120 ; incfsz WREG ; Was Wreg=255? | |
121 ; bcf voting_logic_sensor3 ; Yes, ignore this sensor | |
189
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
122 return |
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
123 |
560 | 124 ; DELETE COMPLETE FUNTION, PARTS OF THE CODE HAVE MIGRATED TO calc_deko_divemode_sensor ## voting logic |
125 ; check_sensor_voting_common: | |
126 ; movf temp1,W | |
127 ; cpfsgt sensor_setpoint | |
128 ; bra check_sensor_voting_common2 ; temp1<sensor_setpoint | |
129 ; ; temp1>sensor_setpoint | |
130 ; movf temp1,W | |
131 ; subwf sensor_setpoint,W | |
132 ; movwf temp1 | |
133 ; check_sensor_voting_common1: | |
134 ; movlw sensor_voting_logic_threshold ; Threshold in 0.01bar | |
135 ; cpfsgt temp1 | |
136 ; retlw .255 ; Within range | |
137 ; retlw .0 ; Out of range | |
138 ; check_sensor_voting_common2: | |
139 ; ; temp1<sensor_setpoint | |
140 ; movf sensor_setpoint,W | |
141 ; subwf temp1,F | |
142 ; bra check_sensor_voting_common1 | |
192 | 143 |
113 | 144 global calibrate_mix |
145 calibrate_mix: | |
146 ; calibrate S8 HUD | |
147 btfss s8_digital ; S8 Digital? | |
148 bra calibrate_mix2 ; No | |
149 | |
189
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
150 ; Yes, calibrate any S8-connected HUD |
113 | 151 clrf temp1 ; Chksum |
152 movlw 0xAA ; Start Byte | |
153 addwf temp1,F | |
154 movff WREG,TXREG2 | |
155 call rs232_wait_tx2 | |
156 | |
157 movlw 0x31 ; Calibrate | |
158 addwf temp1,F | |
159 movff WREG,TXREG2 | |
160 call rs232_wait_tx2 | |
161 | |
560 | 162 movff opt_calibration_O2_ratio,WREG ; Calibration gas %O2 |
113 | 163 addwf temp1,F |
164 movff WREG,TXREG2 | |
165 call rs232_wait_tx2 | |
166 | |
560 | 167 movff amb_pressure+0,WREG ; Ambient pressure |
113 | 168 addwf temp1,F |
169 movff WREG,TXREG2 | |
170 call rs232_wait_tx2 | |
171 movff amb_pressure+1,WREG | |
172 addwf temp1,F | |
173 movff WREG,TXREG2 | |
174 call rs232_wait_tx2 | |
175 | |
560 | 176 movff temp1,TXREG2 ; Chksum |
113 | 177 call rs232_wait_tx2 |
178 | |
179 calibrate_mix2: | |
560 | 180 movff opt_calibration_O2_ratio,WREG ; Calibration gas %O2 |
113 | 181 mullw .100 |
182 movff PRODL,xA+0 | |
183 movff PRODH,xA+1 | |
560 | 184 ; (%O2*100)*[ambient,mbar]/100 -> xC |
113 | 185 movff amb_pressure+0,xB+0 |
186 movff amb_pressure+1,xB+1 | |
448 | 187 rcall calibrate_mix2_helper |
113 | 188 movff o2_mv_sensor1+0,xB+0 |
189 movff o2_mv_sensor1+1,xB+1 | |
190 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
191 ; xC= ppO2/mV | |
192 movff xC+0,opt_x_s1+0 | |
560 | 193 movff xC+1,opt_x_s1+1 ; Factor for Sensor1 |
113 | 194 |
560 | 195 movff opt_calibration_O2_ratio,WREG ; Calibration gas %O2 |
113 | 196 mullw .100 |
197 movff PRODL,xA+0 | |
198 movff PRODH,xA+1 | |
560 | 199 ; (%O2*100)*[ambient,mbar]/100 -> xC |
113 | 200 movff amb_pressure+0,xB+0 |
201 movff amb_pressure+1,xB+1 | |
448 | 202 rcall calibrate_mix2_helper |
113 | 203 movff o2_mv_sensor2+0,xB+0 |
204 movff o2_mv_sensor2+1,xB+1 | |
205 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
206 ; xC= ppO2/mV | |
207 movff xC+0,opt_x_s2+0 | |
560 | 208 movff xC+1,opt_x_s2+1 ; Factor for Sensor2 |
113 | 209 |
560 | 210 movff opt_calibration_O2_ratio,WREG ; Calibration gas %O2 |
113 | 211 mullw .100 |
212 movff PRODL,xA+0 | |
213 movff PRODH,xA+1 | |
560 | 214 ; (%O2*100)*[ambient,mbar]/100 -> xC |
113 | 215 movff amb_pressure+0,xB+0 |
216 movff amb_pressure+1,xB+1 | |
448 | 217 rcall calibrate_mix2_helper |
113 | 218 movff o2_mv_sensor3+0,xB+0 |
219 movff o2_mv_sensor3+1,xB+1 | |
220 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
221 ; xC= ppO2/mV | |
222 movff xC+0,opt_x_s3+0 | |
560 | 223 movff xC+1,opt_x_s3+1 ; Factor for Sensor3 |
113 | 224 |
189
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
225 bsf sensor1_calibrated_ok |
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
226 bsf sensor2_calibrated_ok |
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
227 bsf sensor3_calibrated_ok ; Set flags prior check |
560 | 228 |
189
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
229 rcall check_sensors ; Check O2 sensor thresholds min_mv and max_mv and set use_02_sensorX flags |
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
230 ; initialise internal calibration flags |
192 | 231 btfss use_O2_sensor1 ; Sensor out of range? |
189
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
232 bcf sensor1_calibrated_ok ; Yes, disable this sensor |
192 | 233 btfss use_O2_sensor2 ; Sensor out of range? |
189
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
234 bcf sensor2_calibrated_ok ; Yes, disable this sensor |
192 | 235 btfss use_O2_sensor3 ; Sensor out of range? |
189
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
236 bcf sensor3_calibrated_ok ; Yes, disable this sensor |
113 | 237 |
238 ; When no sensor is found, enable all three to show error state | |
192 | 239 btfsc use_O2_sensor1 |
113 | 240 return |
192 | 241 btfsc use_O2_sensor2 |
113 | 242 return |
192 | 243 btfsc use_O2_sensor3 |
113 | 244 return |
192 | 245 bsf use_O2_sensor1 |
246 bsf use_O2_sensor2 | |
247 bsf use_O2_sensor3 | |
113 | 248 ; Clear factors |
249 banksel opt_x_s1+0 | |
250 clrf opt_x_s1+0 | |
251 clrf opt_x_s1+1 | |
252 clrf opt_x_s2+0 | |
253 clrf opt_x_s2+1 | |
254 clrf opt_x_s3+0 | |
255 clrf opt_x_s3+1 | |
256 banksel common | |
257 return | |
258 | |
560 | 259 |
448 | 260 calibrate_mix2_helper: |
560 | 261 call mult16x16 ; xA*xB=xC |
448 | 262 movlw LOW .100 |
263 movwf xB+0 | |
264 movlw HIGH .100 | |
265 movwf xB+1 | |
560 | 266 goto div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder (And return) |
267 | |
448 | 268 |
560 | 269 ; DELETE COMPLETE FUNTION, PARTS OF THE CODE HAVE MIGRATED TO calc_deko_divemode_sensor ## voting logic |
270 ; compute_ppo2_analog: | |
271 ; call get_analog_inputs | |
272 ; bra compute_ppo2_common | |
113 | 273 |
560 | 274 ; global compute_ppo2 ; compute mv_sensorX and ppo2_sensorX arrays |
275 ; compute_ppo2: | |
276 ; btfss analog_o2_input ; cR hardware? | |
277 ; return ; No | |
113 | 278 |
560 | 279 ; btfss s8_digital ; =1: Digital I/O |
280 ; bra compute_ppo2_analog ; use analog | |
113 | 281 |
560 | 282 ; ; use digital |
283 ; btfss new_s8_data_available ; =1: New data frame recieved | |
284 ; return | |
285 ; rcall compute_mvolts_for_all_sensors | |
113 | 286 |
560 | 287 ; compute_ppo2_common: |
288 ; ; o2_mv_sensor1:2 * opt_x_s1:2 = o2_ppo2_sensor1/10000 | |
289 ; movff o2_mv_sensor1+0,xA+0 | |
290 ; movff o2_mv_sensor1+1,xA+1 | |
291 ; movff opt_x_s1+0,xB+0 | |
292 ; movff opt_x_s1+1,xB+1 | |
293 ; rcall compute_ppo2_common_helper | |
294 ; movff xC+0,o2_ppo2_sensor1 ; result in 0.01bar | |
295 ; ; ; Set to zero if sensor is not active! | |
296 ; ; btfss use_O2_sensor1 | |
297 ; ; clrf o2_ppo2_sensor1 | |
113 | 298 |
560 | 299 ; ; o2_mv_sensor2:2 * opt_x_s1:2 = o2_ppo2_sensor2/10000 |
300 ; movff o2_mv_sensor2+0,xA+0 | |
301 ; movff o2_mv_sensor2+1,xA+1 | |
302 ; movff opt_x_s2+0,xB+0 | |
303 ; movff opt_x_s2+1,xB+1 | |
304 ; rcall compute_ppo2_common_helper | |
305 ; movff xC+0,o2_ppo2_sensor2 ; result in 0.01bar | |
306 ; ; ; Set to zero if sensor is not active! | |
307 ; ; btfss use_O2_sensor2 | |
308 ; ; clrf o2_ppo2_sensor2 | |
113 | 309 |
560 | 310 ; ; o2_mv_sensor3:2 * opt_x_s1:2 = o2_ppo2_sensor3/10000 |
311 ; movff o2_mv_sensor3+0,xA+0 | |
312 ; movff o2_mv_sensor3+1,xA+1 | |
313 ; movff opt_x_s3+0,xB+0 | |
314 ; movff opt_x_s3+1,xB+1 | |
315 ; rcall compute_ppo2_common_helper | |
316 ; movff xC+0,o2_ppo2_sensor3 ; result in 0.01bar | |
317 ; ; ; Set to zero if sensor is not active! | |
318 ; ; btfss use_O2_sensor3 | |
319 ; ; clrf o2_ppo2_sensor3 | |
320 ; return ; Done. | |
448 | 321 |
560 | 322 ; compute_ppo2_common_helper: |
323 ; call mult16x16 ;xA:2*xB:2=xC:4 | |
324 ; movlw LOW .1000 | |
325 ; movwf xB+0 | |
326 ; movlw HIGH .1000 | |
327 ; movwf xB+1 | |
328 ; call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
329 ; movlw d'1' | |
330 ; addwf xC+0,F | |
331 ; movlw d'0' | |
332 ; addwfc xC+1,F | |
333 ; tstfsz xC+1 ; ppO2 is higher then 2.55bar? | |
334 ; setf xC+0 ; Yes. | |
335 ; return | |
113 | 336 |
560 | 337 |
338 global compute_mvolts_for_all_sensors | |
113 | 339 compute_mvolts_for_all_sensors: ; Compute mV or all sensors (S8 Mode) |
340 ; compute AD results in 100µV steps (16bit/sensor) | |
341 ; 24bit AD result is in 244,1406541nV | |
342 ; Devide 24bit value through 409,5999512 -> 410 (0,01% error) | |
560 | 343 #DEFINE ad2mv_factor .410 |
344 ; Sensor 1 | |
345 clrf xC+3 | |
346 movff s8_rawdata_sensor1+2,xC+2 | |
347 movff s8_rawdata_sensor1+1,xC+1 | |
348 movff s8_rawdata_sensor1+0,xC+0 | |
349 movlw LOW ad2mv_factor | |
350 movwf xB+0 | |
351 movlw HIGH ad2mv_factor | |
352 movwf xB+1 | |
353 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
354 movff xC+1,o2_mv_sensor1+1 | |
355 movff xC+0,o2_mv_sensor1+0 ; in 100uV steps | |
356 ; Sensor 2 | |
357 clrf xC+3 | |
358 movff s8_rawdata_sensor2+2,xC+2 | |
359 movff s8_rawdata_sensor2+1,xC+1 | |
360 movff s8_rawdata_sensor2+0,xC+0 | |
361 movlw LOW ad2mv_factor | |
362 movwf xB+0 | |
363 movlw HIGH ad2mv_factor | |
364 movwf xB+1 | |
365 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
366 movff xC+1,o2_mv_sensor2+1 | |
367 movff xC+0,o2_mv_sensor2+0 ; in 100uV steps | |
368 ; Sensor 3 | |
369 clrf xC+3 | |
370 movff s8_rawdata_sensor3+2,xC+2 | |
371 movff s8_rawdata_sensor3+1,xC+1 | |
372 movff s8_rawdata_sensor3+0,xC+0 | |
373 movlw LOW ad2mv_factor | |
374 movwf xB+0 | |
375 movlw HIGH ad2mv_factor | |
376 movwf xB+1 | |
377 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
378 movff xC+1,o2_mv_sensor3+1 | |
379 movff xC+0,o2_mv_sensor3+0 ; in 100uV steps | |
113 | 380 |
560 | 381 bcf new_s8_data_available ; Clear flag |
382 return ; Done. | |
113 | 383 |
560 | 384 |
385 | |
386 global transmit_setpoint ; Transmit current setpoint from WREG (in cbar) to external electronics | |
352
5c6da9fa5cb0
add setpoint change to first sample in CCR mode
heinrichsweikamp
parents:
275
diff
changeset
|
387 transmit_setpoint: |
448 | 388 return |
352
5c6da9fa5cb0
add setpoint change to first sample in CCR mode
heinrichsweikamp
parents:
275
diff
changeset
|
389 btfss s8_digital ; S8 Digital? |
5c6da9fa5cb0
add setpoint change to first sample in CCR mode
heinrichsweikamp
parents:
275
diff
changeset
|
390 return ; No, ignore |
5c6da9fa5cb0
add setpoint change to first sample in CCR mode
heinrichsweikamp
parents:
275
diff
changeset
|
391 |
5c6da9fa5cb0
add setpoint change to first sample in CCR mode
heinrichsweikamp
parents:
275
diff
changeset
|
392 ; Yes, transmit setpoint from WREG |
5c6da9fa5cb0
add setpoint change to first sample in CCR mode
heinrichsweikamp
parents:
275
diff
changeset
|
393 movwf temp2 ; Store setpoint |
5c6da9fa5cb0
add setpoint change to first sample in CCR mode
heinrichsweikamp
parents:
275
diff
changeset
|
394 clrf temp1 ; Chksum |
5c6da9fa5cb0
add setpoint change to first sample in CCR mode
heinrichsweikamp
parents:
275
diff
changeset
|
395 movlw 0xAA ; Start Byte |
5c6da9fa5cb0
add setpoint change to first sample in CCR mode
heinrichsweikamp
parents:
275
diff
changeset
|
396 addwf temp1,F |
5c6da9fa5cb0
add setpoint change to first sample in CCR mode
heinrichsweikamp
parents:
275
diff
changeset
|
397 movff WREG,TXREG2 |
5c6da9fa5cb0
add setpoint change to first sample in CCR mode
heinrichsweikamp
parents:
275
diff
changeset
|
398 call rs232_wait_tx2 |
5c6da9fa5cb0
add setpoint change to first sample in CCR mode
heinrichsweikamp
parents:
275
diff
changeset
|
399 |
5c6da9fa5cb0
add setpoint change to first sample in CCR mode
heinrichsweikamp
parents:
275
diff
changeset
|
400 movlw 0x60 ; New SP |
5c6da9fa5cb0
add setpoint change to first sample in CCR mode
heinrichsweikamp
parents:
275
diff
changeset
|
401 addwf temp1,F |
5c6da9fa5cb0
add setpoint change to first sample in CCR mode
heinrichsweikamp
parents:
275
diff
changeset
|
402 movff WREG,TXREG2 |
5c6da9fa5cb0
add setpoint change to first sample in CCR mode
heinrichsweikamp
parents:
275
diff
changeset
|
403 call rs232_wait_tx2 |
5c6da9fa5cb0
add setpoint change to first sample in CCR mode
heinrichsweikamp
parents:
275
diff
changeset
|
404 |
560 | 405 movff temp2,WREG ; SP in cbar |
352
5c6da9fa5cb0
add setpoint change to first sample in CCR mode
heinrichsweikamp
parents:
275
diff
changeset
|
406 addwf temp1,F |
5c6da9fa5cb0
add setpoint change to first sample in CCR mode
heinrichsweikamp
parents:
275
diff
changeset
|
407 movff WREG,TXREG2 |
5c6da9fa5cb0
add setpoint change to first sample in CCR mode
heinrichsweikamp
parents:
275
diff
changeset
|
408 call rs232_wait_tx2 |
5c6da9fa5cb0
add setpoint change to first sample in CCR mode
heinrichsweikamp
parents:
275
diff
changeset
|
409 |
560 | 410 movff temp1,TXREG2 ; Chksum |
352
5c6da9fa5cb0
add setpoint change to first sample in CCR mode
heinrichsweikamp
parents:
275
diff
changeset
|
411 call rs232_wait_tx2 |
5c6da9fa5cb0
add setpoint change to first sample in CCR mode
heinrichsweikamp
parents:
275
diff
changeset
|
412 return |
113 | 413 |
414 | |
415 END |