Mercurial > public > hwos_code
comparison src/calibrate.asm @ 560:b7eb98dbd800
bump to 2.96beta (REFACTORED VERSION)
author | heinrichsweikamp |
---|---|
date | Wed, 31 Jan 2018 19:39:37 +0100 |
parents | aadfe9f2edaf |
children | 54346c651b6a |
comparison
equal
deleted
inserted
replaced
559:9cb967d844f0 | 560:b7eb98dbd800 |
---|---|
1 ;============================================================================= | 1 ;============================================================================= |
2 ; | 2 ; |
3 ; File calibration.asm | 3 ; File calibration.asm REFACTORED VERSION V2.91 |
4 ; | 4 ; |
5 ; o2 sensor calibration subroutines | 5 ; o2 sensor calibration subroutines |
6 ; | 6 ; |
7 ; Copyright (c) 2014, Heinrichs Weikamp, all right reserved. | 7 ; Copyright (c) 2014, Heinrichs Weikamp, all right reserved. |
8 ;============================================================================= | 8 ;============================================================================= |
13 #include "adc_lightsensor.inc" | 13 #include "adc_lightsensor.inc" |
14 #include "eeprom_rs232.inc" | 14 #include "eeprom_rs232.inc" |
15 | 15 |
16 calibrate CODE | 16 calibrate CODE |
17 | 17 |
18 global check_sensors ; Check O2 sensor thresholds for fallback and voting logic | 18 global check_sensors ; Check O2 sensor thresholds for fallback and voting logic |
19 check_sensors: | 19 check_sensors: |
20 ; Check min_mv | 20 ; Check min_mv |
21 movff o2_mv_sensor1+0, sub_a+0 | 21 movff o2_mv_sensor1+0, sub_a+0 |
22 movff o2_mv_sensor1+1, sub_a+1 | 22 movff o2_mv_sensor1+1, sub_a+1 |
23 movlw LOW min_mv | 23 movlw LOW min_mv |
24 movwf sub_b+0 | 24 movwf sub_b+0 |
25 movlw HIGH min_mv | 25 movlw HIGH min_mv |
48 movwf sub_b+1 | 48 movwf sub_b+1 |
49 call sub16 ; sub_c = sub_a - sub_b | 49 call sub16 ; sub_c = sub_a - sub_b |
50 bsf use_O2_sensor3 ;=1: Use this sensor for deco | 50 bsf use_O2_sensor3 ;=1: Use this sensor for deco |
51 btfsc neg_flag | 51 btfsc neg_flag |
52 bcf use_O2_sensor3 ;=1: Use this sensor for deco | 52 bcf use_O2_sensor3 ;=1: Use this sensor for deco |
53 ; Check max_mv | 53 |
54 ; Check max_mv | |
54 movff o2_mv_sensor1+0, sub_a+0 | 55 movff o2_mv_sensor1+0, sub_a+0 |
55 movff o2_mv_sensor1+1, sub_a+1 | 56 movff o2_mv_sensor1+1, sub_a+1 |
56 movlw LOW max_mv | 57 movlw LOW max_mv |
57 movwf sub_b+0 | 58 movwf sub_b+0 |
58 movlw HIGH max_mv | 59 movlw HIGH max_mv |
92 btfss sensor3_active | 93 btfss sensor3_active |
93 bcf use_O2_sensor3 | 94 bcf use_O2_sensor3 |
94 bra check_sensor3 ; Check for voting logic | 95 bra check_sensor3 ; Check for voting logic |
95 | 96 |
96 check_sensor2: | 97 check_sensor2: |
97 ; Copy disable flags from internal calibration routine | 98 ; Copy disable flags from internal calibration routine |
98 btfss sensor1_calibrated_ok | 99 btfss sensor1_calibrated_ok |
99 bcf use_O2_sensor1 | 100 bcf use_O2_sensor1 |
100 btfss sensor2_calibrated_ok | 101 btfss sensor2_calibrated_ok |
101 bcf use_O2_sensor2 | 102 bcf use_O2_sensor2 |
102 btfss sensor3_calibrated_ok | 103 btfss sensor3_calibrated_ok |
103 bcf use_O2_sensor3 | 104 bcf use_O2_sensor3 |
104 check_sensor3: ; Check for voting logic | 105 check_sensor3: ; Check for voting logic |
105 bsf voting_logic_sensor1 | 106 ; DELETE - voting is done in calc_deko_divemode_sensor ## voting logic |
106 movff o2_ppo2_sensor1,temp1 | 107 ; bsf voting_logic_sensor1 |
107 rcall check_sensor_voting_common | 108 ; movff o2_ppo2_sensor1,temp1 |
108 incfsz WREG ; Was Wreg=255? | 109 ; rcall check_sensor_voting_common |
109 bcf voting_logic_sensor1 ; Yes, ignore this sensor | 110 ; incfsz WREG ; Was Wreg=255? |
110 bsf voting_logic_sensor2 | 111 ; bcf voting_logic_sensor1 ; Yes, ignore this sensor |
111 movff o2_ppo2_sensor2,temp1 | 112 ; bsf voting_logic_sensor2 |
112 rcall check_sensor_voting_common | 113 ; movff o2_ppo2_sensor2,temp1 |
113 incfsz WREG ; Was Wreg=255? | 114 ; rcall check_sensor_voting_common |
114 bcf voting_logic_sensor2 ; Yes, ignore this sensor | 115 ; incfsz WREG ; Was Wreg=255? |
115 bsf voting_logic_sensor3 | 116 ; bcf voting_logic_sensor2 ; Yes, ignore this sensor |
116 movff o2_ppo2_sensor3,temp1 | 117 ; bsf voting_logic_sensor3 |
117 rcall check_sensor_voting_common | 118 ; movff o2_ppo2_sensor3,temp1 |
118 incfsz WREG ; Was Wreg=255? | 119 ; ;rcall check_sensor_voting_common |
119 bcf voting_logic_sensor3 ; Yes, ignore this sensor | 120 ; incfsz WREG ; Was Wreg=255? |
121 ; bcf voting_logic_sensor3 ; Yes, ignore this sensor | |
120 return | 122 return |
121 | 123 |
122 | 124 ; DELETE COMPLETE FUNTION, PARTS OF THE CODE HAVE MIGRATED TO calc_deko_divemode_sensor ## voting logic |
123 check_sensor_voting_common: | 125 ; check_sensor_voting_common: |
124 movf temp1,W | 126 ; movf temp1,W |
125 cpfsgt sensor_setpoint | 127 ; cpfsgt sensor_setpoint |
126 bra check_sensor_voting_common2 ; temp1<sensor_setpoint | 128 ; bra check_sensor_voting_common2 ; temp1<sensor_setpoint |
127 ; temp1>sensor_setpoint | 129 ; ; temp1>sensor_setpoint |
128 movf temp1,W | 130 ; movf temp1,W |
129 subwf sensor_setpoint,W | 131 ; subwf sensor_setpoint,W |
130 movwf temp1 | 132 ; movwf temp1 |
131 check_sensor_voting_common1: | 133 ; check_sensor_voting_common1: |
132 movlw sensor_voting_logic_threshold ; Threshold in 0.01bar | 134 ; movlw sensor_voting_logic_threshold ; Threshold in 0.01bar |
133 cpfsgt temp1 | 135 ; cpfsgt temp1 |
134 retlw .255 ; Within range | 136 ; retlw .255 ; Within range |
135 retlw .0 ; Out of range | 137 ; retlw .0 ; Out of range |
136 check_sensor_voting_common2: | 138 ; check_sensor_voting_common2: |
137 ; temp1<sensor_setpoint | 139 ; ; temp1<sensor_setpoint |
138 movf sensor_setpoint,W | 140 ; movf sensor_setpoint,W |
139 subwf temp1,F | 141 ; subwf temp1,F |
140 bra check_sensor_voting_common1 | 142 ; bra check_sensor_voting_common1 |
141 | 143 |
142 global calibrate_mix | 144 global calibrate_mix |
143 calibrate_mix: | 145 calibrate_mix: |
144 ; calibrate S8 HUD | 146 ; calibrate S8 HUD |
145 btfss s8_digital ; S8 Digital? | 147 btfss s8_digital ; S8 Digital? |
155 movlw 0x31 ; Calibrate | 157 movlw 0x31 ; Calibrate |
156 addwf temp1,F | 158 addwf temp1,F |
157 movff WREG,TXREG2 | 159 movff WREG,TXREG2 |
158 call rs232_wait_tx2 | 160 call rs232_wait_tx2 |
159 | 161 |
160 movff opt_calibration_O2_ratio,WREG ; Calibration gas %O2 | 162 movff opt_calibration_O2_ratio,WREG ; Calibration gas %O2 |
161 addwf temp1,F | 163 addwf temp1,F |
162 movff WREG,TXREG2 | 164 movff WREG,TXREG2 |
163 call rs232_wait_tx2 | 165 call rs232_wait_tx2 |
164 | 166 |
165 movff amb_pressure+0,WREG ; Ambient pressure | 167 movff amb_pressure+0,WREG ; Ambient pressure |
166 addwf temp1,F | 168 addwf temp1,F |
167 movff WREG,TXREG2 | 169 movff WREG,TXREG2 |
168 call rs232_wait_tx2 | 170 call rs232_wait_tx2 |
169 movff amb_pressure+1,WREG | 171 movff amb_pressure+1,WREG |
170 addwf temp1,F | 172 addwf temp1,F |
171 movff WREG,TXREG2 | 173 movff WREG,TXREG2 |
172 call rs232_wait_tx2 | 174 call rs232_wait_tx2 |
173 | 175 |
174 movff temp1,TXREG2 ; Chksum | 176 movff temp1,TXREG2 ; Chksum |
175 call rs232_wait_tx2 | 177 call rs232_wait_tx2 |
176 | 178 |
177 calibrate_mix2: | 179 calibrate_mix2: |
178 movff opt_calibration_O2_ratio,WREG ; Calibration gas %O2 | 180 movff opt_calibration_O2_ratio,WREG ; Calibration gas %O2 |
179 mullw .100 | 181 mullw .100 |
180 movff PRODL,xA+0 | 182 movff PRODL,xA+0 |
181 movff PRODH,xA+1 | 183 movff PRODH,xA+1 |
182 ; (%O2*100)*[ambient,mbar]/100 -> xC | 184 ; (%O2*100)*[ambient,mbar]/100 -> xC |
183 movff amb_pressure+0,xB+0 | 185 movff amb_pressure+0,xB+0 |
184 movff amb_pressure+1,xB+1 | 186 movff amb_pressure+1,xB+1 |
185 rcall calibrate_mix2_helper | 187 rcall calibrate_mix2_helper |
186 movff o2_mv_sensor1+0,xB+0 | 188 movff o2_mv_sensor1+0,xB+0 |
187 movff o2_mv_sensor1+1,xB+1 | 189 movff o2_mv_sensor1+1,xB+1 |
188 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | 190 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder |
189 ; xC= ppO2/mV | 191 ; xC= ppO2/mV |
190 movff xC+0,opt_x_s1+0 | 192 movff xC+0,opt_x_s1+0 |
191 movff xC+1,opt_x_s1+1 ; Factor for Sensor1 | 193 movff xC+1,opt_x_s1+1 ; Factor for Sensor1 |
192 | 194 |
193 movff opt_calibration_O2_ratio,WREG ; Calibration gas %O2 | 195 movff opt_calibration_O2_ratio,WREG ; Calibration gas %O2 |
194 mullw .100 | 196 mullw .100 |
195 movff PRODL,xA+0 | 197 movff PRODL,xA+0 |
196 movff PRODH,xA+1 | 198 movff PRODH,xA+1 |
197 ; (%O2*100)*[ambient,mbar]/100 -> xC | 199 ; (%O2*100)*[ambient,mbar]/100 -> xC |
198 movff amb_pressure+0,xB+0 | 200 movff amb_pressure+0,xB+0 |
199 movff amb_pressure+1,xB+1 | 201 movff amb_pressure+1,xB+1 |
200 rcall calibrate_mix2_helper | 202 rcall calibrate_mix2_helper |
201 movff o2_mv_sensor2+0,xB+0 | 203 movff o2_mv_sensor2+0,xB+0 |
202 movff o2_mv_sensor2+1,xB+1 | 204 movff o2_mv_sensor2+1,xB+1 |
203 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | 205 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder |
204 ; xC= ppO2/mV | 206 ; xC= ppO2/mV |
205 movff xC+0,opt_x_s2+0 | 207 movff xC+0,opt_x_s2+0 |
206 movff xC+1,opt_x_s2+1 ; Factor for Sensor2 | 208 movff xC+1,opt_x_s2+1 ; Factor for Sensor2 |
207 | 209 |
208 movff opt_calibration_O2_ratio,WREG ; Calibration gas %O2 | 210 movff opt_calibration_O2_ratio,WREG ; Calibration gas %O2 |
209 mullw .100 | 211 mullw .100 |
210 movff PRODL,xA+0 | 212 movff PRODL,xA+0 |
211 movff PRODH,xA+1 | 213 movff PRODH,xA+1 |
212 ; (%O2*100)*[ambient,mbar]/100 -> xC | 214 ; (%O2*100)*[ambient,mbar]/100 -> xC |
213 movff amb_pressure+0,xB+0 | 215 movff amb_pressure+0,xB+0 |
214 movff amb_pressure+1,xB+1 | 216 movff amb_pressure+1,xB+1 |
215 rcall calibrate_mix2_helper | 217 rcall calibrate_mix2_helper |
216 movff o2_mv_sensor3+0,xB+0 | 218 movff o2_mv_sensor3+0,xB+0 |
217 movff o2_mv_sensor3+1,xB+1 | 219 movff o2_mv_sensor3+1,xB+1 |
218 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | 220 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder |
219 ; xC= ppO2/mV | 221 ; xC= ppO2/mV |
220 movff xC+0,opt_x_s3+0 | 222 movff xC+0,opt_x_s3+0 |
221 movff xC+1,opt_x_s3+1 ; Factor for Sensor3 | 223 movff xC+1,opt_x_s3+1 ; Factor for Sensor3 |
222 | 224 |
223 bsf sensor1_calibrated_ok | 225 bsf sensor1_calibrated_ok |
224 bsf sensor2_calibrated_ok | 226 bsf sensor2_calibrated_ok |
225 bsf sensor3_calibrated_ok ; Set flags prior check | 227 bsf sensor3_calibrated_ok ; Set flags prior check |
228 | |
226 rcall check_sensors ; Check O2 sensor thresholds min_mv and max_mv and set use_02_sensorX flags | 229 rcall check_sensors ; Check O2 sensor thresholds min_mv and max_mv and set use_02_sensorX flags |
227 ; initialise internal calibration flags | 230 ; initialise internal calibration flags |
228 btfss use_O2_sensor1 ; Sensor out of range? | 231 btfss use_O2_sensor1 ; Sensor out of range? |
229 bcf sensor1_calibrated_ok ; Yes, disable this sensor | 232 bcf sensor1_calibrated_ok ; Yes, disable this sensor |
230 btfss use_O2_sensor2 ; Sensor out of range? | 233 btfss use_O2_sensor2 ; Sensor out of range? |
251 clrf opt_x_s3+0 | 254 clrf opt_x_s3+0 |
252 clrf opt_x_s3+1 | 255 clrf opt_x_s3+1 |
253 banksel common | 256 banksel common |
254 return | 257 return |
255 | 258 |
259 | |
256 calibrate_mix2_helper: | 260 calibrate_mix2_helper: |
257 call mult16x16 ;xA*xB=xC | 261 call mult16x16 ; xA*xB=xC |
258 movlw LOW .100 | 262 movlw LOW .100 |
259 movwf xB+0 | 263 movwf xB+0 |
260 movlw HIGH .100 | 264 movlw HIGH .100 |
261 movwf xB+1 | 265 movwf xB+1 |
262 goto div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder (And return) | 266 goto div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder (And return) |
263 | 267 |
264 | 268 |
265 compute_ppo2_analog: | 269 ; DELETE COMPLETE FUNTION, PARTS OF THE CODE HAVE MIGRATED TO calc_deko_divemode_sensor ## voting logic |
266 call get_analog_inputs | 270 ; compute_ppo2_analog: |
267 bra compute_ppo2_common | 271 ; call get_analog_inputs |
268 | 272 ; bra compute_ppo2_common |
269 global compute_ppo2 ; compute mv_sensorX and ppo2_sensorX arrays | 273 |
270 compute_ppo2: | 274 ; global compute_ppo2 ; compute mv_sensorX and ppo2_sensorX arrays |
271 btfss analog_o2_input ; cR hardware? | 275 ; compute_ppo2: |
272 return ; No | 276 ; btfss analog_o2_input ; cR hardware? |
273 | 277 ; return ; No |
274 btfss s8_digital ; =1: Digital I/O | 278 |
275 bra compute_ppo2_analog ; use analog | 279 ; btfss s8_digital ; =1: Digital I/O |
276 | 280 ; bra compute_ppo2_analog ; use analog |
277 ; use digital | 281 |
278 btfss new_s8_data_available ; =1: New data frame recieved | 282 ; ; use digital |
279 return | 283 ; btfss new_s8_data_available ; =1: New data frame recieved |
280 rcall compute_mvolts_for_all_sensors | 284 ; return |
281 | 285 ; rcall compute_mvolts_for_all_sensors |
282 compute_ppo2_common: | 286 |
283 ; o2_mv_sensor1:2 * opt_x_s1:2 = o2_ppo2_sensor1/10000 | 287 ; compute_ppo2_common: |
284 movff o2_mv_sensor1+0,xA+0 | 288 ; ; o2_mv_sensor1:2 * opt_x_s1:2 = o2_ppo2_sensor1/10000 |
285 movff o2_mv_sensor1+1,xA+1 | 289 ; movff o2_mv_sensor1+0,xA+0 |
286 movff opt_x_s1+0,xB+0 | 290 ; movff o2_mv_sensor1+1,xA+1 |
287 movff opt_x_s1+1,xB+1 | 291 ; movff opt_x_s1+0,xB+0 |
288 rcall compute_ppo2_common_helper | 292 ; movff opt_x_s1+1,xB+1 |
289 movff xC+0,o2_ppo2_sensor1 ; result in 0.01bar | 293 ; rcall compute_ppo2_common_helper |
290 ; ; Set to zero if sensor is not active! | 294 ; movff xC+0,o2_ppo2_sensor1 ; result in 0.01bar |
291 ; btfss use_O2_sensor1 | 295 ; ; ; Set to zero if sensor is not active! |
292 ; clrf o2_ppo2_sensor1 | 296 ; ; btfss use_O2_sensor1 |
293 | 297 ; ; clrf o2_ppo2_sensor1 |
294 ; o2_mv_sensor2:2 * opt_x_s1:2 = o2_ppo2_sensor2/10000 | 298 |
295 movff o2_mv_sensor2+0,xA+0 | 299 ; ; o2_mv_sensor2:2 * opt_x_s1:2 = o2_ppo2_sensor2/10000 |
296 movff o2_mv_sensor2+1,xA+1 | 300 ; movff o2_mv_sensor2+0,xA+0 |
297 movff opt_x_s2+0,xB+0 | 301 ; movff o2_mv_sensor2+1,xA+1 |
298 movff opt_x_s2+1,xB+1 | 302 ; movff opt_x_s2+0,xB+0 |
299 rcall compute_ppo2_common_helper | 303 ; movff opt_x_s2+1,xB+1 |
300 movff xC+0,o2_ppo2_sensor2 ; result in 0.01bar | 304 ; rcall compute_ppo2_common_helper |
301 ; ; Set to zero if sensor is not active! | 305 ; movff xC+0,o2_ppo2_sensor2 ; result in 0.01bar |
302 ; btfss use_O2_sensor2 | 306 ; ; ; Set to zero if sensor is not active! |
303 ; clrf o2_ppo2_sensor2 | 307 ; ; btfss use_O2_sensor2 |
304 | 308 ; ; clrf o2_ppo2_sensor2 |
305 ; o2_mv_sensor3:2 * opt_x_s1:2 = o2_ppo2_sensor3/10000 | 309 |
306 movff o2_mv_sensor3+0,xA+0 | 310 ; ; o2_mv_sensor3:2 * opt_x_s1:2 = o2_ppo2_sensor3/10000 |
307 movff o2_mv_sensor3+1,xA+1 | 311 ; movff o2_mv_sensor3+0,xA+0 |
308 movff opt_x_s3+0,xB+0 | 312 ; movff o2_mv_sensor3+1,xA+1 |
309 movff opt_x_s3+1,xB+1 | 313 ; movff opt_x_s3+0,xB+0 |
310 rcall compute_ppo2_common_helper | 314 ; movff opt_x_s3+1,xB+1 |
311 movff xC+0,o2_ppo2_sensor3 ; result in 0.01bar | 315 ; rcall compute_ppo2_common_helper |
312 ; ; Set to zero if sensor is not active! | 316 ; movff xC+0,o2_ppo2_sensor3 ; result in 0.01bar |
313 ; btfss use_O2_sensor3 | 317 ; ; ; Set to zero if sensor is not active! |
314 ; clrf o2_ppo2_sensor3 | 318 ; ; btfss use_O2_sensor3 |
315 return ; Done. | 319 ; ; clrf o2_ppo2_sensor3 |
316 | 320 ; return ; Done. |
317 compute_ppo2_common_helper: | 321 |
318 call mult16x16 ;xA:2*xB:2=xC:4 | 322 ; compute_ppo2_common_helper: |
319 movlw LOW .1000 | 323 ; call mult16x16 ;xA:2*xB:2=xC:4 |
320 movwf xB+0 | 324 ; movlw LOW .1000 |
321 movlw HIGH .1000 | 325 ; movwf xB+0 |
322 movwf xB+1 | 326 ; movlw HIGH .1000 |
323 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | 327 ; movwf xB+1 |
324 movlw d'1' | 328 ; call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder |
325 addwf xC+0,F | 329 ; movlw d'1' |
326 movlw d'0' | 330 ; addwf xC+0,F |
327 addwfc xC+1,F | 331 ; movlw d'0' |
328 tstfsz xC+1 ; ppO2 is higher then 2.55bar? | 332 ; addwfc xC+1,F |
329 setf xC+0 ; Yes. | 333 ; tstfsz xC+1 ; ppO2 is higher then 2.55bar? |
330 return | 334 ; setf xC+0 ; Yes. |
331 | 335 ; return |
336 | |
337 | |
338 global compute_mvolts_for_all_sensors | |
332 compute_mvolts_for_all_sensors: ; Compute mV or all sensors (S8 Mode) | 339 compute_mvolts_for_all_sensors: ; Compute mV or all sensors (S8 Mode) |
333 ; compute AD results in 100µV steps (16bit/sensor) | 340 ; compute AD results in 100µV steps (16bit/sensor) |
334 ; 24bit AD result is in 244,1406541nV | 341 ; 24bit AD result is in 244,1406541nV |
335 ; Devide 24bit value through 409,5999512 -> 410 (0,01% error) | 342 ; Devide 24bit value through 409,5999512 -> 410 (0,01% error) |
336 #DEFINE ad2mv_factor .410 | 343 #DEFINE ad2mv_factor .410 |
337 ; Sensor 1 | 344 ; Sensor 1 |
338 clrf xC+3 | 345 clrf xC+3 |
339 movff s8_rawdata_sensor1+2,xC+2 | 346 movff s8_rawdata_sensor1+2,xC+2 |
340 movff s8_rawdata_sensor1+1,xC+1 | 347 movff s8_rawdata_sensor1+1,xC+1 |
341 movff s8_rawdata_sensor1+0,xC+0 | 348 movff s8_rawdata_sensor1+0,xC+0 |
342 movlw LOW ad2mv_factor | 349 movlw LOW ad2mv_factor |
343 movwf xB+0 | 350 movwf xB+0 |
344 movlw HIGH ad2mv_factor | 351 movlw HIGH ad2mv_factor |
345 movwf xB+1 | 352 movwf xB+1 |
346 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | 353 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder |
347 movff xC+1,o2_mv_sensor1+1 | 354 movff xC+1,o2_mv_sensor1+1 |
348 movff xC+0,o2_mv_sensor1+0 ; in 100uV steps | 355 movff xC+0,o2_mv_sensor1+0 ; in 100uV steps |
349 ; Sensor 2 | 356 ; Sensor 2 |
350 clrf xC+3 | 357 clrf xC+3 |
351 movff s8_rawdata_sensor2+2,xC+2 | 358 movff s8_rawdata_sensor2+2,xC+2 |
352 movff s8_rawdata_sensor2+1,xC+1 | 359 movff s8_rawdata_sensor2+1,xC+1 |
353 movff s8_rawdata_sensor2+0,xC+0 | 360 movff s8_rawdata_sensor2+0,xC+0 |
354 movlw LOW ad2mv_factor | 361 movlw LOW ad2mv_factor |
355 movwf xB+0 | 362 movwf xB+0 |
356 movlw HIGH ad2mv_factor | 363 movlw HIGH ad2mv_factor |
357 movwf xB+1 | 364 movwf xB+1 |
358 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | 365 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder |
359 movff xC+1,o2_mv_sensor2+1 | 366 movff xC+1,o2_mv_sensor2+1 |
360 movff xC+0,o2_mv_sensor2+0 ; in 100uV steps | 367 movff xC+0,o2_mv_sensor2+0 ; in 100uV steps |
361 ; Sensor 3 | 368 ; Sensor 3 |
362 clrf xC+3 | 369 clrf xC+3 |
363 movff s8_rawdata_sensor3+2,xC+2 | 370 movff s8_rawdata_sensor3+2,xC+2 |
364 movff s8_rawdata_sensor3+1,xC+1 | 371 movff s8_rawdata_sensor3+1,xC+1 |
365 movff s8_rawdata_sensor3+0,xC+0 | 372 movff s8_rawdata_sensor3+0,xC+0 |
366 movlw LOW ad2mv_factor | 373 movlw LOW ad2mv_factor |
367 movwf xB+0 | 374 movwf xB+0 |
368 movlw HIGH ad2mv_factor | 375 movlw HIGH ad2mv_factor |
369 movwf xB+1 | 376 movwf xB+1 |
370 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | 377 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder |
371 movff xC+1,o2_mv_sensor3+1 | 378 movff xC+1,o2_mv_sensor3+1 |
372 movff xC+0,o2_mv_sensor3+0 ; in 100uV steps | 379 movff xC+0,o2_mv_sensor3+0 ; in 100uV steps |
373 | 380 |
374 bcf new_s8_data_available ; Clear flag | 381 bcf new_s8_data_available ; Clear flag |
375 return ; Done. | 382 return ; Done. |
376 | 383 |
377 global transmit_setpoint ; Transmit current setpoint from WREG (in cbar) to external electronics | 384 |
385 | |
386 global transmit_setpoint ; Transmit current setpoint from WREG (in cbar) to external electronics | |
378 transmit_setpoint: | 387 transmit_setpoint: |
379 return | 388 return |
380 btfss s8_digital ; S8 Digital? | 389 btfss s8_digital ; S8 Digital? |
381 return ; No, ignore | 390 return ; No, ignore |
382 | 391 |
391 movlw 0x60 ; New SP | 400 movlw 0x60 ; New SP |
392 addwf temp1,F | 401 addwf temp1,F |
393 movff WREG,TXREG2 | 402 movff WREG,TXREG2 |
394 call rs232_wait_tx2 | 403 call rs232_wait_tx2 |
395 | 404 |
396 movff temp2,WREG ; SP in cbar | 405 movff temp2,WREG ; SP in cbar |
397 addwf temp1,F | 406 addwf temp1,F |
398 movff WREG,TXREG2 | 407 movff WREG,TXREG2 |
399 call rs232_wait_tx2 | 408 call rs232_wait_tx2 |
400 | 409 |
401 movff temp1,TXREG2 ; Chksum | 410 movff temp1,TXREG2 ; Chksum |
402 call rs232_wait_tx2 | 411 call rs232_wait_tx2 |
403 return | 412 return |
404 | 413 |
405 | 414 |
406 END | 415 END |