diff --git a/src/main/fc/settings.c b/src/main/fc/settings.c index 7ed9931c88..7ce63c7656 100644 --- a/src/main/fc/settings.c +++ b/src/main/fc/settings.c @@ -418,7 +418,7 @@ const clivalue_t valueTable[] = { { "vbat_hysteresis", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, 250 }, PG_BATTERY_CONFIG, offsetof(batteryConfig_t, vbathysteresis) }, { "current_meter", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_CURRENT_METER }, PG_BATTERY_CONFIG, offsetof(batteryConfig_t, currentMeterSource) }, { "battery_meter", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_VOLTAGE_METER }, PG_BATTERY_CONFIG, offsetof(batteryConfig_t, voltageMeterSource) }, - { "bat_detect_thresh", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, 200 }, PG_BATTERY_CONFIG, offsetof(batteryConfig_t, batteryNotPresentLevel) }, + { "vbat_detect_cell_voltage", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, 200 }, PG_BATTERY_CONFIG, offsetof(batteryConfig_t, vbatnotpresentcellvoltage) }, { "use_vbat_alerts", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_BATTERY_CONFIG, offsetof(batteryConfig_t, useVBatAlerts) }, { "use_cbat_alerts", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, .config.lookup = { TABLE_OFF_ON }, PG_BATTERY_CONFIG, offsetof(batteryConfig_t, useConsumptionAlerts) }, { "cbat_alert_percent", VAR_UINT8 | MASTER_VALUE, .config.minmax = { 0, 100 }, PG_BATTERY_CONFIG, offsetof(batteryConfig_t, consumptionWarningPercentage) }, diff --git a/src/main/sensors/battery.c b/src/main/sensors/battery.c index a0e7af7956..b97792e9c3 100644 --- a/src/main/sensors/battery.c +++ b/src/main/sensors/battery.c @@ -97,12 +97,12 @@ PG_RESET_TEMPLATE(batteryConfig_t, batteryConfig, .vbatmaxcellvoltage = 43, .vbatmincellvoltage = 33, .vbatwarningcellvoltage = 35, - .batteryNotPresentLevel = 55, // VBAT below 5.5 V will be ignored + .vbatnotpresentcellvoltage = 30, //A cell below 3 will be ignored .voltageMeterSource = DEFAULT_VOLTAGE_METER_SOURCE, // current .batteryCapacity = 0, - .currentMeterSource = DEFAULT_VOLTAGE_METER_SOURCE, + .currentMeterSource = DEFAULT_CURRENT_METER_SOURCE, // warnings / alerts .useVBatAlerts = true, @@ -162,16 +162,19 @@ void batteryUpdatePresence(void) { static uint16_t previousVoltage = 0; - bool isVoltageStable = ( - previousVoltage > 0 - && ABS(voltageMeter.filtered - previousVoltage) <= VBAT_STABLE_MAX_DELTA - ); + bool isVoltageStable = ABS(voltageMeter.filtered - previousVoltage) <= VBAT_STABLE_MAX_DELTA; + + bool isVoltageFromBat = (voltageMeter.filtered >= batteryConfig()->vbatnotpresentcellvoltage //above ~0V + && voltageMeter.filtered <= batteryConfig()->vbatmaxcellvoltage) //1s max cell voltage check + || voltageMeter.filtered > batteryConfig()->vbatnotpresentcellvoltage*2; //USB voltage - 2s or more check + if ( voltageState == BATTERY_NOT_PRESENT - && voltageMeter.filtered > batteryConfig()->batteryNotPresentLevel + && isVoltageFromBat && isVoltageStable ) { + /* Want to disable battery getting detected around USB voltage or 0V*/ /* battery has just been connected - calculate cells, warning voltages and reset state */ @@ -187,10 +190,10 @@ void batteryUpdatePresence(void) batteryCriticalVoltage = batteryCellCount * batteryConfig()->vbatmincellvoltage; } else if ( voltageState != BATTERY_NOT_PRESENT - && voltageMeter.filtered <= batteryConfig()->batteryNotPresentLevel && isVoltageStable + && !isVoltageFromBat ) { - /* battery has been disconnected - can take a while for filter cap to disharge so we use a threshold of batteryConfig()->batterynotpresentlevel */ + /* battery has been disconnected - can take a while for filter cap to disharge so we use a threshold of batteryConfig()->vbatnotpresentcellvoltage */ consumptionState = voltageState = BATTERY_NOT_PRESENT; diff --git a/src/main/sensors/battery.h b/src/main/sensors/battery.h index 799e5318c0..6695a7e1f0 100644 --- a/src/main/sensors/battery.h +++ b/src/main/sensors/battery.h @@ -29,7 +29,7 @@ typedef struct batteryConfig_s { uint8_t vbatmaxcellvoltage; // maximum voltage per cell, used for auto-detecting battery voltage in 0.1V units, default is 43 (4.3V) uint8_t vbatmincellvoltage; // minimum voltage per cell, this triggers battery critical alarm, in 0.1V units, default is 33 (3.3V) uint8_t vbatwarningcellvoltage; // warning voltage per cell, this triggers battery warning alarm, in 0.1V units, default is 35 (3.5V) - uint8_t batteryNotPresentLevel; // Below this level battery is considered as not present + uint8_t vbatnotpresentcellvoltage; // Between vbatmaxcellvoltage and 2*this is considered to be USB powered. Below this it is notpresent voltageMeterSource_e voltageMeterSource; // source of battery voltage meter used, either ADC or ESC