Mercurial > public > hwos_code
annotate src/calibrate.asm @ 189:e79bc535ef9e
ignore un-calibrated sensors even if they become valid
author | heinrichsweikamp |
---|---|
date | Wed, 29 Oct 2014 12:53:01 +0100 |
parents | 669b5d00706d |
children | a0f9ec25852e |
rev | line source |
---|---|
113 | 1 ;============================================================================= |
2 ; | |
3 ; File calibration.asm | |
4 ; | |
5 ; o2 sensor calibration subroutines | |
6 ; | |
7 ; Copyright (c) 2014, Heinrichs Weikamp, all right reserved. | |
8 ;============================================================================= | |
9 | |
10 #include "ostc3.inc" | |
11 #include "shared_definitions.h" ; Mailbox between c and asm | |
12 #include "math.inc" | |
13 #include "adc_lightsensor.inc" | |
14 #include "eeprom_rs232.inc" | |
15 | |
16 calibrate CODE | |
17 | |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
18 global check_sensors ; Check O2 sensor thresholds for fallback |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
19 check_sensors: |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
20 ; Check min_mv |
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 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
28 bsf use_02_sensor1 ;=1: Use this sensor for deco |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
29 btfsc neg_flag |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
30 bcf use_02_sensor1 ;=1: Use this sensor for deco |
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 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
39 bsf use_02_sensor2 ;=1: Use this sensor for deco |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
40 btfsc neg_flag |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
41 bcf use_02_sensor2 ;=1: Use this sensor for deco |
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 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
50 bsf use_02_sensor3 ;=1: Use this sensor for deco |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
51 btfsc neg_flag |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
52 bcf use_02_sensor3 ;=1: Use this sensor for deco |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
53 ; Check max_mv |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
54 movff o2_mv_sensor1+0, sub_a+0 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
55 movff o2_mv_sensor1+1, sub_a+1 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
56 movlw LOW max_mv |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
57 movwf sub_b+0 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
58 movlw HIGH max_mv |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
59 movwf sub_b+1 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
60 call sub16 ; sub_c = sub_a - sub_b |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
61 btfss neg_flag |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
62 bcf use_02_sensor1 ;=1: Use this sensor for deco |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
63 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
64 movff o2_mv_sensor2+0, sub_a+0 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
65 movff o2_mv_sensor2+1, sub_a+1 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
66 movlw LOW max_mv |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
67 movwf sub_b+0 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
68 movlw HIGH max_mv |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
69 movwf sub_b+1 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
70 call sub16 ; sub_c = sub_a - sub_b |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
71 btfss neg_flag |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
72 bcf use_02_sensor2 ;=1: Use this sensor for deco |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
73 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
74 movff o2_mv_sensor3+0, sub_a+0 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
75 movff o2_mv_sensor3+1, sub_a+1 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
76 movlw LOW max_mv |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
77 movwf sub_b+0 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
78 movlw HIGH max_mv |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
79 movwf sub_b+1 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
80 call sub16 ; sub_c = sub_a - sub_b |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
81 btfss neg_flag |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
82 bcf use_02_sensor3 ;=1: Use this sensor for deco |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
83 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
84 btfss hud_connection_ok ;=1: HUD connection ok |
189
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
85 bra check_sensor2 ; No HUD/Digital data |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
86 |
147 | 87 ; Copy disable flags from digital input |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
88 btfss sensor1_active |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
89 bcf use_02_sensor1 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
90 btfss sensor2_active |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
91 bcf use_02_sensor2 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
92 btfss sensor3_active |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
93 bcf use_02_sensor3 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
94 return |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
95 |
189
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
96 check_sensor2: |
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
97 ; Copy disable flags from internal calibration routine |
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
98 btfss sensor1_calibrated_ok |
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
99 bcf use_02_sensor1 |
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
100 btfss sensor2_calibrated_ok |
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
101 bcf use_02_sensor2 |
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
102 btfss sensor3_calibrated_ok |
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
103 bcf use_02_sensor3 |
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
104 return |
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
105 |
113 | 106 global calibrate_mix |
107 calibrate_mix: | |
108 ; calibrate S8 HUD | |
109 btfss s8_digital ; S8 Digital? | |
110 bra calibrate_mix2 ; No | |
111 | |
189
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
112 ; Yes, calibrate any S8-connected HUD |
113 | 113 clrf temp1 ; Chksum |
114 movlw 0xAA ; Start Byte | |
115 addwf temp1,F | |
116 movff WREG,TXREG2 | |
117 call rs232_wait_tx2 | |
118 | |
119 movlw 0x31 ; Calibrate | |
120 addwf temp1,F | |
121 movff WREG,TXREG2 | |
122 call rs232_wait_tx2 | |
123 | |
124 movff opt_calibration_O2_ratio,WREG ; Calibration gas %O2 | |
125 addwf temp1,F | |
126 movff WREG,TXREG2 | |
127 call rs232_wait_tx2 | |
128 | |
129 movff amb_pressure+0,WREG ; Ambient pressure | |
130 addwf temp1,F | |
131 movff WREG,TXREG2 | |
132 call rs232_wait_tx2 | |
133 movff amb_pressure+1,WREG | |
134 addwf temp1,F | |
135 movff WREG,TXREG2 | |
136 call rs232_wait_tx2 | |
137 | |
138 movff temp1,TXREG2 ; Chksum | |
139 call rs232_wait_tx2 | |
140 | |
141 calibrate_mix2: | |
142 movff opt_calibration_O2_ratio,WREG ; Calibration gas %O2 | |
143 mullw .100 | |
144 movff PRODL,xA+0 | |
145 movff PRODH,xA+1 | |
146 ; (%O2*100)*[ambient,mbar]/100 -> xC | |
147 movff amb_pressure+0,xB+0 | |
148 movff amb_pressure+1,xB+1 | |
149 call mult16x16 ;xA*xB=xC | |
150 movlw LOW .100 | |
151 movwf xB+0 | |
152 movlw HIGH .100 | |
153 movwf xB+1 | |
154 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
155 movff o2_mv_sensor1+0,xB+0 | |
156 movff o2_mv_sensor1+1,xB+1 | |
157 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
158 ; xC= ppO2/mV | |
159 movff xC+0,opt_x_s1+0 | |
160 movff xC+1,opt_x_s1+1 ; Factor for Sensor1 | |
161 | |
162 movff opt_calibration_O2_ratio,WREG ; Calibration gas %O2 | |
163 mullw .100 | |
164 movff PRODL,xA+0 | |
165 movff PRODH,xA+1 | |
166 ; (%O2*100)*[ambient,mbar]/100 -> xC | |
167 movff amb_pressure+0,xB+0 | |
168 movff amb_pressure+1,xB+1 | |
169 call mult16x16 ;xA*xB=xC | |
170 movlw LOW .100 | |
171 movwf xB+0 | |
172 movlw HIGH .100 | |
173 movwf xB+1 | |
174 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
175 movff o2_mv_sensor2+0,xB+0 | |
176 movff o2_mv_sensor2+1,xB+1 | |
177 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
178 ; xC= ppO2/mV | |
179 movff xC+0,opt_x_s2+0 | |
180 movff xC+1,opt_x_s2+1 ; Factor for Sensor2 | |
181 | |
182 movff opt_calibration_O2_ratio,WREG ; Calibration gas %O2 | |
183 mullw .100 | |
184 movff PRODL,xA+0 | |
185 movff PRODH,xA+1 | |
186 ; (%O2*100)*[ambient,mbar]/100 -> xC | |
187 movff amb_pressure+0,xB+0 | |
188 movff amb_pressure+1,xB+1 | |
189 call mult16x16 ;xA*xB=xC | |
190 movlw LOW .100 | |
191 movwf xB+0 | |
192 movlw HIGH .100 | |
193 movwf xB+1 | |
194 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
195 movff o2_mv_sensor3+0,xB+0 | |
196 movff o2_mv_sensor3+1,xB+1 | |
197 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
198 ; xC= ppO2/mV | |
199 movff xC+0,opt_x_s3+0 | |
200 movff xC+1,opt_x_s3+1 ; Factor for Sensor3 | |
201 | |
189
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
202 bsf sensor1_calibrated_ok |
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
203 bsf sensor2_calibrated_ok |
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
204 bsf sensor3_calibrated_ok ; Set flags prior check |
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
205 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
|
206 ; initialise internal calibration flags |
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
207 btfss use_02_sensor1 ; Sensor out of range? |
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
208 bcf sensor1_calibrated_ok ; Yes, disable this sensor |
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
209 btfss use_02_sensor2 ; Sensor out of range? |
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
210 bcf sensor2_calibrated_ok ; Yes, disable this sensor |
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
211 btfss use_02_sensor3 ; Sensor out of range? |
e79bc535ef9e
ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents:
187
diff
changeset
|
212 bcf sensor3_calibrated_ok ; Yes, disable this sensor |
113 | 213 |
214 ; When no sensor is found, enable all three to show error state | |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
215 btfsc use_02_sensor1 |
113 | 216 return |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
217 btfsc use_02_sensor2 |
113 | 218 return |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
219 btfsc use_02_sensor3 |
113 | 220 return |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
221 bsf use_02_sensor1 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
222 bsf use_02_sensor2 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
223 bsf use_02_sensor3 |
113 | 224 ; Clear factors |
225 banksel opt_x_s1+0 | |
226 clrf opt_x_s1+0 | |
227 clrf opt_x_s1+1 | |
228 clrf opt_x_s2+0 | |
229 clrf opt_x_s2+1 | |
230 clrf opt_x_s3+0 | |
231 clrf opt_x_s3+1 | |
232 banksel common | |
233 return | |
234 | |
235 compute_ppo2_analog: | |
236 call get_analog_inputs | |
237 bra compute_ppo2_common | |
238 | |
239 global compute_ppo2 ; compute mv_sensorX and ppo2_sensorX arrays | |
240 compute_ppo2: | |
241 btfss c3_hardware ; C3 hardware? | |
242 return ; No | |
243 | |
244 btfss s8_digital ; =1: Digital I/O | |
245 bra compute_ppo2_analog ; use analog | |
246 | |
247 ; use digital | |
248 btfss new_s8_data_available ; =1: New data frame recieved | |
249 return | |
250 call compute_mvolts_for_all_sensors | |
251 | |
252 compute_ppo2_common: | |
253 ; o2_mv_sensor1:2 * opt_x_s1:2 = o2_ppo2_sensor1/10000 | |
254 movff o2_mv_sensor1+0,xA+0 | |
255 movff o2_mv_sensor1+1,xA+1 | |
256 movff opt_x_s1+0,xB+0 | |
257 movff opt_x_s1+1,xB+1 | |
258 call mult16x16 ;xA:2*xB:2=xC:4 | |
259 movlw LOW .1000 | |
260 movwf xB+0 | |
261 movlw HIGH .1000 | |
262 movwf xB+1 | |
263 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
264 movlw d'1' | |
265 addwf xC+0,F | |
266 movlw d'0' | |
267 addwfc xC+1,F | |
268 movff xC+0,o2_ppo2_sensor1+0 | |
269 movff xC+1,o2_ppo2_sensor1+1 ; result in 0.01bar | |
270 ; Set to zero if sensor is not active! | |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
271 btfss use_02_sensor1 |
113 | 272 clrf o2_ppo2_sensor1+0 |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
273 btfss use_02_sensor1 |
113 | 274 clrf o2_ppo2_sensor1+1 |
275 | |
276 ; o2_mv_sensor2:2 * opt_x_s1:2 = o2_ppo2_sensor2/10000 | |
277 movff o2_mv_sensor2+0,xA+0 | |
278 movff o2_mv_sensor2+1,xA+1 | |
279 movff opt_x_s2+0,xB+0 | |
280 movff opt_x_s2+1,xB+1 | |
281 call mult16x16 ;xA:2*xB:2=xC:4 | |
282 movlw LOW .1000 | |
283 movwf xB+0 | |
284 movlw HIGH .1000 | |
285 movwf xB+1 | |
286 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
287 movlw d'1' | |
288 addwf xC+0,F | |
289 movlw d'0' | |
290 addwfc xC+1,F | |
291 movff xC+0,o2_ppo2_sensor2+0 | |
292 movff xC+1,o2_ppo2_sensor2+1 ; result in 0.01bar | |
293 ; Set to zero if sensor is not active! | |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
294 btfss use_02_sensor2 |
113 | 295 clrf o2_ppo2_sensor2+0 |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
296 btfss use_02_sensor2 |
113 | 297 clrf o2_ppo2_sensor2+1 |
298 | |
299 ; o2_mv_sensor3:2 * opt_x_s1:2 = o2_ppo2_sensor3/10000 | |
300 movff o2_mv_sensor3+0,xA+0 | |
301 movff o2_mv_sensor3+1,xA+1 | |
302 movff opt_x_s3+0,xB+0 | |
303 movff opt_x_s3+1,xB+1 | |
304 call mult16x16 ;xA:2*xB:2=xC:4 | |
305 movlw LOW .1000 | |
306 movwf xB+0 | |
307 movlw HIGH .1000 | |
308 movwf xB+1 | |
309 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
310 movlw d'1' | |
311 addwf xC+0,F | |
312 movlw d'0' | |
313 addwfc xC+1,F | |
314 movff xC+0,o2_ppo2_sensor3+0 | |
315 movff xC+1,o2_ppo2_sensor3+1 ; result in 0.01bar | |
316 ; Set to zero if sensor is not active! | |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
317 btfss use_02_sensor3 |
113 | 318 clrf o2_ppo2_sensor3+0 |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
319 btfss use_02_sensor3 |
113 | 320 clrf o2_ppo2_sensor3+1 |
321 | |
322 return ; Done. | |
323 | |
324 | |
325 compute_mvolts_for_all_sensors: ; Compute mV or all sensors (S8 Mode) | |
326 ; compute AD results in 100µV steps (16bit/sensor) | |
327 ; 24bit AD result is in 244,1406541nV | |
328 ; Devide 24bit value through 409,5999512 -> 410 (0,01% error) | |
329 #DEFINE ad2mv_factor .410 | |
330 ; Sensor 1 | |
331 clrf xC+3 | |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
147
diff
changeset
|
332 movff ir_s8_buffer+.6,xC+2 |
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
147
diff
changeset
|
333 movff ir_s8_buffer+.5,xC+1 |
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
147
diff
changeset
|
334 movff ir_s8_buffer+.4,xC+0 |
113 | 335 movlw LOW ad2mv_factor |
336 movwf xB+0 | |
337 movlw HIGH ad2mv_factor | |
338 movwf xB+1 | |
339 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
340 movff xC+1,o2_mv_sensor1+1 | |
341 movff xC+0,o2_mv_sensor1+0 ; in 100uV steps | |
342 ; Sensor 2 | |
343 clrf xC+3 | |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
147
diff
changeset
|
344 movff ir_s8_buffer+.9,xC+2 |
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
147
diff
changeset
|
345 movff ir_s8_buffer+.8,xC+1 |
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
147
diff
changeset
|
346 movff ir_s8_buffer+.7,xC+0 |
113 | 347 movlw LOW ad2mv_factor |
348 movwf xB+0 | |
349 movlw HIGH ad2mv_factor | |
350 movwf xB+1 | |
351 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
352 movff xC+1,o2_mv_sensor2+1 | |
353 movff xC+0,o2_mv_sensor2+0 ; in 100uV steps | |
354 ; Sensor 3 | |
355 clrf xC+3 | |
187
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
147
diff
changeset
|
356 movff ir_s8_buffer+.12,xC+2 |
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
147
diff
changeset
|
357 movff ir_s8_buffer+.11,xC+1 |
669b5d00706d
CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents:
147
diff
changeset
|
358 movff ir_s8_buffer+.10,xC+0 |
113 | 359 movlw LOW ad2mv_factor |
360 movwf xB+0 | |
361 movlw HIGH ad2mv_factor | |
362 movwf xB+1 | |
363 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
364 movff xC+1,o2_mv_sensor3+1 | |
365 movff xC+0,o2_mv_sensor3+0 ; in 100uV steps | |
366 | |
367 bcf new_s8_data_available ; Clear flag | |
368 return ; Done. | |
369 | |
370 | |
371 | |
372 END |