annotate src/calibrate.asm @ 647:357341239438

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