fix(power): latch low-battery decision in RTC memory and add recovery hysteresis#10440
Open
DatanoiseTV wants to merge 1 commit into
Open
fix(power): latch low-battery decision in RTC memory and add recovery hysteresis#10440DatanoiseTV wants to merge 1 commit into
DatanoiseTV wants to merge 1 commit into
Conversation
…eresis The previous low-voltage handler counted 11 consecutive readings under OCV[min] and triggered EVENT_LOW_BATTERY, but on SDS wake the counter reset to 0. With the cell still flat, the count climbed back to 11 and deep-slept again — wake-thrash burning boot energy each cycle. There was also no recovery hysteresis: a brief spike across the threshold would clear the count even with the battery still effectively flat. Persist the latch in RTC memory so SDS doesn't lose it. Once latched, clearing requires K consecutive readings above OCV[min] + 100 mV. If the device wakes and is still latched-flat, immediately re-enter SDS without running a normal boot.
8 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens low-battery handling to reduce boot-energy waste on flat cells by persisting a “low battery” decision across deep sleep and adding a recovery hysteresis requirement before clearing that decision.
Changes:
- Add a persisted low-battery latch (
RTC_DATA_ATTRon ESP32) so SDS wake-ups don’t lose the low-battery decision. - Add recovery hysteresis requiring multiple consecutive readings above
OCV[min] + 100mV/cellbefore clearing the latch. - If still latched and below the recovery threshold, re-trigger low-battery sleep instead of proceeding normally.
Comment on lines
+990
to
+994
| // OCV[] is per-cell; getBattVoltage() returns pack voltage. Scale by | ||
| // NUM_CELLS to keep the comparison consistent with the per-cell | ||
| // table on multi-cell variants (e.g. chatter2, station-g1). | ||
| constexpr int LOW_BATT_HYSTERESIS_MV_PER_CELL = 100; | ||
| const int v = batteryLevel->getBattVoltage(); |
Comment on lines
+1006
to
+1009
| low_voltage_counter = 0; | ||
| LOG_INFO("Latched low-battery still flat at %dmV, re-enter deep sleep", v); | ||
| powerFSM.trigger(EVENT_LOW_BATTERY); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The previous low-voltage handler counted 11 consecutive readings under
OCV[min] and triggered EVENT_LOW_BATTERY, but on SDS wake the counter
reset to 0. With the cell still flat, the count climbed back to 11 and
deep-slept again — wake-thrash burning boot energy each cycle. There
was also no recovery hysteresis: a brief spike across the threshold
would clear the count even with the battery still effectively flat.
Persist the latch in RTC memory so SDS doesn't lose it. Once latched,
clearing requires K consecutive readings above OCV[min] + 100 mV. If
the device wakes and is still latched-flat, immediately re-enter SDS
without running a normal boot.
Split out from #10425 — single-concern PR.
Build verification
pio run -e t-deck-tftsucceeds, no new warnings.Attestations
t-deck-tftonly.