annotate src/adc_lightsensor.asm @ 629:237931377539

3.07 stable release
author heinrichsweikamp
date Fri, 29 Nov 2019 18:48:11 +0100
parents cd58f7fc86db
children 185ba2f91f59
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
heinrichsweikamp
parents:
diff changeset
1 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
2 ;
629
237931377539 3.07 stable release
heinrichsweikamp
parents: 628
diff changeset
3 ; File adc_lightsensor.asm combined next generation V3.06.1
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
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
18 adc_light CODE
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
19
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
20 ;=============================================================================
0
heinrichsweikamp
parents:
diff changeset
21
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
22 wait_adc: ; bank-safe
0
heinrichsweikamp
parents:
diff changeset
23 movwf ADCON0
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
24 nop
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
25 bsf ADCON0,1 ; start ADC
0
heinrichsweikamp
parents:
diff changeset
26 wait_adc2:
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
27 btfsc ADCON0,1 ; wait...
0
heinrichsweikamp
parents:
diff changeset
28 bra wait_adc2
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
29 return
0
heinrichsweikamp
parents:
diff changeset
30
heinrichsweikamp
parents:
diff changeset
31 global get_battery_voltage
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
32 get_battery_voltage: ; start ADC and wait until finished
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
33 btfss battery_gauge_available ; battery gauge IC available?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
34 bra get_battery_voltage_2 ; NO - OSTC hardware without gauge IC
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
35 call lt2942_get_accumulated_charge ; YES - read coulomb counter
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
36 call lt2942_get_voltage ; - read battery voltage
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
37 call lt2942_get_temperature ; - read battery temperature
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
38 tstfsz batt_voltage+1 ; - read voltage < 256 mV ?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
39 bra get_battery_voltage_1 ; NO - proceed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
40 call lt2942_get_accumulated_charge ; YES - re-read coulomb counter
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
41 call lt2942_get_voltage ; - re-read battery voltage
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
42 call lt2942_get_temperature ; - re-read battery temperature
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
43 ;bra get_battery_voltage_1 ; - proceed
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
44
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
45 get_battery_voltage_1:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
46 btfsc divemode ; in dive mode?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
47 return ; YES - done
120
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
48
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
49 bcf cv_active ; clear CV charing status by default
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
50 bcf cc_active ; clear CC charing status ny default
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
51 bcf LEDr ; switch off red LED
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
52 bcf TRISJ,2 ; activate Chrg-Out output
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
53 bsf CHRG_OUT ; start charger
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
54 btfss CHRG_IN ; charging?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
55 bra charge_cc_active ; YES - charging in CC mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
56 bcf CHRG_OUT ; NO - stop charger
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
57 bsf TRISJ,2 ; - set Chrg-Out output to high impedance
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
58 WAITMS d'1' ; - wait 1 ms
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
59 btfsc CHRG_IN ; - still charging?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
60 return ; NO - done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
61 ;bra charge_cv_active ; YES - charging in CV mode
120
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
62
603
00b24fb4324d second method to detect a full charge
heinrichsweikamp
parents: 582
diff changeset
63 charge_cv_active:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
64 decfsz get_bat_volt_counter,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
65 return
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
66 movlw .15
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
67 cpfsgt batt_voltage+1 ; battery voltage >= 16*256mV (4.096V) ?
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
68 bra charge_cc_active ; NO
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
69 bsf cc_active
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
70 bsf cv_active
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
71 bsf LEDr ; indicate charging
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
72 call lt2942_charge_done ; reset accumulating registers to 0xFFFF
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
73 WAITMS d'10'
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
74 bcf LEDr ; indicate charging
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
75 bsf get_bat_volt_counter,0 ; =1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
76 return
120
e2f04bb2539c battery check in sleep
heinrichsweikamp
parents: 118
diff changeset
77
207
f5d909e03f52 charge indicator on surface screen
heinrichsweikamp
parents: 204
diff changeset
78 charge_cc_active:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
79 bsf cc_active
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
80 bsf LEDr ; indicate charging
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
81 bcf CHRG_OUT
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
82 bsf TRISJ,2 ; set chrg-Out output to high impedance
603
00b24fb4324d second method to detect a full charge
heinrichsweikamp
parents: 582
diff changeset
83 movlw .15
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
84 cpfsgt batt_voltage+1 ; battery voltage >= 16*256mV (4.096 V)?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
85 bra charge_cc_active2 ; NO
603
00b24fb4324d second method to detect a full charge
heinrichsweikamp
parents: 582
diff changeset
86 movlw .81
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
87 cpfslt batt_voltage+0 ; battery voltage >= 80mV (+4096mV from batt_voltage+1)?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
88 bra charge_cv_active ; YES
603
00b24fb4324d second method to detect a full charge
heinrichsweikamp
parents: 582
diff changeset
89 charge_cc_active2:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
90 movlw .10
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
91 movwf get_bat_volt_counter
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
92 return
113
heinrichsweikamp
parents: 44
diff changeset
93
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
94 get_battery_voltage_2: ; no gauge IC available, use ADC to measure battery voltage
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
95 ; additional charging disable in software
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
96 bsf charge_disable ; set charging-inhibit signal
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
97 bcf charge_enable ; activate charging-inhibit signal
615
b87f23fae743 work on new battery menu
heinrichsweikamp
parents: 608
diff changeset
98
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
99 bsf adc_is_running ; =1: the ADC is in use
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
100 movlw b'00100000' ; 2.048 Volt Vref+ -> 1 LSB = 500 µV
0
heinrichsweikamp
parents:
diff changeset
101 movwf ADCON1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
102 movlw b'00011001' ; power on ADC, select AN6
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
103 rcall wait_adc
0
heinrichsweikamp
parents:
diff changeset
104
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
105 MOVII ADRESL,batt_voltage ; store value
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
106 bcf ADCON0,0 ; power off ADC
0
heinrichsweikamp
parents:
diff changeset
107
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
108 ; Multiply with 2.006 to be exact here...
0
heinrichsweikamp
parents:
diff changeset
109 ; bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
110 ; rlcf xA+0,F
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
111 ; rlcf xA+1,F ; x2
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
112 ; MOVII xA,batt_voltage ; store value
0
heinrichsweikamp
parents:
diff changeset
113
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
114 bcf battery_is_36v ; by default assume it is a 1.5 battery
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
115 MOVII batt_voltage,sub_b ; load measured battery voltage
0
heinrichsweikamp
parents:
diff changeset
116
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
117 ; Check if the battery is a 3.6V lithium
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
118 MOVLI lithium_36v_low,sub_a ; load threshold for 3.6 Volt lithium battery
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
119 call cmpU16 ; sub_a - sub_b
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
120 btfss neg_flag ; battery voltage > 3.6 V lithium threshold ?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
121 bra get_battery_voltage_9 ; NO - keep assumption of 1.5V battery
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
122 bsf battery_is_36v ; YES - set flag
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
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
125 MOVLI lithium_36v_empty,sub_a ; load threshold for near-dead lithium battery
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
126 call cmpU16 ; sub_a - sub_b
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
127 btfsc neg_flag ; battery voltage > dead-battery threshold ?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
128 bra get_battery_voltage_3 ; YES - battery is still ok
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
129 movlw .128 ; NO - battery is probably dead very soon, set ">=24Ah used"
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
130 movff WREG,battery_gauge+5 ; - into battery gauge registers
0
heinrichsweikamp
parents:
diff changeset
131
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
132 get_battery_voltage_3: ; 3.6V battery gauge mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
133 ; SMOVFF "by hand" as the macro does not work with arguments that have a '+something' with them
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
134 bcf trigger_isr_updates ; clear flag, it will be set by the ISR in case it had kicked in
0
heinrichsweikamp
parents:
diff changeset
135 movff battery_gauge+5,xC+3
heinrichsweikamp
parents:
diff changeset
136 movff battery_gauge+4,xC+2
heinrichsweikamp
parents:
diff changeset
137 movff battery_gauge+3,xC+1
heinrichsweikamp
parents:
diff changeset
138 movff battery_gauge+2,xC+0
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
139 btfsc trigger_isr_updates ; did the ISR kicked in since we cleared the flag?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
140 bra get_battery_voltage_3 ; YES - retry copy
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
141
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
142 ; battery_gauge: 6 is nAs
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
143 ; divide through 65536
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
144 ; divide through battery_capacity:2
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
145 ; result is in percent
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
146 MOVII battery_capacity_internal,xB
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
147 call div32x16 ; xC:4 = xC:4 / xB:2 with xA as remainder
0
heinrichsweikamp
parents:
diff changeset
148 movff xC+0,lo
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
149 ; limit to 100
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
150 movlw .100
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
151 cpfslt lo
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
152 movwf lo
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
153 ; lo will be between 0 (full) and 100 (empty)
0
heinrichsweikamp
parents:
diff changeset
154 movf lo,W
heinrichsweikamp
parents:
diff changeset
155 sublw .100
heinrichsweikamp
parents:
diff changeset
156 movwf lo
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
157 get_battery_voltage_4:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
158 movlw .100 ; start with default of 100%
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
159 cpfslt lo ; > 100%
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
160 movwf lo ; YES - limit to 100%
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
161 ; lo will be between 100 (full) and 0 (empty)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
162 ; use 3.6V battery sensing based on 50 mA load
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
163 MOVLI lithium_36v_75,sub_a ; load threshold for > 75%
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
164 call cmpU16 ; sub_a - sub_b
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
165 btfsc neg_flag ; battery voltage above 75% level?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
166 bra get_battery_voltage_5 ; YES
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
167 movlw .75 ; NO - set to 75%
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
168 movwf lo
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
169 get_battery_voltage_5:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
170 ; 50%
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
171 MOVLI lithium_36v_50,sub_a ; load threshold for > 50%
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
172 call cmpU16 ; sub_a - sub_b
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
173 btfsc neg_flag ; battery voltage above 75% level?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
174 bra get_battery_voltage_6 ; YES
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
175 movlw .50 ; NO - set to 50%
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
176 movwf lo
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
177 get_battery_voltage_6:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
178 ; 25%
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
179 MOVLI lithium_36v_25,sub_a ; load threshold for > 25%
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
180 call cmpU16 ; sub_a - sub_b
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
181 btfsc neg_flag ; battery voltage above 25% level?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
182 bra get_battery_voltage_7 ; YES
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
183 movlw .25 ; NO - set to 25%
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
184 movwf lo
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
185 get_battery_voltage_7:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
186 ; 10%
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
187 MOVLI lithium_36v_10,sub_a ; load threshold for > 10%
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
188 call cmpU16 ; sub_a - sub_b
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
189 btfsc neg_flag ; battery voltage above 10% level?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
190 bra get_battery_voltage_8 ; YES
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
191 movlw .10 ; NO - set to 10%
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
192 movwf lo
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
193 get_battery_voltage_8:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
194 movlw .100 ; maximum is 100 (%)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
195 cpfslt lo ; > 100% ?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
196 movwf lo ; YES - limit to 100%
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
197 movf batt_percent,W ; get last battery percentage
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
198 cpfsgt lo ; current battery % < last battery % ?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
199 movff lo,batt_percent ; YES - take new value (keep batt_percent on the lowest value found)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
200 btfsc battery_is_36v ; using a 3.6 volt battery?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
201 movff lo,batt_percent ; YES - take new value (always use computed value for 3.6V battery)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
202 bcf adc_is_running ; done with ADC
0
heinrichsweikamp
parents:
diff changeset
203 return
heinrichsweikamp
parents:
diff changeset
204
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
205 get_battery_voltage_9:
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
206 ; use 1.5V battery voltage mode
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
207 ; use approximation (batt_voltage-aa_15v_low)/4 = lo
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
208 MOVII batt_voltage,sub_a ; load battery voltage
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
209 MOVLI aa_15v_low, sub_b ; load offset
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
210 call subU16 ; sub_c = sub_a - sub_b
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
211 bcf STATUS,C ; shift right to divide / 2
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
212 rrcf sub_c+1
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
213 rrcf sub_c+0
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
214 bcf STATUS,C ; another shift right to divide / 4
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
215 rrcf sub_c+1
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
216 rrcf sub_c+0
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
217 movff sub_c+0,lo ; store result
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
218 bra get_battery_voltage_8 ; check limits and return
0
heinrichsweikamp
parents:
diff changeset
219
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
220
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
221 global get_ambient_level ; called from ISR only, in context bank isr_backup
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
222 get_ambient_level:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
223 btfsc sleepmode ; in sleep mode?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
224 return ; YES - done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
225 btfsc adc_is_running ; NO - ADC in use?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
226 return ; YES - return
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
227 banksel HW_descriptor ; NO - select bank where hardware descriptor is stored
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
228 btfsc ambient_sensor ; - ambient sensor available?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
229 bra get_ambient_level1 ; YES - use sensor
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
230 banksel isr_backup ; NO - back to ISR default bank
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
231 movff opt_brightness,isr_lo ; - get brightness selection
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
232 incf isr_lo,F ; - 0-2 -> 1-3
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
233 movlw ambient_light_max_high_cr ; - default selection to brightest setting
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
234 dcfsnz isr_lo,F ; - level 0 (eco) selected?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
235 movlw ambient_light_max_eco ; YES - select eco brightness
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
236 dcfsnz isr_lo,F ; - level 1 (medium) selected?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
237 movlw ambient_light_max_medium ; YES - select medium brightness
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
238 movwf ambient_light+0 ; - store selection
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
239 movwf max_CCPR1L ; - store value for dimming in TMR7 interrupt
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
240 return ; - done
203
dd9b167e82dc 1.64 (Fix ambient light for cR)
heinrichsweikamp
parents: 201
diff changeset
241
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
242 get_ambient_level1: ; using ambient sensor
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
243 banksel isr_backup ; back to ISR default bank
629
237931377539 3.07 stable release
heinrichsweikamp
parents: 628
diff changeset
244 clrf ADCON1 ; Vref+ = Vdd
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
245 movlw b'00011101' ; power on ADC, select AN7
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
246 rcall wait_adc
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
247 MOVII ADRESL,ambient_light
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
248 bcf ADCON0,0 ; power off ADC
0
heinrichsweikamp
parents:
diff changeset
249
heinrichsweikamp
parents:
diff changeset
250 ; ambient_light:2 is between 4096 (direct sunlight) and about 200 (darkness)
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
251 ; first: divide by 16
0
heinrichsweikamp
parents:
diff changeset
252 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
253 rrcf ambient_light+1
heinrichsweikamp
parents:
diff changeset
254 rrcf ambient_light+0
heinrichsweikamp
parents:
diff changeset
255 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
256 rrcf ambient_light+1
heinrichsweikamp
parents:
diff changeset
257 rrcf ambient_light+0
heinrichsweikamp
parents:
diff changeset
258 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
259 rrcf ambient_light+1
heinrichsweikamp
parents:
diff changeset
260 rrcf ambient_light+0
heinrichsweikamp
parents:
diff changeset
261 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
262 rrcf ambient_light+1
heinrichsweikamp
parents:
diff changeset
263 rrcf ambient_light+0
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
264 ; result: ambient_light:2/16
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
265 ; now make sure to have value between ambient_light_low and ambient_light_max
0
heinrichsweikamp
parents:
diff changeset
266
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
267 movlw .254
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
268 tstfsz ambient_light+1 ; > 255 ?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
269 movwf ambient_light+0 ; YES - avoid ADC clipping
0
heinrichsweikamp
parents:
diff changeset
270
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
271 incfsz ambient_light+0,W ; = 255 ?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
272 bra get_ambient_level2 ; NO - continue
0
heinrichsweikamp
parents:
diff changeset
273
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
274 movlw .254
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
275 movwf ambient_light+0 ; avoid ADC clipping
0
heinrichsweikamp
parents:
diff changeset
276
heinrichsweikamp
parents:
diff changeset
277 get_ambient_level2:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
278 ; movlw .10
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
279 ; subwf ambient_light+0,F ; subtract 10 (ADC Offset)
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
280 ; btfsc STATUS,N
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
281 ; movwf ambient_light+0 ; avoid clipping
201
82faedf8fd58 lower minimum backlight in eco mode
heinrichsweikamp
parents: 200
diff changeset
282
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
283 movff opt_brightness,isr_lo ; get brightness setting
0
heinrichsweikamp
parents:
diff changeset
284
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
285 btfsc RCSTA1,7 ; UART module on?
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
286 clrf isr_lo ; YES - set temporary to eco mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
287 incf isr_lo,F ; adjust 0-2 to 1-3
0
heinrichsweikamp
parents:
diff changeset
288
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
289 movlw ambient_light_max_high_cr ; cR and 2 hardware brightest setting
0
heinrichsweikamp
parents:
diff changeset
290
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
291 banksel HW_descriptor ; select bank where hardware descriptor and model variant is stored
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
292 btfss battery_gauge_available
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
293 movlw ambient_light_max_high_15V ; 1.5V battery brightest setting
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
294 btfsc battery_is_36v ; 3.6V battery in use?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
295 movlw ambient_light_max_high_36V ; YES - 3.6V battery brightest setting
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
296 banksel isr_backup ; back to ISR default bank
0
heinrichsweikamp
parents:
diff changeset
297
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
298 dcfsnz isr_lo,F
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
299 movlw ambient_light_max_eco ; eco setting
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
300 dcfsnz isr_lo,F
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
301 movlw ambient_light_max_medium ; brightest setting
0
heinrichsweikamp
parents:
diff changeset
302
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
303 incf ambient_light+0,F ; +1
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
304 cpfslt ambient_light+0 ; smaller than WREG?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
305 movwf ambient_light+0 ; NO - set to max.
0
heinrichsweikamp
parents:
diff changeset
306
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
307 movff opt_brightness,isr_lo
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
308 incf isr_lo,F ; adjust 0-2 to 1-3
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
309 movlw ambient_light_min_high ; darkest setting
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
310 dcfsnz isr_lo,F
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
311 movlw ambient_light_min_eco ; darkest setting
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
312 dcfsnz isr_lo,F
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
313 movlw ambient_light_min_medium ; darkest setting
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
314 dcfsnz isr_lo,F
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
315 movlw ambient_light_min_high ; darkest setting
0
heinrichsweikamp
parents:
diff changeset
316
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
317 cpfsgt ambient_light+0 ; bigger than WREG?
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
318 movwf ambient_light+0 ; NO - set to min
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
319
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
320 movff ambient_light+0,max_CCPR1L ; store value for dimming in TMR7 interrupt
0
heinrichsweikamp
parents:
diff changeset
321 return
heinrichsweikamp
parents:
diff changeset
322
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
323
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
324 ;=============================================================================
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
325 ; routines for reading analog-attached external sensors
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
326 ;
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
327 IFDEF _external_sensor
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
328
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
329 global get_analog_inputs ; called from outside ISR only
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
330 get_analog_inputs: ; start ADC and wait until finished
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
331 bsf adc_is_running ; =1: the ADC is in use
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
332 btfsc TFT_PWM
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
333 bra get_analog_inputs ; wait for PWM low
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
334 movlw b'00100000' ; 2.048V Vref+ -> 1 LSB = 500 µV
113
heinrichsweikamp
parents: 44
diff changeset
335 movwf ADCON1
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
336 banksel sensor1_mv ; select bank where sensor1_mv is stored
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
337 ; Sensor 1
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
338 movlw b'00100001' ; power on ADC, select AN8
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
339 rcall wait_adc
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
340 bcf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
341 rrcf ADRESH,F ; /2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
342 rrcf ADRESL,W
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
343 addwf sensor1_mv+0,F ; add to sensor1_mv:2
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
344 movf ADRESH,W
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
345 addwfc sensor1_mv+1,F
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
346 bcf STATUS,C
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
347 rrcf sensor1_mv+1,F ; divide /2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
348 rrcf sensor1_mv+0,F
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
349 movlw HIGH ignore_mv
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
350 cpfsgt sensor1_mv+1 ; > ignore_mv ?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
351 bra get_analog_inputs1a ; NO
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
352 CLRI sensor1_mv ; YES - ignore this reading
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
353 get_analog_inputs1a: ; ignore 1.9 mV noise for not-connected inputs
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
354 tstfsz sensor1_mv+1 ; > 25.5 mV ?
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
355 bra get_analog_inputs2 ; YES - skip here
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
356 movlw .19
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
357 cpfsgt sensor1_mv+0 ; > 1.9 mV ?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
358 clrf sensor1_mv+0 ; NO - clear result
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
359
187
669b5d00706d CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents: 158
diff changeset
360 get_analog_inputs2:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
361 ; Sensor 2
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
362 movlw b'00100101' ; power on ADC, select AN9
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
363 rcall wait_adc
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
364 bcf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
365 rrcf ADRESH,F ; /2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
366 rrcf ADRESL,W
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
367 addwf sensor2_mv+0,F ; add to sensor2_mv:2
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
368 movf ADRESH,W
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
369 addwfc sensor2_mv+1,F
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
370 bcf STATUS,C
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
371 rrcf sensor2_mv+1,F ; divide /2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
372 rrcf sensor2_mv+0,F
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
373 movlw HIGH ignore_mv
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
374 cpfsgt sensor2_mv+1 ; > ignore_mv ?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
375 bra get_analog_inputs2a ; NO
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
376 CLRI sensor2_mv ; YES - ignore this reading
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
377 get_analog_inputs2a: ; ignore 1.9 mV noise for not-connected inputs
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
378 tstfsz sensor2_mv+1 ; > 25.5 mV ?
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
379 bra get_analog_inputs3 ; YES - skip here
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
380 movlw .19
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
381 cpfsgt sensor2_mv+0 ; > 1.9 mV ?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
382 clrf sensor2_mv+0 ; NO - clear result
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
383
187
669b5d00706d CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents: 158
diff changeset
384 get_analog_inputs3:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
385 ; Sensor 3
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
386 movlw b'00101001' ; power on ADC, select AN10
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
387 rcall wait_adc
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
388 bcf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
389 rrcf ADRESH,F ; /2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
390 rrcf ADRESL,W
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
391 addwf sensor3_mv+0,F ; add to sensor3_mv:2
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
392 movf ADRESH,W
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
393 addwfc sensor3_mv+1,F
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
394 bcf STATUS,C
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
395 rrcf sensor3_mv+1,F ; divide /2
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
396 rrcf sensor3_mv+0,F
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
397 movlw HIGH ignore_mv
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
398 cpfsgt sensor3_mv+1 ; > ignore_mv ?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
399 bra get_analog_inputs3a ; NO
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
400 CLRI sensor3_mv ; YES - ignore this reading
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
401 get_analog_inputs3a: ; ignore 1.9 mV noise for not-connected inputs
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
402 tstfsz sensor3_mv+1 ; > 25.5 mV ?
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
403 bra get_analog_inputs4 ; YES - skip here
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
404 movlw .19
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
405 cpfsgt sensor3_mv+0 ; > 1.9 mV ?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
406 clrf sensor3_mv+0 ; NO - clear result
187
669b5d00706d CHANGE: Longer timeout (4 min) for calibration menu
heinrichsweikamp
parents: 158
diff changeset
407 get_analog_inputs4:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
408 banksel common ; back to bank common
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
409 bcf ADCON0,0 ; power off ADC
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
410 bcf adc_is_running ; done with ADC
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
411 return
0
heinrichsweikamp
parents:
diff changeset
412
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
413 ENDIF ; _external_sensor
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
414
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
415 ;=============================================================================
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
416
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
417 global piezo_config ; called from outside ISR only
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
418 piezo_config: ; set up sensitivity of heinrichsweikamp piezo buttons (~30ms)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
419 clrf TMR5H ; clear TMR5H first
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
420 clrf TMR5L ; clear TMR5L thereafter
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
421 bcf PIR5,TMR5IF ; clear timer 5 overrun flag, will take ~ 2 seconds to overrun after reset
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
422 bcf switch_right ; clear left-over button events
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
423 bcf switch_left ; ...
416
4389fe9673b2 NEW: Support for new logbook memory chip (minor hardware change)
heinrichsweikamp
parents: 357
diff changeset
424 piezo_config0:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
425 btfsc switch_right ; user still pressing the right button?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
426 bra piezo_config ; YES - loop to wait for release
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
427 btfsc switch_left ; user still pressing the left button?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
428 bra piezo_config ; YES - loop to wait for release
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
429
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
430 btfss PIR5,TMR5IF ; timeout?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
431 bra piezo_config0 ; NO - not yet, loop
468
heinrichsweikamp
parents: 466
diff changeset
432
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
433 bcf INTCON,GIE
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
434
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
435 movff opt_cR_button_right,WREG ; right button
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
436 btfsc flip_screen ; 180° rotation ?
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
437 movff opt_cR_button_left,WREG ; YES - left button
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
438 rcall piezo_config_tx
343
34e2f5bdc5a2 BUGFIX: Rotate button sensitivity with screen (OSTC 2 and cR)
heinrichsweikamp
parents: 275
diff changeset
439
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
440 movff opt_cR_button_left,WREG ; left button
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
441 btfsc flip_screen ; 180° rotation ?
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
442 movff opt_cR_button_right,WREG ; YES - right button
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
443 rcall piezo_config_tx
343
34e2f5bdc5a2 BUGFIX: Rotate button sensitivity with screen (OSTC 2 and cR)
heinrichsweikamp
parents: 275
diff changeset
444
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
445 movlw .20 ; reserved
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
446 rcall piezo_config_tx
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
447 movlw .20 ; reserved
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
448 rcall piezo_config_tx
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
449
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
450 bsf INTCON,GIE
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
451 return
204
heinrichsweikamp
parents: 203
diff changeset
452
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
453 piezo_config_tx: ; send one byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
454 movwf lo ; store byte
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
455 movlw .8
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
456 movwf hi ; bit counter
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
457 bcf TX3_PIEZO_CFG ; start bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
458 rcall piezo_config_wait_bit
113
heinrichsweikamp
parents: 44
diff changeset
459 piezo_config_tx_loop:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
460 btfss lo,0 ; LSB first
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
461 bcf TX3_PIEZO_CFG
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
462 btfsc lo,0 ; LSB first
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
463 bsf TX3_PIEZO_CFG
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
464 rcall piezo_config_wait_bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
465 rrncf lo,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
466 decfsz hi,F
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
467 bra piezo_config_tx_loop
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
468 bsf TX3_PIEZO_CFG ; stop bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
469 rcall piezo_config_wait_bit
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
470 return
113
heinrichsweikamp
parents: 44
diff changeset
471
heinrichsweikamp
parents: 44
diff changeset
472 piezo_config_wait_bit:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
473 setf TMR5H ; set TMR5H first (to 255)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
474 movlw .255-.26 ; 26 x 31.5 µs = 819 us
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
475 movwf TMR5L ; set TMR5L thereafter
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
476 bcf PIR5,TMR5IF ; clear timer 5 overrun flag
113
heinrichsweikamp
parents: 44
diff changeset
477 piezo_config_wait_bit3:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
478 btfss PIR5,TMR5IF ; timeout?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
479 bra piezo_config_wait_bit3 ; NO - loop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
480 return ; YES - done
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
481
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
482
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
483 global get_analog_switches ; called from ISR and from sleep mode, returns in bank common
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
484 get_analog_switches: ; start ADC and wait until finished
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
485 banksel HW_variants ; switch to bank where OSTC model variant is stored
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
486 btfsc analog_switches ; does the OSTC have analog switches?
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
487 bra get_analog_switches_1 ; YES
629
237931377539 3.07 stable release
heinrichsweikamp
parents: 628
diff changeset
488 get_analog_switches0:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
489 banksel common ; NO - back to bank common
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
490 bcf analog_sw1_pressed ; - clear flag for analog switch 1
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
491 bcf analog_sw2_pressed ; - clear flag for analog switch 2
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
492 return ; - done
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
493
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
494 get_analog_switches_1:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
495 banksel common ; back to bank common
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
496 btfsc adc_is_running ; ADC in use?
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
497 return ; YES - abort
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
498 btfsc cc_active ; NO - charging?
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
499 bra get_analog_switches0 ; YES - abort (And clear both flags)
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
500 ;bra get_analog_switches_2 ; NO - read switches
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
501
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
502 get_analog_switches_2:
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
503 bsf adc_is_running
629
237931377539 3.07 stable release
heinrichsweikamp
parents: 628
diff changeset
504 bcf ADCON2,ADFM ; left justified
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
505 clrf ADCON1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
506 movlw b'00100101' ; power on ADC, select AN9
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
507 rcall wait_adc
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
508
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
509 banksel isr_backup ; select bank ISR data
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
510 movff ADRESH,WREG
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
511 addwf analog_sw2_raw+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
512 movlw .0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
513 addwfc analog_sw2_raw+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
514 decfsz analog_counter,F ; continue averaging?
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
515 bra get_analog_switches_2a ; YES
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
516 bcf STATUS,C ; NO - done, compute average
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
517 rrcf analog_sw2_raw+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
518 rrcf analog_sw2_raw+0 ; /2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
519 bcf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
520 rrcf analog_sw2_raw+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
521 rrcf analog_sw2_raw+0 ; /4
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
522 bcf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
523 rrcf analog_sw2_raw+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
524 rrcf analog_sw2_raw+0 ; /8
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
525 bcf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
526 rrcf analog_sw2_raw+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
527 rrcf analog_sw2_raw+0 ; /16
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
528 movff analog_sw2_raw+0,analog_sw2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
529 clrf analog_sw2_raw+1
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
530 clrf analog_sw2_raw+0 ; reset average registers
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
531 ; movlw .16
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
532 ; movwf analog_counter ; only once...
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
533
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
534 get_analog_switches_2a:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
535 bcf analog_sw2_pressed ; default to not pressed
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
536 movff opt_cR_button_left,WREG ; 20-100
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
537 bcf STATUS,C
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
538 rrcf WREG ; /2 -> 10-50
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
539 bcf STATUS,C
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
540 rrcf WREG ; /2 -> 5-25
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
541 decf WREG,W ; -1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
542 decf WREG,W ; -1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
543 decf WREG,W ; -1 -> 2-22
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
544 btfss button_polarity,1 ; (1= normal, 0=inverted)
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
545 bra get_analog_switches_sw2_inv
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
546 addwf analog_sw2,W ; average (~128)
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
547 cpfsgt ADRESH ; pressed?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
548 bra get_analog_switches_3 ; NO
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
549 bra get_analog_switches_sw2_pressed ; YES (left button normal)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
550
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
551 get_analog_switches_sw2_inv:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
552 subwf analog_sw2,W ; average (~128)
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
553 cpfslt ADRESH ; pressed?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
554 bra get_analog_switches_3 ; NO
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
555 ;bra get_analog_switches_sw2_pressed ; YES (left button inverted)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
556
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
557 get_analog_switches_sw2_pressed:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
558 bsf analog_sw2_pressed ; set left button as pressed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
559
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
560 get_analog_switches_3:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
561 movlw b'00101001' ; power on ADC, select AN10
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
562 rcall wait_adc
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
563 movff ADRESH,WREG
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
564 addwf analog_sw1_raw+0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
565 movlw .0
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
566 addwfc analog_sw1_raw+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
567 tstfsz analog_counter ; continue averaging?
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
568 bra get_analog_switches_3a ; YES
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
569 bcf STATUS,C ; NO - done, compute average
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
570 rrcf analog_sw1_raw+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
571 rrcf analog_sw1_raw+0 ; /2
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
572 bcf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
573 rrcf analog_sw1_raw+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
574 rrcf analog_sw1_raw+0 ; /4
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
575 bcf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
576 rrcf analog_sw1_raw+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
577 rrcf analog_sw1_raw+0 ; /8
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
578 bcf STATUS,C
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
579 rrcf analog_sw1_raw+1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
580 rrcf analog_sw1_raw+0 ; /16
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
581 movff analog_sw1_raw+0,analog_sw1
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
582 clrf analog_sw1_raw+1
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
583 clrf analog_sw1_raw+0 ; reset average registers
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
584 movlw .16
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
585 movwf analog_counter ; only once...
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
586
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
587 get_analog_switches_3a:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
588 bcf analog_sw1_pressed ; default to not pressed
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
589 movff opt_cR_button_right,WREG ; 20-100
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
590 bcf STATUS,C
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
591 rrcf WREG ; /2 -> 10-50
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
592 bcf STATUS,C
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
593 rrcf WREG ; /2 -> 5-25
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
594 decf WREG,W ; -1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
595 decf WREG,W ; -1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
596 decf WREG,W ; -1 -> 2-22
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 603
diff changeset
597 btfss button_polarity,0 ; (1= normal, 0=inverted)
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
598 bra get_analog_switches_sw1_inv
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
599 addwf analog_sw1,W ; average (~128)
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
600 cpfsgt ADRESH ; pressed?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
601 bra get_analog_switches_4 ; NO
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
602 bra get_analog_switches_sw1_pressed ; YES (right button normal)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
603
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
604 get_analog_switches_sw1_inv:
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
605 subwf analog_sw1,W ; average (~128)
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
606 cpfslt ADRESH ; pressed?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
607 bra get_analog_switches_4 ; NO
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
608 ;bra get_analog_switches_sw1_pressed ; YES (right button inverted)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
609
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
610 get_analog_switches_sw1_pressed:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
611 bsf analog_sw1_pressed ; set right button as pressed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
612
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
613 get_analog_switches_4:
629
237931377539 3.07 stable release
heinrichsweikamp
parents: 628
diff changeset
614 bsf ADCON2,ADFM ; restore to right justified
628
cd58f7fc86db 3.05 stable work
heinrichsweikamp
parents: 623
diff changeset
615 bcf adc_is_running
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
616 banksel common ; back to bank common
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
617 btfsc analog_sw1_pressed ; right button pressed?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
618 return ; YES - done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
619 btfsc analog_sw2_pressed ; left button pressed?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
620 return ; YES - done
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 615
diff changeset
621 setf TMR1H ; NO to both - no button pressed, set timer1 to overflow quickly
582
b455b31ce022 work on 2.97 stable
heinrichsweikamp
parents: 475
diff changeset
622 return
448
aadfe9f2edaf work on new battery options
heinrichsweikamp
parents: 416
diff changeset
623
0
heinrichsweikamp
parents:
diff changeset
624 END