Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 9 of 9

Thread: Measure Vcc like Arduino SecretVoltmeter

  1. #1
    Junior Member
    Join Date
    Aug 2014
    Location
    Kuala Lumpur, Malaysia
    Posts
    10

    Measure Vcc like Arduino SecretVoltmeter

    Hi,

    Does the Teensy 3.1 / ARM Cortex-M4 hv something similar to Arduino SecretVoltmeter measuring the Vcc ?

    HTML Code:
    http://provideyourown.com/2012/secret-arduino-voltmeter-measure-battery-voltage/
    Thanks...

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,464
    Yes, you can measure the internal 1.2V reference as an analog input, using the 3.3V power as a reference, and then do some simple math to figure out what the 3.3V level actually was.

  3. #3
    Junior Member
    Join Date
    Aug 2014
    Location
    Kuala Lumpur, Malaysia
    Posts
    10
    Thanks, I was thinking of something similar like the SecretVoltmeter without using up an analog pin for this purpose..

    Do u hv a sample codes for this ?

  4. #4
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,574
    Code:
    void setup() {
      analogReference(DEFAULT);
      analogReadResolution(12);
      analogReadAveraging(32);
    }
    
    void loop() {
      int mv;
      mv = 1195 * 4096 /analogRead(39);
      Serial.println(mv);
      delay(2000);
    }
    Last edited by manitou; 02-21-2015 at 01:15 AM.

  5. #5
    Junior Member
    Join Date
    Aug 2014
    Location
    Kuala Lumpur, Malaysia
    Posts
    10
    Ok, thanks... tried it and got a value of 3293, I would assume this is 3.293V ...

    Not sure what does those number means ( 1195 * 4096 ) , care to enlighten me or point me to the correct pages ?

    What is analogRead(39) ? Is this an internal pin ?

  6. #6
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,574
    yep, sketch calculates millivolts. analog "channel" 39 is mapped by core library (hardware/teensy/cores/teensy3/analog.c) to the internal ADC input. Teensy 3.1 reference manual 3.7.1.4.1 enumerates various ADC inputs. The datasheet gives specs of 1.195v The analog resolution is set to 12 bits, hence 4096.

    Paul actually measured the internal AREF here
    http://forum.pjrc.com/threads/26059-...ll=1#post50064

    More discussions of voltage measurement here
    http://forum.pjrc.com/threads/26117-...-battery-alert
    Last edited by manitou; 08-12-2014 at 01:04 PM.

  7. #7
    Junior Member
    Join Date
    Sep 2016
    Posts
    19
    Quote Originally Posted by manitou View Post
    Code:
    void setup() {
      analogReference(DEFAULT);
      analogReadResolution(12);
      analogReadAveraging(32);
    }
    
    void loop() {
      int mv;
      mv = 1195 * 4096 /analogRead(39);
      Serial.println(mv);
      delay(2000);
    }
    I've done this exactly on a 3.5 but I am getting 1325 abouts as my reading. Other external ADC reads operate fine, but I seem to have an issue measuring the internal reference this way.

    If i switch to using the 1.2V internal reference, and then measure external ADC pins this also behaves as expected.

    Pulling my hair out to why this isn't working for me. Any suggestions?

  8. #8
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,574
    Sadly a symbolic name has never been assigned to these internal ADC channels. For T3.5/3.6, use analogRead(71)

    hardware/teensy/avr/cores/teensy3/analog.c

  9. #9
    Junior Member
    Join Date
    Sep 2016
    Posts
    19
    Quote Originally Posted by manitou View Post
    Sadly a symbolic name has never been assigned to these internal ADC channels. For T3.5/3.6, use analogRead(71)

    hardware/teensy/avr/cores/teensy3/analog.c
    ARGH At least it wasn't a mistake starring me in the face.

    Would be nice to give that a symbolic name if it keeps changing across the boards. And/or maybe an "Analog IO" page is worthwhile on the Teensy reference (https://www.pjrc.com/teensy/teensyduino.html) to match the digital IO page. Could explain all the advanced (or specific to Teensy) Analog stuff you can do.

    Thanks Paul for answering me on Twitter too.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •