Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/main/sensors/battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Loading