News:

Let's find out together what makes a PIC Tick!

Main Menu

Linearising a temp sensor

Started by Peter Truman, Oct 31, 2024, 06:27 AM

Previous topic - Next topic

Peter Truman

Linearizing a LM335 temp sensor LM335

Hi - I'm having trouble figuring out how to linearize my ADC reading from this temp sensor

I have the positive side of this sensor held high (5v) via a 4.7k pullup resistor, through a 10k series resistor and an 0.1uf ceramic cap to ground - feeding the non inverting input of a unity gain Opamp. Opamp output to the inverting input - I have another series 10k resistor and finally a 0.1uf Ceramic cap between the opamp output and the uC (18F2525)


This temp sensor is supposed to give an output of 10mv per 1 deg K

I have the PIC configured like this
Declare Adin_Res 10         '10 bit result
Declare Adin_Tad FRC        'clock source
Declare Adin_Stime 50       'time to dx cap
ADCON2.7=1                  'make sure it is LEFT justified  for a 10 bit result
   

The ADC reading I'm getting on PortA.1 is:
0 deg C (Ice slush) = 567
100 deg C (Boiling water - only a bit above sea level) = 706


373 deg (k) / 706 = 0.52532 (so a reading of (706 * 0.52532) - 273 = 97.87 deg C (close enough)

but..

273 deg (k) / 567 = 0.4814 (not even close to the value above)

(567 * 0.52532) - 273 = 24.85 deg C (miles away!)

I suspect I may have upset the ADC reading by adding various resistors and caps to try and smooth out the reading?

Is there a way to linearize these results to give a reasonable deg C reading from 0 to 100 deg? Or would I need a lookup table of some sort?

Thanks in anticipation

 


 

John Lawton

What does a DVM read, does it agree with your ADC readings?

John

david

Hi,
If you have a 0.1uF on the end of a 10k resistor then you shouldn't need an op-amp and it may not have the common mode range needed at the lower temperatures.  A crude picture might explain things a bit more (I learnt to do them at primary school....)
A large cap on the ADC input pin will do much the same as a unity gain buffer but without the offset or common mode issues.

David

Pepe

#3
567×5/1023=2,77126099V
2,77126099V-2,73V=0,041V -> 4 °C

706x5/1023=3,4506353V
3,4506353V-2,73V=0,72V -> 72 °C


0°C  ->  558
100°C  -> 763

Peter Truman

Quote from: John Lawton on Oct 31, 2024, 06:38 AMWhat does a DVM read, does it agree with your ADC readings?

John
Hi John

I see 2.7275v at freezing and 3.4162 at boiling

I was trying to figure out how my ADC readings relate to the voltages. I have a span of decimal 139 between 0 and 100 deg. So I divided 100deg by 139 which gives me 0.7194244 which I figure should cover it.

I got up this morning and read the forum and thanks to you guys it all suddenly works! Amazing what just a nudge in the right direction and a good nights sleep does for problem solving!

At freezing I should the ADC of 567-567 * 0.7194244 =0 deg
At boiling I should have 706-567 * 0.7194244 = 99.99

I'll code this and see how it looks in terms of linearity

Thanks for the help, I appreciate it


Peter Truman

Quote from: david on Oct 31, 2024, 08:26 AMHi,
If you have a 0.1uF on the end of a 10k resistor then you shouldn't need an op-amp and it may not have the common mode range needed at the lower temperatures.  A crude picture might explain things a bit more (I learnt to do them at primary school....)
A large cap on the ADC input pin will do much the same as a unity gain buffer but without the offset or common mode issues.

David
Hi David

This is hardware I designed years ago - I did a do-over of the board design (not the schematic) and just kept the same circuit in place - I remember being paranoid about protecting the PIC. The Opamp is an LM358S single supply which I have used for years - it's seemingly unbreakable! I use the other side of the Opamp to condition a V input from a pressure sensor. The sensor could be a 0-5v (in which case I just use the opamp as a voltage follower). If a 0-10v sensor is used, I have a jumper that connects a voltage divider to give me a gain of 0.5 It just seemed to make sense to use the spare channel to condition the temp sensor in the same way.

At the end of the day I'm little more than a self taught 'enthusiastic amateur' with all this stuff - but I find myself making a few bob from it nevertheless (only because I don't give up!)

I did want to post a screen grab of the schematic but I've not figured out how to paste the pic into the forum? I see an option to 'paste an image' but that just asks for a URL

david

Hello Peter,
All understood.  Just wasn't sure what op-amp you may have been using but the old LM358 is pretty good in that the common mode range includes ground and the output can swing fairly low in you're not sinking too much current.  Just not very quick though.
Of course these days you could use a barometer chip which inherently has temperature measurement also.  Totally digital with no analogue in sight.  Bosch has a big range of them and they're widely used in drones for altitude and rate of climb measurements. 
Good luck with the project.

Cheers,
David

Peter Truman

Quote from: david on Oct 31, 2024, 11:29 PMHello Peter,
All understood.  Just wasn't sure what op-amp you may have been using but the old LM358 is pretty good in that the common mode range includes ground and the output can swing fairly low in you're not sinking too much current.  Just not very quick though.
Of course these days you could use a barometer chip which inherently has temperature measurement also.  Totally digital with no analogue in sight.  Bosch has a big range of them and they're widely used in drones for altitude and rate of climb measurements. 
Good luck with the project.

Cheers,
David

Thanks David - just looked up a Barometric sensor chip for interest (not used one so far) - I looked at the ENS220 from Sciosense (since that was the first one to come up in my digikey search) - what a useful bit of kit! Now I need to think of a project I can use of of these in. Another sleepless night of inventing LOL Thanks for the tip.