Read Thermistor Temp. Data from Teensy?

Svarun123

Member
I'm attempting to read temperature data from a simple 2-pin thermistor sensor. I'm using a Teensy 4.0.

I've used this simple thermistor many times, and it has worked very well so far with both Teensys and Arduinos. However, I'm running into an issue with this set of thermistors lately, only on the Teensy.

I first connected the thermistor to my Arduino Uno R3, according to the following Arduino tutorial.

The thermistor I'm using has a resistance value of 10K, and so has the resistor I'm using in my circuit, instead of the 100K they use in the tutorial I used, as such:

image0.jpg

Alongside the following code, as per the same Arduino tutorial above:
Code:
int ThermistorPin = A0;
int Vo;
float R1 = 10000;
float logR2, R2, T;
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;

void setup() {
Serial.begin(9600);
}

void loop() {

  Vo = analogRead(ThermistorPin);
  R2 = R1 * (1023.0 / (float)Vo - 1.0);
  logR2 = log(R2);
  T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
  T = T - 273.15;
  T = (T * 9.0)/ 5.0 + 32.0; 

  Serial.print("Temperature: "); 
  Serial.print(T);
  Serial.println(" F"); 

  delay(500);
}

The setup and code above work to produce correct temperature readings from the sensor.

I then went to build the same setup with my Teensy 4.0, as such:

image1.jpg

Using the same exact code.

However, this setup does not work correctly, and my temperature values are off. I also tried swapping out the 10K resistor for a 100K one, to no avail.

What is going wrong here with the Teensy? As far as I understand, the Teensy data pins are each rated for 3.3V, which should not be an issue here.

Thanks for reading my post, any guidance is appreciated.
 
You are powering the thermistor-resistor divider from the 5V. You better power it from the 3V3 pin ["3V"]:
[1] the Teensy will not survive a voltage higher than 3V3 on its input pins,
[2] the ADC range of the Teensy is 0V - 3V3.

Paul
 
You are powering the thermistor-resistor divider from the 5V. You better power it from the 3V3 pin ["3V"]:
I know that with the potential divider that you should only see circa 2.5V on A0 but if one or other of the pins become
unconnected it is possible that A0 might have seen 5V and have been damaged.

I use this library for reading thermistors without problem.

It can be used without parameters where values will be assumed for parameters or with user supplied parameters, see below:
Code:
Thermistor(
	uint8_t pin,
	bool genericSimpleFormula = true,
	long seriesResistor = SERIESRESISTOR,
	long thermistorNominalResistance = THERMISTORNOMINAL,
	float temperatureNominal = TEMPERATURENOMINAL,
	long bCoefficent = BCOEFFICIENT,
	uint8_t numSamples = NUMSAMPLES);
I suggest, use 3V3 for Thermistor supply, try another input pin and try the above library.
 
The problem, not mentioned in that tutorial, is that the analog input is a SAR type ADC.

I recall the sampling capacitor for the Teensy 4. is something like 30 or 40 pf. They almost always are in that range because of the famous kT/C noise.

(See this post on using a SAR adc with spice model illustrations)

One way to look at the problem is that when you connect the resistor divider network to the analog input, the sampling capacitor is not able to charge up to the right voltage within the time it takes for the SAR to finish sampling the input.

The best solution is (a) use a buffer with and RC to act as charge reservoir. Next best, (b) at least use a buffer. And if you insist on direct connection of the divider to the analog input, you might get away with it if you can (c) lengthen the sampling window/

Regarding (c), if you want 1% accuracy, a 1.5usec window might work. Similary, for 12 bits, then 3 usec. I believe the API for the ADC has a control to set the sampling window, I do not know how long it can be.

To help make it super clear, here is a SPICE model for what happens when you connect that divider to the analog input. The circuit on the right represents the input to your SAR. The switching constants are from an actual 1MSPS SAR ADC by Analog.

The red curve is the voltage at the analog input. The grey is the clock that operates the switched capacitor.

See the sag in the input voltage. And notice, it does not recover before the end of the sampling window. So in this case you have an error of about 20%.

SAR_thermistor10K.png



Here is what it looks like with an opamp buffer (opton b above). Notice the recovery is fast, with the opamp to supply current. But now you have spikes and they even appear on the input to the opamp. But maybe your situation can probably tolerate that.


SAR_opamp_R100_cropped.jpg



And here is what it looks like if you follow option a, add an RC network to act as a charge reservoir for the SAR. I switched to a sine wave for this, I happen to have the model around already.

Notice the kickback is pretty much gone.


SAR_opamp_RC20x1_cropped.jpg



Here is what the current flows look like with the RC network as charge reservoir Notice that the charge current for C1 comes from C2, and there is a slower replenishment current for C2 through R1. That is the way it supposed to work with a SAR ADC.


SAR_opamp_RC20x1_currents_cropped.jpg





Finally, if you are going to implement this, I sincerely suggest a soldered board and not solderless breadboard. The parasitic impedances in those breadboard and jumper wire system are not helpful.

Read the post that I linked at the top. It gives you more detail and it is very specifically focused on actually using the SAR.
 
Last edited:
Back
Top