annotate src/calibrate.asm @ 313:0ce5fa241b8e

FIX minor comment about deco offset unit...
author jDG
date Wed, 10 Jun 2015 16:03:21 +0200
parents 653a3ab08062
children 5c6da9fa5cb0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
113
heinrichsweikamp
parents:
diff changeset
1 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
2 ;
heinrichsweikamp
parents:
diff changeset
3 ; File calibration.asm
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
275
653a3ab08062 rename into hwOS
heinrichsweikamp
parents: 268
diff changeset
10 #include "hwos.inc"
113
heinrichsweikamp
parents:
diff changeset
11 #include "shared_definitions.h" ; Mailbox between c and asm
heinrichsweikamp
parents:
diff changeset
12 #include "math.inc"
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
192
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
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:
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
20 ; Check min_mv
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
21 movff o2_mv_sensor1+0, sub_a+0
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
22 movff o2_mv_sensor1+1, sub_a+1
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
23 movlw LOW min_mv
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
24 movwf sub_b+0
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
25 movlw HIGH min_mv
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
26 movwf sub_b+1
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
27 call sub16 ; sub_c = sub_a - sub_b
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
145
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
53 ; Check max_mv
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
54 movff o2_mv_sensor1+0, sub_a+0
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
55 movff o2_mv_sensor1+1, sub_a+1
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
56 movlw LOW max_mv
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
57 movwf sub_b+0
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
58 movlw HIGH max_mv
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
59 movwf sub_b+1
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
60 call sub16 ; sub_c = sub_a - sub_b
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
61 btfss neg_flag
192
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
62 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
63
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
64 movff o2_mv_sensor2+0, sub_a+0
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
65 movff o2_mv_sensor2+1, sub_a+1
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
66 movlw LOW max_mv
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
67 movwf sub_b+0
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
68 movlw HIGH max_mv
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
69 movwf sub_b+1
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
70 call sub16 ; sub_c = sub_a - sub_b
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
71 btfss neg_flag
192
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
72 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
73
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
74 movff o2_mv_sensor3+0, sub_a+0
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
75 movff o2_mv_sensor3+1, sub_a+1
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
76 movlw LOW max_mv
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
77 movwf sub_b+0
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
78 movlw HIGH max_mv
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
79 movwf sub_b+1
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
80 call sub16 ; sub_c = sub_a - sub_b
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
81 btfss neg_flag
192
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
82 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
83
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
84 btfss hud_connection_ok ;=1: HUD connection ok
189
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
85 bra check_sensor2 ; No HUD/Digital data
145
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
86
147
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 145
diff changeset
87 ; Copy disable flags from digital input
227
03946aa48fa5 NEW: Support for hwHUD without the LED module
heinrichsweikamp
parents: 224
diff changeset
88 btfss sensor1_active
03946aa48fa5 NEW: Support for hwHUD without the LED module
heinrichsweikamp
parents: 224
diff changeset
89 bcf use_O2_sensor1
03946aa48fa5 NEW: Support for hwHUD without the LED module
heinrichsweikamp
parents: 224
diff changeset
90 btfss sensor2_active
03946aa48fa5 NEW: Support for hwHUD without the LED module
heinrichsweikamp
parents: 224
diff changeset
91 bcf use_O2_sensor2
03946aa48fa5 NEW: Support for hwHUD without the LED module
heinrichsweikamp
parents: 224
diff changeset
92 btfss sensor3_active
03946aa48fa5 NEW: Support for hwHUD without the LED module
heinrichsweikamp
parents: 224
diff changeset
93 bcf use_O2_sensor3
192
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
94 bra check_sensor3 ; Check for voting logic
145
e3ac5b2021bc NEW: Setpoint-Fallback option for external O2 sensor failure
heinrichsweikamp
parents: 113
diff changeset
95
189
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
96 check_sensor2:
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
97 ; Copy disable flags from internal calibration routine
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
98 btfss sensor1_calibrated_ok
192
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
99 bcf use_O2_sensor1
189
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
100 btfss sensor2_calibrated_ok
192
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
101 bcf use_O2_sensor2
189
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
102 btfss sensor3_calibrated_ok
192
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
103 bcf use_O2_sensor3
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
104 check_sensor3: ; Check for voting logic
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
105 bsf voting_logic_sensor1
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
106 movff o2_ppo2_sensor1,temp1
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
107 rcall check_sensor_voting_common
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
108 incfsz WREG ; Was Wreg=255?
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
109 bcf voting_logic_sensor1 ; Yes, ignore this sensor
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
110 bsf voting_logic_sensor2
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
111 movff o2_ppo2_sensor2,temp1
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
112 rcall check_sensor_voting_common
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
113 incfsz WREG ; Was Wreg=255?
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
114 bcf voting_logic_sensor2 ; Yes, ignore this sensor
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
115 bsf voting_logic_sensor3
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
116 movff o2_ppo2_sensor3,temp1
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
117 rcall check_sensor_voting_common
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
118 incfsz WREG ; Was Wreg=255?
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
119 bcf voting_logic_sensor3 ; Yes, ignore this sensor
189
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
120 return
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
121
192
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
122
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
123 check_sensor_voting_common:
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
124 movf temp1,W
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
125 cpfsgt sensor_setpoint
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
126 bra check_sensor_voting_common2 ; temp1<sensor_setpoint
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
127 ; temp1>sensor_setpoint
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
128 movf temp1,W
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
129 subwf sensor_setpoint,W
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
130 movwf temp1
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
131 check_sensor_voting_common1:
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
132 movlw sensor_voting_logic_threshold ; Threshold in 0.01bar
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
133 cpfsgt temp1
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
134 retlw .255 ; Within range
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
135 retlw .0 ; Out of range
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
136 check_sensor_voting_common2:
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
137 ; temp1<sensor_setpoint
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
138 movf sensor_setpoint,W
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
139 subwf temp1,F
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
140 bra check_sensor_voting_common1
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
141
113
heinrichsweikamp
parents:
diff changeset
142 global calibrate_mix
heinrichsweikamp
parents:
diff changeset
143 calibrate_mix:
heinrichsweikamp
parents:
diff changeset
144 ; calibrate S8 HUD
heinrichsweikamp
parents:
diff changeset
145 btfss s8_digital ; S8 Digital?
heinrichsweikamp
parents:
diff changeset
146 bra calibrate_mix2 ; No
heinrichsweikamp
parents:
diff changeset
147
189
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
148 ; Yes, calibrate any S8-connected HUD
113
heinrichsweikamp
parents:
diff changeset
149 clrf temp1 ; Chksum
heinrichsweikamp
parents:
diff changeset
150 movlw 0xAA ; Start Byte
heinrichsweikamp
parents:
diff changeset
151 addwf temp1,F
heinrichsweikamp
parents:
diff changeset
152 movff WREG,TXREG2
heinrichsweikamp
parents:
diff changeset
153 call rs232_wait_tx2
heinrichsweikamp
parents:
diff changeset
154
heinrichsweikamp
parents:
diff changeset
155 movlw 0x31 ; Calibrate
heinrichsweikamp
parents:
diff changeset
156 addwf temp1,F
heinrichsweikamp
parents:
diff changeset
157 movff WREG,TXREG2
heinrichsweikamp
parents:
diff changeset
158 call rs232_wait_tx2
heinrichsweikamp
parents:
diff changeset
159
heinrichsweikamp
parents:
diff changeset
160 movff opt_calibration_O2_ratio,WREG ; Calibration gas %O2
heinrichsweikamp
parents:
diff changeset
161 addwf temp1,F
heinrichsweikamp
parents:
diff changeset
162 movff WREG,TXREG2
heinrichsweikamp
parents:
diff changeset
163 call rs232_wait_tx2
heinrichsweikamp
parents:
diff changeset
164
heinrichsweikamp
parents:
diff changeset
165 movff amb_pressure+0,WREG ; Ambient pressure
heinrichsweikamp
parents:
diff changeset
166 addwf temp1,F
heinrichsweikamp
parents:
diff changeset
167 movff WREG,TXREG2
heinrichsweikamp
parents:
diff changeset
168 call rs232_wait_tx2
heinrichsweikamp
parents:
diff changeset
169 movff amb_pressure+1,WREG
heinrichsweikamp
parents:
diff changeset
170 addwf temp1,F
heinrichsweikamp
parents:
diff changeset
171 movff WREG,TXREG2
heinrichsweikamp
parents:
diff changeset
172 call rs232_wait_tx2
heinrichsweikamp
parents:
diff changeset
173
heinrichsweikamp
parents:
diff changeset
174 movff temp1,TXREG2 ; Chksum
heinrichsweikamp
parents:
diff changeset
175 call rs232_wait_tx2
heinrichsweikamp
parents:
diff changeset
176
heinrichsweikamp
parents:
diff changeset
177 calibrate_mix2:
heinrichsweikamp
parents:
diff changeset
178 movff opt_calibration_O2_ratio,WREG ; Calibration gas %O2
heinrichsweikamp
parents:
diff changeset
179 mullw .100
heinrichsweikamp
parents:
diff changeset
180 movff PRODL,xA+0
heinrichsweikamp
parents:
diff changeset
181 movff PRODH,xA+1
heinrichsweikamp
parents:
diff changeset
182 ; (%O2*100)*[ambient,mbar]/100 -> xC
heinrichsweikamp
parents:
diff changeset
183 movff amb_pressure+0,xB+0
heinrichsweikamp
parents:
diff changeset
184 movff amb_pressure+1,xB+1
heinrichsweikamp
parents:
diff changeset
185 call mult16x16 ;xA*xB=xC
heinrichsweikamp
parents:
diff changeset
186 movlw LOW .100
heinrichsweikamp
parents:
diff changeset
187 movwf xB+0
heinrichsweikamp
parents:
diff changeset
188 movlw HIGH .100
heinrichsweikamp
parents:
diff changeset
189 movwf xB+1
heinrichsweikamp
parents:
diff changeset
190 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
heinrichsweikamp
parents:
diff changeset
191 movff o2_mv_sensor1+0,xB+0
heinrichsweikamp
parents:
diff changeset
192 movff o2_mv_sensor1+1,xB+1
heinrichsweikamp
parents:
diff changeset
193 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
heinrichsweikamp
parents:
diff changeset
194 ; xC= ppO2/mV
heinrichsweikamp
parents:
diff changeset
195 movff xC+0,opt_x_s1+0
heinrichsweikamp
parents:
diff changeset
196 movff xC+1,opt_x_s1+1 ; Factor for Sensor1
heinrichsweikamp
parents:
diff changeset
197
heinrichsweikamp
parents:
diff changeset
198 movff opt_calibration_O2_ratio,WREG ; Calibration gas %O2
heinrichsweikamp
parents:
diff changeset
199 mullw .100
heinrichsweikamp
parents:
diff changeset
200 movff PRODL,xA+0
heinrichsweikamp
parents:
diff changeset
201 movff PRODH,xA+1
heinrichsweikamp
parents:
diff changeset
202 ; (%O2*100)*[ambient,mbar]/100 -> xC
heinrichsweikamp
parents:
diff changeset
203 movff amb_pressure+0,xB+0
heinrichsweikamp
parents:
diff changeset
204 movff amb_pressure+1,xB+1
heinrichsweikamp
parents:
diff changeset
205 call mult16x16 ;xA*xB=xC
heinrichsweikamp
parents:
diff changeset
206 movlw LOW .100
heinrichsweikamp
parents:
diff changeset
207 movwf xB+0
heinrichsweikamp
parents:
diff changeset
208 movlw HIGH .100
heinrichsweikamp
parents:
diff changeset
209 movwf xB+1
heinrichsweikamp
parents:
diff changeset
210 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
heinrichsweikamp
parents:
diff changeset
211 movff o2_mv_sensor2+0,xB+0
heinrichsweikamp
parents:
diff changeset
212 movff o2_mv_sensor2+1,xB+1
heinrichsweikamp
parents:
diff changeset
213 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
heinrichsweikamp
parents:
diff changeset
214 ; xC= ppO2/mV
heinrichsweikamp
parents:
diff changeset
215 movff xC+0,opt_x_s2+0
heinrichsweikamp
parents:
diff changeset
216 movff xC+1,opt_x_s2+1 ; Factor for Sensor2
heinrichsweikamp
parents:
diff changeset
217
heinrichsweikamp
parents:
diff changeset
218 movff opt_calibration_O2_ratio,WREG ; Calibration gas %O2
heinrichsweikamp
parents:
diff changeset
219 mullw .100
heinrichsweikamp
parents:
diff changeset
220 movff PRODL,xA+0
heinrichsweikamp
parents:
diff changeset
221 movff PRODH,xA+1
heinrichsweikamp
parents:
diff changeset
222 ; (%O2*100)*[ambient,mbar]/100 -> xC
heinrichsweikamp
parents:
diff changeset
223 movff amb_pressure+0,xB+0
heinrichsweikamp
parents:
diff changeset
224 movff amb_pressure+1,xB+1
heinrichsweikamp
parents:
diff changeset
225 call mult16x16 ;xA*xB=xC
heinrichsweikamp
parents:
diff changeset
226 movlw LOW .100
heinrichsweikamp
parents:
diff changeset
227 movwf xB+0
heinrichsweikamp
parents:
diff changeset
228 movlw HIGH .100
heinrichsweikamp
parents:
diff changeset
229 movwf xB+1
heinrichsweikamp
parents:
diff changeset
230 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
heinrichsweikamp
parents:
diff changeset
231 movff o2_mv_sensor3+0,xB+0
heinrichsweikamp
parents:
diff changeset
232 movff o2_mv_sensor3+1,xB+1
heinrichsweikamp
parents:
diff changeset
233 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
heinrichsweikamp
parents:
diff changeset
234 ; xC= ppO2/mV
heinrichsweikamp
parents:
diff changeset
235 movff xC+0,opt_x_s3+0
heinrichsweikamp
parents:
diff changeset
236 movff xC+1,opt_x_s3+1 ; Factor for Sensor3
heinrichsweikamp
parents:
diff changeset
237
189
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
238 bsf sensor1_calibrated_ok
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
239 bsf sensor2_calibrated_ok
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
240 bsf sensor3_calibrated_ok ; Set flags prior check
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
241 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
242 ; initialise internal calibration flags
192
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
243 btfss use_O2_sensor1 ; Sensor out of range?
189
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
244 bcf sensor1_calibrated_ok ; Yes, disable this sensor
192
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
245 btfss use_O2_sensor2 ; Sensor out of range?
189
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
246 bcf sensor2_calibrated_ok ; Yes, disable this sensor
192
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
247 btfss use_O2_sensor3 ; Sensor out of range?
189
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
248 bcf sensor3_calibrated_ok ; Yes, disable this sensor
113
heinrichsweikamp
parents:
diff changeset
249
heinrichsweikamp
parents:
diff changeset
250 ; When no sensor is found, enable all three to show error state
192
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
251 btfsc use_O2_sensor1
113
heinrichsweikamp
parents:
diff changeset
252 return
192
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
253 btfsc use_O2_sensor2
113
heinrichsweikamp
parents:
diff changeset
254 return
192
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
255 btfsc use_O2_sensor3
113
heinrichsweikamp
parents:
diff changeset
256 return
192
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
257 bsf use_O2_sensor1
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
258 bsf use_O2_sensor2
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
259 bsf use_O2_sensor3
113
heinrichsweikamp
parents:
diff changeset
260 ; Clear factors
heinrichsweikamp
parents:
diff changeset
261 banksel opt_x_s1+0
heinrichsweikamp
parents:
diff changeset
262 clrf opt_x_s1+0
heinrichsweikamp
parents:
diff changeset
263 clrf opt_x_s1+1
heinrichsweikamp
parents:
diff changeset
264 clrf opt_x_s2+0
heinrichsweikamp
parents:
diff changeset
265 clrf opt_x_s2+1
heinrichsweikamp
parents:
diff changeset
266 clrf opt_x_s3+0
heinrichsweikamp
parents:
diff changeset
267 clrf opt_x_s3+1
heinrichsweikamp
parents:
diff changeset
268 banksel common
heinrichsweikamp
parents:
diff changeset
269 return
heinrichsweikamp
parents:
diff changeset
270
heinrichsweikamp
parents:
diff changeset
271 compute_ppo2_analog:
heinrichsweikamp
parents:
diff changeset
272 call get_analog_inputs
heinrichsweikamp
parents:
diff changeset
273 bra compute_ppo2_common
heinrichsweikamp
parents:
diff changeset
274
heinrichsweikamp
parents:
diff changeset
275 global compute_ppo2 ; compute mv_sensorX and ppo2_sensorX arrays
heinrichsweikamp
parents:
diff changeset
276 compute_ppo2:
236
e2ea74646127 configure hardware_flag byte
heinrichsweikamp
parents: 235
diff changeset
277 btfss analog_o2_input ; cR hardware?
113
heinrichsweikamp
parents:
diff changeset
278 return ; No
heinrichsweikamp
parents:
diff changeset
279
heinrichsweikamp
parents:
diff changeset
280 btfss s8_digital ; =1: Digital I/O
heinrichsweikamp
parents:
diff changeset
281 bra compute_ppo2_analog ; use analog
heinrichsweikamp
parents:
diff changeset
282
heinrichsweikamp
parents:
diff changeset
283 ; use digital
heinrichsweikamp
parents:
diff changeset
284 btfss new_s8_data_available ; =1: New data frame recieved
heinrichsweikamp
parents:
diff changeset
285 return
heinrichsweikamp
parents:
diff changeset
286 call compute_mvolts_for_all_sensors
heinrichsweikamp
parents:
diff changeset
287
heinrichsweikamp
parents:
diff changeset
288 compute_ppo2_common:
heinrichsweikamp
parents:
diff changeset
289 ; o2_mv_sensor1:2 * opt_x_s1:2 = o2_ppo2_sensor1/10000
heinrichsweikamp
parents:
diff changeset
290 movff o2_mv_sensor1+0,xA+0
heinrichsweikamp
parents:
diff changeset
291 movff o2_mv_sensor1+1,xA+1
heinrichsweikamp
parents:
diff changeset
292 movff opt_x_s1+0,xB+0
heinrichsweikamp
parents:
diff changeset
293 movff opt_x_s1+1,xB+1
heinrichsweikamp
parents:
diff changeset
294 call mult16x16 ;xA:2*xB:2=xC:4
heinrichsweikamp
parents:
diff changeset
295 movlw LOW .1000
heinrichsweikamp
parents:
diff changeset
296 movwf xB+0
heinrichsweikamp
parents:
diff changeset
297 movlw HIGH .1000
heinrichsweikamp
parents:
diff changeset
298 movwf xB+1
heinrichsweikamp
parents:
diff changeset
299 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
heinrichsweikamp
parents:
diff changeset
300 movlw d'1'
heinrichsweikamp
parents:
diff changeset
301 addwf xC+0,F
heinrichsweikamp
parents:
diff changeset
302 movlw d'0'
heinrichsweikamp
parents:
diff changeset
303 addwfc xC+1,F
190
a0f9ec25852e limit sensor-read ppO2 to 2.55bar
heinrichsweikamp
parents: 189
diff changeset
304 tstfsz xC+1 ; ppO2 is higher then 2.55bar?
a0f9ec25852e limit sensor-read ppO2 to 2.55bar
heinrichsweikamp
parents: 189
diff changeset
305 setf xC+0 ; Yes.
a0f9ec25852e limit sensor-read ppO2 to 2.55bar
heinrichsweikamp
parents: 189
diff changeset
306 movff xC+0,o2_ppo2_sensor1 ; result in 0.01bar
192
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
307 ; ; Set to zero if sensor is not active!
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
308 ; btfss use_O2_sensor1
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
309 ; clrf o2_ppo2_sensor1
113
heinrichsweikamp
parents:
diff changeset
310
heinrichsweikamp
parents:
diff changeset
311 ; o2_mv_sensor2:2 * opt_x_s1:2 = o2_ppo2_sensor2/10000
heinrichsweikamp
parents:
diff changeset
312 movff o2_mv_sensor2+0,xA+0
heinrichsweikamp
parents:
diff changeset
313 movff o2_mv_sensor2+1,xA+1
heinrichsweikamp
parents:
diff changeset
314 movff opt_x_s2+0,xB+0
heinrichsweikamp
parents:
diff changeset
315 movff opt_x_s2+1,xB+1
heinrichsweikamp
parents:
diff changeset
316 call mult16x16 ;xA:2*xB:2=xC:4
heinrichsweikamp
parents:
diff changeset
317 movlw LOW .1000
heinrichsweikamp
parents:
diff changeset
318 movwf xB+0
heinrichsweikamp
parents:
diff changeset
319 movlw HIGH .1000
heinrichsweikamp
parents:
diff changeset
320 movwf xB+1
heinrichsweikamp
parents:
diff changeset
321 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
heinrichsweikamp
parents:
diff changeset
322 movlw d'1'
heinrichsweikamp
parents:
diff changeset
323 addwf xC+0,F
heinrichsweikamp
parents:
diff changeset
324 movlw d'0'
heinrichsweikamp
parents:
diff changeset
325 addwfc xC+1,F
190
a0f9ec25852e limit sensor-read ppO2 to 2.55bar
heinrichsweikamp
parents: 189
diff changeset
326 tstfsz xC+1 ; ppO2 is higher then 2.55bar?
a0f9ec25852e limit sensor-read ppO2 to 2.55bar
heinrichsweikamp
parents: 189
diff changeset
327 setf xC+0 ; Yes.
a0f9ec25852e limit sensor-read ppO2 to 2.55bar
heinrichsweikamp
parents: 189
diff changeset
328 movff xC+0,o2_ppo2_sensor2 ; result in 0.01bar
192
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
329 ; ; Set to zero if sensor is not active!
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
330 ; btfss use_O2_sensor2
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
331 ; clrf o2_ppo2_sensor2
113
heinrichsweikamp
parents:
diff changeset
332
heinrichsweikamp
parents:
diff changeset
333 ; o2_mv_sensor3:2 * opt_x_s1:2 = o2_ppo2_sensor3/10000
heinrichsweikamp
parents:
diff changeset
334 movff o2_mv_sensor3+0,xA+0
heinrichsweikamp
parents:
diff changeset
335 movff o2_mv_sensor3+1,xA+1
heinrichsweikamp
parents:
diff changeset
336 movff opt_x_s3+0,xB+0
heinrichsweikamp
parents:
diff changeset
337 movff opt_x_s3+1,xB+1
heinrichsweikamp
parents:
diff changeset
338 call mult16x16 ;xA:2*xB:2=xC:4
heinrichsweikamp
parents:
diff changeset
339 movlw LOW .1000
heinrichsweikamp
parents:
diff changeset
340 movwf xB+0
heinrichsweikamp
parents:
diff changeset
341 movlw HIGH .1000
heinrichsweikamp
parents:
diff changeset
342 movwf xB+1
heinrichsweikamp
parents:
diff changeset
343 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
heinrichsweikamp
parents:
diff changeset
344 movlw d'1'
heinrichsweikamp
parents:
diff changeset
345 addwf xC+0,F
heinrichsweikamp
parents:
diff changeset
346 movlw d'0'
heinrichsweikamp
parents:
diff changeset
347 addwfc xC+1,F
190
a0f9ec25852e limit sensor-read ppO2 to 2.55bar
heinrichsweikamp
parents: 189
diff changeset
348 tstfsz xC+1 ; ppO2 is higher then 2.55bar?
a0f9ec25852e limit sensor-read ppO2 to 2.55bar
heinrichsweikamp
parents: 189
diff changeset
349 setf xC+0 ; Yes.
a0f9ec25852e limit sensor-read ppO2 to 2.55bar
heinrichsweikamp
parents: 189
diff changeset
350 movff xC+0,o2_ppo2_sensor3 ; result in 0.01bar
192
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
351 ; ; Set to zero if sensor is not active!
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
352 ; btfss use_O2_sensor3
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
353 ; clrf o2_ppo2_sensor3
113
heinrichsweikamp
parents:
diff changeset
354 return ; Done.
heinrichsweikamp
parents:
diff changeset
355
heinrichsweikamp
parents:
diff changeset
356
heinrichsweikamp
parents:
diff changeset
357 compute_mvolts_for_all_sensors: ; Compute mV or all sensors (S8 Mode)
heinrichsweikamp
parents:
diff changeset
358 ; compute AD results in 100µV steps (16bit/sensor)
heinrichsweikamp
parents:
diff changeset
359 ; 24bit AD result is in 244,1406541nV
heinrichsweikamp
parents:
diff changeset
360 ; Devide 24bit value through 409,5999512 -> 410 (0,01% error)
heinrichsweikamp
parents:
diff changeset
361 #DEFINE ad2mv_factor .410
heinrichsweikamp
parents:
diff changeset
362 ; Sensor 1
heinrichsweikamp
parents:
diff changeset
363 clrf xC+3
268
29acdb601548 BUGFIX: Increase timing tolerance for S8 HUD (cR only)
heinrichsweikamp
parents: 236
diff changeset
364 movff s8_rawdata_sensor1+2,xC+2
29acdb601548 BUGFIX: Increase timing tolerance for S8 HUD (cR only)
heinrichsweikamp
parents: 236
diff changeset
365 movff s8_rawdata_sensor1+1,xC+1
29acdb601548 BUGFIX: Increase timing tolerance for S8 HUD (cR only)
heinrichsweikamp
parents: 236
diff changeset
366 movff s8_rawdata_sensor1+0,xC+0
113
heinrichsweikamp
parents:
diff changeset
367 movlw LOW ad2mv_factor
heinrichsweikamp
parents:
diff changeset
368 movwf xB+0
heinrichsweikamp
parents:
diff changeset
369 movlw HIGH ad2mv_factor
heinrichsweikamp
parents:
diff changeset
370 movwf xB+1
heinrichsweikamp
parents:
diff changeset
371 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
heinrichsweikamp
parents:
diff changeset
372 movff xC+1,o2_mv_sensor1+1
heinrichsweikamp
parents:
diff changeset
373 movff xC+0,o2_mv_sensor1+0 ; in 100uV steps
heinrichsweikamp
parents:
diff changeset
374 ; Sensor 2
heinrichsweikamp
parents:
diff changeset
375 clrf xC+3
268
29acdb601548 BUGFIX: Increase timing tolerance for S8 HUD (cR only)
heinrichsweikamp
parents: 236
diff changeset
376 movff s8_rawdata_sensor2+2,xC+2
29acdb601548 BUGFIX: Increase timing tolerance for S8 HUD (cR only)
heinrichsweikamp
parents: 236
diff changeset
377 movff s8_rawdata_sensor2+1,xC+1
29acdb601548 BUGFIX: Increase timing tolerance for S8 HUD (cR only)
heinrichsweikamp
parents: 236
diff changeset
378 movff s8_rawdata_sensor2+0,xC+0
113
heinrichsweikamp
parents:
diff changeset
379 movlw LOW ad2mv_factor
heinrichsweikamp
parents:
diff changeset
380 movwf xB+0
heinrichsweikamp
parents:
diff changeset
381 movlw HIGH ad2mv_factor
heinrichsweikamp
parents:
diff changeset
382 movwf xB+1
heinrichsweikamp
parents:
diff changeset
383 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
heinrichsweikamp
parents:
diff changeset
384 movff xC+1,o2_mv_sensor2+1
heinrichsweikamp
parents:
diff changeset
385 movff xC+0,o2_mv_sensor2+0 ; in 100uV steps
heinrichsweikamp
parents:
diff changeset
386 ; Sensor 3
heinrichsweikamp
parents:
diff changeset
387 clrf xC+3
268
29acdb601548 BUGFIX: Increase timing tolerance for S8 HUD (cR only)
heinrichsweikamp
parents: 236
diff changeset
388 movff s8_rawdata_sensor3+2,xC+2
29acdb601548 BUGFIX: Increase timing tolerance for S8 HUD (cR only)
heinrichsweikamp
parents: 236
diff changeset
389 movff s8_rawdata_sensor3+1,xC+1
29acdb601548 BUGFIX: Increase timing tolerance for S8 HUD (cR only)
heinrichsweikamp
parents: 236
diff changeset
390 movff s8_rawdata_sensor3+0,xC+0
113
heinrichsweikamp
parents:
diff changeset
391 movlw LOW ad2mv_factor
heinrichsweikamp
parents:
diff changeset
392 movwf xB+0
heinrichsweikamp
parents:
diff changeset
393 movlw HIGH ad2mv_factor
heinrichsweikamp
parents:
diff changeset
394 movwf xB+1
heinrichsweikamp
parents:
diff changeset
395 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
heinrichsweikamp
parents:
diff changeset
396 movff xC+1,o2_mv_sensor3+1
heinrichsweikamp
parents:
diff changeset
397 movff xC+0,o2_mv_sensor3+0 ; in 100uV steps
heinrichsweikamp
parents:
diff changeset
398
heinrichsweikamp
parents:
diff changeset
399 bcf new_s8_data_available ; Clear flag
heinrichsweikamp
parents:
diff changeset
400 return ; Done.
heinrichsweikamp
parents:
diff changeset
401
heinrichsweikamp
parents:
diff changeset
402
heinrichsweikamp
parents:
diff changeset
403
heinrichsweikamp
parents:
diff changeset
404 END