summaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/main.c b/main.c
index beeb87a..a16101d 100644
--- a/main.c
+++ b/main.c
@@ -100,6 +100,28 @@ static inline void flash_led(void)
}
}
+static inline uint16_t get_bat_volt(void)
+{
+ uint16_t vbg;
+
+ ADMUX |= (1 << REFS0);
+ ADCSRA |= (1 << ADEN) | (1 << ADPS2) | (1 << ADPS1); /* clk: 50-200 kHz */
+
+ // https://www.sciencetronics.com/greenphotons/?p=1521
+ _delay_us(500);
+
+ ADCSRA |= (1 << ADSC);
+ while (ADCSRA & (1 << ADSC))
+ ;
+
+ ADCSRA &= ~(1 << ADEN);
+ vbg = 3300UL / 1024 * ADC
+
+ ADCSRA &= ~(1 << ADEN);
+
+ return vbg * 3;
+}
+
int main(void)
{
uint16_t id;
@@ -124,7 +146,7 @@ int main(void)
TCCR1A |= (1 << COM1A1);
SERVO_DDR |= (1 << SERVO_PIN);
- /* battery check */
+ /* bat check */
LED_DDR |= (1 << LED_PIN);
LED_PORT &= ~(1 << LED_PIN);