From: Jan "Yenya" Kasprzak Date: Sun, 21 Dec 2014 22:05:48 +0000 (+0100) Subject: Low battery bugfix: X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;p=heater.git Low battery bugfix: - when the battery is low, we have previously disabled the load, which caused the battery voltage to increase slightly, so we never switched the system off, and the load was switched on only for a brief periods of time. Now we have the following battery voltage levels: < 3.0 V: we do not enable the load, blink the status LED faster, and after 60 iterations, power the system off <3.0 V .. 3.15 V): we still enable the load, but switch the system off after 60 iterations of LED blink <3.15 V .. 3.45 V): battery is low <3.45 V .. 3.8 V): battery is OK >= 3.8 V: battery is fully charged --- diff --git a/firmware/main.c b/firmware/main.c index a6cc1a8..65801e8 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -79,9 +79,10 @@ static volatile uint16_t batt_on, batt_off; // measured voltage * (1024UL * (mV)) \ / (6UL * ADC_1100MV_VALUE)) >> 8)) static unsigned char batt_levels[] = { - MV_TO_ADC8(3350), - MV_TO_ADC8(3700), - MV_TO_ADC8(3900), + MV_TO_ADC8(3000), // below this, do not enable load, and switch off + MV_TO_ADC8(3150), // below this, switch off after some time + MV_TO_ADC8(3450), // battery low + MV_TO_ADC8(3800), // battery ok, above that almost full }; #define BATT_N_LEVELS (sizeof(batt_levels) / sizeof(batt_levels[0])) @@ -395,7 +396,7 @@ static void status_led_next_pattern() } } else { unsigned char b_level = battery_level(); - if (b_level) { + if (b_level > 1) { battery_exhausted = 0; } else if (battery_exhausted) { if (!--battery_exhausted) @@ -404,8 +405,8 @@ static void status_led_next_pattern() battery_exhausted = LED_BATTEMPTY_COUNT; } - n_blinks = b_level + 1; - blink_on_time = 4; + n_blinks = b_level ? b_level : 1; + blink_on_time = b_level ? 4 : 2; blink_off_time = 0; }