Maker Pro
Maker Pro

Interfacing a NTC thermistor to a PIC

Rajinder

Jan 30, 2016
568
Joined
Jan 30, 2016
Messages
568
Hi
I have a NTC thermistor.
I want to connect to a PIC (PIC18F4520) A/D for temperature measurements.
Is a simple voltage divider circuit good enough?
The curve is non linear for the thermistor. Is there anyway of overcoming this in hardware? Or Software.
Finally if i use a PTC thermistor are there any circuit changes to be made?
Thanks in advance.
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,769
Joined
Nov 17, 2011
Messages
13,769
Is a simple voltage divider circuit good enough?
What is "good enough" for you? Yes, it will work.

Is there anyway of overcoming this in hardware?
Any way certainly, but rather complex and not economic.

Or Software.
Yes, and this is the usual way. You can either approximate the non-linear characteristic by an equation or approximate the characteristic by a piecewise linear characteristic where you store a set of data points and interpolate in between.

Finally if i use a PTC thermistor are there any circuit changes to be made?
Depends on your PTC. You'll have to implement the new characteristic in software to accommodate the different type of sensor.

Read this for more information.
 

WHONOES

May 20, 2017
1,217
Joined
May 20, 2017
Messages
1,217
You could use a Platinum Resistance Thermometer (PRT) instead. They are very linear and come in 100Ω or less commonly 1KΩ resistances. These quoted values are for when the element is at 0 deg C. They are a bit more expensive than your proposed NTC's or PTC's but, would not require any complex and time consuming linearization in either hardware or software saving a lot of time.
 

timff

Apr 13, 2018
19
Joined
Apr 13, 2018
Messages
19
If you are unable to use a more linear sensing element, you might be able to translate your readings with a non-linear formula (if one is available for your device) or a look up table.

One additional thought. You may wish to select a thermistor that can give you a wide resistance change over your target temperature so you get greater resolution. For example, if you select a part that has a 100 ohm change in series with a 10k resistor to form a voltage divider, you may not see as much of a voltage change as you would like for the microprocessor to measure.
 

Rajinder

Jan 30, 2016
568
Joined
Jan 30, 2016
Messages
568
HI all,
Thanks for the advice and help.
I am looking to measure from -10 to 70C
The part that I have selected is NCP series from murata, it is 10K.
I was thinking if I use this as a voltage divider with another 10K and feed into a PIC. How can I compensate for lead resistance?
I am trying to achieve the same as using a 1n4148 diode which can be used as a temperature indicator i.e. 2mV change in voltage gives 1C degree change.

Is there any easy way to make the output linear using hardware?
Best regards,
Raj
 

Rajinder

Jan 30, 2016
568
Joined
Jan 30, 2016
Messages
568
I have a further couple of questions :
If R(25) = 10K at say beta of 4200 for example
Then how do i calculate the R(25)/(100) from a typical graph? I know it is the difference between resistance at 25C and 100C but where does beta and constant K fit into all of this?
thanks
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,769
Joined
Nov 17, 2011
Messages
13,769
How can I compensate for lead resistance?
How long are your leads? at 10 k resistance of the sensor the lead resistance is likely irrelevant - plus taking into account the tolerance of the sensor and the other resistor.

Then how do i calculate the R(25)/(100) from a typical graph?
You either use the graph or the equation, not both.

You will have to trim the circuit and software anyway because each individual NTC will have a slightly different characteristic within its tolerances.
 

WHONOES

May 20, 2017
1,217
Joined
May 20, 2017
Messages
1,217
Using a PRT, it would be very straight forward. As they are linear over the temp range you quote, it would just need a bit of straightforward scaling with an opamp to provide an output compatible with you chosen pic.
 

OBW0549

Jul 5, 2016
157
Joined
Jul 5, 2016
Messages
157
I agree; for the temperature range you're wanting to measure over, using a platinum RTD would be a much better choice, as it wouldn't require a lot of math to linearize it. The circuit doesn't have to be very complex; here's a very simple design I used on one project to interface a 1000Ω RTD to a PIC's ADC:

temp.png
VREF was +5V, which also powered the op amp. For your use, resistors R14 and R15 will need to be changed to get the offset & scaling you need.
 

Rajinder

Jan 30, 2016
568
Joined
Jan 30, 2016
Messages
568
Hi
I will look at the platinum RTD. I think they are expensive than a thermistor. I was slso thinking of using a diode to measure temperature, which could be cheaper still.
Am i correct in saying that R13 and R14 set a voltage at the inverting input. R12 and RTD set an adjustable voltage at non inverting input. The opamp will try to keep both inputs the same at its input and hence tge feefback resistor is used to set a gain / offset?
Sorry about my lack of opamp knowledge.
Raj
 

