hwCPUVoltage() on AVR screws up analogRead() readings
-
Can I use
hwCPUVoltage()
function to read cpu power supply voltage in my sketch? As far as I understand this function is not documented.I'm asking because this function affects
analogReference(INTERNAL)
with furtheranalogRead(pin)
call. According to source code it seems for me thathwCPUVoltage()
isn't restoring ADC settings before return.Simple code to test is looking something like this:
void setup() { analogReference(INTERNAL); } void loop() { analogRead(pin_number); // good value hwCPUVoltage(); analogRead(pin_number); // bad value }
-
There is a vcc voltage library if you want to read voltage supplied but I heard it isn't very accurate