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
    }
    

    Log in to reply
     

  • 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
 

1 out of 2

Suggested Topics


  • Controllers   9 Aug 2014, 10:44

    33

  • Bug Reports   3 Mar 2021, 18:48

    11
  • 8

  • Bug Reports   30 Mar 2023, 15:40

    5
  • 3

  • Bug Reports   1 Jun 2022, 16:02

    2

0
Online

11.5k
Users

11.1k
Topics

112.8k
Posts