Mercurial > public > hwos_code
comparison src/adc_lightsensor.asm @ 448:aadfe9f2edaf
work on new battery options
author | heinrichsweikamp |
---|---|
date | Tue, 30 Aug 2016 17:26:21 +0200 |
parents | 4389fe9673b2 |
children | 66049b6f2c0b |
comparison
equal
deleted
inserted
replaced
447:f2a1d535347f | 448:aadfe9f2edaf |
---|---|
25 bra wait_adc2 | 25 bra wait_adc2 |
26 return | 26 return |
27 | 27 |
28 global get_battery_voltage | 28 global get_battery_voltage |
29 get_battery_voltage: ; starts ADC and waits until fnished | 29 get_battery_voltage: ; starts ADC and waits until fnished |
30 btfss rechargeable | 30 btfss battery_gauge_available |
31 bra get_battery_voltage1 ; Normal ostc3 hardware | 31 bra get_battery_voltage1 ; Normal ostc3 hardware |
32 | 32 |
33 call lt2942_get_accumulated_charge | 33 call lt2942_get_accumulated_charge |
34 call lt2942_get_voltage | 34 call lt2942_get_voltage |
35 | 35 |
130 movff battery_gauge+4,xC+2 | 130 movff battery_gauge+4,xC+2 |
131 movff battery_gauge+3,xC+1 | 131 movff battery_gauge+3,xC+1 |
132 movff battery_gauge+2,xC+0 | 132 movff battery_gauge+2,xC+0 |
133 ; battery_gauge:6 is nAs | 133 ; battery_gauge:6 is nAs |
134 ; devide through 65536 | 134 ; devide through 65536 |
135 ; devide through 364 | 135 ; devide through battery_capacity:2 |
136 ; Result is in percent of a 2,4Ah Battery | 136 ; Result is in percent |
137 movlw LOW .364 | 137 movff internal_battery_capacity+0,xB+0 |
138 movwf xB+0 | 138 movff internal_battery_capacity+1,xB+1 |
139 movlw HIGH .364 | |
140 movwf xB+1 | |
141 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder | 139 call div32x16 ; xC:4 / xB:2 = xC+3:xC+2 with xC+1:xC+0 as remainder |
142 movff xC+0,lo | 140 movff xC+0,lo |
143 ; Limit to 100 | 141 ; Limit to 100 |
144 movlw .100 | 142 movlw .100 |
145 cpfslt lo | 143 cpfslt lo |
304 | 302 |
305 incf isr1_temp,F ; adjust 0-2 to 1-3 | 303 incf isr1_temp,F ; adjust 0-2 to 1-3 |
306 | 304 |
307 banksel common ; flag is in bank1 | 305 banksel common ; flag is in bank1 |
308 movlw ambient_light_max_high_cr; cR and 2 hardware brightest setting | 306 movlw ambient_light_max_high_cr; cR and 2 hardware brightest setting |
309 btfss rechargeable | 307 btfss battery_gauge_available |
310 movlw ambient_light_max_high_15V; 1,5V battery brightest setting | 308 movlw ambient_light_max_high_15V; 1,5V battery brightest setting |
311 btfsc battery_is_36v ; 3,6V battery in use? | 309 btfsc battery_is_36v ; 3,6V battery in use? |
312 movlw ambient_light_max_high_36V ; 3,6V battery brightest setting | 310 movlw ambient_light_max_high_36V ; 3,6V battery brightest setting |
313 banksel isr_backup ; Back to Bank0 ISR data | 311 banksel isr_backup ; Back to Bank0 ISR data |
314 | 312 |
495 piezo_config_wait_bit3: | 493 piezo_config_wait_bit3: |
496 btfss PIR5,TMR5IF | 494 btfss PIR5,TMR5IF |
497 bra piezo_config_wait_bit3 ; Wait loop | 495 bra piezo_config_wait_bit3 ; Wait loop |
498 return | 496 return |
499 | 497 |
500 global reset_battery_pointer | 498 global reset_battery_pointer, reset_battery_internal_only |
501 reset_battery_pointer: ; Resets battery pointer 0x07-0x0C and battery_gauge:5 | 499 reset_battery_pointer: ; Resets battery pointer 0x07-0x0C and battery_gauge:5 |
502 extern lt2942_charge_done | 500 extern lt2942_charge_done |
503 btfsc rechargeable ; Something to reset? | 501 btfsc battery_gauge_available ; Something to reset? |
504 call lt2942_charge_done ; Yes, reset accumulating registers to 0xFFFF | 502 call lt2942_charge_done ; Yes, reset accumulating registers to 0xFFFF |
503 reset_battery_internal_only: | |
505 clrf EEADRH | 504 clrf EEADRH |
506 clrf EEDATA ; Delete to zero | 505 clrf EEDATA ; Delete to zero |
507 write_int_eeprom 0x07 | 506 write_int_eeprom 0x07 |
508 write_int_eeprom 0x08 | 507 write_int_eeprom 0x08 |
509 write_int_eeprom 0x09 | 508 write_int_eeprom 0x09 |
510 write_int_eeprom 0x0A | 509 write_int_eeprom 0x0A |
511 write_int_eeprom 0x0B | 510 write_int_eeprom 0x0B |
512 write_int_eeprom 0x0C | 511 write_int_eeprom 0x0C |
513 banksel battery_gauge+0 | 512 banksel battery_gauge+0 |
514 clrf battery_gauge+0 | 513 clrf battery_gauge+0 |
515 clrf battery_gauge+1 | 514 clrf battery_gauge+1 |
516 clrf battery_gauge+2 | 515 clrf battery_gauge+2 |
517 clrf battery_gauge+3 | 516 clrf battery_gauge+3 |
520 banksel common | 519 banksel common |
521 movlw .100 | 520 movlw .100 |
522 movwf batt_percent | 521 movwf batt_percent |
523 return | 522 return |
524 | 523 |
524 global get_analog_switches | |
525 get_analog_switches: ; starts ADC and waits until finished | |
526 return | |
527 btfsc analog_switches | |
528 bra get_analog_switches2 | |
529 ; no analog switches | |
530 bcf analog_sw2_pressed | |
531 bcf analog_sw1_pressed | |
532 return ; Done. | |
533 get_analog_switches2: | |
534 btfsc adc_running ; ADC in use? | |
535 return ; Yes, return | |
536 | |
537 movlw b'00001001' ; left justified | |
538 movwf ADCON2 | |
539 movlw b'00000000' ; Vref+ = Vdd | |
540 movwf ADCON1 | |
541 movlw b'00100101' ; power on ADC, select AN9 | |
542 rcall wait_adc | |
543 movff ADRESH,analog_sw2 | |
544 bcf analog_sw2_pressed | |
545 movlw .64 ; lower limit | |
546 cpfsgt ADRESH | |
547 bra sw2_pressed | |
548 movlw .192 ; upper limit | |
549 cpfsgt ADRESH | |
550 bra get_analog_sw1 | |
551 sw2_pressed: | |
552 bsf analog_sw2_pressed | |
553 get_analog_sw1: | |
554 movlw b'00101001' ; power on ADC, select AN10 | |
555 rcall wait_adc | |
556 movff ADRESH,analog_sw1 | |
557 bcf analog_sw1_pressed | |
558 movlw .64 ; lower limit | |
559 cpfsgt ADRESH | |
560 bra sw1_pressed | |
561 movlw .192 ; upper limit | |
562 cpfsgt ADRESH | |
563 bra get_analog_sw_done | |
564 sw1_pressed: | |
565 bsf analog_sw1_pressed | |
566 get_analog_sw_done: | |
567 movlw b'10001101' ; Restore to right justified | |
568 movwf ADCON2 | |
569 return | |
570 | |
525 | 571 |
526 END | 572 END |