X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?p=bike-lights.git;a=blobdiff_plain;f=firmware%2Fbattery.c;fp=firmware%2Fbattery.c;h=284c096b34230b38f53702539d6ed4792f901dcb;hp=472c1c47f099093c59bfe6454983276687e9dad8;hb=b0e6a5b47836a04116631e3a5427b8a508fc5cbf;hpb=320b394fa14a973bcb68fcbd2af65a79462e30bc 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 }