annotate src/calibrate.asm @ 603:00b24fb4324d

second method to detect a full charge
author heinrichsweikamp
date Thu, 11 Oct 2018 21:06:29 +0200
parents b455b31ce022
children ca4556fb60b9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
113
heinrichsweikamp
parents:
diff changeset
1 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
2 ;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
3 ; File calibration.asm REFACTORED VERSION V2.98
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"
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
11 #include "shared_definitions.h" ; Mailbox between c and asm
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
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
19 global check_sensors ; Check O2 sensor thresholds for fallback and voting logic
145
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
20 check_sensors:
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
21 ; Check min_mv
145
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
22 movff o2_mv_sensor1+0, sub_a+0
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
23 movff o2_mv_sensor1+1, sub_a+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
24 movlw LOW min_mv
145
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
25 movwf sub_b+0
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
26 movlw HIGH min_mv
145
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
27 movwf sub_b+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
28 call sub16 ; sub_c = sub_a - sub_b
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
29 bsf use_O2_sensor1 ;=1: Use this sensor for deco
145
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
30 btfsc neg_flag
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
31 bcf use_O2_sensor1 ;=1: Use this sensor for deco
145
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
32
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
33 movff o2_mv_sensor2+0, sub_a+0
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
34 movff o2_mv_sensor2+1, sub_a+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
35 movlw LOW min_mv
145
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
36 movwf sub_b+0
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
37 movlw HIGH min_mv
145
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
38 movwf sub_b+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
39 call sub16 ; sub_c = sub_a - sub_b
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
40 bsf use_O2_sensor2 ;=1: Use this sensor for deco
145
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
41 btfsc neg_flag
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
42 bcf use_O2_sensor2 ;=1: Use this sensor for deco
145
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
43
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
44 movff o2_mv_sensor3+0, sub_a+0
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
45 movff o2_mv_sensor3+1, sub_a+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
46 movlw LOW min_mv
145
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
47 movwf sub_b+0
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
48 movlw HIGH min_mv
145
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
49 movwf sub_b+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
50 call sub16 ; sub_c = sub_a - sub_b
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
51 bsf use_O2_sensor3 ;=1: Use this sensor for deco
145
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
52 btfsc neg_flag
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
53 bcf use_O2_sensor3 ;=1: Use this sensor for deco
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
54
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
55 ; Check max_mv
145
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
56 movff o2_mv_sensor1+0, sub_a+0
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
57 movff o2_mv_sensor1+1, sub_a+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
58 movlw LOW max_mv
145
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
59 movwf sub_b+0
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
60 movlw HIGH max_mv
145
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
61 movwf sub_b+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
62 call sub16 ; sub_c = sub_a - sub_b
145
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
63 btfss neg_flag
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
64 bcf use_O2_sensor1 ;=1: Use this sensor for deco
145
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
65
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
66 movff o2_mv_sensor2+0, sub_a+0
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
67 movff o2_mv_sensor2+1, sub_a+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
68 movlw LOW max_mv
145
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
69 movwf sub_b+0
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
70 movlw HIGH max_mv
145
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
71 movwf sub_b+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
72 call sub16 ; sub_c = sub_a - sub_b
145
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
73 btfss neg_flag
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
74 bcf use_O2_sensor2 ;=1: Use this sensor for deco
145
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
75
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
76 movff o2_mv_sensor3+0, sub_a+0
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
77 movff o2_mv_sensor3+1, sub_a+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
78 movlw LOW max_mv
145
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
79 movwf sub_b+0
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
80 movlw HIGH max_mv
145
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
81 movwf sub_b+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
82 call sub16 ; sub_c = sub_a - sub_b
145
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
83 btfss neg_flag
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
84 bcf use_O2_sensor3 ;=1: Use this sensor for deco
145
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
85
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
86 btfss hud_connection_ok ;=1: HUD connection ok
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
87 bra check_sensor2 ; No HUD/Digital data
145
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
88
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
89 ; Copy disable flags from digital input
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
90 btfss sensor1_active
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
91 bcf use_O2_sensor1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
92 btfss sensor2_active
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
93 bcf use_O2_sensor2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
94 btfss sensor3_active
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
95 bcf use_O2_sensor3
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
96 return
145
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
97
189
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
98 check_sensor2:
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
99 ; Copy disable flags from internal calibration routine
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
100 btfss sensor1_calibrated_ok
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
101 bcf use_O2_sensor1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
102 btfss sensor2_calibrated_ok
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
103 bcf use_O2_sensor2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
104 btfss sensor3_calibrated_ok
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
105 bcf use_O2_sensor3
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
106 return
189
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
107
192
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
108
113
heinrichsweikamp
parents:
diff changeset
109 global calibrate_mix
heinrichsweikamp
parents:
diff changeset
110 calibrate_mix:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
111 ; calibrate S8 HUD
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
112 btfss s8_digital ; S8 Digital?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
113 bra calibrate_mix2 ; No
113
heinrichsweikamp
parents:
diff changeset
114
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
115 ; Yes, calibrate any S8-connected HUD
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
116 clrf lo ; Checksum
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
117 movlw 0xAA ; Start Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
118 addwf lo,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
119 movff WREG,TXREG2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
120 call rs232_wait_tx2
113
heinrichsweikamp
parents:
diff changeset
121
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
122 movlw 0x31 ; Calibrate
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
123 addwf lo,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
124 movff WREG,TXREG2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
125 call rs232_wait_tx2
113
heinrichsweikamp
parents:
diff changeset
126
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
127 movff opt_calibration_O2_ratio,WREG ; Calibration gas %O2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
128 addwf lo,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
129 movff WREG,TXREG2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
130 call rs232_wait_tx2
113
heinrichsweikamp
parents:
diff changeset
131
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
132 movff amb_pressure+0,WREG ; Ambient pressure
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
133 addwf lo,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
134 movff WREG,TXREG2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
135 call rs232_wait_tx2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
136 movff amb_pressure+1,WREG
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
137 addwf lo,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
138 movff WREG,TXREG2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
139 call rs232_wait_tx2
113
heinrichsweikamp
parents:
diff changeset
140
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
141 movff lo,TXREG2 ; Checksum
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
142 call rs232_wait_tx2
113
heinrichsweikamp
parents:
diff changeset
143
heinrichsweikamp
parents:
diff changeset
144 calibrate_mix2:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
145 movff opt_calibration_O2_ratio,WREG ; Calibration gas %O2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
146 mullw .100
113
heinrichsweikamp
parents:
diff changeset
147 movff PRODL,xA+0
heinrichsweikamp
parents:
diff changeset
148 movff PRODH,xA+1
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
149 ; (%O2*100)*[ambient,mbar]/100 -> xC
113
heinrichsweikamp
parents:
diff changeset
150 movff amb_pressure+0,xB+0
heinrichsweikamp
parents:
diff changeset
151 movff amb_pressure+1,xB+1
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 352
diff changeset
152 rcall calibrate_mix2_helper
113
heinrichsweikamp
parents:
diff changeset
153 movff o2_mv_sensor1+0,xB+0
heinrichsweikamp
parents:
diff changeset
154 movff o2_mv_sensor1+1,xB+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
155 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
113
heinrichsweikamp
parents:
diff changeset
156 ; xC= ppO2/mV
heinrichsweikamp
parents:
diff changeset
157 movff xC+0,opt_x_s1+0
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
158 movff xC+1,opt_x_s1+1 ; Factor for Sensor1
113
heinrichsweikamp
parents:
diff changeset
159
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
160 movff opt_calibration_O2_ratio,WREG ; Calibration gas %O2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
161 mullw .100
113
heinrichsweikamp
parents:
diff changeset
162 movff PRODL,xA+0
heinrichsweikamp
parents:
diff changeset
163 movff PRODH,xA+1
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
164 ; (%O2*100)*[ambient,mbar]/100 -> xC
113
heinrichsweikamp
parents:
diff changeset
165 movff amb_pressure+0,xB+0
heinrichsweikamp
parents:
diff changeset
166 movff amb_pressure+1,xB+1
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 352
diff changeset
167 rcall calibrate_mix2_helper
113
heinrichsweikamp
parents:
diff changeset
168 movff o2_mv_sensor2+0,xB+0
heinrichsweikamp
parents:
diff changeset
169 movff o2_mv_sensor2+1,xB+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
170 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
113
heinrichsweikamp
parents:
diff changeset
171 ; xC= ppO2/mV
heinrichsweikamp
parents:
diff changeset
172 movff xC+0,opt_x_s2+0
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
173 movff xC+1,opt_x_s2+1 ; Factor for Sensor2
113
heinrichsweikamp
parents:
diff changeset
174
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
175 movff opt_calibration_O2_ratio,WREG ; Calibration gas %O2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
176 mullw .100
113
heinrichsweikamp
parents:
diff changeset
177 movff PRODL,xA+0
heinrichsweikamp
parents:
diff changeset
178 movff PRODH,xA+1
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
179 ; (%O2*100)*[ambient,mbar]/100 -> xC
113
heinrichsweikamp
parents:
diff changeset
180 movff amb_pressure+0,xB+0
heinrichsweikamp
parents:
diff changeset
181 movff amb_pressure+1,xB+1
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 352
diff changeset
182 rcall calibrate_mix2_helper
113
heinrichsweikamp
parents:
diff changeset
183 movff o2_mv_sensor3+0,xB+0
heinrichsweikamp
parents:
diff changeset
184 movff o2_mv_sensor3+1,xB+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
185 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
113
heinrichsweikamp
parents:
diff changeset
186 ; xC= ppO2/mV
heinrichsweikamp
parents:
diff changeset
187 movff xC+0,opt_x_s3+0
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
188 movff xC+1,opt_x_s3+1 ; Factor for Sensor3
113
heinrichsweikamp
parents:
diff changeset
189
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
190 bsf sensor1_calibrated_ok
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
191 bsf sensor2_calibrated_ok
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
192 bsf sensor3_calibrated_ok ; Set flags prior check
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
193
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
194 rcall check_sensors ; Check O2 sensor thresholds min_mv and max_mv and set use_02_sensorX flags
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
195 ; initialize internal calibration flags
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
196 btfss use_O2_sensor1 ; Sensor out of range?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
197 bcf sensor1_calibrated_ok ; Yes, disable this sensor
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
198 btfss use_O2_sensor2 ; Sensor out of range?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
199 bcf sensor2_calibrated_ok ; Yes, disable this sensor
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
200 btfss use_O2_sensor3 ; Sensor out of range?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
201 bcf sensor3_calibrated_ok ; Yes, disable this sensor
113
heinrichsweikamp
parents:
diff changeset
202
heinrichsweikamp
parents:
diff changeset
203 ; When no sensor is found, enable all three to show error state
192
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
204 btfsc use_O2_sensor1
113
heinrichsweikamp
parents:
diff changeset
205 return
192
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
206 btfsc use_O2_sensor2
113
heinrichsweikamp
parents:
diff changeset
207 return
192
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
208 btfsc use_O2_sensor3
113
heinrichsweikamp
parents:
diff changeset
209 return
192
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
210 bsf use_O2_sensor1
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
211 bsf use_O2_sensor2
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
212 bsf use_O2_sensor3
113
heinrichsweikamp
parents:
diff changeset
213 ; Clear factors
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
214 banksel opt_x_s1+0
113
heinrichsweikamp
parents:
diff changeset
215 clrf opt_x_s1+0
heinrichsweikamp
parents:
diff changeset
216 clrf opt_x_s1+1
heinrichsweikamp
parents:
diff changeset
217 clrf opt_x_s2+0
heinrichsweikamp
parents:
diff changeset
218 clrf opt_x_s2+1
heinrichsweikamp
parents:
diff changeset
219 clrf opt_x_s3+0
heinrichsweikamp
parents:
diff changeset
220 clrf opt_x_s3+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
221 banksel common
113
heinrichsweikamp
parents:
diff changeset
222 return
heinrichsweikamp
parents:
diff changeset
223
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
224
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
225 calibrate_mix2_helper:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
226 call mult16x16 ; xA*xB=xC
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
227 movlw LOW .100
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 352
diff changeset
228 movwf xB+0
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
229 movlw HIGH .100
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 352
diff changeset
230 movwf xB+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
231 goto div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder (And return)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
232
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 352
diff changeset
233
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
234 global compute_mvolts_for_all_sensors
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
235 compute_mvolts_for_all_sensors: ; Compute mV or all sensors (S8 Mode)
113
heinrichsweikamp
parents:
diff changeset
236 ; compute AD results in 100µV steps (16bit/sensor)
heinrichsweikamp
parents:
diff changeset
237 ; 24bit AD result is in 244,1406541nV
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
238 ; Divide 24bit value through 409,5999512 -> 410 (0,01% error)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
239 #DEFINE ad2mv_factor .410
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
240 ; Sensor 1
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
241 clrf xC+3
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
242 movff s8_rawdata_sensor1+2,xC+2
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
243 movff s8_rawdata_sensor1+1,xC+1
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
244 movff s8_rawdata_sensor1+0,xC+0
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
245 movlw LOW ad2mv_factor
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
246 movwf xB+0
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
247 movlw HIGH ad2mv_factor
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
248 movwf xB+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
249 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
250 movff xC+1,o2_mv_sensor1+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
251 movff xC+0,o2_mv_sensor1+0 ; in 100uV steps
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
252 ; Sensor 2
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
253 clrf xC+3
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
254 movff s8_rawdata_sensor2+2,xC+2
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
255 movff s8_rawdata_sensor2+1,xC+1
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
256 movff s8_rawdata_sensor2+0,xC+0
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
257 movlw LOW ad2mv_factor
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
258 movwf xB+0
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
259 movlw HIGH ad2mv_factor
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
260 movwf xB+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
261 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
262 movff xC+1,o2_mv_sensor2+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
263 movff xC+0,o2_mv_sensor2+0 ; in 100uV steps
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
264 ; Sensor 3
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
265 clrf xC+3
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
266 movff s8_rawdata_sensor3+2,xC+2
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
267 movff s8_rawdata_sensor3+1,xC+1
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
268 movff s8_rawdata_sensor3+0,xC+0
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
269 movlw LOW ad2mv_factor
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
270 movwf xB+0
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
271 movlw HIGH ad2mv_factor
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
272 movwf xB+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
273 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
274 movff xC+1,o2_mv_sensor3+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
275 movff xC+0,o2_mv_sensor3+0 ; in 100uV steps
113
heinrichsweikamp
parents:
diff changeset
276
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
277 bcf new_s8_data_available ; Clear flag
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
278 return ; Done.
113
heinrichsweikamp
parents:
diff changeset
279
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
280
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
281 global transmit_setpoint ; Transmit current setpoint from WREG (in cbar) to external electronics
352
5c6da9fa5cb0 add setpoint change to first sample in CCR mode
heinrichsweikamp
parents: 275
diff changeset
282 transmit_setpoint:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
283 return ; !!!! FUNCTION IS CURRENTLY DISABLED !!!!
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
284 btfss s8_digital ; S8 Digital?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
285 return ; No, ignore
352
5c6da9fa5cb0 add setpoint change to first sample in CCR mode
heinrichsweikamp
parents: 275
diff changeset
286
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
287 ; Yes, transmit setpoint from WREG
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
288 movwf hi ; Store setpoint
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
289 clrf lo ; Checksum
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
290 movlw 0xAA ; Start Byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
291 addwf lo,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
292 movff WREG,TXREG2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
293 call rs232_wait_tx2
352
5c6da9fa5cb0 add setpoint change to first sample in CCR mode
heinrichsweikamp
parents: 275
diff changeset
294
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
295 movlw 0x60 ; New SP
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
296 addwf lo,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
297 movff WREG,TXREG2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
298 call rs232_wait_tx2
352
5c6da9fa5cb0 add setpoint change to first sample in CCR mode
heinrichsweikamp
parents: 275
diff changeset
299
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
300 movff hi,WREG ; SP in cbar
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
301 addwf lo,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
302 movff WREG,TXREG2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
303 call rs232_wait_tx2
352
5c6da9fa5cb0 add setpoint change to first sample in CCR mode
heinrichsweikamp
parents: 275
diff changeset
304
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
305 movff lo,TXREG2 ; Checksum
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
306 call rs232_wait_tx2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 564
diff changeset
307 return
113
heinrichsweikamp
parents:
diff changeset
308
heinrichsweikamp
parents:
diff changeset
309
heinrichsweikamp
parents:
diff changeset
310 END