diff --git a/src/main/sensors/battery.c b/src/main/sensors/battery.c index a29fa2e07cf..e9167e09120 100644 --- a/src/main/sensors/battery.c +++ b/src/main/sensors/battery.c @@ -351,16 +351,23 @@ static void checkBatteryCapacityState(void) void batteryUpdate(timeUs_t timeDelta) { + static timeUs_t batteryConnectedTime = 0; /* battery has just been connected*/ if (batteryState == BATTERY_NOT_PRESENT && vbat > VBATT_PRESENT_THRESHOLD) { + if(batteryConnectedTime == 0) { + batteryConnectedTime = micros(); + return; + } - /* Actual battery state is calculated below, this is really BATTERY_PRESENT */ - batteryState = BATTERY_OK; /* wait for VBatt to stabilise then we can calc number of cells (using the filtered value takes a long time to ramp up) - We only do this on the ground so don't care if we do block, not - worse than original code anyway*/ - delay(VBATT_STABLE_DELAY); + Blocking can cause issues with some ESCs */ + if((micros() - batteryConnectedTime) < VBATT_STABLE_DELAY) { + return; + } + + /* Actual battery state is calculated below, this is really BATTERY_PRESENT */ + batteryState = BATTERY_OK; updateBatteryVoltage(timeDelta, true); int8_t detectedProfileIndex = -1; @@ -396,6 +403,7 @@ void batteryUpdate(timeUs_t timeDelta) /* battery has been disconnected - can take a while for filter cap to disharge so we use a threshold of VBATT_PRESENT_THRESHOLD */ if (batteryState != BATTERY_NOT_PRESENT && vbat <= VBATT_PRESENT_THRESHOLD) { batteryState = BATTERY_NOT_PRESENT; + batteryConnectedTime = 0; batteryCellCount = 0; batteryWarningVoltage = 0; batteryCriticalVoltage = 0;