DEL
(DEL)
1081
I think I figured out internal Vcc measurement (so we can remove R1/R2).
Its all in 17.13.1 (page 134) of the datasheet.
The only required ADC-configuration change is to set the ADMUX register to use Vcc as reference voltage. (Note this configuration will give a 10-bit result, to be read from the ADC register.):
ADMUX = b00001100;
If we want to read internal temperature, ADMUX need to be set back to read ADC4 with Vbg as reference:
ADMUX = b10001111;
…and we then alternate between the two configurations with a small time delay after each change. Possibly we also need to read the ADC twice each time, to get more accurate results.
To figure out the ADC result for Vcc:
adc_result = ADC; //16-bit integer
where adc_result = (Vbg / Vcc) * 1024;
= Vbg / (Vbat - D1) * 1024;
where Vbg = 1.1 V
and D1 = drop over Schottky = ~0.25 V
So adc_result = 1.1 * 1024 / (Vbat - 0.25)
The typical lookup table we use will look like this for Vbat:
4.2 V = 285
4.1 V = 293
.
.
.
2.5 V = 501
Note lower Vbat gives higher results (Vbg becomes larger as a percentage of Vcc). This would also be an opportunity to finally upgrade to 10-bit ADC operation.