comparison src/calibrate.asm @ 192:efe70488a04b

voting logic for external monitoring
author heinrichsweikamp
date Mon, 03 Nov 2014 17:25:19 +0100
parents a0f9ec25852e
children dcd513840c6c
comparison
equal deleted inserted replaced
191:d049511b25c6 192:efe70488a04b
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 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
26 movwf sub_b+1 26 movwf sub_b+1
27 call sub16 ; sub_c = sub_a - sub_b 27 call sub16 ; sub_c = sub_a - sub_b
28 bsf use_02_sensor1 ;=1: Use this sensor for deco 28 bsf use_O2_sensor1 ;=1: Use this sensor for deco
29 btfsc neg_flag 29 btfsc neg_flag
30 bcf use_02_sensor1 ;=1: Use this sensor for deco 30 bcf use_O2_sensor1 ;=1: Use this sensor for deco
31 31
32 movff o2_mv_sensor2+0, sub_a+0 32 movff o2_mv_sensor2+0, sub_a+0
33 movff o2_mv_sensor2+1, sub_a+1 33 movff o2_mv_sensor2+1, sub_a+1
34 movlw LOW min_mv 34 movlw LOW min_mv
35 movwf sub_b+0 35 movwf sub_b+0
36 movlw HIGH min_mv 36 movlw HIGH min_mv
37 movwf sub_b+1 37 movwf sub_b+1
38 call sub16 ; sub_c = sub_a - sub_b 38 call sub16 ; sub_c = sub_a - sub_b
39 bsf use_02_sensor2 ;=1: Use this sensor for deco 39 bsf use_O2_sensor2 ;=1: Use this sensor for deco
40 btfsc neg_flag 40 btfsc neg_flag
41 bcf use_02_sensor2 ;=1: Use this sensor for deco 41 bcf use_O2_sensor2 ;=1: Use this sensor for deco
42 42
43 movff o2_mv_sensor3+0, sub_a+0 43 movff o2_mv_sensor3+0, sub_a+0
44 movff o2_mv_sensor3+1, sub_a+1 44 movff o2_mv_sensor3+1, sub_a+1
45 movlw LOW min_mv 45 movlw LOW min_mv
46 movwf sub_b+0 46 movwf sub_b+0
47 movlw HIGH min_mv 47 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_02_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_02_sensor3 ;=1: Use this sensor for deco 52 bcf use_O2_sensor3 ;=1: Use this sensor for deco
53 ; Check max_mv 53 ; Check max_mv
54 movff o2_mv_sensor1+0, sub_a+0 54 movff o2_mv_sensor1+0, sub_a+0
55 movff o2_mv_sensor1+1, sub_a+1 55 movff o2_mv_sensor1+1, sub_a+1
56 movlw LOW max_mv 56 movlw LOW max_mv
57 movwf sub_b+0 57 movwf sub_b+0
58 movlw HIGH max_mv 58 movlw HIGH max_mv
59 movwf sub_b+1 59 movwf sub_b+1
60 call sub16 ; sub_c = sub_a - sub_b 60 call sub16 ; sub_c = sub_a - sub_b
61 btfss neg_flag 61 btfss neg_flag
62 bcf use_02_sensor1 ;=1: Use this sensor for deco 62 bcf use_O2_sensor1 ;=1: Use this sensor for deco
63 63
64 movff o2_mv_sensor2+0, sub_a+0 64 movff o2_mv_sensor2+0, sub_a+0
65 movff o2_mv_sensor2+1, sub_a+1 65 movff o2_mv_sensor2+1, sub_a+1
66 movlw LOW max_mv 66 movlw LOW max_mv
67 movwf sub_b+0 67 movwf sub_b+0
68 movlw HIGH max_mv 68 movlw HIGH max_mv
69 movwf sub_b+1 69 movwf sub_b+1
70 call sub16 ; sub_c = sub_a - sub_b 70 call sub16 ; sub_c = sub_a - sub_b
71 btfss neg_flag 71 btfss neg_flag
72 bcf use_02_sensor2 ;=1: Use this sensor for deco 72 bcf use_O2_sensor2 ;=1: Use this sensor for deco
73 73
74 movff o2_mv_sensor3+0, sub_a+0 74 movff o2_mv_sensor3+0, sub_a+0
75 movff o2_mv_sensor3+1, sub_a+1 75 movff o2_mv_sensor3+1, sub_a+1
76 movlw LOW max_mv 76 movlw LOW max_mv
77 movwf sub_b+0 77 movwf sub_b+0
78 movlw HIGH max_mv 78 movlw HIGH max_mv
79 movwf sub_b+1 79 movwf sub_b+1
80 call sub16 ; sub_c = sub_a - sub_b 80 call sub16 ; sub_c = sub_a - sub_b
81 btfss neg_flag 81 btfss neg_flag
82 bcf use_02_sensor3 ;=1: Use this sensor for deco 82 bcf use_O2_sensor3 ;=1: Use this sensor for deco
83 83
84 btfss hud_connection_ok ;=1: HUD connection ok 84 btfss hud_connection_ok ;=1: HUD connection ok
85 bra check_sensor2 ; No HUD/Digital data 85 bra check_sensor2 ; No HUD/Digital data
86 86
87 ; Copy disable flags from digital input 87 ; Copy disable flags from digital input
88 btfss sensor1_active 88 btfss sensor1_active
89 bcf use_02_sensor1 89 bcf use_O2_sensor1
90 btfss sensor2_active 90 btfss sensor2_active
91 bcf use_02_sensor2 91 bcf use_O2_sensor2
92 btfss sensor3_active 92 btfss sensor3_active
93 bcf use_02_sensor3 93 bcf use_O2_sensor3
94 return 94 bra check_sensor3 ; Check for voting logic
95 95
96 check_sensor2: 96 check_sensor2:
97 ; Copy disable flags from internal calibration routine 97 ; Copy disable flags from internal calibration routine
98 btfss sensor1_calibrated_ok 98 btfss sensor1_calibrated_ok
99 bcf use_02_sensor1 99 bcf use_O2_sensor1
100 btfss sensor2_calibrated_ok 100 btfss sensor2_calibrated_ok
101 bcf use_02_sensor2 101 bcf use_O2_sensor2
102 btfss sensor3_calibrated_ok 102 btfss sensor3_calibrated_ok
103 bcf use_02_sensor3 103 bcf use_O2_sensor3
104 check_sensor3: ; Check for voting logic
105 bsf voting_logic_sensor1
106 movff o2_ppo2_sensor1,temp1
107 rcall check_sensor_voting_common
108 incfsz WREG ; Was Wreg=255?
109 bcf voting_logic_sensor1 ; Yes, ignore this sensor
110 bsf voting_logic_sensor2
111 movff o2_ppo2_sensor2,temp1
112 rcall check_sensor_voting_common
113 incfsz WREG ; Was Wreg=255?
114 bcf voting_logic_sensor2 ; Yes, ignore this sensor
115 bsf voting_logic_sensor3
116 movff o2_ppo2_sensor3,temp1
117 rcall check_sensor_voting_common
118 incfsz WREG ; Was Wreg=255?
119 bcf voting_logic_sensor3 ; Yes, ignore this sensor
104 return 120 return
121
122
123 check_sensor_voting_common:
124 movf temp1,W
125 cpfsgt sensor_setpoint
126 bra check_sensor_voting_common2 ; temp1<sensor_setpoint
127 ; temp1>sensor_setpoint
128 movf temp1,W
129 subwf sensor_setpoint,W
130 movwf temp1
131 check_sensor_voting_common1:
132 movlw sensor_voting_logic_threshold ; Threshold in 0.01bar
133 cpfsgt temp1
134 retlw .255 ; Within range
135 retlw .0 ; Out of range
136 check_sensor_voting_common2:
137 ; temp1<sensor_setpoint
138 movf sensor_setpoint,W
139 subwf temp1,F
140 bra check_sensor_voting_common1
105 141
106 global calibrate_mix 142 global calibrate_mix
107 calibrate_mix: 143 calibrate_mix:
108 ; calibrate S8 HUD 144 ; calibrate S8 HUD
109 btfss s8_digital ; S8 Digital? 145 btfss s8_digital ; S8 Digital?
202 bsf sensor1_calibrated_ok 238 bsf sensor1_calibrated_ok
203 bsf sensor2_calibrated_ok 239 bsf sensor2_calibrated_ok
204 bsf sensor3_calibrated_ok ; Set flags prior check 240 bsf sensor3_calibrated_ok ; Set flags prior check
205 rcall check_sensors ; Check O2 sensor thresholds min_mv and max_mv and set use_02_sensorX flags 241 rcall check_sensors ; Check O2 sensor thresholds min_mv and max_mv and set use_02_sensorX flags
206 ; initialise internal calibration flags 242 ; initialise internal calibration flags
207 btfss use_02_sensor1 ; Sensor out of range? 243 btfss use_O2_sensor1 ; Sensor out of range?
208 bcf sensor1_calibrated_ok ; Yes, disable this sensor 244 bcf sensor1_calibrated_ok ; Yes, disable this sensor
209 btfss use_02_sensor2 ; Sensor out of range? 245 btfss use_O2_sensor2 ; Sensor out of range?
210 bcf sensor2_calibrated_ok ; Yes, disable this sensor 246 bcf sensor2_calibrated_ok ; Yes, disable this sensor
211 btfss use_02_sensor3 ; Sensor out of range? 247 btfss use_O2_sensor3 ; Sensor out of range?
212 bcf sensor3_calibrated_ok ; Yes, disable this sensor 248 bcf sensor3_calibrated_ok ; Yes, disable this sensor
213 249
214 ; When no sensor is found, enable all three to show error state 250 ; When no sensor is found, enable all three to show error state
215 btfsc use_02_sensor1 251 btfsc use_O2_sensor1
216 return 252 return
217 btfsc use_02_sensor2 253 btfsc use_O2_sensor2
218 return 254 return
219 btfsc use_02_sensor3 255 btfsc use_O2_sensor3
220 return 256 return
221 bsf use_02_sensor1 257 bsf use_O2_sensor1
222 bsf use_02_sensor2 258 bsf use_O2_sensor2
223 bsf use_02_sensor3 259 bsf use_O2_sensor3
224 ; Clear factors 260 ; Clear factors
225 banksel opt_x_s1+0 261 banksel opt_x_s1+0
226 clrf opt_x_s1+0 262 clrf opt_x_s1+0
227 clrf opt_x_s1+1 263 clrf opt_x_s1+1
228 clrf opt_x_s2+0 264 clrf opt_x_s2+0
266 movlw d'0' 302 movlw d'0'
267 addwfc xC+1,F 303 addwfc xC+1,F
268 tstfsz xC+1 ; ppO2 is higher then 2.55bar? 304 tstfsz xC+1 ; ppO2 is higher then 2.55bar?
269 setf xC+0 ; Yes. 305 setf xC+0 ; Yes.
270 movff xC+0,o2_ppo2_sensor1 ; result in 0.01bar 306 movff xC+0,o2_ppo2_sensor1 ; result in 0.01bar
271 ; Set to zero if sensor is not active! 307 ; ; Set to zero if sensor is not active!
272 btfss use_02_sensor1 308 ; btfss use_O2_sensor1
273 clrf o2_ppo2_sensor1 309 ; clrf o2_ppo2_sensor1
274 310
275 ; o2_mv_sensor2:2 * opt_x_s1:2 = o2_ppo2_sensor2/10000 311 ; o2_mv_sensor2:2 * opt_x_s1:2 = o2_ppo2_sensor2/10000
276 movff o2_mv_sensor2+0,xA+0 312 movff o2_mv_sensor2+0,xA+0
277 movff o2_mv_sensor2+1,xA+1 313 movff o2_mv_sensor2+1,xA+1
278 movff opt_x_s2+0,xB+0 314 movff opt_x_s2+0,xB+0
288 movlw d'0' 324 movlw d'0'
289 addwfc xC+1,F 325 addwfc xC+1,F
290 tstfsz xC+1 ; ppO2 is higher then 2.55bar? 326 tstfsz xC+1 ; ppO2 is higher then 2.55bar?
291 setf xC+0 ; Yes. 327 setf xC+0 ; Yes.
292 movff xC+0,o2_ppo2_sensor2 ; result in 0.01bar 328 movff xC+0,o2_ppo2_sensor2 ; result in 0.01bar
293 ; Set to zero if sensor is not active! 329 ; ; Set to zero if sensor is not active!
294 btfss use_02_sensor2 330 ; btfss use_O2_sensor2
295 clrf o2_ppo2_sensor2 331 ; clrf o2_ppo2_sensor2
296 332
297 ; o2_mv_sensor3:2 * opt_x_s1:2 = o2_ppo2_sensor3/10000 333 ; o2_mv_sensor3:2 * opt_x_s1:2 = o2_ppo2_sensor3/10000
298 movff o2_mv_sensor3+0,xA+0 334 movff o2_mv_sensor3+0,xA+0
299 movff o2_mv_sensor3+1,xA+1 335 movff o2_mv_sensor3+1,xA+1
300 movff opt_x_s3+0,xB+0 336 movff opt_x_s3+0,xB+0
310 movlw d'0' 346 movlw d'0'
311 addwfc xC+1,F 347 addwfc xC+1,F
312 tstfsz xC+1 ; ppO2 is higher then 2.55bar? 348 tstfsz xC+1 ; ppO2 is higher then 2.55bar?
313 setf xC+0 ; Yes. 349 setf xC+0 ; Yes.
314 movff xC+0,o2_ppo2_sensor3 ; result in 0.01bar 350 movff xC+0,o2_ppo2_sensor3 ; result in 0.01bar
315 ; Set to zero if sensor is not active! 351 ; ; Set to zero if sensor is not active!
316 btfss use_02_sensor3 352 ; btfss use_O2_sensor3
317 clrf o2_ppo2_sensor3 353 ; clrf o2_ppo2_sensor3
318 return ; Done. 354 return ; Done.
319 355
320 356
321 compute_mvolts_for_all_sensors: ; Compute mV or all sensors (S8 Mode) 357 compute_mvolts_for_all_sensors: ; Compute mV or all sensors (S8 Mode)
322 ; compute AD results in 100µV steps (16bit/sensor) 358 ; compute AD results in 100µV steps (16bit/sensor)