comparison src/calibrate.asm @ 145:e3ac5b2021bc

NEW: Setpoint-Fallback option for external O2 sensor failure
author heinrichsweikamp
date Tue, 05 Aug 2014 16:55:09 +0200
parents f3062a611eef
children fdd4e30846ae
comparison
equal deleted inserted replaced
144:b839972db982 145:e3ac5b2021bc
12 #include "math.inc" 12 #include "math.inc"
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
18 global check_sensors ; Check O2 sensor thresholds for fallback
19 check_sensors:
20 ; Check min_mv
21 movff o2_mv_sensor1+0, sub_a+0
22 movff o2_mv_sensor1+1, sub_a+1
23 movlw LOW min_mv
24 movwf sub_b+0
25 movlw HIGH min_mv
26 movwf sub_b+1
27 call sub16 ; sub_c = sub_a - sub_b
28 bsf use_02_sensor1 ;=1: Use this sensor for deco
29 btfsc neg_flag
30 bcf use_02_sensor1 ;=1: Use this sensor for deco
31
32 movff o2_mv_sensor2+0, sub_a+0
33 movff o2_mv_sensor2+1, sub_a+1
34 movlw LOW min_mv
35 movwf sub_b+0
36 movlw HIGH min_mv
37 movwf sub_b+1
38 call sub16 ; sub_c = sub_a - sub_b
39 bsf use_02_sensor2 ;=1: Use this sensor for deco
40 btfsc neg_flag
41 bcf use_02_sensor2 ;=1: Use this sensor for deco
42
43 movff o2_mv_sensor3+0, sub_a+0
44 movff o2_mv_sensor3+1, sub_a+1
45 movlw LOW min_mv
46 movwf sub_b+0
47 movlw HIGH min_mv
48 movwf sub_b+1
49 call sub16 ; sub_c = sub_a - sub_b
50 bsf use_02_sensor3 ;=1: Use this sensor for deco
51 btfsc neg_flag
52 bcf use_02_sensor3 ;=1: Use this sensor for deco
53 ; Check max_mv
54 movff o2_mv_sensor1+0, sub_a+0
55 movff o2_mv_sensor1+1, sub_a+1
56 movlw LOW max_mv
57 movwf sub_b+0
58 movlw HIGH max_mv
59 movwf sub_b+1
60 call sub16 ; sub_c = sub_a - sub_b
61 btfss neg_flag
62 bcf use_02_sensor1 ;=1: Use this sensor for deco
63
64 movff o2_mv_sensor2+0, sub_a+0
65 movff o2_mv_sensor2+1, sub_a+1
66 movlw LOW max_mv
67 movwf sub_b+0
68 movlw HIGH max_mv
69 movwf sub_b+1
70 call sub16 ; sub_c = sub_a - sub_b
71 btfss neg_flag
72 bcf use_02_sensor2 ;=1: Use this sensor for deco
73
74 movff o2_mv_sensor3+0, sub_a+0
75 movff o2_mv_sensor3+1, sub_a+1
76 movlw LOW max_mv
77 movwf sub_b+0
78 movlw HIGH max_mv
79 movwf sub_b+1
80 call sub16 ; sub_c = sub_a - sub_b
81 btfss neg_flag
82 bcf use_02_sensor3 ;=1: Use this sensor for deco
83
84 btfss hud_connection_ok ;=1: HUD connection ok
85 return ; No HUD/Digital data
86
87 ; Copy disbale flags from digital input
88 btfss sensor1_active
89 bcf use_02_sensor1
90 btfss sensor2_active
91 bcf use_02_sensor2
92 btfss sensor3_active
93 bcf use_02_sensor3
94 return
17 95
18 global calibrate_mix 96 global calibrate_mix
19 calibrate_mix: 97 calibrate_mix:
20 ; calibrate S8 HUD 98 ; calibrate S8 HUD
21 btfss s8_digital ; S8 Digital? 99 btfss s8_digital ; S8 Digital?
116 movlw LOW min_mv 194 movlw LOW min_mv
117 movwf sub_b+0 195 movwf sub_b+0
118 movlw HIGH min_mv 196 movlw HIGH min_mv
119 movwf sub_b+1 197 movwf sub_b+1
120 call sub16 ; sub_c = sub_a - sub_b 198 call sub16 ; sub_c = sub_a - sub_b
121 bsf sensor1_active ; Sensor active! 199 bsf use_02_sensor1 ; Sensor active!
122 btfsc neg_flag 200 btfsc neg_flag
123 bcf sensor1_active 201 bcf use_02_sensor1
124 202
125 ; Result is in 100µV 203 ; Result is in 100µV
126 movff o2_mv_sensor2+0, sub_a+0 204 movff o2_mv_sensor2+0, sub_a+0
127 movff o2_mv_sensor2+1, sub_a+1 205 movff o2_mv_sensor2+1, sub_a+1
128 movlw LOW min_mv 206 movlw LOW min_mv
129 movwf sub_b+0 207 movwf sub_b+0
130 movlw HIGH min_mv 208 movlw HIGH min_mv
131 movwf sub_b+1 209 movwf sub_b+1
132 call sub16 ; sub_c = sub_a - sub_b 210 call sub16 ; sub_c = sub_a - sub_b
133 bsf sensor2_active ; Sensor active! 211 bsf use_02_sensor2 ; Sensor active!
134 btfsc neg_flag 212 btfsc neg_flag
135 bcf sensor2_active 213 bcf use_02_sensor2
136 214
137 ; Result is in 100µV 215 ; Result is in 100µV
138 movff o2_mv_sensor3+0, sub_a+0 216 movff o2_mv_sensor3+0, sub_a+0
139 movff o2_mv_sensor3+1, sub_a+1 217 movff o2_mv_sensor3+1, sub_a+1
140 movlw LOW min_mv 218 movlw LOW min_mv
141 movwf sub_b+0 219 movwf sub_b+0
142 movlw HIGH min_mv 220 movlw HIGH min_mv
143 movwf sub_b+1 221 movwf sub_b+1
144 call sub16 ; sub_c = sub_a - sub_b 222 call sub16 ; sub_c = sub_a - sub_b
145 bsf sensor3_active ; Sensor active! 223 bsf use_02_sensor3 ; Sensor active!
146 btfsc neg_flag 224 btfsc neg_flag
147 bcf sensor3_active 225 bcf use_02_sensor3
148 226
149 ; When no sensor is found, enable all three to show error state 227 ; When no sensor is found, enable all three to show error state
150 btfsc sensor1_active 228 btfsc use_02_sensor1
151 return 229 return
152 btfsc sensor2_active 230 btfsc use_02_sensor2
153 return 231 return
154 btfsc sensor3_active 232 btfsc use_02_sensor3
155 return 233 return
156 bsf sensor1_active 234 bsf use_02_sensor1
157 bsf sensor2_active 235 bsf use_02_sensor2
158 bsf sensor3_active 236 bsf use_02_sensor3
159 ; Clear factors 237 ; Clear factors
160 banksel opt_x_s1+0 238 banksel opt_x_s1+0
161 clrf opt_x_s1+0 239 clrf opt_x_s1+0
162 clrf opt_x_s1+1 240 clrf opt_x_s1+1
163 clrf opt_x_s2+0 241 clrf opt_x_s2+0
201 movlw d'0' 279 movlw d'0'
202 addwfc xC+1,F 280 addwfc xC+1,F
203 movff xC+0,o2_ppo2_sensor1+0 281 movff xC+0,o2_ppo2_sensor1+0
204 movff xC+1,o2_ppo2_sensor1+1 ; result in 0.01bar 282 movff xC+1,o2_ppo2_sensor1+1 ; result in 0.01bar
205 ; Set to zero if sensor is not active! 283 ; Set to zero if sensor is not active!
206 btfss sensor1_active 284 btfss use_02_sensor1
207 clrf o2_ppo2_sensor1+0 285 clrf o2_ppo2_sensor1+0
208 btfss sensor1_active 286 btfss use_02_sensor1
209 clrf o2_ppo2_sensor1+1 287 clrf o2_ppo2_sensor1+1
210 288
211 ; o2_mv_sensor2:2 * opt_x_s1:2 = o2_ppo2_sensor2/10000 289 ; o2_mv_sensor2:2 * opt_x_s1:2 = o2_ppo2_sensor2/10000
212 movff o2_mv_sensor2+0,xA+0 290 movff o2_mv_sensor2+0,xA+0
213 movff o2_mv_sensor2+1,xA+1 291 movff o2_mv_sensor2+1,xA+1
224 movlw d'0' 302 movlw d'0'
225 addwfc xC+1,F 303 addwfc xC+1,F
226 movff xC+0,o2_ppo2_sensor2+0 304 movff xC+0,o2_ppo2_sensor2+0
227 movff xC+1,o2_ppo2_sensor2+1 ; result in 0.01bar 305 movff xC+1,o2_ppo2_sensor2+1 ; result in 0.01bar
228 ; Set to zero if sensor is not active! 306 ; Set to zero if sensor is not active!
229 btfss sensor2_active 307 btfss use_02_sensor2
230 clrf o2_ppo2_sensor2+0 308 clrf o2_ppo2_sensor2+0
231 btfss sensor2_active 309 btfss use_02_sensor2
232 clrf o2_ppo2_sensor2+1 310 clrf o2_ppo2_sensor2+1
233 311
234 ; o2_mv_sensor3:2 * opt_x_s1:2 = o2_ppo2_sensor3/10000 312 ; o2_mv_sensor3:2 * opt_x_s1:2 = o2_ppo2_sensor3/10000
235 movff o2_mv_sensor3+0,xA+0 313 movff o2_mv_sensor3+0,xA+0
236 movff o2_mv_sensor3+1,xA+1 314 movff o2_mv_sensor3+1,xA+1
247 movlw d'0' 325 movlw d'0'
248 addwfc xC+1,F 326 addwfc xC+1,F
249 movff xC+0,o2_ppo2_sensor3+0 327 movff xC+0,o2_ppo2_sensor3+0
250 movff xC+1,o2_ppo2_sensor3+1 ; result in 0.01bar 328 movff xC+1,o2_ppo2_sensor3+1 ; result in 0.01bar
251 ; Set to zero if sensor is not active! 329 ; Set to zero if sensor is not active!
252 btfss sensor3_active 330 btfss use_02_sensor3
253 clrf o2_ppo2_sensor3+0 331 clrf o2_ppo2_sensor3+0
254 btfss sensor3_active 332 btfss use_02_sensor3
255 clrf o2_ppo2_sensor3+1 333 clrf o2_ppo2_sensor3+1
256 334
257 return ; Done. 335 return ; Done.
258 336
259 337