annotate src/calibrate.asm @ 560:b7eb98dbd800

bump to 2.96beta (REFACTORED VERSION)
author heinrichsweikamp
date Wed, 31 Jan 2018 19:39:37 +0100
parents aadfe9f2edaf
children 54346c651b6a
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 ; DELETE - voting is done in calc_deko_divemode_sensor ## voting logic
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
107 ; bsf voting_logic_sensor1
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
108 ; movff o2_ppo2_sensor1,temp1
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
109 ; rcall check_sensor_voting_common
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
110 ; incfsz WREG ; Was Wreg=255?
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
111 ; bcf voting_logic_sensor1 ; Yes, ignore this sensor
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
112 ; bsf voting_logic_sensor2
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
113 ; movff o2_ppo2_sensor2,temp1
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
114 ; rcall check_sensor_voting_common
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
115 ; incfsz WREG ; Was Wreg=255?
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
116 ; bcf voting_logic_sensor2 ; Yes, ignore this sensor
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
117 ; bsf voting_logic_sensor3
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
118 ; movff o2_ppo2_sensor3,temp1
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
119 ; ;rcall check_sensor_voting_common
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
120 ; incfsz WREG ; Was Wreg=255?
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
121 ; bcf voting_logic_sensor3 ; Yes, ignore this sensor
189
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
122 return
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
123
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
124 ; DELETE COMPLETE FUNTION, PARTS OF THE CODE HAVE MIGRATED TO calc_deko_divemode_sensor ## voting logic
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
125 ; check_sensor_voting_common:
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
126 ; movf temp1,W
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
127 ; cpfsgt sensor_setpoint
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
128 ; bra check_sensor_voting_common2 ; temp1<sensor_setpoint
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
129 ; ; temp1>sensor_setpoint
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
130 ; movf temp1,W
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
131 ; subwf sensor_setpoint,W
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
132 ; movwf temp1
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
133 ; check_sensor_voting_common1:
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
134 ; movlw sensor_voting_logic_threshold ; Threshold in 0.01bar
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
135 ; cpfsgt temp1
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
136 ; retlw .255 ; Within range
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
137 ; retlw .0 ; Out of range
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
138 ; check_sensor_voting_common2:
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
139 ; ; temp1<sensor_setpoint
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
140 ; movf sensor_setpoint,W
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
141 ; subwf temp1,F
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
142 ; bra check_sensor_voting_common1
192
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
143
113
heinrichsweikamp
parents:
diff changeset
144 global calibrate_mix
heinrichsweikamp
parents:
diff changeset
145 calibrate_mix:
heinrichsweikamp
parents:
diff changeset
146 ; calibrate S8 HUD
heinrichsweikamp
parents:
diff changeset
147 btfss s8_digital ; S8 Digital?
heinrichsweikamp
parents:
diff changeset
148 bra calibrate_mix2 ; No
heinrichsweikamp
parents:
diff changeset
149
189
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
150 ; Yes, calibrate any S8-connected HUD
113
heinrichsweikamp
parents:
diff changeset
151 clrf temp1 ; Chksum
heinrichsweikamp
parents:
diff changeset
152 movlw 0xAA ; Start Byte
heinrichsweikamp
parents:
diff changeset
153 addwf temp1,F
heinrichsweikamp
parents:
diff changeset
154 movff WREG,TXREG2
heinrichsweikamp
parents:
diff changeset
155 call rs232_wait_tx2
heinrichsweikamp
parents:
diff changeset
156
heinrichsweikamp
parents:
diff changeset
157 movlw 0x31 ; Calibrate
heinrichsweikamp
parents:
diff changeset
158 addwf temp1,F
heinrichsweikamp
parents:
diff changeset
159 movff WREG,TXREG2
heinrichsweikamp
parents:
diff changeset
160 call rs232_wait_tx2
heinrichsweikamp
parents:
diff changeset
161
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
162 movff opt_calibration_O2_ratio,WREG ; Calibration gas %O2
113
heinrichsweikamp
parents:
diff changeset
163 addwf temp1,F
heinrichsweikamp
parents:
diff changeset
164 movff WREG,TXREG2
heinrichsweikamp
parents:
diff changeset
165 call rs232_wait_tx2
heinrichsweikamp
parents:
diff changeset
166
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
167 movff amb_pressure+0,WREG ; Ambient pressure
113
heinrichsweikamp
parents:
diff changeset
168 addwf temp1,F
heinrichsweikamp
parents:
diff changeset
169 movff WREG,TXREG2
heinrichsweikamp
parents:
diff changeset
170 call rs232_wait_tx2
heinrichsweikamp
parents:
diff changeset
171 movff amb_pressure+1,WREG
heinrichsweikamp
parents:
diff changeset
172 addwf temp1,F
heinrichsweikamp
parents:
diff changeset
173 movff WREG,TXREG2
heinrichsweikamp
parents:
diff changeset
174 call rs232_wait_tx2
heinrichsweikamp
parents:
diff changeset
175
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
176 movff temp1,TXREG2 ; Chksum
113
heinrichsweikamp
parents:
diff changeset
177 call rs232_wait_tx2
heinrichsweikamp
parents:
diff changeset
178
heinrichsweikamp
parents:
diff changeset
179 calibrate_mix2:
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
180 movff opt_calibration_O2_ratio,WREG ; Calibration gas %O2
113
heinrichsweikamp
parents:
diff changeset
181 mullw .100
heinrichsweikamp
parents:
diff changeset
182 movff PRODL,xA+0
heinrichsweikamp
parents:
diff changeset
183 movff PRODH,xA+1
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
184 ; (%O2*100)*[ambient,mbar]/100 -> xC
113
heinrichsweikamp
parents:
diff changeset
185 movff amb_pressure+0,xB+0
heinrichsweikamp
parents:
diff changeset
186 movff amb_pressure+1,xB+1
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 352
diff changeset
187 rcall calibrate_mix2_helper
113
heinrichsweikamp
parents:
diff changeset
188 movff o2_mv_sensor1+0,xB+0
heinrichsweikamp
parents:
diff changeset
189 movff o2_mv_sensor1+1,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 ; xC= ppO2/mV
heinrichsweikamp
parents:
diff changeset
192 movff xC+0,opt_x_s1+0
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
193 movff xC+1,opt_x_s1+1 ; Factor for Sensor1
113
heinrichsweikamp
parents:
diff changeset
194
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
195 movff opt_calibration_O2_ratio,WREG ; Calibration gas %O2
113
heinrichsweikamp
parents:
diff changeset
196 mullw .100
heinrichsweikamp
parents:
diff changeset
197 movff PRODL,xA+0
heinrichsweikamp
parents:
diff changeset
198 movff PRODH,xA+1
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
199 ; (%O2*100)*[ambient,mbar]/100 -> xC
113
heinrichsweikamp
parents:
diff changeset
200 movff amb_pressure+0,xB+0
heinrichsweikamp
parents:
diff changeset
201 movff amb_pressure+1,xB+1
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 352
diff changeset
202 rcall calibrate_mix2_helper
113
heinrichsweikamp
parents:
diff changeset
203 movff o2_mv_sensor2+0,xB+0
heinrichsweikamp
parents:
diff changeset
204 movff o2_mv_sensor2+1,xB+1
heinrichsweikamp
parents:
diff changeset
205 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
heinrichsweikamp
parents:
diff changeset
206 ; xC= ppO2/mV
heinrichsweikamp
parents:
diff changeset
207 movff xC+0,opt_x_s2+0
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
208 movff xC+1,opt_x_s2+1 ; Factor for Sensor2
113
heinrichsweikamp
parents:
diff changeset
209
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
210 movff opt_calibration_O2_ratio,WREG ; Calibration gas %O2
113
heinrichsweikamp
parents:
diff changeset
211 mullw .100
heinrichsweikamp
parents:
diff changeset
212 movff PRODL,xA+0
heinrichsweikamp
parents:
diff changeset
213 movff PRODH,xA+1
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
214 ; (%O2*100)*[ambient,mbar]/100 -> xC
113
heinrichsweikamp
parents:
diff changeset
215 movff amb_pressure+0,xB+0
heinrichsweikamp
parents:
diff changeset
216 movff amb_pressure+1,xB+1
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 352
diff changeset
217 rcall calibrate_mix2_helper
113
heinrichsweikamp
parents:
diff changeset
218 movff o2_mv_sensor3+0,xB+0
heinrichsweikamp
parents:
diff changeset
219 movff o2_mv_sensor3+1,xB+1
heinrichsweikamp
parents:
diff changeset
220 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
heinrichsweikamp
parents:
diff changeset
221 ; xC= ppO2/mV
heinrichsweikamp
parents:
diff changeset
222 movff xC+0,opt_x_s3+0
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
223 movff xC+1,opt_x_s3+1 ; Factor for Sensor3
113
heinrichsweikamp
parents:
diff changeset
224
189
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
225 bsf sensor1_calibrated_ok
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
226 bsf sensor2_calibrated_ok
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
227 bsf sensor3_calibrated_ok ; Set flags prior check
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
228
189
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
229 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
230 ; initialise internal calibration flags
192
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
231 btfss use_O2_sensor1 ; Sensor out of range?
189
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
232 bcf sensor1_calibrated_ok ; Yes, disable this sensor
192
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
233 btfss use_O2_sensor2 ; Sensor out of range?
189
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
234 bcf sensor2_calibrated_ok ; Yes, disable this sensor
192
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
235 btfss use_O2_sensor3 ; Sensor out of range?
189
e79bc535ef9e ignore un-calibrated sensors even if they become valid
heinrichsweikamp
parents: 187
diff changeset
236 bcf sensor3_calibrated_ok ; Yes, disable this sensor
113
heinrichsweikamp
parents:
diff changeset
237
heinrichsweikamp
parents:
diff changeset
238 ; When no sensor is found, enable all three to show error state
192
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
239 btfsc use_O2_sensor1
113
heinrichsweikamp
parents:
diff changeset
240 return
192
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
241 btfsc use_O2_sensor2
113
heinrichsweikamp
parents:
diff changeset
242 return
192
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
243 btfsc use_O2_sensor3
113
heinrichsweikamp
parents:
diff changeset
244 return
192
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
245 bsf use_O2_sensor1
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
246 bsf use_O2_sensor2
efe70488a04b voting logic for external monitoring
heinrichsweikamp
parents: 190
diff changeset
247 bsf use_O2_sensor3
113
heinrichsweikamp
parents:
diff changeset
248 ; Clear factors
heinrichsweikamp
parents:
diff changeset
249 banksel opt_x_s1+0
heinrichsweikamp
parents:
diff changeset
250 clrf opt_x_s1+0
heinrichsweikamp
parents:
diff changeset
251 clrf opt_x_s1+1
heinrichsweikamp
parents:
diff changeset
252 clrf opt_x_s2+0
heinrichsweikamp
parents:
diff changeset
253 clrf opt_x_s2+1
heinrichsweikamp
parents:
diff changeset
254 clrf opt_x_s3+0
heinrichsweikamp
parents:
diff changeset
255 clrf opt_x_s3+1
heinrichsweikamp
parents:
diff changeset
256 banksel common
heinrichsweikamp
parents:
diff changeset
257 return
heinrichsweikamp
parents:
diff changeset
258
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
259
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 352
diff changeset
260 calibrate_mix2_helper:
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
261 call mult16x16 ; xA*xB=xC
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 352
diff changeset
262 movlw LOW .100
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 352
diff changeset
263 movwf xB+0
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 352
diff changeset
264 movlw HIGH .100
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 352
diff changeset
265 movwf xB+1
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
266 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
267
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 352
diff changeset
268
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
269 ; DELETE COMPLETE FUNTION, PARTS OF THE CODE HAVE MIGRATED TO calc_deko_divemode_sensor ## voting logic
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
270 ; compute_ppo2_analog:
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
271 ; call get_analog_inputs
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
272 ; bra compute_ppo2_common
113
heinrichsweikamp
parents:
diff changeset
273
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
274 ; global compute_ppo2 ; compute mv_sensorX and ppo2_sensorX arrays
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
275 ; compute_ppo2:
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
276 ; btfss analog_o2_input ; cR hardware?
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
277 ; return ; No
113
heinrichsweikamp
parents:
diff changeset
278
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
279 ; btfss s8_digital ; =1: Digital I/O
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
280 ; bra compute_ppo2_analog ; use analog
113
heinrichsweikamp
parents:
diff changeset
281
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
282 ; ; use digital
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
283 ; btfss new_s8_data_available ; =1: New data frame recieved
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
284 ; return
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
285 ; rcall compute_mvolts_for_all_sensors
113
heinrichsweikamp
parents:
diff changeset
286
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
287 ; compute_ppo2_common:
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
288 ; ; o2_mv_sensor1:2 * opt_x_s1:2 = o2_ppo2_sensor1/10000
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
289 ; movff o2_mv_sensor1+0,xA+0
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
290 ; movff o2_mv_sensor1+1,xA+1
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
291 ; movff opt_x_s1+0,xB+0
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
292 ; movff opt_x_s1+1,xB+1
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
293 ; rcall compute_ppo2_common_helper
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
294 ; movff xC+0,o2_ppo2_sensor1 ; result in 0.01bar
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
295 ; ; ; Set to zero if sensor is not active!
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
296 ; ; btfss use_O2_sensor1
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
297 ; ; clrf o2_ppo2_sensor1
113
heinrichsweikamp
parents:
diff changeset
298
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
299 ; ; o2_mv_sensor2:2 * opt_x_s1:2 = o2_ppo2_sensor2/10000
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
300 ; movff o2_mv_sensor2+0,xA+0
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
301 ; movff o2_mv_sensor2+1,xA+1
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
302 ; movff opt_x_s2+0,xB+0
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
303 ; movff opt_x_s2+1,xB+1
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
304 ; rcall compute_ppo2_common_helper
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
305 ; movff xC+0,o2_ppo2_sensor2 ; result in 0.01bar
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
306 ; ; ; Set to zero if sensor is not active!
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
307 ; ; btfss use_O2_sensor2
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
308 ; ; clrf o2_ppo2_sensor2
113
heinrichsweikamp
parents:
diff changeset
309
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
310 ; ; o2_mv_sensor3:2 * opt_x_s1:2 = o2_ppo2_sensor3/10000
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
311 ; movff o2_mv_sensor3+0,xA+0
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
312 ; movff o2_mv_sensor3+1,xA+1
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
313 ; movff opt_x_s3+0,xB+0
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
314 ; movff opt_x_s3+1,xB+1
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
315 ; rcall compute_ppo2_common_helper
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
316 ; movff xC+0,o2_ppo2_sensor3 ; result in 0.01bar
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
317 ; ; ; Set to zero if sensor is not active!
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
318 ; ; btfss use_O2_sensor3
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
319 ; ; clrf o2_ppo2_sensor3
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
320 ; return ; Done.
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 352
diff changeset
321
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
322 ; compute_ppo2_common_helper:
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
323 ; call mult16x16 ;xA:2*xB:2=xC:4
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
324 ; movlw LOW .1000
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
325 ; movwf xB+0
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
326 ; movlw HIGH .1000
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
327 ; movwf xB+1
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
328 ; 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
329 ; movlw d'1'
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
330 ; addwf xC+0,F
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
331 ; movlw d'0'
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
332 ; addwfc xC+1,F
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
333 ; tstfsz xC+1 ; ppO2 is higher then 2.55bar?
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
334 ; setf xC+0 ; Yes.
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
335 ; return
113
heinrichsweikamp
parents:
diff changeset
336
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
337
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
338 global compute_mvolts_for_all_sensors
113
heinrichsweikamp
parents:
diff changeset
339 compute_mvolts_for_all_sensors: ; Compute mV or all sensors (S8 Mode)
heinrichsweikamp
parents:
diff changeset
340 ; compute AD results in 100µV steps (16bit/sensor)
heinrichsweikamp
parents:
diff changeset
341 ; 24bit AD result is in 244,1406541nV
heinrichsweikamp
parents:
diff changeset
342 ; Devide 24bit value through 409,5999512 -> 410 (0,01% error)
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
343 #DEFINE ad2mv_factor .410
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
344 ; Sensor 1
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
345 clrf xC+3
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
346 movff s8_rawdata_sensor1+2,xC+2
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
347 movff s8_rawdata_sensor1+1,xC+1
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
348 movff s8_rawdata_sensor1+0,xC+0
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
349 movlw LOW ad2mv_factor
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
350 movwf xB+0
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
351 movlw HIGH ad2mv_factor
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
352 movwf xB+1
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
353 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
354 movff xC+1,o2_mv_sensor1+1
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
355 movff xC+0,o2_mv_sensor1+0 ; in 100uV steps
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
356 ; Sensor 2
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
357 clrf xC+3
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
358 movff s8_rawdata_sensor2+2,xC+2
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
359 movff s8_rawdata_sensor2+1,xC+1
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
360 movff s8_rawdata_sensor2+0,xC+0
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
361 movlw LOW ad2mv_factor
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
362 movwf xB+0
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
363 movlw HIGH ad2mv_factor
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
364 movwf xB+1
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
365 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
366 movff xC+1,o2_mv_sensor2+1
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
367 movff xC+0,o2_mv_sensor2+0 ; in 100uV steps
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
368 ; Sensor 3
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
369 clrf xC+3
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
370 movff s8_rawdata_sensor3+2,xC+2
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
371 movff s8_rawdata_sensor3+1,xC+1
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
372 movff s8_rawdata_sensor3+0,xC+0
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
373 movlw LOW ad2mv_factor
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
374 movwf xB+0
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
375 movlw HIGH ad2mv_factor
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
376 movwf xB+1
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
377 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
378 movff xC+1,o2_mv_sensor3+1
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
379 movff xC+0,o2_mv_sensor3+0 ; in 100uV steps
113
heinrichsweikamp
parents:
diff changeset
380
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
381 bcf new_s8_data_available ; Clear flag
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
382 return ; Done.
113
heinrichsweikamp
parents:
diff changeset
383
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
384
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
385
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
386 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
387 transmit_setpoint:
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 352
diff changeset
388 return
352
5c6da9fa5cb0 add setpoint change to first sample in CCR mode
heinrichsweikamp
parents: 275
diff changeset
389 btfss s8_digital ; S8 Digital?
5c6da9fa5cb0 add setpoint change to first sample in CCR mode
heinrichsweikamp
parents: 275
diff changeset
390 return ; No, ignore
5c6da9fa5cb0 add setpoint change to first sample in CCR mode
heinrichsweikamp
parents: 275
diff changeset
391
5c6da9fa5cb0 add setpoint change to first sample in CCR mode
heinrichsweikamp
parents: 275
diff changeset
392 ; Yes, transmit setpoint from WREG
5c6da9fa5cb0 add setpoint change to first sample in CCR mode
heinrichsweikamp
parents: 275
diff changeset
393 movwf temp2 ; Store setpoint
5c6da9fa5cb0 add setpoint change to first sample in CCR mode
heinrichsweikamp
parents: 275
diff changeset
394 clrf temp1 ; Chksum
5c6da9fa5cb0 add setpoint change to first sample in CCR mode
heinrichsweikamp
parents: 275
diff changeset
395 movlw 0xAA ; Start Byte
5c6da9fa5cb0 add setpoint change to first sample in CCR mode
heinrichsweikamp
parents: 275
diff changeset
396 addwf temp1,F
5c6da9fa5cb0 add setpoint change to first sample in CCR mode
heinrichsweikamp
parents: 275
diff changeset
397 movff WREG,TXREG2
5c6da9fa5cb0 add setpoint change to first sample in CCR mode
heinrichsweikamp
parents: 275
diff changeset
398 call rs232_wait_tx2
5c6da9fa5cb0 add setpoint change to first sample in CCR mode
heinrichsweikamp
parents: 275
diff changeset
399
5c6da9fa5cb0 add setpoint change to first sample in CCR mode
heinrichsweikamp
parents: 275
diff changeset
400 movlw 0x60 ; New SP
5c6da9fa5cb0 add setpoint change to first sample in CCR mode
heinrichsweikamp
parents: 275
diff changeset
401 addwf temp1,F
5c6da9fa5cb0 add setpoint change to first sample in CCR mode
heinrichsweikamp
parents: 275
diff changeset
402 movff WREG,TXREG2
5c6da9fa5cb0 add setpoint change to first sample in CCR mode
heinrichsweikamp
parents: 275
diff changeset
403 call rs232_wait_tx2
5c6da9fa5cb0 add setpoint change to first sample in CCR mode
heinrichsweikamp
parents: 275
diff changeset
404
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
405 movff temp2,WREG ; SP in cbar
352
5c6da9fa5cb0 add setpoint change to first sample in CCR mode
heinrichsweikamp
parents: 275
diff changeset
406 addwf temp1,F
5c6da9fa5cb0 add setpoint change to first sample in CCR mode
heinrichsweikamp
parents: 275
diff changeset
407 movff WREG,TXREG2
5c6da9fa5cb0 add setpoint change to first sample in CCR mode
heinrichsweikamp
parents: 275
diff changeset
408 call rs232_wait_tx2
5c6da9fa5cb0 add setpoint change to first sample in CCR mode
heinrichsweikamp
parents: 275
diff changeset
409
560
b7eb98dbd800 bump to 2.96beta (REFACTORED VERSION)
heinrichsweikamp
parents: 448
diff changeset
410 movff temp1,TXREG2 ; Chksum
352
5c6da9fa5cb0 add setpoint change to first sample in CCR mode
heinrichsweikamp
parents: 275
diff changeset
411 call rs232_wait_tx2
5c6da9fa5cb0 add setpoint change to first sample in CCR mode
heinrichsweikamp
parents: 275
diff changeset
412 return
113
heinrichsweikamp
parents:
diff changeset
413
heinrichsweikamp
parents:
diff changeset
414
heinrichsweikamp
parents:
diff changeset
415 END