annotate src/adc_lightsensor.asm @ 584:d63dec562d50

CNS fix
author heinrichsweikamp
date Wed, 28 Feb 2018 10:24:54 +0100
parents b455b31ce022
children 00b24fb4324d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
heinrichsweikamp
parents:
diff changeset
1 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
2 ;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
3 ; File adc.asm V2.98
0
heinrichsweikamp
parents:
diff changeset
4 ;
heinrichsweikamp
parents:
diff changeset
5 ;
heinrichsweikamp
parents:
diff changeset
6 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
heinrichsweikamp
parents:
diff changeset
7 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
8 ; HISTORY
heinrichsweikamp
parents:
diff changeset
9 ; 2011-08-08 : [mH] moving from OSTC code
heinrichsweikamp
parents:
diff changeset
10
275
653a3ab08062 rename into hwOS
heinrichsweikamp
parents: 270
diff changeset
11 #include "hwos.inc"
0
heinrichsweikamp
parents:
diff changeset
12 #include "math.inc"
heinrichsweikamp
parents:
diff changeset
13 #include "wait.inc"
heinrichsweikamp
parents:
diff changeset
14 #include "eeprom_rs232.inc"
113
heinrichsweikamp
parents: 44
diff changeset
15 #include "i2c.inc"
0
heinrichsweikamp
parents:
diff changeset
16
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
17 extern reset_battery_internal_only
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
18
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
19 sensors CODE
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
20
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
21 ;=============================================================================
0
heinrichsweikamp
parents:
diff changeset
22
heinrichsweikamp
parents:
diff changeset
23 wait_adc:
heinrichsweikamp
parents:
diff changeset
24 movwf ADCON0
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
25 nop
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
26 bsf ADCON0,1 ; start ADC
0
heinrichsweikamp
parents:
diff changeset
27 wait_adc2:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
28 btfsc ADCON0,1 ; Wait...
0
heinrichsweikamp
parents:
diff changeset
29 bra wait_adc2
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
30 return
0
heinrichsweikamp
parents:
diff changeset
31
heinrichsweikamp
parents:
diff changeset
32 global get_battery_voltage
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
33 get_battery_voltage: ; starts ADC and waits until finished
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
34 btfss battery_gauge_available
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
35 bra get_battery_voltage1 ; Normal ostc3 hardware
113
heinrichsweikamp
parents: 44
diff changeset
36
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
37 call lt2942_get_accumulated_charge
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
38 call lt2942_get_voltage
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
39
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
40 tstfsz batt_voltage+1 ; <256mV?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
41 bra get_battery_voltage_noretry ; No
218
8fbd8c5ac51f 1.71beta start
heinrichsweikamp
parents: 207
diff changeset
42
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
43 ; Retry
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
44 call lt2942_get_accumulated_charge
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
45 call lt2942_get_voltage
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
46
466
7f4c3b2e6bb7 battery gauge handling
heinrichsweikamp
parents: 465
diff changeset
47 get_battery_voltage_noretry:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
48 btfsc divemode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
49 return ; Not in divemode
218
8fbd8c5ac51f 1.71beta start
heinrichsweikamp
parents: 207
diff changeset
50
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
51 bcf cv_active
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
52 bcf cc_active
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
53 bcf LEDr
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
54 bcf TRISJ,2 ; Chrg-Out output
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
55 bsf CHRG_OUT
120
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
56
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
57 btfss CHRG_IN
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
58 bra charge_cc_active
120
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
59
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
60 bcf CHRG_OUT
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
61 bsf TRISJ,2 ; Chrg-Out high impedance
120
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
62
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
63 WAITMS d'1'
120
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
64
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
65 btfsc CHRG_IN
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
66 return
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
67 ;cv_active:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
68 decfsz get_bat_volt_counter,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
69 return
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
70 movlw .15
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
71 cpfsgt batt_voltage+1 ; Batt Voltage >= 16*256mV (4,096V)?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
72 bra charge_cc_active ; No
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
73 bsf cc_active
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
74 bsf cv_active
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
75 bsf LEDr ; Indicate charging
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
76 call lt2942_charge_done ; Reset accumulating registers to 0xFFFF
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
77 WAITMS d'10'
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
78 bcf LEDr ; Indicate charging
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
79 bsf get_bat_volt_counter,0 ; =1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
80 return
120
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
81
207
f5d909e03f52 charge indicator on surface screen
heinrichsweikamp
parents: 204
diff changeset
82 charge_cc_active:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
83 bsf cc_active
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
84 bsf LEDr ; Indicate charging
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
85 bcf CHRG_OUT
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
86 bsf TRISJ,2 ; Chrg-Out high impedance
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
87 movlw .10
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
88 movwf get_bat_volt_counter
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
89 return
113
heinrichsweikamp
parents: 44
diff changeset
90
heinrichsweikamp
parents: 44
diff changeset
91 get_battery_voltage1:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
92 bsf adc_running ; =1: The ADC is in use
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
93 movlw b'00100000' ; 2.048V Vref+ -> 1LSB = 500µV
0
heinrichsweikamp
parents:
diff changeset
94 movwf ADCON1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
95 movlw b'00011001' ; power on ADC, select AN6
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
96 rcall wait_adc
0
heinrichsweikamp
parents:
diff changeset
97
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
98 movff ADRESH,batt_voltage+1 ; store value
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
99 movff ADRESL,batt_voltage+0 ; store value
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
100 bcf ADCON0,0 ; power off ADC
0
heinrichsweikamp
parents:
diff changeset
101
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
102 ; Multiply with 2,006 to be exact here...
0
heinrichsweikamp
parents:
diff changeset
103 ; bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
104 ; rlcf xA+0,F
heinrichsweikamp
parents:
diff changeset
105 ;
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
106 ; rlcf xA+1,F ; x2
0
heinrichsweikamp
parents:
diff changeset
107
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
108 ; movff xA+0,batt_voltage+0 ; store value
0
heinrichsweikamp
parents:
diff changeset
109 ; movff xA+1,batt_voltage+1
heinrichsweikamp
parents:
diff changeset
110
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
111 movlw LOW lithium_36v_low
0
heinrichsweikamp
parents:
diff changeset
112 movwf sub_a+0
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
113 movlw HIGH lithium_36v_low
0
heinrichsweikamp
parents:
diff changeset
114 movwf sub_a+1
heinrichsweikamp
parents:
diff changeset
115 movff batt_voltage+0,sub_b+0
heinrichsweikamp
parents:
diff changeset
116 movff batt_voltage+1,sub_b+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
117 call subU16 ; sub_c = sub_a - sub_b
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
118 ; Battery is 3,6V (>lithium_36v_low?)
0
heinrichsweikamp
parents:
diff changeset
119 btfss neg_flag
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
120 bra get_battery_voltage4 ; No, use 1,5V
0
heinrichsweikamp
parents:
diff changeset
121
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
122 bsf battery_is_36v ; Yes, set flag (Cleared in power-on reset only!)
0
heinrichsweikamp
parents:
diff changeset
123
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
124 ; Check if the battery is near-dead already
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
125 movlw LOW lithium_36v_empty
0
heinrichsweikamp
parents:
diff changeset
126 movwf sub_a+0
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
127 movlw HIGH lithium_36v_empty
0
heinrichsweikamp
parents:
diff changeset
128 movwf sub_a+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
129 call subU16 ; sub_c = sub_a - sub_b
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
130 ; Battery is not dead yet (>lithium_36v_empty?)
0
heinrichsweikamp
parents:
diff changeset
131 btfsc neg_flag
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
132 bra get_battery_voltage2 ; Yes, battery is still ok
0
heinrichsweikamp
parents:
diff changeset
133
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
134 ; Battery is probably dead very soon
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
135 ; Set ">=24Ah used" into battery gauge registers
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
136 movlw .128
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
137 movff WREG,battery_gauge+5
0
heinrichsweikamp
parents:
diff changeset
138
heinrichsweikamp
parents:
diff changeset
139 get_battery_voltage2:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
140 ; Use 3,6V battery gauging mode
0
heinrichsweikamp
parents:
diff changeset
141 movff battery_gauge+5,xC+3
heinrichsweikamp
parents:
diff changeset
142 movff battery_gauge+4,xC+2
heinrichsweikamp
parents:
diff changeset
143 movff battery_gauge+3,xC+1
heinrichsweikamp
parents:
diff changeset
144 movff battery_gauge+2,xC+0
heinrichsweikamp
parents:
diff changeset
145 ; battery_gauge:6 is nAs
heinrichsweikamp
parents:
diff changeset
146 ; devide through 65536
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
147 ; devide through battery_capacity:2
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
148 ; Result is in percent
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
149 movff internal_battery_capacity+0,xB+0
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
150 movff internal_battery_capacity+1,xB+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
151 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder
0
heinrichsweikamp
parents:
diff changeset
152 movff xC+0,lo
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
153 ; Limit to 100
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
154 movlw .100
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
155 cpfslt lo
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
156 movwf lo
0
heinrichsweikamp
parents:
diff changeset
157 ; lo will be between 0 (Full) and 100 (empty)
heinrichsweikamp
parents:
diff changeset
158 movf lo,W
heinrichsweikamp
parents:
diff changeset
159 sublw .100
heinrichsweikamp
parents:
diff changeset
160 movwf lo
heinrichsweikamp
parents:
diff changeset
161 get_battery_voltage3:
heinrichsweikamp
parents:
diff changeset
162 movlw .100
heinrichsweikamp
parents:
diff changeset
163 cpfslt lo
heinrichsweikamp
parents:
diff changeset
164 movwf lo
heinrichsweikamp
parents:
diff changeset
165 ; lo will be between 100 (Full) and 0 (empty)
37
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
166
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
167 ; use 3,6V battery sensing based on 50mA load
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
168 ; 75%
37
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
169 movff batt_voltage+0,sub_b+0
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
170 movff batt_voltage+1,sub_b+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
171 movlw LOW lithium_36v_75
37
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
172 movwf sub_a+0
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
173 movlw HIGH lithium_36v_75
37
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
174 movwf sub_a+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
175 call subU16 ; sub_c = sub_a - sub_b
37
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
176 btfsc neg_flag
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
177 bra get_battery_voltage3a
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
178 movlw .75
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
179 movwf lo
37
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
180 get_battery_voltage3a:
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
181 ; 50%
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
182 movlw LOW lithium_36v_50
37
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
183 movwf sub_a+0
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
184 movlw HIGH lithium_36v_50
37
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
185 movwf sub_a+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
186 call subU16 ; sub_c = sub_a - sub_b
37
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
187 btfsc neg_flag
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
188 bra get_battery_voltage3b
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
189 movlw .50
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
190 movwf lo
37
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
191 get_battery_voltage3b:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
192 ; 25%
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
193 movlw LOW lithium_36v_25
37
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
194 movwf sub_a+0
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
195 movlw HIGH lithium_36v_25
37
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
196 movwf sub_a+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
197 call subU16 ; sub_c = sub_a - sub_b
37
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
198 btfsc neg_flag
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
199 bra get_battery_voltage3c
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
200 movlw .25
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
201 movwf lo
37
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
202 get_battery_voltage3c:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
203 ; 10%
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
204 movlw LOW lithium_36v_10
37
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
205 movwf sub_a+0
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
206 movlw HIGH lithium_36v_10
37
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
207 movwf sub_a+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
208 call subU16 ; sub_c = sub_a - sub_b
37
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
209 btfsc neg_flag
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
210 bra get_battery_voltage3d
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
211 movlw .10
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
212 movwf lo
37
0e1723f2761e use four additional data points for the battery monitor
mh@mh-THINK.fritz.box
parents: 0
diff changeset
213 get_battery_voltage3d:
44
18fe4e668baa BUGFIX: Percent display with 1,5V batteries
heinrichsweikamp
parents: 37
diff changeset
214 movlw .100
18fe4e668baa BUGFIX: Percent display with 1,5V batteries
heinrichsweikamp
parents: 37
diff changeset
215 cpfslt lo
18fe4e668baa BUGFIX: Percent display with 1,5V batteries
heinrichsweikamp
parents: 37
diff changeset
216 movwf lo
18fe4e668baa BUGFIX: Percent display with 1,5V batteries
heinrichsweikamp
parents: 37
diff changeset
217 ; lo will be between 100 (Full) and 0 (empty)
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
218 movf batt_percent,W
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
219 cpfsgt lo ; keep batt_percent on the lowest value found
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
220 movff lo,batt_percent ; store value
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
221 btfsc battery_is_36v ; but always use computed value for 3,6V battery
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
222 movff lo,batt_percent ; store value
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
223 bcf adc_running ; =1: The ADC is in use
0
heinrichsweikamp
parents:
diff changeset
224 return
heinrichsweikamp
parents:
diff changeset
225
heinrichsweikamp
parents:
diff changeset
226 get_battery_voltage4:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
227 ; Use 1,5V battery voltage mode
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
228 ; Use approximation (batt_voltage:2-aa_15v_low)/4 = lo
0
heinrichsweikamp
parents:
diff changeset
229 movff batt_voltage+0,sub_a+0
heinrichsweikamp
parents:
diff changeset
230 movff batt_voltage+1,sub_a+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
231 movlw LOW aa_15v_low
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
232 movwf sub_b+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
233 movlw HIGH aa_15v_low
0
heinrichsweikamp
parents:
diff changeset
234 movwf sub_b+1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
235 call subU16 ; sub_c = sub_a - sub_b
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
236 bcf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
237 rrcf sub_c+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
238 rrcf sub_c+0 ; /2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
239 bcf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
240 rrcf sub_c+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
241 rrcf sub_c+0 ; /4
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
242 movff sub_c+0,lo
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
243 bra get_battery_voltage3d ; Check limits and return
0
heinrichsweikamp
parents:
diff changeset
244
heinrichsweikamp
parents:
diff changeset
245 global get_ambient_level
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
246 get_ambient_level: ; starts ADC and waits until finished
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
247 btfsc adc_running ; ADC in use?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
248 return ; Yes, return
0
heinrichsweikamp
parents:
diff changeset
249
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
250 btfsc ambient_sensor
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
251 bra get_ambient_level1 ; Normal ostc3 hardware
203
dd9b167e82dc 1.64 (Fix ambient light for cR)
heinrichsweikamp
parents: 201
diff changeset
252
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
253 banksel isr_backup ; Back to Bank0 ISR data
203
dd9b167e82dc 1.64 (Fix ambient light for cR)
heinrichsweikamp
parents: 201
diff changeset
254 movff opt_brightness,isr1_temp
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
255 incf isr1_temp,F ; adjust 0-2 to 1-3
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
256 movlw ambient_light_max_high_cr ; cR and 2 hardware brightest setting
203
dd9b167e82dc 1.64 (Fix ambient light for cR)
heinrichsweikamp
parents: 201
diff changeset
257 dcfsnz isr1_temp,F
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
258 movlw ambient_light_max_eco ; brightest setting
203
dd9b167e82dc 1.64 (Fix ambient light for cR)
heinrichsweikamp
parents: 201
diff changeset
259 dcfsnz isr1_temp,F
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
260 movlw ambient_light_max_medium ; brightest setting
203
dd9b167e82dc 1.64 (Fix ambient light for cR)
heinrichsweikamp
parents: 201
diff changeset
261
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
262 movff WREG,ambient_light+0 ; Set to max.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
263 movff ambient_light+0,max_CCPR1L ; Store value for dimming in TMR7 interrupt
203
dd9b167e82dc 1.64 (Fix ambient light for cR)
heinrichsweikamp
parents: 201
diff changeset
264 return
113
heinrichsweikamp
parents: 44
diff changeset
265
heinrichsweikamp
parents: 44
diff changeset
266 get_ambient_level1:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
267 movlw b'00000000' ; Vref+ = Vdd
0
heinrichsweikamp
parents:
diff changeset
268 movwf ADCON1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
269 movlw b'00011101' ; power on ADC, select AN7
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
270 rcall wait_adc
0
heinrichsweikamp
parents:
diff changeset
271
heinrichsweikamp
parents:
diff changeset
272 movff ADRESH,ambient_light+1
heinrichsweikamp
parents:
diff changeset
273 movff ADRESL,ambient_light+0
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
274 bcf ADCON0,0 ; power off ADC
0
heinrichsweikamp
parents:
diff changeset
275
heinrichsweikamp
parents:
diff changeset
276 ; ambient_light:2 is between 4096 (direct sunlight) and about 200 (darkness)
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
277 ; First: Divide by 16
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
278 banksel ambient_light
0
heinrichsweikamp
parents:
diff changeset
279 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
280 rrcf ambient_light+1
heinrichsweikamp
parents:
diff changeset
281 rrcf ambient_light+0
heinrichsweikamp
parents:
diff changeset
282 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
283 rrcf ambient_light+1
heinrichsweikamp
parents:
diff changeset
284 rrcf ambient_light+0
heinrichsweikamp
parents:
diff changeset
285 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
286 rrcf ambient_light+1
heinrichsweikamp
parents:
diff changeset
287 rrcf ambient_light+0
heinrichsweikamp
parents:
diff changeset
288 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
289 rrcf ambient_light+1
heinrichsweikamp
parents:
diff changeset
290 rrcf ambient_light+0
heinrichsweikamp
parents:
diff changeset
291 ; Result: ambient_light:2/16
heinrichsweikamp
parents:
diff changeset
292 ; Now, make sure to have value between ambient_light_low and ambient_light_max
heinrichsweikamp
parents:
diff changeset
293
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
294 movlw .254
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
295 tstfsz ambient_light+1 ; >255?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
296 movwf ambient_light+0 ; avoid ADC clipping
0
heinrichsweikamp
parents:
diff changeset
297
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
298 incfsz ambient_light+0,W ; =255?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
299 bra get_ambient_level2 ; No, continue
0
heinrichsweikamp
parents:
diff changeset
300
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
301 movlw .254
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
302 movwf ambient_light+0 ; avoid ADC clipping
0
heinrichsweikamp
parents:
diff changeset
303
heinrichsweikamp
parents:
diff changeset
304 get_ambient_level2:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
305 ; movlw .10
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
306 ; subwf ambient_light+0,F ; Subtract 10 (ADC Offset)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
307 ; btfsc STATUS,N
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
308 ; movwf ambient_light+0 ; avoid clipping
201
82faedf8fd58 lower minimum backlight in eco mode
heinrichsweikamp
parents: 200
diff changeset
309
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
310 banksel isr_backup ; Back to Bank0 ISR data
0
heinrichsweikamp
parents:
diff changeset
311 movff opt_brightness,isr1_temp
heinrichsweikamp
parents:
diff changeset
312
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
313 btfsc RCSTA1,7 ; UART module on?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
314 clrf isr1_temp ; Yes, set temporally to eco mode
0
heinrichsweikamp
parents:
diff changeset
315
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
316 incf isr1_temp,F ; adjust 0-2 to 1-3
0
heinrichsweikamp
parents:
diff changeset
317
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
318 banksel common ; flag is in bank1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
319 movlw ambient_light_max_high_cr ; cR and 2 hardware brightest setting
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
320 btfss battery_gauge_available
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
321 movlw ambient_light_max_high_15V ; 1,5V battery brightest setting
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
322 btfsc battery_is_36v ; 3,6V battery in use?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
323 movlw ambient_light_max_high_36V ; 3,6V battery brightest setting
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
324 banksel isr_backup ; Back to Bank0 ISR data
0
heinrichsweikamp
parents:
diff changeset
325
heinrichsweikamp
parents:
diff changeset
326 dcfsnz isr1_temp,F
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
327 movlw ambient_light_max_eco ; brightest setting
0
heinrichsweikamp
parents:
diff changeset
328 dcfsnz isr1_temp,F
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
329 movlw ambient_light_max_medium ; brightest setting
0
heinrichsweikamp
parents:
diff changeset
330
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
331 banksel ambient_light
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
332 incf ambient_light+0,F ; +1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
333 cpfslt ambient_light+0 ; smaller then WREG?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
334 movwf ambient_light+0 ; No, set to max.
0
heinrichsweikamp
parents:
diff changeset
335
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
336 banksel isr_backup ; Back to Bank0 ISR data
0
heinrichsweikamp
parents:
diff changeset
337 movff opt_brightness,isr1_temp
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
338 incf isr1_temp,F ; adjust 0-2 to 1-3
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
339 movlw ambient_light_min_high ; darkest setting
0
heinrichsweikamp
parents:
diff changeset
340
heinrichsweikamp
parents:
diff changeset
341 dcfsnz isr1_temp,F
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
342 movlw ambient_light_min_eco ; darkest setting
0
heinrichsweikamp
parents:
diff changeset
343 dcfsnz isr1_temp,F
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
344 movlw ambient_light_min_medium ; darkest setting
0
heinrichsweikamp
parents:
diff changeset
345 dcfsnz isr1_temp,F
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
346 movlw ambient_light_min_high ; darkest setting
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
347
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
348 banksel ambient_light
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
349 cpfsgt ambient_light+0 ; bigger then WREG?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
350 movwf ambient_light+0 ; No, set to min
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
351 banksel common
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
352
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
353 movff ambient_light+0,max_CCPR1L ; Store value for dimming in TMR7 interrupt
0
heinrichsweikamp
parents:
diff changeset
354 return
heinrichsweikamp
parents:
diff changeset
355
113
heinrichsweikamp
parents: 44
diff changeset
356 global get_analog_inputs
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
357 get_analog_inputs: ; starts ADC and waits until finished
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
358 bsf adc_running ; =1: The ADC is in use
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
359 btfsc TFT_PWM
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
360 bra get_analog_inputs ; Wait for PWM low
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
361 movlw b'00100000' ; 2.048V Vref+ -> 1LSB = 500µV
113
heinrichsweikamp
parents: 44
diff changeset
362 movwf ADCON1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
363 movlw b'00100001' ; power on ADC, select AN8
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
364 rcall wait_adc
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
365 bcf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
366 rrcf ADRESH,F ; /2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
367 rrcf ADRESL,W
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
368 ; add to o2_mv_sensor1:2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
369 addwf o2_mv_sensor1+0,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
370 movf ADRESH,W
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
371 addwfc o2_mv_sensor1+1,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
372 ; Devide by 2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
373 bcf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
374 rrcf o2_mv_sensor1+1,F ; /2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
375 rrcf o2_mv_sensor1+0,F
196
a0e0ddfc1b49 suppress ghost readings for long, open cables
heinrichsweikamp
parents: 189
diff changeset
376
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
377 movlw HIGH ignore_mv
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
378 cpfsgt o2_mv_sensor1+1 ; >ignore_mv?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
379 bra get_analog_inputs2a ; No
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
380 ; Yes, ignore this reading
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
381 clrf o2_mv_sensor1+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
382 clrf o2_mv_sensor1+0
196
a0e0ddfc1b49 suppress ghost readings for long, open cables
heinrichsweikamp
parents: 189
diff changeset
383 get_analog_inputs2a:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
384 ; Ignore 1,9mV noise for not-connected inputs
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
385 tstfsz o2_mv_sensor1+1 ; >25,5mV?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
386 bra get_analog_inputs2 ; Yes, skip here
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
387 movlw .19
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
388 cpfsgt o2_mv_sensor1+0 ; >1,9mV?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
389 clrf o2_mv_sensor1+0 ; no, clear result
187
669b5d00706d CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents: 158
diff changeset
390 get_analog_inputs2:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
391 movlw b'00100101' ; power on ADC, select AN9
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
392 rcall wait_adc
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
393 bcf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
394 rrcf ADRESH,F ; /2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
395 rrcf ADRESL,W
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
396 ; add to o2_mv_sensor2:2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
397 addwf o2_mv_sensor2+0,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
398 movf ADRESH,W
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
399 addwfc o2_mv_sensor2+1,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
400 ; Devide by 2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
401 bcf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
402 rrcf o2_mv_sensor2+1,F ; /2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
403 rrcf o2_mv_sensor2+0,F
196
a0e0ddfc1b49 suppress ghost readings for long, open cables
heinrichsweikamp
parents: 189
diff changeset
404
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
405 movlw HIGH ignore_mv
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
406 cpfsgt o2_mv_sensor2+1 ; >ignore_mv?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
407 bra get_analog_inputs3a ; No
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
408 ; Yes, ignore this reading
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
409 clrf o2_mv_sensor2+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
410 clrf o2_mv_sensor2+0
196
a0e0ddfc1b49 suppress ghost readings for long, open cables
heinrichsweikamp
parents: 189
diff changeset
411 get_analog_inputs3a:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
412 ; Ignore 1,9mV noise for not-connected inputs
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
413 tstfsz o2_mv_sensor2+1 ; >25,5mV?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
414 bra get_analog_inputs3 ; Yes, skip here
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
415 movlw .19
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
416 cpfsgt o2_mv_sensor2+0 ; >1,9mV?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
417 clrf o2_mv_sensor2+0 ; no, clear result
187
669b5d00706d CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents: 158
diff changeset
418 get_analog_inputs3:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
419 movlw b'00101001' ; power on ADC, select AN10
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
420 rcall wait_adc
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
421 bcf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
422 rrcf ADRESH,F ; /2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
423 rrcf ADRESL,W
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
424 ; add to o2_mv_sensor3:2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
425 addwf o2_mv_sensor3+0,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
426 movf ADRESH,W
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
427 addwfc o2_mv_sensor3+1,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
428 ; Devide by 2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
429 bcf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
430 rrcf o2_mv_sensor3+1,F ; /2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
431 rrcf o2_mv_sensor3+0,F
196
a0e0ddfc1b49 suppress ghost readings for long, open cables
heinrichsweikamp
parents: 189
diff changeset
432
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
433 movlw HIGH ignore_mv
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
434 cpfsgt o2_mv_sensor3+1 ; >ignore_mv?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
435 bra get_analog_inputs4a ; No
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
436 ; Yes, ignore this reading
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
437 clrf o2_mv_sensor3+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
438 clrf o2_mv_sensor3+0
196
a0e0ddfc1b49 suppress ghost readings for long, open cables
heinrichsweikamp
parents: 189
diff changeset
439 get_analog_inputs4a:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
440 ; Ignore 1,9mV noise for not-connected inputs
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
441 tstfsz o2_mv_sensor3+1 ; >25,5mV?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
442 bra get_analog_inputs4 ; Yes, skip here
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
443 movlw .19
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
444 cpfsgt o2_mv_sensor3+0 ; >1,9mV?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
445 clrf o2_mv_sensor3+0 ; no, clear result
187
669b5d00706d CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents: 158
diff changeset
446 get_analog_inputs4:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
447 bcf ADCON0,0 ; power off ADC
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
448 bcf adc_running ; =1: The ADC is in use
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
449 return
0
heinrichsweikamp
parents:
diff changeset
450
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
451 global piezo_config ; sets up piezo sensitivity of heinrichs weikamp piezo buttons (~30ms)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
452 piezo_config: ; Settings between 20 and 200
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
453 clrf TMR5H
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
454 clrf TMR5L ; ~2sec
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
455 bcf PIR5,TMR5IF ; Clear flag
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
456 bcf switch_right
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
457 bcf switch_left
416
4389fe9673b2 NEW: Support for new logbook memory chip (minor hardware change)
heinrichsweikamp
parents: 357
diff changeset
458 piezo_config0:
4389fe9673b2 NEW: Support for new logbook memory chip (minor hardware change)
heinrichsweikamp
parents: 357
diff changeset
459 btfsc switch_right
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
460 bra piezo_config
416
4389fe9673b2 NEW: Support for new logbook memory chip (minor hardware change)
heinrichsweikamp
parents: 357
diff changeset
461 btfsc switch_left
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
462 bra piezo_config ; Restart on button press
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
463
416
4389fe9673b2 NEW: Support for new logbook memory chip (minor hardware change)
heinrichsweikamp
parents: 357
diff changeset
464 btfss PIR5,TMR5IF
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
465 bra piezo_config0 ; Wait loop
468
heinrichsweikamp
parents: 466
diff changeset
466
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
467 bcf INTCON,GIE
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
468 movff opt_cR_button_right,WREG ; right button
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
469 btfsc flip_screen ; 180° rotation ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
470 movff opt_cR_button_left,WREG ; Yes, left button
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
471 rcall piezo_config_tx
343
34e2f5bdc5a2 BUGFIX: Rotate button sensitivity with screen (OSTC 2 and cR)
heinrichsweikamp
parents: 275
diff changeset
472
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
473 movff opt_cR_button_left,WREG ; left button
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
474 btfsc flip_screen ; 180° rotation ?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
475 movff opt_cR_button_right,WREG ; Yes, right button
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
476 rcall piezo_config_tx
343
34e2f5bdc5a2 BUGFIX: Rotate button sensitivity with screen (OSTC 2 and cR)
heinrichsweikamp
parents: 275
diff changeset
477
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
478 movlw .20 ; reserved
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
479 rcall piezo_config_tx
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
480 movlw .20 ; reserved
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
481 rcall piezo_config_tx
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
482 bsf INTCON,GIE
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
483 return
204
heinrichsweikamp
parents: 203
diff changeset
484
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
485 piezo_config_tx: ; send one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
486 movwf lo ; store byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
487 movlw .8
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
488 movwf hi ; bit counter
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
489 bcf TX3_PIEZO_CFG ; start bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
490 rcall piezo_config_wait_bit
113
heinrichsweikamp
parents: 44
diff changeset
491 piezo_config_tx_loop:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
492 btfss lo,0 ; LSB first
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
493 bcf TX3_PIEZO_CFG
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
494 btfsc lo,0 ; LSB first
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
495 bsf TX3_PIEZO_CFG
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
496 rcall piezo_config_wait_bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
497 rrncf lo,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
498 decfsz hi,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
499 bra piezo_config_tx_loop
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
500 bsf TX3_PIEZO_CFG ; stop bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
501 rcall piezo_config_wait_bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
502 return
113
heinrichsweikamp
parents: 44
diff changeset
503
heinrichsweikamp
parents: 44
diff changeset
504 piezo_config_wait_bit:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
505 setf TMR5H
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
506 movlw .255-.26 ; 26 x 31,5µs = 819us
113
heinrichsweikamp
parents: 44
diff changeset
507 movwf TMR5L
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
508 bcf PIR5,TMR5IF ; Clear flag
113
heinrichsweikamp
parents: 44
diff changeset
509 piezo_config_wait_bit3:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
510 btfss PIR5,TMR5IF
113
heinrichsweikamp
parents: 44
diff changeset
511 bra piezo_config_wait_bit3 ; Wait loop
heinrichsweikamp
parents: 44
diff changeset
512 return
heinrichsweikamp
parents: 44
diff changeset
513
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
514 global reset_battery_pointer
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
515 reset_battery_pointer: ; Resets battery pointer 0x07-0x0C and battery_gauge:5
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
516 extern lt2942_charge_done
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
517 btfsc battery_gauge_available ; Something to reset?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
518 call lt2942_charge_done ; Yes, reset accumulating registers to 0xFFFF
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
519 goto reset_battery_internal_only ; and return
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
520
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
521
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
522 global get_analog_switches
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
523 get_analog_switches: ; starts ADC and waits until finished
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
524 btfsc analog_switches
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
525 bra get_analog_switches2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
526 ; no analog switches
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
527 bcf analog_sw2_pressed
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
528 bcf analog_sw1_pressed
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
529 return ; Done.
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
530 get_analog_switches2:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
531 btfsc adc_running ; ADC in use?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
532 return ; Yes, return
0
heinrichsweikamp
parents:
diff changeset
533
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
534 movlw b'00001001' ; left justified
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
535 movwf ADCON2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
536 ; movlw b'00000000' ; Vref+ = Vdd
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
537 clrf ADCON1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
538 movlw b'00100101' ; power on ADC, select AN9
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
539 rcall wait_adc
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
540 banksel analog_counter
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
541 movff ADRESH,WREG
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
542 addwf analog_sw2_raw+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
543 movlw .0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
544 addwfc analog_sw2_raw+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
545 decfsz analog_counter,F ; continue averaging?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
546 bra get_analog_switches2a ; Yes
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
547 ; Done. Compute average
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
548 bcf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
549 rrcf analog_sw2_raw+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
550 rrcf analog_sw2_raw+0 ; /2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
551 bcf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
552 rrcf analog_sw2_raw+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
553 rrcf analog_sw2_raw+0 ; /4
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
554 bcf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
555 rrcf analog_sw2_raw+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
556 rrcf analog_sw2_raw+0 ; /8
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
557 bcf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
558 rrcf analog_sw2_raw+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
559 rrcf analog_sw2_raw+0 ; /16
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
560 movff analog_sw2_raw+0,analog_sw2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
561 clrf analog_sw2_raw+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
562 clrf analog_sw2_raw+0 ; Reset average registers
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
563 ; movlw .16
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
564 ; movwf analog_counter ; only once...
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
565 get_analog_switches2a:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
566 banksel common
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
567 bcf analog_sw2_pressed
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
568 movff opt_cR_button_left,WREG ;20-100
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
569 bcf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
570 rrcf WREG ;/2 -> 10-50
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
571 bcf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
572 rrcf WREG ;/2 -> 5-25
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
573 decf WREG,W ;-1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
574 decf WREG,W ;-1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
575 decf WREG,W ;-1 -> 2-22
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
576 banksel analog_sw2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
577 btfss button_polarity,1 ;(1= normal, 0=inverted)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
578 bra sw2_inverted
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
579 addwf analog_sw2,W ; average (~128)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
580 cpfsgt ADRESH
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
581 bra get_analog_sw1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
582 banksel common
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
583 bsf analog_sw2_pressed ; Left button normal
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
584 bra get_analog_sw1
475
237afdfb4918 2.12 release candidate...
heinrichsweikamp
parents: 474
diff changeset
585 sw2_inverted:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
586 subwf analog_sw2,W ; average (~128)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
587 cpfslt ADRESH
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
588 bra get_analog_sw1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
589 banksel common
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
590 bsf analog_sw2_pressed ; Left button inverted
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
591 get_analog_sw1:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
592 banksel common
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
593 movlw b'00101001' ; power on ADC, select AN10
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
594 rcall wait_adc
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
595 banksel analog_counter
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
596 movff ADRESH,WREG
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
597 addwf analog_sw1_raw+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
598 movlw .0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
599 addwfc analog_sw1_raw+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
600 tstfsz analog_counter ; continue averaging?
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
601 bra get_analog_switches1a ; Yes
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
602 ; Done. Compute average
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
603 bcf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
604 rrcf analog_sw1_raw+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
605 rrcf analog_sw1_raw+0 ; /2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
606 bcf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
607 rrcf analog_sw1_raw+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
608 rrcf analog_sw1_raw+0 ; /4
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
609 bcf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
610 rrcf analog_sw1_raw+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
611 rrcf analog_sw1_raw+0 ; /8
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
612 bcf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
613 rrcf analog_sw1_raw+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
614 rrcf analog_sw1_raw+0 ; /16
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
615 movff analog_sw1_raw+0,analog_sw1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
616 clrf analog_sw1_raw+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
617 clrf analog_sw1_raw+0 ; Reset average registers
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
618 movlw .16
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
619 movwf analog_counter ; only once...
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
620 get_analog_switches1a:
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
621 banksel common
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
622 bcf analog_sw1_pressed
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
623 movff opt_cR_button_right,WREG ;20-100
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
624 bcf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
625 rrcf WREG ;/2 -> 10-50
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
626 bcf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
627 rrcf WREG ;/2 -> 5-25
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
628 decf WREG,W ;-1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
629 decf WREG,W ;-1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
630 decf WREG,W ;-1 -> 2-22
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
631 banksel analog_sw1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
632 btfss button_polarity,0 ;(1= normal, 0=inverted)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
633 bra sw1_inverted
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
634 addwf analog_sw1,W ; average (~128)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
635 cpfsgt ADRESH
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
636 bra get_analog_sw_done
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
637 banksel common
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
638 bsf analog_sw1_pressed ; right button normal
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
639 bra get_analog_sw_done
475
237afdfb4918 2.12 release candidate...
heinrichsweikamp
parents: 474
diff changeset
640 sw1_inverted:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
641 subwf analog_sw1,W ; average (~128)
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
642 cpfslt ADRESH
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
643 bra get_analog_sw_done
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
644 banksel common
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
645 bsf analog_sw1_pressed ; right button inverted
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
646 get_analog_sw_done:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
647 banksel common
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
648 movlw b'10001101' ; Restore to right justified
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
649 movwf ADCON2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
650 btfsc analog_sw1_pressed
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
651 return
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
652 btfsc analog_sw2_pressed
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
653 return
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
654 setf TMR1H ; No button pressed, enhance timer1 to overflow quickly
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
655 return
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
656
0
heinrichsweikamp
parents:
diff changeset
657 END