Measure Vcc like Arduino SecretVoltmeter

stanley

Member
Hi,

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

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

Thanks...
 
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.
 
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 ?
 
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:
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 ?
 
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...teensy-3-and-3-1?p=50064&viewfull=1#post50064

More discussions of voltage measurement here
http://forum.pjrc.com/threads/26117-Teensy-3-1-Voltage-sensing-and-low-battery-alert
 
Last edited:
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?
 
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
 
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.
 
Back
Top