I'm writing an embedded app for ATtiny88 - one of its task is to measure voltages of serial connected two 12 V car batteries.
The microcontroller is powered from around 4.5-5 V (LM317), measured voltages (~24 V and ~12 V) are connected to two ADC channels via proper voltage dividers. In my application I have to use internal bandgap reference theoretically equal to 1.1 V.
I should probably do some kind of calibration procedure, so right now I figured something like this:
- Apply exact 24 V (12 V) from an external, stabilized power supply to the voltage divider.
- Calculate gain coefficient for each used channel (24 (12) / mean value from ADC channel)
- Store these coefficients in EEPROM and use it as a scaling factor for calculating measured voltages.
I tried to measure the internal bandgap reference - one of the ADC channels is internally connected to it - but it always returns 1023 - maximum value for a 10-bit ADC.
My question is, how to measure the voltages most accurately? The bandgap reference voltage probably varies between different chips (datasheet says 1- 1.2 V). Is there any better way to do calibration than the one I'm doing it right now? Please help.