# Can I estimate remaining battery life by measuring its voltage with the same MCU that it powers?

I'd like to estimate the remaining battery life of a battery that powers a microcontroller. Could I accomplish this by simply leading the battery into the MCU's built-in ADC?

My idea is that I could plot the voltage over time to figure out how much battery life remains. But would the change in voltage be noticeable? And would it be a problem that the same battery powers the MCU (and ADC)?

You can do this (assuming voltage is a predictable function of remaining life, but that's another issue) as long as there is a fixed voltage reference available in the system somewhere. Some micros have a fixed voltage reference built in, which can usually be read by the internal A/D or applied as the A/D scale. If not, you have to supply some external reference. Note that due to power consumption you may want the micro to switch on this reference only for a short time around battery readings, which don't need be very often relative to the time it takes to do a reading.

You can measure with a μC the voltage of the battery which directly powers this μC (without a voltage regulator). You need to have a reference voltage, which doesn't change as the battery voltage changes. The idea is either to measure the battery voltage w.r.t voltage reference, or to measure the voltage reference w.r.t battery voltage. Many μCs have a built-in voltage reference, which can be enabled from software. Some μCs can output a reference voltage to a pin. An external voltage reference would work too.

To conserve battery charge, you can use the μC pin to turn on the battery voltage measurement circuit only occasionally. Here's one of the variants of the circuit.

Which topology to use depends, in part on which type of the μC you're using. (?)

You might find that sensing battery voltage is not an accurate enough way of sensing the remaining capacity. In portable equipment (cell phones, laptops), battery capacity is estimated by measuring current in and out of the battery. There are dozens of specialized battery fuel gauge ICs (bq27200, for example), which help with this task.

Some microcontrollers even have this built in. The MSP430 ADC (regardless of version) section usually has some variation of an internal switch with a resistor voltage dividing Vcc down to a usable sampling voltage. This is then compared to the selected reference voltage so you can measure what Vcc is at.

INCHx is the ADC input channel selection register. The switch is closed when INCH is 0b1011, allowing the ADC to measure Vcc through the resistor divider. The thing on the right is the internal temp sensor.

Other microcontrollers might have this same feature. You should look through their datasheets to find out.