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 further analogRead(pin) call. According to source code it seems for me that hwCPUVoltage() 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
    }
    

  • Mod

    There is a vcc voltage library if you want to read voltage supplied but I heard it isn't very accurate


Log in to reply
 

Suggested Topics

  • 33
  • 11
  • 8
  • 2
  • 6
  • 3

21
Online

11.4k
Users

11.1k
Topics

112.7k
Posts