read ADC in one step and adjust calculation (most probably it doesn't

make much of a difference)
This commit is contained in:
Nicu Hodos 2018-12-31 18:07:20 +01:00
parent 3d7e0e3ec6
commit bd36cfed2d

View File

@ -35,15 +35,11 @@ protected:
delay(2); // Wait for Vref to settle
ADCSRA |= _BV(ADSC); // Start conversion
while (bit_is_set(ADCSRA, ADSC))
; // measuring
while (bit_is_set(ADCSRA, ADSC)); // measuring
uint8_t low = ADCL; // must read ADCL first - it then locks ADCH
uint8_t high = ADCH; // unlocks both
uint16_t result = ADC; // read ADC in one step
long result = (high << 8) | low;
result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000
result = 1126400L / result; // Calculate Vcc (in mV); 1126400 = 1.1*1024*1000
return result; // Vcc in millivolts
}