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.