Xiao nRF52840 accurate battery management

Here bellow is a piece of code that i wrote in order to manage battery voltage measurement and capacity calculation.

It contains a “calibration” routine to effectively measure the capacitance of the battery according with its voltage. It intends to be used with smal battery (not 18650!) for very long time setting applications.
The calibration routine assume that your application have a constant consumption in the order of C/10 the battery capacity (value is not critical) so that it takes about 10 hours to discharge it.

as you can see on this graph, two different batteries have significant different voltage curves.

ViKairn_VBAT.zip (5,1 Ko)

Any comments are welcome.

Hi there,
Nice code, I think that no 2 batteries will have the exact same Internal Resistance even same chemistry or type. so they will only be close not exact, It’s like comparing the capacitance against the battery voltage.
cool,
GL :slight_smile: PJ

Hi,
I am running a small statistics on that too. I will post the results.
Regards,
fbd38

I tested on three different Batteries and get almost the same curve.