- 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
* (1024UL * (mV)) \
/ (6UL * ADC_1100MV_VALUE)) >> 8))
static unsigned char batt_levels[] = {
* (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]))
};
#define BATT_N_LEVELS (sizeof(batt_levels) / sizeof(batt_levels[0]))
}
} else {
unsigned char b_level = battery_level();
}
} else {
unsigned char b_level = battery_level();
battery_exhausted = 0;
} else if (battery_exhausted) {
if (!--battery_exhausted)
battery_exhausted = 0;
} else if (battery_exhausted) {
if (!--battery_exhausted)
battery_exhausted = LED_BATTEMPTY_COUNT;
}
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;