# \[TRACKING\] Battery flipping between charging and discharging / Draws from battery even on AC

**URL:** <https://community.frame.work/t/tracking-battery-flipping-between-charging-and-discharging-draws-from-battery-even-on-ac/22484>\
**Category:** Linux\
**Tags:** arch\
**Created:** [September 12, 2022, 10:53am UTC](https://community.frame.work/t/tracking-battery-flipping-between-charging-and-discharging-draws-from-battery-even-on-ac/22484 "2022-09-12T10:53:49Z")\
**Posts on this page:** 1\
**Showing post:** 244

<div class="post-metadata">

**Author:** ![James3](https://avatars.discourse-cdn.com/v4/letter/j/b5e925/32.png) [@James3](https://community.frame.work/u/James3)\
**Post date:** [May 1, 2025, 9:27am UTC](https://community.frame.work/t/tracking-battery-flipping-between-charging-and-discharging-draws-from-battery-even-on-ac/22484/244 "2025-05-01T09:27:47Z")

</div>

Regarding my fixes for the mini-cycles charge / idle / discharge bug in the EC. There has been no peep from FW as to whether they wish to include my changes or not.  
I had an initial email thread open with them regarding one aspect, whether all FW main boards supported the IDLE state, they have been silent since then.  
So, I have no idea whether or not they will actually really fix all the edge cases with their upcoming BIOS release.  
Here are some of the edge cases:

1. The battery BMS re-calibrates itself periodically. This can result in the charge % changing, thus trigger charge / idle / discharge cycles.
2. Not all uses wish the battery to discharge with the AC PSU connected. So if the user changes the battery limit from 80% to 60% they don’t expect it to immediately discharge, whereas others do like that behavior. This should therefore be configurable.
3. There is need for a hysteresis around the transition between IDLE and Normal (Charge).
4. There is a need for a hysteresis around the Discharge / Idle. During charge there is a possibility for the charge of overshoot the battery limit %. It should switch to IDLE here, instead of immediately discharge back to the battery limit %. It add unnecessary charge/discharge cycles.
5. The charge can skip the battery limit value, e.g. during a BMS re-calibration, and in this case, currently it just keeps charging up to 100%.

My EC fixes, cover all these edge cases by improving the battery sustain code to have 3 limits.  
Limits are: lower, upper, discharge  
SOC = Current charge %  
State NORMAL (Charge if AC connected).  
If SOC \> upper, switch to IDLE.  
if SOC \> discharge, switch to DISCHARGE  
State IDLE (Don’t try to charge, even if AC connected)  
If SOC \< lower, switch to NORMAL  
if SOC \> discharge, switch to DISCHARGE  
State DISCHARGE (Discharge the battery, even if AC is connected)  
if SOC \< upper, switch to IDLE.  
if SOC \< lower, switch to NORMAL.

If the user does not wish to ever force the DISCHARGE state, they set the “discharge” limit to \> 100%, e.g. 120%, so it can never be reached.

It is a very simple state machine, but covers all the edge cases well.

---

_[View the full topic](https://community.frame.work/t/tracking-battery-flipping-between-charging-and-discharging-draws-from-battery-even-on-ac/22484)._
