annotate src/calibrate.asm @ 631:185ba2f91f59

3.09 beta 1 release
author heinrichsweikamp
date Fri, 28 Feb 2020 15:45:07 +0100
parents c40025d8e750
children 4050675965ea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
113
heinrichsweikamp
parents:
diff changeset
1 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
2 ;
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
3 ; File calibration.asm combined next generation V3.08.8
113
heinrichsweikamp
parents:
diff changeset
4 ;
heinrichsweikamp
parents:
diff changeset
5 ; o2 sensor calibration subroutines
heinrichsweikamp
parents:
diff changeset
6 ;
heinrichsweikamp
parents:
diff changeset
7 ; Copyright (c) 2014, Heinrichs Weikamp, all right reserved.
heinrichsweikamp
parents:
diff changeset
8 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
9
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
10 #include "hwos.inc"
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
11 #include "shared_definitions.h" ; mailbox between c and asm
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
12 #include "math.inc"
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
13 #include "adc_lightsensor.inc"
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
14 #include "eeprom_rs232.inc"
113
heinrichsweikamp
parents:
diff changeset
15
heinrichsweikamp
parents:
diff changeset
16
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
17 calibrate CODE
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
18
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
19 ;=============================================================================
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
20
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
21 IFDEF _external_sensor
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
22
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
23 global transmit_setpoint ; transmit current setpoint from WREG (in cbar) to external electronics
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
24 transmit_setpoint:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
25 return ; !!!! FUNCTION IS CURRENTLY DISABLED !!!!
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
26 btfss s8_digital_avail ; do we have a digital S8 interface?
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
27 return ; NO - ignore
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
28 ; YES - transmit setpoint from WREG
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
29 clrf lo ; initialize checksum
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
30 movff char_I_const_ppO2,hi ; copy setpoint value to hi
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
31 movlw 0xAA ; start byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
32 rcall tx_to_HUD ; transmit to HUD
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
33 movlw 0x60 ; command new SP
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
34 rcall tx_to_HUD ; transmit to HUD
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
35 movff hi,WREG ; SP in cbar
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
36 rcall tx_to_HUD ; transmit to HUD
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
37 movff lo,WREG ; checksum
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
38 rcall tx_to_HUD_cs ; transmit checksum
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
39 return
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
40
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
41 tx_to_HUD: ; entry point to transmit a byte to the HUD
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
42 addwf lo,F ; add byte to checksum
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
43 tx_to_HUD_cs: ; entry point to transmit the checksum
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
44 movff WREG,TXREG2 ; transmit byte
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 623
diff changeset
45 call ir_s8_wait_tx ; wait for UART
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
46 return
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
47
145
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
48
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
49 global calibrate_mix
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
50 calibrate_mix:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
51 ; set usage and calibration flags as per default
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
52 bsf use_O2_sensor1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
53 bsf use_O2_sensor2
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
54 bsf use_O2_sensor3
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
55 bsf sensor1_calibrated_ok
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
56 bsf sensor2_calibrated_ok
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
57 bsf sensor3_calibrated_ok
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
58
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
59 ; ISR-safe 2 byte copy of the current pressure to xB for later use
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
60 SMOVII pressure_abs,xB
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
61
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
62 ; check for HUD
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
63 btfss s8_digital_avail ; do we have a digital S8 interface?
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
64 bra calibrate_mix1 ; NO - skip HUD part
145
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
65
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
66 ; calibrate any S8-connected HUD
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
67 clrf lo ; initialize checksum
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
68 movlw 0xAA ; start byte
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
69 rcall tx_to_HUD ; transmit to HUD
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
70 movlw 0x31 ; calibration command
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
71 rcall tx_to_HUD ; transmit to HUD
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
72 movff opt_calibration_O2_ratio,WREG ; calibration gas %O2
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
73 rcall tx_to_HUD ; transmit to HUD
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
74 movff xB+0,WREG ; current absolute pressure low byte
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
75 rcall tx_to_HUD ; transmit to HUD
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
76 movff xB+1,WREG ; current absolute pressure high byte
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
77 rcall tx_to_HUD ; transmit to HUD
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
78 movff lo,WREG ; checksum
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
79 rcall tx_to_HUD_cs ; transmit to HUD
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
80 ; bra calibrate_mix2
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
81
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
82 ; calibrate internal sensors
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
83 calibrate_mix1: ; compute %O2 * 100 * absolute pressure [mbar] / 100
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
84 movff opt_calibration_O2_ratio,WREG
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
85 mullw .100
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
86 MOVII PROD,xA
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
87 call mult16x16 ; xA*xB=xC
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
88 MOVLI .100,xB
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
89 call div32x16 ; xC:4 = xC:4 / xB:2 with xA as remainder
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
90
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
91 ; keep a copy of the result
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
92 movff xC+0,mpr+0
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
93 movff xC+1,mpr+1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
94 movff xC+2,mpr+2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
95 movff xC+3,mpr+3
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
96
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
97 ; compute factor for sensor 1
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
98 MOVII sensor1_mv,xB
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
99 call div32x16 ; xC:4 = xC:4 / xB:2 with xA as remainder
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
100 MOVII xC,opt_x_s1 ; xC = ppO2/mV as factor for sensor 1
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
101
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
102 ; restore result
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
103 movff mpr+0,xC+0
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
104 movff mpr+1,xC+1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
105 movff mpr+2,xC+2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
106 movff mpr+3,xC+3
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
107
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
108 ; compute factor for sensor 2
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
109 MOVII sensor2_mv,xB
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
110 call div32x16 ; xC:4 = xC:4 / xB:2 with xA as remainder
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
111 MOVII xC,opt_x_s2 ; xC = ppO2/mV as factor for sensor 2
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
112
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
113 ; restore result
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
114 movff mpr+0,xC+0
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
115 movff mpr+1,xC+1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
116 movff mpr+2,xC+2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
117 movff mpr+3,xC+3
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
118
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
119 ; compute factor for sensor 3
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
120 MOVII sensor3_mv,xB
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
121 call div32x16 ; xC:4 = xC:4 / xB:2 with xA as remainder
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
122 MOVII xC,opt_x_s3 ; xC = ppO2/mV as factor for sensor 3
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
123
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
124 ; check sensor 1 for min/max mV
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
125 MOVII sensor1_mv,sub_a ; get mV from sensor 1
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
126 rcall calibrate_mix_helper ; check mV for min/max thresholds, returns with WREG = 0 if ok, else WREG = 1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
127 TSTFSZ WREG ; sensor mV within thresholds?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
128 bcf use_O2_sensor1 ; NO - clear usage flag
145
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
129
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
130 ; check sensor 2 for min/max mV
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
131 MOVII sensor2_mv,sub_a ; get mV from sensor 2
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
132 rcall calibrate_mix_helper ; check mV for min/max thresholds, returns with WREG = 0 if ok, else WREG = 1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
133 TSTFSZ WREG ; sensor mV within thresholds?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
134 bcf use_O2_sensor2 ; NO - clear usage flag
145
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
135
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
136 ; check sensor 3 for min/max mV
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
137 MOVII sensor3_mv,sub_a ; get mV from sensor 3
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
138 rcall calibrate_mix_helper ; check mV for min/max thresholds, returns with WREG = 0 if ok, else WREG = 1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
139 TSTFSZ WREG ; sensor mV within thresholds?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
140 bcf use_O2_sensor3 ; NO - clear usage flag
145
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
141
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
142 calibrate_mix2:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
143 ; check for HUD
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
144 btfss hud_connection_ok ; HUD connection existing?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
145 bra calibrate_mix3 ; NO - skip HUD part
145
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
146
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
147 ; copy disable flags from HUD digital input
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
148 btfss sensor1_active
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
149 bcf use_O2_sensor1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
150 btfss sensor2_active
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
151 bcf use_O2_sensor2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
152 btfss sensor3_active
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
153 bcf use_O2_sensor3
113
heinrichsweikamp
parents:
diff changeset
154
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
155 calibrate_mix3:
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
156 ; clear calibration flags if sensors are not found to be ok
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
157 btfss use_O2_sensor1 ; sensor 1 out of range?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
158 bcf sensor1_calibrated_ok ; YES - disable this sensor
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
159 btfss use_O2_sensor2 ; sensor 2 out of range?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
160 bcf sensor2_calibrated_ok ; YES - disable this sensor
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
161 btfss use_O2_sensor3 ; sensor 3 out of range?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
162 bcf sensor3_calibrated_ok ; YES - disable this sensor
113
heinrichsweikamp
parents:
diff changeset
163
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
164 ; when no sensor is found, enable all three to show error state and clear calibration factors
192
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
165 btfsc use_O2_sensor1
113
heinrichsweikamp
parents:
diff changeset
166 return
192
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
167 btfsc use_O2_sensor2
113
heinrichsweikamp
parents:
diff changeset
168 return
192
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
169 btfsc use_O2_sensor3
113
heinrichsweikamp
parents:
diff changeset
170 return
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
171
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
172 ; enable all sensors
192
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
173 bsf use_O2_sensor1
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
174 bsf use_O2_sensor2
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
175 bsf use_O2_sensor3
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
176 ; clear calibration factors
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
177 banksel opt_x_s1 ; switch to bank options table
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
178 CLRI opt_x_s1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
179 CLRI opt_x_s2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
180 CLRI opt_x_s3
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
181 banksel common ; back to bank common
113
heinrichsweikamp
parents:
diff changeset
182 return
heinrichsweikamp
parents:
diff changeset
183
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
184 calibrate_mix_helper:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
185 MOVLI min_mv,sub_b ; load minimum threshold into sub_b
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
186 call sub16 ; sub_c = sub_a - sub_b
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
187 btfsc neg_flag ; sensor mV lower than minimum threshold?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
188 retlw .1 ; YES - return signaling threshold violation
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
189 MOVLI max_mv,sub_b ; load maximum threshold into sub_b
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
190 call sub16 ; sub_c = sub_a - sub_b
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
191 btfss neg_flag ; sensor mV higher than maximum threshold?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
192 retlw .1 ; YES - return signaling threshold violation
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
193 retlw .0 ; NO - return signaling min/max ok
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
194
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 352
diff changeset
195
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
196 global compute_mvolts_for_all_sensors
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
197 compute_mvolts_for_all_sensors: ; compute mV or all sensors (S8 mode)
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
198 ; compute AD results in 100 µV steps (16 bit/sensor)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
199 ; 24 bit AD result is in 244.1406541 nV
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
200 ; divide 24 bit value by 409.5999512 -> 410 with only 0.01% error
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
201 #DEFINE ad2mv_factor .410
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
202
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
203 MOVLI ad2mv_factor,xB
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
204
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
205 ; Sensor 1
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
206 SMOVTT s8_rawdata_sensor1,xC ; ISR-safe copy of 3 bytes to xC
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
207 clrf xC+3 ; clear MSB of xC
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
208 call div32x16 ; xC:4 = xC:4 / xB:2 with xA as remainder
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
209 MOVII xC,sensor1_mv ; in 100 µV steps
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
210
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
211 ; Sensor 2
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
212 SMOVTT s8_rawdata_sensor2,xC ; ISR-safe copy of 3 bytes to xC
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
213 clrf xC+3 ; clear MSB of xC
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
214 call div32x16 ; xC:4 = xC:4 / xB:2 with xA as remainder
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
215 MOVII xC,sensor2_mv ; in 100 µV steps
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
216
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
217 ; Sensor 3
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
218 SMOVTT s8_rawdata_sensor3,xC ; ISR-safe copy of 3 bytes to xC
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
219 clrf xC+3 ; clear MSB of xC
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
220 call div32x16 ; xC:4 = xC:4 / xB:2 with xA as remainder
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
221 MOVII xC,sensor3_mv ; in 100 µV steps
352
5c6da9fa5cb0 add setpoint change to first sample in CCR mode
heinrichsweikamp
parents: 275
diff changeset
222
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 582
diff changeset
223 return ; done
113
heinrichsweikamp
parents:
diff changeset
224
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
225 ENDIF ; _external_sensor
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
226
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
227 ;=============================================================================
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
228
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
229 END