analogRead() on Teensy 4.0 not linear?

Status
Not open for further replies.

JohanesK

New member
Hi!
I'm going through the tutorials with my new Teensy 4.0 and am having issues with the temperature sensor (https://www.pjrc.com/teensy/tutorial4.html).

My code and breadboard is identical to the example, and I connected the temperature sensor to pin 23 (A9).
However, at ambient temperature, I'm getting an analog value of ~770, which would indicate a room temperature around 52C/126F. I would expect the temperature to be somewhere around 20C/68F, which would mean I should get a much lower code!

I then tried to replace the thermistor with another 10K resistor, thus measuring the voltage between the two 10K resistor.
My board delivers 4.93V, and my multimeter says this voltage is 2.46V, which is exactly Vcc/2. At this mid-point of the analog spectrum, I would expect the analogRead() to return 1024/2 = 512, but alas, it is returning 769!

(Now, assuming 770 = 2.46V, the RT can be calculated to RT = R1/(Vcc/Vx-1) where R1 = 10K, Vcc=4.93, Vx=2.46V and thus RT = 9,960, which should be just over 25C/77F according to the data sheet (and the tutorial).

Thus, it seems that the analog input is not completely linear!

I have tried and Vx = 0V gives code "0" and Vx=Vcc=4.93V gives code 1023.

Am I missing something here? How should I read the analog input?
 
ATTENTION 4.93 Volt is much too high and will kill the Teensy.
The Teensy 4 is *NOT* 5 Volt compatible.

 
ATTENTION 4.93 Volt is much too high and will kill the Teensy.
The Teensy 4 is *NOT* 5 Volt compatible.

That is funny. If I connect my Teensy 4 to my computer via USB, and measure the voltage between pin "G" and pin "5V", I get 4.93V...
 
No, you are funny :)
The 5V are *before* the voltage regulator.

Teensy 4 is NOT 5V tolerant. Except VIN or VUSB no pin can stand more than 3.3 Volt.
 
You are using a tutorial that is talking about a Teensy 2 and a Teensy++, not a Teensy 4.

For a 3.3V microcontroller you need to use the 3.3V rail for the voltage divider involving the thermistor.

As chips get faster the supply voltage has to drop, due to the physics, so faster/newer microcontrollers
are typically 3.3V or lower.
 
In your example of getting analogRead() = 769, and the Teensy 4.0 being a 3.3V device, it would follow that the converted voltage is 2.48V (3.3/1024*769). Teensy4.0 is working fine and linearly, and yes please do not expose any signal pin to more than 3.3V.
 
@MarkT, thank you, that explains it! I haven't worked with electronic circuits in 20+ years, but wanted to get cracking again with the Teensy board. Never ever realized the tutorial wasn't for newer boards. Tutorial 2 explicitly said "Add +5V connection", so I just did exactly that. Glad that the board still seems to be fine!

Changing the rails to be supplied from the 5V to 3.3V makes everything work perfect! I'm getting a code of 512 (right on) when I do the 10K + 10K ohm divider circuit, which is what it should be, and when connecting the thermistor I'm getting a code of 475 = 21.7C / 71.12F which is also very believable. And as @linarism explains, it all actually makes sense!

Thank you all for helping me understand this. Is there any way for me to help contribute to updating the tutorial on the site?
 
Status
Not open for further replies.
Back
Top