From 39d2e9f2b7d221c1e7a2f6018ba7646e3ec22413 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Tue, 26 Mar 2024 04:31:04 -0600 Subject: weak battery detection: use different thresholds for AA and Li-Ion (also, fixed bug where a totally empty li-ion didn't get limited) --- hw/hank/emisar-d3aa/hwdef.c | 24 ++++++++++++++---------- hw/hank/emisar-d3aa/hwdef.h | 5 +++-- 2 files changed, 17 insertions(+), 12 deletions(-) (limited to 'hw') diff --git a/hw/hank/emisar-d3aa/hwdef.c b/hw/hank/emisar-d3aa/hwdef.c index d6cb2fd..8aaa893 100644 --- a/hw/hank/emisar-d3aa/hwdef.c +++ b/hw/hank/emisar-d3aa/hwdef.c @@ -138,22 +138,26 @@ void detect_weak_battery() { //resting = voltage_raw2cooked(adc_smooth[0]); // probably not settled yet resting = quick_volt_measurement(); + // set thresholds per cell type + uint8_t sag_limit, crit_voltage; + if (resting > DUAL_VOLTAGE_FLOOR) { + sag_limit = WEAK_BATTERY_SAG_THRESHOLD_LIION; + crit_voltage = VOLTAGE_LOW; + } else { + sag_limit = WEAK_BATTERY_SAG_THRESHOLD_AA; + crit_voltage = DUAL_VOLTAGE_LOW_LOW; + } + // progressively turn up the power until sag threshold is hit, // or critical voltage, or max testing level is reached for (uint8_t l=1; l WEAK_BATTERY_SAG_THRESHOLD) || - // Li-ion critical voltage - ((resting > VOLTAGE_LOW) && (loaded < VOLTAGE_LOW)) - ) { - ramp_level_hard_limit = l; - break; + if ( (loaded <= crit_voltage) || (sag > sag_limit) ) { + // battery empty or weak + ramp_level_hard_limit = l; + break; } } set_level(0); diff --git a/hw/hank/emisar-d3aa/hwdef.h b/hw/hank/emisar-d3aa/hwdef.h index 7cd2849..7fbffbe 100644 --- a/hw/hank/emisar-d3aa/hwdef.h +++ b/hw/hank/emisar-d3aa/hwdef.h @@ -119,8 +119,9 @@ enum CHANNEL_MODES { // (also helps protect firmware flashing adapters from overload) #define USE_RAMP_LEVEL_HARD_LIMIT #define USE_WEAK_BATTERY_PROTECTION -#define WEAK_BATTERY_TEST_MAX_LEVEL 75 // about 300 mA -#define WEAK_BATTERY_SAG_THRESHOLD (5*4) // 0.5 V +#define WEAK_BATTERY_TEST_MAX_LEVEL 75 // about 300 mA +#define WEAK_BATTERY_SAG_THRESHOLD_AA (3*4) // 0.3 V +#define WEAK_BATTERY_SAG_THRESHOLD_LIION (6*4) // 0.6 V // average drop across diode on this hardware #ifndef VOLTAGE_FUDGE_FACTOR -- cgit v1.2.3