]> git.donarmstrong.com Git - tmk_firmware.git/commitdiff
Add FET swtich for battery ADC
authortmk <nobody@nowhere>
Fri, 19 Sep 2014 21:12:49 +0000 (06:12 +0900)
committertmk <nobody@nowhere>
Fri, 19 Sep 2014 21:12:49 +0000 (06:12 +0900)
keyboard/hhkb_rn42/MEMO.txt
keyboard/hhkb_rn42/rn42/battery.c

index 11f64b8c4c43d751ca251e62f52b6c40db894338..2f61574c30ba5b39f70c04c5cfed9e0f07e09a35 100644 (file)
@@ -15,12 +15,19 @@ Power saving:
 - deep sleep MCU and BT module(keyboard is not used for long time)
 - deep sleep MCU and turn off BT module(keyboard is not used and not connected)
 - Battery ADC; switching, high resistance
+    - switching gnd end of divider with PF4
+    - high resistor 100K/1M?
+        capacitor   10nF
+        http://www.eevblog.com/forum/beginners/measuring-battery-voltage-without-consuming-current/
 
 Improving:
 - BT LED; connecting, linked, sleeping, deep sleeping
 - Battry LED; blink(using timer?)
 - move rn42 to protocol directory when it becomes reusable stack
 - LUFA sendchar should be buffered and serial_uart.c buffur size is too large(256).
+- ADC resolution
+    AVR120
+    AVR32138
 
 Testing:
 - Factroy reset doesn't work; need to **test again** 10K pull-up is too high?
index c6988fe33645b40ce54b0cf3e7965ed7ad77c068..0320e1baf1aa7a3c28b05bbc7ff70f9fd84e0209 100644 (file)
@@ -21,6 +21,10 @@ void battery_init(void)
     ADMUX = (1<<REFS1) | (1<<REFS0);
     ADCSRA = (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0);
     ADCSRA |= (1<<ADEN);
+
+    // ADC disable voltate divider(PF4)
+    DDRF  |=  (1<<4);
+    PORTF &= ~(1<<4);
 }
 
 // Indicator for battery
@@ -79,6 +83,10 @@ bool battery_charging(void)
 // Returns voltage in mV
 uint16_t battery_voltage(void)
 {
+    // ADC disable voltate divider(PF4)
+    DDRF  |=  (1<<4);
+    PORTF |=  (1<<4);
+
     volatile uint16_t bat;
     //ADCSRA |= (1<<ADEN);
 
@@ -98,6 +106,10 @@ uint16_t battery_voltage(void)
 
     //ADCSRA &= ~(1<<ADEN);
 
+    // ADC disable voltate divider(PF4)
+    DDRF  |=  (1<<4);
+    PORTF &= ~(1<<4);
+
     return (bat - BATTERY_ADC_OFFSET) * BATTERY_ADC_RESOLUTION;
 }