Author Topic: Converting non-linear Thermistors  (Read 10375 times)

Enertyr

  • Newbie
  • Posts: 8
  • I'm a llama!
    • View Profile
Converting non-linear Thermistors
« on: September 17, 2005, 10:02:48 PM »
I'm using 10k thermistors to measure temperature in ADC[1] through [5].  Because the output is non-linear, I need a simple way (other than a signal conditioner) to get near accurate temperature readings.

I read somewhere to use a tables (DM
  • ) and interpolating values.  Does anyone have sample code on working with tables, extracting the data and interpolating?


Alternately, is there a some other "soft" routine to calculate a reasonable temperature value?

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:Converting non-linear Thermistors
« Reply #1 on: September 19, 2005, 08:48:35 AM »
You need to find out the ADC reading that corresponds to the correct temperature range of interest, then store the value in a DM where the index of the DM is used to find the temperature.


E.g.  for a very crude table with just 4 entries

ADC     Temp    
---------------------

4000    20
3000    30
2000    45
1000    67.5

We will store the temperature reading in DM[1] to DM[4]

N = ADC/1000

So   DM[1] = 675  ' means 67.5 degree
       DM[2] = 450
       DM[3] = 300
       DM[4] = 200   ' means 20.0 degree

So if you have a ADC reading of 2700, it is between DM[2] and DM[3], you will have to interpolate the reading which is:

    Temp = DM[2] + ( DM[3] - DM[2])* (2700-2000)/1000

 =>   Temp = 450 + (300-450) * 700/1000 = 345  or 34.5 degree.

Of course we are using linear interpolation which is subject to some nonlinearity error in our interpolation. But when you have a larger table with closer range of values then the behavior from one table value to the next is quite near to linear and the error is reduced.







       
« Last Edit: September 19, 2005, 11:29:34 AM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

Terry

  • Guest
Re:Converting non-linear Thermistors
« Reply #2 on: September 19, 2005, 09:28:01 AM »
Thanks ... you've confirmed what I figured out through trial and error.  What I also included was a multi dimensional array as part of a CALL routine.

Using the FOR / NEXT  function with a IF/ELSE test, I could loop the routine to find the appropriate index value and subsequent temp  point.

DM[G] = (ADC(G)-DM[H-1])*(DM[H+100]-DM[H+99])/(DM[H]-DM[H-1]) + DM[H+99]

You need to watch out that for interger mathematics.  

101 - 199 - index value = ADC raw value
201 - 299 - temp points for T1
301 - 399 - temp points for T2
etc.

This was easier to program as I used the concatenate function in Excel to generate the definition text string.
e.g.  =CONCATENATE(X42,": ",Y42,": ",Z42) which gives

'initialize data table
DM[138]=2310: DM[238]=770: DM[338]=250
DM[139]=2398: DM[239]=806: DM[339]=270
etc.

Then all you need to do is cut and paste ... no extensive typing where you might make a typo.


Hope this helps others.