annotate src/calibrate.asm @ 564:54346c651b6a

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