From b0e6a5b47836a04116631e3a5427b8a508fc5cbf Mon Sep 17 00:00:00 2001 From: "Jan \"Yenya\" Kasprzak" Date: Sat, 17 Nov 2012 22:21:35 +0100 Subject: [PATCH] firmware/battery: init function, new resistor sizes --- firmware/battery.c | 11 ++++++++--- firmware/lights.h | 1 + firmware/main.c | 1 + 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/firmware/battery.c b/firmware/battery.c index 472c1c4..284c096 100644 --- a/firmware/battery.c +++ b/firmware/battery.c @@ -3,9 +3,14 @@ #include "lights.h" #define RESISTOR_HI 1500 // kOhm -#define RESISTOR_LO 150 // kOhm +#define RESISTOR_LO 100 // kOhm -volatile unsigned char battery_100mv; +volatile unsigned char battery_100mv = 0; + +void init_battery() +{ + battery_100mv = 0; +} void battery_adc(uint16_t adcval) { @@ -18,7 +23,7 @@ void battery_adc(uint16_t adcval) * is coarse (0.1 V). */ battery_100mv = (unsigned char) - ((adcval * 11 // 1.1V + ((uint16_t)(adcval * 11 // 1.1V * (RESISTOR_HI+RESISTOR_LO)/RESISTOR_LO // resistor ratio / 4) >> 8); // divide by 1024 } diff --git a/firmware/lights.h b/firmware/lights.h index f822384..43915bd 100644 --- a/firmware/lights.h +++ b/firmware/lights.h @@ -80,6 +80,7 @@ void timer_check_buttons(); /* battery.c */ extern volatile unsigned char battery_100mv; void battery_adc(); +void init_battery(); /* main.c */ void hw_setup(); diff --git a/firmware/main.c b/firmware/main.c index d10a322..25ea829 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -10,6 +10,7 @@ void hw_setup() { wdt_enable(WDTO_1S); + init_battery(); init_pwm(); init_adc(); init_tmr(); -- 2.43.5