Hi I am building a pocket altitude, temperature and humidity meter with 1.8" TFT display. I have a 1000mah 3.3v Li-ion battery to power the whole system. I also need to display the battery level in percentage in the device. I am confused about which way i need to use. The same battery is powering the device so using voltage divider is not useful because of the ADC reference depends on the battery. Can you guys help me to overcome this?
The same battery is powering the device so using voltage divider is not useful because of the ADC reference depends on the battery.
It sounds like you are running this without a voltage regulator, such that the supply voltage to the MCU varies with the battery.
In that situation, the best course of action is typically to momentarily turn on the ATmega's internal bandgap reference, measure that with the supply-referenced ADC, and then calculate backwards from the data sheet's value of the bandgap reference to the supply voltage that would produce the measured ADC counts. (Some MCU's also get a factory-measured item-unique calibration value stored somewhere you can read at runtime, not sure the ATmega does however)
Then you can turn the internal reference back off to save power. Probably you want to put some thought into what else you can turn off, and sleeping the processor, turning off the display, etc to save power. Or even give it a manual power switch.