I recently lost a NAS HDD so I don't have the code but 4-5 years back I designed a generic, battery powered ADC module. My battery monitor used a couple of pins so it probably is not applicable here but it may be useful for others. In my case, I needed only a single ADC input pin so I had a surplus of pins.
I used two BR2032 coin cells. BR type cells maintain their rated charge until slightly before their end of life while CR type cells fall off gradually throughout their life.
The batteries connected to Vdd and I fed an LP2980 LDO from a PIC pin. Vdd was 6V but the PIC12F675 (and PIC12F615) can handle 6.5V. The output of the LDO was used to power the attached analog sensor and also connected to Vref. A second pin can also supply the LDO if more current is needed.
To monitor the battery, measure the output of the LDO using Vdd as reference. Initially, the reading will be something less than maximum but will approach maximum as the batteries start to drop off just before end of life.
This wasn't my original idea but I cannot recall where I came across it.
Bookmarks