How to measure battery voltage - LDmicro/LDmicro GitHub Wiki

Discussion at the LDmicro Forum - How to measure battery voltage using ATmega8 processor
AN546 Using the Analog-to-Digital (A/D) Converter

  • Internal Voltage Reference

ATmega8 operating voltages are Vcc = 2.7-5.5V.
The AVCC pin on the device should be connected to the digital VCC supply voltage via an LC network L1-C1.
Internal Voltage Reference Vref = 2.56V +/-10% with external capacitor C2 at AREF pin is selected.
To select the internal voltage reference, see ADC Voltage Reference.
R1-R2 is measurement divider to avoid Vadc2 > Vref.
SW1 and RV1 - the simulation model of a battery.
image
To calculate the value of Vcc, two "magic" constants are used: a multiplier and a divider.
They are calculated for Vref = 2.56V. If the Vref of your MCU is different, you need to change the divider.
image
Also, to control the LEDs, you can compare Vcc with a value of 30 (3V), 40 (4V), 50 (5V) instead of using the raw ADC value.
The additional calculation in the table.
image
adc battery voltage.zip

  • External Reference Voltage

Try to use LM385 from AN546.
Reference voltage of LM385 is 1.2V +/-1%.
image
image
image
adc battery voltage ext ref.zip
Series Voltage References

Any questions to [email protected]