2 Theory
Normally the voltage measurement can be calculated based on the formula shown below, supposing that ADC is 10-bit.
where RESadc is the value in the ADC result register, Vin is the input to the ADC, and Vref is the voltage reference for the ADC.
A general way to measure the voltage, is to select external input voltage as ADC Vin, and select internal VCC or Vbg as the ADC Vref. This solution is just to the contrary, namely to select Vbg as Vin, and to select VCC as Vref. The formula can be updated to:
Then the VCC value can be determined by the RESadc result and the known Vbg, as shown in the formula:
This solution helps to measure the VCC without any external components or I/O pins. But, as every coin has two sides, there are two main limitations to this solution.
- Non-linearity.
In this design, the formula is y = m/x, where m = (1024*Vbg), x stands for the ADC result register value, and y stands for the target VCC value. To avoid measuring accuracy influence from the non-linearity, the users can make a piecewise fitting in algorithm for further research.
- Not all AVR® parts are suitable.
The user's MCU to apply this method must fully support the core idea:
- Internal reference voltage can be the ADC input
- The VCC can be the ADC reference
Check the list about tinyAVR® and megaAVR® in the Appendix to see if the MCU is suitable.
