Mercurial > public > hwos_code
annotate src/calibrate.asm @ 151:5cb177f0948a
work on flip screen...
author | heinrichsweikamp |
---|---|
date | Mon, 18 Aug 2014 17:37:00 +0200 |
parents | fdd4e30846ae |
children | 669b5d00706d |
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 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
85 return ; No HUD/Digital data |
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 |
113 | 96 global calibrate_mix |
97 calibrate_mix: | |
98 ; calibrate S8 HUD | |
99 btfss s8_digital ; S8 Digital? | |
100 bra calibrate_mix2 ; No | |
101 | |
102 clrf temp1 ; Chksum | |
103 movlw 0xAA ; Start Byte | |
104 addwf temp1,F | |
105 movff WREG,TXREG2 | |
106 call rs232_wait_tx2 | |
107 | |
108 movlw 0x31 ; Calibrate | |
109 addwf temp1,F | |
110 movff WREG,TXREG2 | |
111 call rs232_wait_tx2 | |
112 | |
113 movff opt_calibration_O2_ratio,WREG ; Calibration gas %O2 | |
114 addwf temp1,F | |
115 movff WREG,TXREG2 | |
116 call rs232_wait_tx2 | |
117 | |
118 movff amb_pressure+0,WREG ; Ambient pressure | |
119 addwf temp1,F | |
120 movff WREG,TXREG2 | |
121 call rs232_wait_tx2 | |
122 movff amb_pressure+1,WREG | |
123 addwf temp1,F | |
124 movff WREG,TXREG2 | |
125 call rs232_wait_tx2 | |
126 | |
127 movff temp1,TXREG2 ; Chksum | |
128 call rs232_wait_tx2 | |
129 | |
130 calibrate_mix2: | |
131 movff opt_calibration_O2_ratio,WREG ; Calibration gas %O2 | |
132 mullw .100 | |
133 movff PRODL,xA+0 | |
134 movff PRODH,xA+1 | |
135 ; (%O2*100)*[ambient,mbar]/100 -> xC | |
136 movff amb_pressure+0,xB+0 | |
137 movff amb_pressure+1,xB+1 | |
138 call mult16x16 ;xA*xB=xC | |
139 movlw LOW .100 | |
140 movwf xB+0 | |
141 movlw HIGH .100 | |
142 movwf xB+1 | |
143 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
144 movff o2_mv_sensor1+0,xB+0 | |
145 movff o2_mv_sensor1+1,xB+1 | |
146 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
147 ; xC= ppO2/mV | |
148 movff xC+0,opt_x_s1+0 | |
149 movff xC+1,opt_x_s1+1 ; Factor for Sensor1 | |
150 | |
151 movff opt_calibration_O2_ratio,WREG ; Calibration gas %O2 | |
152 mullw .100 | |
153 movff PRODL,xA+0 | |
154 movff PRODH,xA+1 | |
155 ; (%O2*100)*[ambient,mbar]/100 -> xC | |
156 movff amb_pressure+0,xB+0 | |
157 movff amb_pressure+1,xB+1 | |
158 call mult16x16 ;xA*xB=xC | |
159 movlw LOW .100 | |
160 movwf xB+0 | |
161 movlw HIGH .100 | |
162 movwf xB+1 | |
163 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
164 movff o2_mv_sensor2+0,xB+0 | |
165 movff o2_mv_sensor2+1,xB+1 | |
166 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
167 ; xC= ppO2/mV | |
168 movff xC+0,opt_x_s2+0 | |
169 movff xC+1,opt_x_s2+1 ; Factor for Sensor2 | |
170 | |
171 movff opt_calibration_O2_ratio,WREG ; Calibration gas %O2 | |
172 mullw .100 | |
173 movff PRODL,xA+0 | |
174 movff PRODH,xA+1 | |
175 ; (%O2*100)*[ambient,mbar]/100 -> xC | |
176 movff amb_pressure+0,xB+0 | |
177 movff amb_pressure+1,xB+1 | |
178 call mult16x16 ;xA*xB=xC | |
179 movlw LOW .100 | |
180 movwf xB+0 | |
181 movlw HIGH .100 | |
182 movwf xB+1 | |
183 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
184 movff o2_mv_sensor3+0,xB+0 | |
185 movff o2_mv_sensor3+1,xB+1 | |
186 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
187 ; xC= ppO2/mV | |
188 movff xC+0,opt_x_s3+0 | |
189 movff xC+1,opt_x_s3+1 ; Factor for Sensor3 | |
190 | |
191 ; Result is in 100µV | |
192 movff o2_mv_sensor1+0, sub_a+0 | |
193 movff o2_mv_sensor1+1, sub_a+1 | |
194 movlw LOW min_mv | |
195 movwf sub_b+0 | |
196 movlw HIGH min_mv | |
197 movwf sub_b+1 | |
198 call sub16 ; sub_c = sub_a - sub_b | |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
199 bsf use_02_sensor1 ; Sensor active! |
113 | 200 btfsc neg_flag |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
201 bcf use_02_sensor1 |
113 | 202 |
203 ; Result is in 100µV | |
204 movff o2_mv_sensor2+0, sub_a+0 | |
205 movff o2_mv_sensor2+1, sub_a+1 | |
206 movlw LOW min_mv | |
207 movwf sub_b+0 | |
208 movlw HIGH min_mv | |
209 movwf sub_b+1 | |
210 call sub16 ; sub_c = sub_a - sub_b | |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
211 bsf use_02_sensor2 ; Sensor active! |
113 | 212 btfsc neg_flag |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
213 bcf use_02_sensor2 |
113 | 214 |
215 ; Result is in 100µV | |
216 movff o2_mv_sensor3+0, sub_a+0 | |
217 movff o2_mv_sensor3+1, sub_a+1 | |
218 movlw LOW min_mv | |
219 movwf sub_b+0 | |
220 movlw HIGH min_mv | |
221 movwf sub_b+1 | |
222 call sub16 ; sub_c = sub_a - sub_b | |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
223 bsf use_02_sensor3 ; Sensor active! |
113 | 224 btfsc neg_flag |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
225 bcf use_02_sensor3 |
113 | 226 |
227 ; 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
|
228 btfsc use_02_sensor1 |
113 | 229 return |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
230 btfsc use_02_sensor2 |
113 | 231 return |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
232 btfsc use_02_sensor3 |
113 | 233 return |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
234 bsf use_02_sensor1 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
235 bsf use_02_sensor2 |
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
236 bsf use_02_sensor3 |
113 | 237 ; Clear factors |
238 banksel opt_x_s1+0 | |
239 clrf opt_x_s1+0 | |
240 clrf opt_x_s1+1 | |
241 clrf opt_x_s2+0 | |
242 clrf opt_x_s2+1 | |
243 clrf opt_x_s3+0 | |
244 clrf opt_x_s3+1 | |
245 banksel common | |
246 return | |
247 | |
248 compute_ppo2_analog: | |
249 call get_analog_inputs | |
250 bra compute_ppo2_common | |
251 | |
252 global compute_ppo2 ; compute mv_sensorX and ppo2_sensorX arrays | |
253 compute_ppo2: | |
254 btfss c3_hardware ; C3 hardware? | |
255 return ; No | |
256 | |
257 btfss s8_digital ; =1: Digital I/O | |
258 bra compute_ppo2_analog ; use analog | |
259 | |
260 ; use digital | |
261 btfss new_s8_data_available ; =1: New data frame recieved | |
262 return | |
263 call compute_mvolts_for_all_sensors | |
264 | |
265 compute_ppo2_common: | |
266 ; o2_mv_sensor1:2 * opt_x_s1:2 = o2_ppo2_sensor1/10000 | |
267 movff o2_mv_sensor1+0,xA+0 | |
268 movff o2_mv_sensor1+1,xA+1 | |
269 movff opt_x_s1+0,xB+0 | |
270 movff opt_x_s1+1,xB+1 | |
271 call mult16x16 ;xA:2*xB:2=xC:4 | |
272 movlw LOW .1000 | |
273 movwf xB+0 | |
274 movlw HIGH .1000 | |
275 movwf xB+1 | |
276 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
277 movlw d'1' | |
278 addwf xC+0,F | |
279 movlw d'0' | |
280 addwfc xC+1,F | |
281 movff xC+0,o2_ppo2_sensor1+0 | |
282 movff xC+1,o2_ppo2_sensor1+1 ; result in 0.01bar | |
283 ; Set to zero if sensor is not active! | |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
284 btfss use_02_sensor1 |
113 | 285 clrf o2_ppo2_sensor1+0 |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
286 btfss use_02_sensor1 |
113 | 287 clrf o2_ppo2_sensor1+1 |
288 | |
289 ; o2_mv_sensor2:2 * opt_x_s1:2 = o2_ppo2_sensor2/10000 | |
290 movff o2_mv_sensor2+0,xA+0 | |
291 movff o2_mv_sensor2+1,xA+1 | |
292 movff opt_x_s2+0,xB+0 | |
293 movff opt_x_s2+1,xB+1 | |
294 call mult16x16 ;xA:2*xB:2=xC:4 | |
295 movlw LOW .1000 | |
296 movwf xB+0 | |
297 movlw HIGH .1000 | |
298 movwf xB+1 | |
299 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
300 movlw d'1' | |
301 addwf xC+0,F | |
302 movlw d'0' | |
303 addwfc xC+1,F | |
304 movff xC+0,o2_ppo2_sensor2+0 | |
305 movff xC+1,o2_ppo2_sensor2+1 ; result in 0.01bar | |
306 ; Set to zero if sensor is not active! | |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
307 btfss use_02_sensor2 |
113 | 308 clrf o2_ppo2_sensor2+0 |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
309 btfss use_02_sensor2 |
113 | 310 clrf o2_ppo2_sensor2+1 |
311 | |
312 ; o2_mv_sensor3:2 * opt_x_s1:2 = o2_ppo2_sensor3/10000 | |
313 movff o2_mv_sensor3+0,xA+0 | |
314 movff o2_mv_sensor3+1,xA+1 | |
315 movff opt_x_s3+0,xB+0 | |
316 movff opt_x_s3+1,xB+1 | |
317 call mult16x16 ;xA:2*xB:2=xC:4 | |
318 movlw LOW .1000 | |
319 movwf xB+0 | |
320 movlw HIGH .1000 | |
321 movwf xB+1 | |
322 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
323 movlw d'1' | |
324 addwf xC+0,F | |
325 movlw d'0' | |
326 addwfc xC+1,F | |
327 movff xC+0,o2_ppo2_sensor3+0 | |
328 movff xC+1,o2_ppo2_sensor3+1 ; result in 0.01bar | |
329 ; Set to zero if sensor is not active! | |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
330 btfss use_02_sensor3 |
113 | 331 clrf o2_ppo2_sensor3+0 |
145
e3ac5b2021bc
NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents:
113
diff
changeset
|
332 btfss use_02_sensor3 |
113 | 333 clrf o2_ppo2_sensor3+1 |
334 | |
335 return ; Done. | |
336 | |
337 | |
338 compute_mvolts_for_all_sensors: ; Compute mV or all sensors (S8 Mode) | |
339 ; compute AD results in 100µV steps (16bit/sensor) | |
340 ; 24bit AD result is in 244,1406541nV | |
341 ; Devide 24bit value through 409,5999512 -> 410 (0,01% error) | |
342 #DEFINE ad2mv_factor .410 | |
343 ; Sensor 1 | |
344 clrf xC+3 | |
345 movff ir_buffer+.6,xC+2 | |
346 movff ir_buffer+.5,xC+1 | |
347 movff ir_buffer+.4,xC+0 | |
348 movlw LOW ad2mv_factor | |
349 movwf xB+0 | |
350 movlw HIGH ad2mv_factor | |
351 movwf xB+1 | |
352 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
353 movff xC+1,o2_mv_sensor1+1 | |
354 movff xC+0,o2_mv_sensor1+0 ; in 100uV steps | |
355 ; Sensor 2 | |
356 clrf xC+3 | |
357 movff ir_buffer+.9,xC+2 | |
358 movff ir_buffer+.8,xC+1 | |
359 movff ir_buffer+.7,xC+0 | |
360 movlw LOW ad2mv_factor | |
361 movwf xB+0 | |
362 movlw HIGH ad2mv_factor | |
363 movwf xB+1 | |
364 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
365 movff xC+1,o2_mv_sensor2+1 | |
366 movff xC+0,o2_mv_sensor2+0 ; in 100uV steps | |
367 ; Sensor 3 | |
368 clrf xC+3 | |
369 movff ir_buffer+.12,xC+2 | |
370 movff ir_buffer+.11,xC+1 | |
371 movff ir_buffer+.10,xC+0 | |
372 movlw LOW ad2mv_factor | |
373 movwf xB+0 | |
374 movlw HIGH ad2mv_factor | |
375 movwf xB+1 | |
376 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
377 movff xC+1,o2_mv_sensor3+1 | |
378 movff xC+0,o2_mv_sensor3+0 ; in 100uV steps | |
379 | |
380 bcf new_s8_data_available ; Clear flag | |
381 return ; Done. | |
382 | |
383 | |
384 | |
385 END |