read ADC in one step and adjust calculation (most probably it doesn't
make much of a difference)
This commit is contained in:
parent
3d7e0e3ec6
commit
bd36cfed2d
@ -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
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user