Mercurial > public > hwos_code
comparison src/calibrate.asm @ 448:aadfe9f2edaf
work on new battery options
author | heinrichsweikamp |
---|---|
date | Tue, 30 Aug 2016 17:26:21 +0200 |
parents | 5c6da9fa5cb0 |
children | b7eb98dbd800 |
comparison
equal
deleted
inserted
replaced
447:f2a1d535347f | 448:aadfe9f2edaf |
---|---|
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 ;============================================================================= |
9 | 9 |
10 #include "hwos.inc" | 10 #include "hwos.inc" |
11 #include "shared_definitions.h" ; Mailbox between c and asm | 11 #include "shared_definitions.h" ; Mailbox between c and asm |
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 | 17 |
180 movff PRODL,xA+0 | 180 movff PRODL,xA+0 |
181 movff PRODH,xA+1 | 181 movff PRODH,xA+1 |
182 ; (%O2*100)*[ambient,mbar]/100 -> xC | 182 ; (%O2*100)*[ambient,mbar]/100 -> xC |
183 movff amb_pressure+0,xB+0 | 183 movff amb_pressure+0,xB+0 |
184 movff amb_pressure+1,xB+1 | 184 movff amb_pressure+1,xB+1 |
185 call mult16x16 ;xA*xB=xC | 185 rcall calibrate_mix2_helper |
186 movlw LOW .100 | |
187 movwf xB+0 | |
188 movlw HIGH .100 | |
189 movwf xB+1 | |
190 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
191 movff o2_mv_sensor1+0,xB+0 | 186 movff o2_mv_sensor1+0,xB+0 |
192 movff o2_mv_sensor1+1,xB+1 | 187 movff o2_mv_sensor1+1,xB+1 |
193 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | 188 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder |
194 ; xC= ppO2/mV | 189 ; xC= ppO2/mV |
195 movff xC+0,opt_x_s1+0 | 190 movff xC+0,opt_x_s1+0 |
200 movff PRODL,xA+0 | 195 movff PRODL,xA+0 |
201 movff PRODH,xA+1 | 196 movff PRODH,xA+1 |
202 ; (%O2*100)*[ambient,mbar]/100 -> xC | 197 ; (%O2*100)*[ambient,mbar]/100 -> xC |
203 movff amb_pressure+0,xB+0 | 198 movff amb_pressure+0,xB+0 |
204 movff amb_pressure+1,xB+1 | 199 movff amb_pressure+1,xB+1 |
205 call mult16x16 ;xA*xB=xC | 200 rcall calibrate_mix2_helper |
206 movlw LOW .100 | |
207 movwf xB+0 | |
208 movlw HIGH .100 | |
209 movwf xB+1 | |
210 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
211 movff o2_mv_sensor2+0,xB+0 | 201 movff o2_mv_sensor2+0,xB+0 |
212 movff o2_mv_sensor2+1,xB+1 | 202 movff o2_mv_sensor2+1,xB+1 |
213 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | 203 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder |
214 ; xC= ppO2/mV | 204 ; xC= ppO2/mV |
215 movff xC+0,opt_x_s2+0 | 205 movff xC+0,opt_x_s2+0 |
220 movff PRODL,xA+0 | 210 movff PRODL,xA+0 |
221 movff PRODH,xA+1 | 211 movff PRODH,xA+1 |
222 ; (%O2*100)*[ambient,mbar]/100 -> xC | 212 ; (%O2*100)*[ambient,mbar]/100 -> xC |
223 movff amb_pressure+0,xB+0 | 213 movff amb_pressure+0,xB+0 |
224 movff amb_pressure+1,xB+1 | 214 movff amb_pressure+1,xB+1 |
225 call mult16x16 ;xA*xB=xC | 215 rcall calibrate_mix2_helper |
226 movlw LOW .100 | |
227 movwf xB+0 | |
228 movlw HIGH .100 | |
229 movwf xB+1 | |
230 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
231 movff o2_mv_sensor3+0,xB+0 | 216 movff o2_mv_sensor3+0,xB+0 |
232 movff o2_mv_sensor3+1,xB+1 | 217 movff o2_mv_sensor3+1,xB+1 |
233 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | 218 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder |
234 ; xC= ppO2/mV | 219 ; xC= ppO2/mV |
235 movff xC+0,opt_x_s3+0 | 220 movff xC+0,opt_x_s3+0 |
266 clrf opt_x_s3+0 | 251 clrf opt_x_s3+0 |
267 clrf opt_x_s3+1 | 252 clrf opt_x_s3+1 |
268 banksel common | 253 banksel common |
269 return | 254 return |
270 | 255 |
256 calibrate_mix2_helper: | |
257 call mult16x16 ;xA*xB=xC | |
258 movlw LOW .100 | |
259 movwf xB+0 | |
260 movlw HIGH .100 | |
261 movwf xB+1 | |
262 goto div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder (And return) | |
263 | |
264 | |
271 compute_ppo2_analog: | 265 compute_ppo2_analog: |
272 call get_analog_inputs | 266 call get_analog_inputs |
273 bra compute_ppo2_common | 267 bra compute_ppo2_common |
274 | 268 |
275 global compute_ppo2 ; compute mv_sensorX and ppo2_sensorX arrays | 269 global compute_ppo2 ; compute mv_sensorX and ppo2_sensorX arrays |
281 bra compute_ppo2_analog ; use analog | 275 bra compute_ppo2_analog ; use analog |
282 | 276 |
283 ; use digital | 277 ; use digital |
284 btfss new_s8_data_available ; =1: New data frame recieved | 278 btfss new_s8_data_available ; =1: New data frame recieved |
285 return | 279 return |
286 call compute_mvolts_for_all_sensors | 280 rcall compute_mvolts_for_all_sensors |
287 | 281 |
288 compute_ppo2_common: | 282 compute_ppo2_common: |
289 ; o2_mv_sensor1:2 * opt_x_s1:2 = o2_ppo2_sensor1/10000 | 283 ; o2_mv_sensor1:2 * opt_x_s1:2 = o2_ppo2_sensor1/10000 |
290 movff o2_mv_sensor1+0,xA+0 | 284 movff o2_mv_sensor1+0,xA+0 |
291 movff o2_mv_sensor1+1,xA+1 | 285 movff o2_mv_sensor1+1,xA+1 |
292 movff opt_x_s1+0,xB+0 | 286 movff opt_x_s1+0,xB+0 |
293 movff opt_x_s1+1,xB+1 | 287 movff opt_x_s1+1,xB+1 |
288 rcall compute_ppo2_common_helper | |
289 movff xC+0,o2_ppo2_sensor1 ; result in 0.01bar | |
290 ; ; Set to zero if sensor is not active! | |
291 ; btfss use_O2_sensor1 | |
292 ; clrf o2_ppo2_sensor1 | |
293 | |
294 ; o2_mv_sensor2:2 * opt_x_s1:2 = o2_ppo2_sensor2/10000 | |
295 movff o2_mv_sensor2+0,xA+0 | |
296 movff o2_mv_sensor2+1,xA+1 | |
297 movff opt_x_s2+0,xB+0 | |
298 movff opt_x_s2+1,xB+1 | |
299 rcall compute_ppo2_common_helper | |
300 movff xC+0,o2_ppo2_sensor2 ; result in 0.01bar | |
301 ; ; Set to zero if sensor is not active! | |
302 ; btfss use_O2_sensor2 | |
303 ; clrf o2_ppo2_sensor2 | |
304 | |
305 ; o2_mv_sensor3:2 * opt_x_s1:2 = o2_ppo2_sensor3/10000 | |
306 movff o2_mv_sensor3+0,xA+0 | |
307 movff o2_mv_sensor3+1,xA+1 | |
308 movff opt_x_s3+0,xB+0 | |
309 movff opt_x_s3+1,xB+1 | |
310 rcall compute_ppo2_common_helper | |
311 movff xC+0,o2_ppo2_sensor3 ; result in 0.01bar | |
312 ; ; Set to zero if sensor is not active! | |
313 ; btfss use_O2_sensor3 | |
314 ; clrf o2_ppo2_sensor3 | |
315 return ; Done. | |
316 | |
317 compute_ppo2_common_helper: | |
294 call mult16x16 ;xA:2*xB:2=xC:4 | 318 call mult16x16 ;xA:2*xB:2=xC:4 |
295 movlw LOW .1000 | 319 movlw LOW .1000 |
296 movwf xB+0 | 320 movwf xB+0 |
297 movlw HIGH .1000 | 321 movlw HIGH .1000 |
298 movwf xB+1 | 322 movwf xB+1 |
299 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | 323 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder |
300 movlw d'1' | 324 movlw d'1' |
301 addwf xC+0,F | 325 addwf xC+0,F |
302 movlw d'0' | 326 movlw d'0' |
303 addwfc xC+1,F | 327 addwfc xC+1,F |
304 tstfsz xC+1 ; ppO2 is higher then 2.55bar? | 328 tstfsz xC+1 ; ppO2 is higher then 2.55bar? |
305 setf xC+0 ; Yes. | 329 setf xC+0 ; Yes. |
306 movff xC+0,o2_ppo2_sensor1 ; result in 0.01bar | 330 return |
307 ; ; Set to zero if sensor is not active! | |
308 ; btfss use_O2_sensor1 | |
309 ; clrf o2_ppo2_sensor1 | |
310 | |
311 ; o2_mv_sensor2:2 * opt_x_s1:2 = o2_ppo2_sensor2/10000 | |
312 movff o2_mv_sensor2+0,xA+0 | |
313 movff o2_mv_sensor2+1,xA+1 | |
314 movff opt_x_s2+0,xB+0 | |
315 movff opt_x_s2+1,xB+1 | |
316 call mult16x16 ;xA:2*xB:2=xC:4 | |
317 movlw LOW .1000 | |
318 movwf xB+0 | |
319 movlw HIGH .1000 | |
320 movwf xB+1 | |
321 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
322 movlw d'1' | |
323 addwf xC+0,F | |
324 movlw d'0' | |
325 addwfc xC+1,F | |
326 tstfsz xC+1 ; ppO2 is higher then 2.55bar? | |
327 setf xC+0 ; Yes. | |
328 movff xC+0,o2_ppo2_sensor2 ; result in 0.01bar | |
329 ; ; Set to zero if sensor is not active! | |
330 ; btfss use_O2_sensor2 | |
331 ; clrf o2_ppo2_sensor2 | |
332 | |
333 ; o2_mv_sensor3:2 * opt_x_s1:2 = o2_ppo2_sensor3/10000 | |
334 movff o2_mv_sensor3+0,xA+0 | |
335 movff o2_mv_sensor3+1,xA+1 | |
336 movff opt_x_s3+0,xB+0 | |
337 movff opt_x_s3+1,xB+1 | |
338 call mult16x16 ;xA:2*xB:2=xC:4 | |
339 movlw LOW .1000 | |
340 movwf xB+0 | |
341 movlw HIGH .1000 | |
342 movwf xB+1 | |
343 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | |
344 movlw d'1' | |
345 addwf xC+0,F | |
346 movlw d'0' | |
347 addwfc xC+1,F | |
348 tstfsz xC+1 ; ppO2 is higher then 2.55bar? | |
349 setf xC+0 ; Yes. | |
350 movff xC+0,o2_ppo2_sensor3 ; result in 0.01bar | |
351 ; ; Set to zero if sensor is not active! | |
352 ; btfss use_O2_sensor3 | |
353 ; clrf o2_ppo2_sensor3 | |
354 return ; Done. | |
355 | |
356 | 331 |
357 compute_mvolts_for_all_sensors: ; Compute mV or all sensors (S8 Mode) | 332 compute_mvolts_for_all_sensors: ; Compute mV or all sensors (S8 Mode) |
358 ; compute AD results in 100µV steps (16bit/sensor) | 333 ; compute AD results in 100µV steps (16bit/sensor) |
359 ; 24bit AD result is in 244,1406541nV | 334 ; 24bit AD result is in 244,1406541nV |
360 ; Devide 24bit value through 409,5999512 -> 410 (0,01% error) | 335 ; Devide 24bit value through 409,5999512 -> 410 (0,01% error) |
399 bcf new_s8_data_available ; Clear flag | 374 bcf new_s8_data_available ; Clear flag |
400 return ; Done. | 375 return ; Done. |
401 | 376 |
402 global transmit_setpoint ; Transmit current setpoint from WREG (in cbar) to external electronics | 377 global transmit_setpoint ; Transmit current setpoint from WREG (in cbar) to external electronics |
403 transmit_setpoint: | 378 transmit_setpoint: |
379 return | |
404 btfss s8_digital ; S8 Digital? | 380 btfss s8_digital ; S8 Digital? |
405 return ; No, ignore | 381 return ; No, ignore |
406 | 382 |
407 ; Yes, transmit setpoint from WREG | 383 ; Yes, transmit setpoint from WREG |
408 movwf temp2 ; Store setpoint | 384 movwf temp2 ; Store setpoint |
420 movff temp2,WREG ; SP in cbar | 396 movff temp2,WREG ; SP in cbar |
421 addwf temp1,F | 397 addwf temp1,F |
422 movff WREG,TXREG2 | 398 movff WREG,TXREG2 |
423 call rs232_wait_tx2 | 399 call rs232_wait_tx2 |
424 | 400 |
425 movff temp1,TXREG2 ; Chksum | 401 movff temp1,TXREG2 ; Chksum |
426 call rs232_wait_tx2 | 402 call rs232_wait_tx2 |
427 return | 403 return |
428 | 404 |
429 | 405 |
430 END | 406 END |