Close

Update: use moving averages to inform charging and LED states

A project log for Smart ML2032 Coin Cell Charger Module

ATtiny824-powered battery charger uses integrated analog-to-digital converter circuitry to monitor charging

zachary-murtishiZachary Murtishi 08/03/2025 at 21:450 Comments

I've noticed that the module's LEDs will flicker between states if it is on the edge of thresholds for charging during normal use. As it was implemented, single ADC readings were used to inform device decisions. It seems as noise in the ADC readings might result in single readings being inaccurate for informing the module's LED and charging states. I've decided to implement a simple moving average algorithm to smooth out any fluctuations.

Simply put, the MCU will collect ADC readings as they become available and immediately index them into a FILO queue. As new data becomes available, the oldest ADC data will be overwritten by the newest addition. A simple average is calculated using the data in this queue every time new data replaces old data. This average is then used to inform any decisions to change the LED state or cease/begin charging.

As the MCU is currently configured, it will collect new ADC readings and perform this averaging every 100 ms.

Discussions