diff options
| author | Selene ToyKeeper | 2024-03-26 04:31:04 -0600 |
|---|---|---|
| committer | Selene ToyKeeper | 2024-03-26 04:31:04 -0600 |
| commit | 39d2e9f2b7d221c1e7a2f6018ba7646e3ec22413 (patch) | |
| tree | fd29c395b561959508e9af3d68bd9a0bfb6cd9a2 | |
| parent | d3aa: got weak battery detection actually working, (diff) | |
| download | anduril-39d2e9f2b7d221c1e7a2f6018ba7646e3ec22413.tar.gz anduril-39d2e9f2b7d221c1e7a2f6018ba7646e3ec22413.tar.bz2 anduril-39d2e9f2b7d221c1e7a2f6018ba7646e3ec22413.zip | |
weak battery detection: use different thresholds for AA and Li-Ion
(also, fixed bug where a totally empty li-ion didn't get limited)
Diffstat (limited to '')
| -rw-r--r-- | hw/hank/emisar-d3aa/hwdef.c | 24 | ||||
| -rw-r--r-- | hw/hank/emisar-d3aa/hwdef.h | 5 |
2 files changed, 17 insertions, 12 deletions
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_TEST_MAX_LEVEL; l++) { set_level(l); loaded = quick_volt_measurement(); int16_t sag = resting - loaded; - if ( - // AA/NiMH critical voltage - (loaded <= DUAL_VOLTAGE_LOW_LOW) || - // weak battery chemistry, can't handle much power - (sag > 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 |
