]> www.fi.muni.cz Git - bike-lights.git/blobdiff - firmware/battery.c
ambient.c: zone adjustments
[bike-lights.git] / firmware / battery.c
index 472c1c47f099093c59bfe6454983276687e9dad8..01337db1bb8c196fde0d0ff3efa61b1457bce7a8 100644 (file)
@@ -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,8 +23,8 @@ 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
+               / 4)) >> 8);                               // divide by 1024
 }