The battery gauge that took 3 hours to say 10%
Three battery complaints turned out to be three different bugs. One gauge took 3 hours to show its first 10%, and now takes 1.5. Another got stuck at 99%; it now reaches 100%, proven with a simulated −40 mV ADC offset.
Three battery complaints came in from the field. On one model, the gauge took 3 hours to show its first 10%. Some devices stopped charging below 4.15 V. Others sat at 99% forever after a full charge.
It looked like one battery problem. It was three separate bugs.
The wrong table
The slow model was using the percentage table for a 170 mAh cell on a 1,000 mAh battery. I built new tables for 170, 1,000 and 1,800 mAh cells. I also wrote and documented an algorithm that moves toward the measured value and can’t get stuck.
Believing the charger too early
The early stop came from the charger chip reporting DONE too early, and the firmware believing it. Now the firmware retries up to 3 early DONE signals before it accepts one. The noisy charger status lines also got a 3-sample debounce with hysteresis.
Stuck at 99%
The charger stops at 4,125–4,140 mV, but the table needs at least 4,148 mV for 100%. So a full battery always came out 8–23 mV short. On top of that, an older guard blocked the 10-minute recalculation, so the gauge never moved off 99%. Now, when the firmware accepts the battery as full, it sets 100%.
Testing with field conditions
To test the 99% fix, I built a test image with a simulated −40 mV ADC offset, like the readings from the field. The fixed build held 100%. Each fix also has a unit test.
Conclusion
The gauge now shows 10% after 1.5 hours instead of 3, holds a steady 100% without flickering back to 99, and batteries charge to 4.15 V again.
Splitting the complaints apart early meant each bug got its own fix and its own test.