OBW0549

Jul 5, 2016
157
Joined
Jul 5, 2016
Messages
157
I will look at the platinum RTD. I think they are expensive than a thermistor.
Yes, they're a bit more expensive-- but a lot less trouble to work with because they're much more linear.

I was slso thinking of using a diode to measure temperature, which could be cheaper still.
A diode (or a transistor with the base shorted to the collector) can be used, but the problem is the extremely large variation in forward voltage from unit to unit. Unlike RTDs and accurate thermistors, each unit has to be calibrated at a known temperature.

Am i correct in saying that R13 and R14 set a voltage at the inverting input. R12 and RTD set an adjustable voltage at non inverting input. The opamp will try to keep both inputs the same at its input and hence tge feefback resistor is used to set a gain / offset?
The feedback resistor R15 is used to adjust the gain, and the R13/R14 ratio adjusts the offset. However, the two adjustments interact somewhat.
 

WHONOES

May 20, 2017
1,217
Joined
May 20, 2017
Messages
1,217
I agree; for the temperature range you're wanting to measure over, using a platinum RTD would be a much better choice, as it wouldn't require a lot of math to linearize it. The circuit doesn't have to be very complex; here's a very simple design I used on one project to interface a 1000Ω RTD to a PIC's ADC:

View attachment 40709
VREF was +5V, which also powered the op amp. For your use, resistors R14 and R15 will need to be changed to get the offset & scaling you need.
I like your follow up to my suggestion for using a PRT. It would be possible with a small mod to remove the influence of the offsetting on the gain.
 

OBW0549

Jul 5, 2016
157
Joined
Jul 5, 2016
Messages
157
I like your follow up to my suggestion for using a PRT. It would be possible with a small mod to remove the influence of the offsetting on the gain.
True. It's also possible, by adding a large-ish resistor between the op amp output and its non-inverting input, to correct for the slight nonlinearity that results from feeding the RTD from a resistor instead of a constant-current source. With a small tweak, that same resistor can also cancel out the negative second-order term in the RTD's resistance vs temperature characteristic.

But for the application of the circuit I posted above, perfect linearity was not important, and calibration was done in software so neither gain nor offset needed to be done by trimming resistor values. The most important design requirement was low component count, hence the circuit's lack of "nice" features.
 

WHONOES

May 20, 2017
1,217
Joined
May 20, 2017
Messages
1,217
True. It's also possible, by adding a large-ish resistor between the op amp output and its non-inverting input, to correct for the slight nonlinearity that results from feeding the RTD from a resistor instead of a constant-current source. With a small tweak, that same resistor can also cancel out the negative second-order term in the RTD's resistance vs temperature characteristic.

But for the application of the circuit I posted above, perfect linearity was not important, and calibration was done in software so neither gain nor offset needed to be done by trimming resistor values. The most important design requirement was low component count, hence the circuit's lack of "nice" features.
Absolutely right, a constant current source would indeed improve linearity, it just depends on how accurate Rajinder needs it to be. Hopefully he will tell us.
 

Rajinder

Jan 30, 2016
568
Joined
Jan 30, 2016
Messages
568
The accuracy i require is thst it must perform as good as a diode. If you apply a constant current to a diode (1n4148) then the temperature can ve neasured by 1C/2mV
1 degree for 2mV.
So something like this or better.
Thanks
 

OBW0549

Jul 5, 2016
157
Joined
Jul 5, 2016
Messages
157
If you apply a constant current to a diode (1n4148) then the temperature can ve neasured by 1C/2mV
No, it cannot. You can measure temperature deviations from some reference temperature, but you cannot directly measure temperature itself because at any particular forward current and temperature, the forward voltage drop will differ from one diode to the next.

Moreover, that 2 mV/C is only approximate; it can vary from diode to diode and depends somewhat on forward current.

So "as good as a diode" doesn't tell us much.

The foregoing posts pretty much lay out the options available to you. In my opinion, your best course of action would be to use a simple thermistor/resistor voltage divider, feed the resulting voltage divider output into your PIC's ADC, and do the linearization in software.
 

Rajinder

Jan 30, 2016
568
Joined
Jan 30, 2016
Messages
568
Hi thanks for your reply.
I was looking to at least measure a change on 1C.
So think the thermistor and voltage divider will be the best option.
Thanks
 
Top