OWL2 to LM34 & AD590 temperature sensors

(c) 1998 , 2001 EME Systems, Berkeley CA U.S.A.
 <stamp index> <home>

Contents (updated 7/5/2004)

 

LM34 and LM35 Temperature sensors, TF and TC probes

top

We offer both a field-ready probe (TF for Fahrenheit and TC for Celsius) and do-it-yourself kit of parts for cable mounting the LM34 or LM35 temperature sensors from National Semiconductor. The sensor has the following characteristics:

  • It is a three-terminal device with voltage output that can connect directly to the OWL2c analog inputs.
  • It has a high level linear voltage output,10mV per 'F or 10mV per 'C respectively.
  • The output voltage is zero at zero degrees Fahrentheit (TF, LM34), or zero degrees Celsius (TC, LM35). Compare that offset to other sensors which are offset relative to zero Kelvin or are nonlinear.
  • The calibration is accurate right from the factory. The highest grade sensors we use in the TF and TC probes is accurate to within +/- 1 'F (+/- 0.5 'C).
  • EME Systems provides additional calibration at one or two points to reduce the error to +/- 0.25 'F (+/- 0.125'C) over the biological temperature range:
  • The operating temperature for the TF probe is 0.0 to 230 'F (-17 'C to +110 'C), and for the TC probe it is 0'C to +110'C for the TC probe.
  • The output from these sensors connects directly to the OWL2c A/D converter, and gives a resolution of 1/8'F or 1/8'C.
  • EME Systems has developed a three-dimensional circuit board that turns the LM34 or LM35 into robust and stable cable-mounted probe, good for 100 feet (30 meters) or more extension from the measuring system.

We usually recommend using the TF probe to cover the biological temperature range due to fact that the range that extends below freezing. It is easy to convert to Celsius in software if necessary. (Celsius=Farenheit -32 * 5/9)

gosub ADread             ' result in millivolts
degF=result              ' degree F * 10, 1/8 degree resolution
degC=degF*5/9-178     ' convert to degrees Celsius * 10
debug REP "-"\degC.bit15,DEC abs degC,".",SDEC1 degC

There are other ways to do the computation. The subtraction is done after the multiplication and division sot that it will handle temperatures down to -17.8 Celsius. (The stamp does not divide negative numbers properly.) The DEBUG statement prints out the value, and it is complicated by the need to display negative values for Celsius, with one decimal point and the tenths. 


AD590 and AD592 Temperature sensor, TK probe.

top

For temperature measurement, one classic sensor is the AD590 (metal can or ceramic flatpak) or AD592 (plastic TO92), from Analog Devices. The sensor has the following characteristics:

  • The sensor is a two terminal device--only a single pair of wires is necessary to carry both the power supply and the signal.
  • The output of the sensor is a current--the signal is degraded neither by the resistance of long wires between the sensor and the measuring instrument, nor too much by induced noise voltages. It is easy to operate these sensors over several hundred feet of twisted pair wire (shielded if necessary).
  • The output current of the sensor is one microamp per Kelvin, linear, so that calculations in software are very easy (compared to say, thermistors, which are quite nonlinear over large ranges.)
  • The current can be turned into a voltage by a simple resistor at the measuring instrument, for standard analog to digital converters such as the OWL2c with the TLC2543 A/D converter. The value of the resistor can be trimmed to calibrate the sensor. Often only this single-point calibration is necessary.
  • Or the current can be used to implement a simple interface using the RCtime command on the BASIC Stamp. Because the sensor is a current source, it can charge a capacitor with a linear ramp, so the equation relating the RCtime value to temperature is a simple reciprocal, and only one temperature calibration point is required.
  • The initial error can be trimmed by calibration of the sensor at one point. With one trim, the AD590I (the cheapest grade) is guarenteed to have a ±2 degree accuracy over the range 0 to 50'C. With two trims, that will be ±0.4 degrees over the same range. In experience, the values of run of the mill devices is well within the guarenteed specs. The worst case error occurs at the extremes of the range.
  • The sensor is available in several accuracy grades. The initial calibration is determined by the sensor output at 25'C, which should be 298 microamps. The error can range from ±5 degrees C for the cheapest grade of the part, to ±0.5 'C for the best grade. In each price catagory, the AD592 has greater initial accuracy.
  • The sensor is economical. The lower grades cost less than $2 each. The higher (initial accuracy and overall linearity) grades cost considerably more, up to $80 each for the most accurate. These price tradeoffs must be considered in the application in terms of interchangability of sensors and the feasibility of in-circuit calibration.
  • The AD590 in its metal package or ceramic flat-pack is characterized for operation from -55'C up to +150'C, and the AD592 in its plastic package operates from -25'C up to +125'C. Special Mil spec devices are available.
  • The sensor is easy to multiplex, so as to scan many sensors with just a few control lines--the signal is not degraded by passing through analog switches.
  • The minimum voltage needed across the AD590 is 4 volts. In fact, it works quite will down to 3 volts of overhead. This means that it can even be operated from a 5 or 6 volt power supply.
  • The sensor is rugged with respect to voltage surges and operator error. It withstands supply voltages up to 44 volts DC, and reverse voltages up to -20 volts DC.
  • It is relatively easy to construct probes using the part, because only the two wires and no additional parts need to be attached directly to the sensor leads.
  • The AD590 is available with the military designation is 5962-87571, available in class V qualified for space applications, RHA (Radiation Hardness Assurance) per MILPRF38585. etc. etc.

The AD590 or AD592 may be used with BASIC stamp in a couple of ways. The most accurate is to use a 12-bit or better A/D converter. The other way, less accurate but very easy to implement, is to use the RCtime command of the BASIC Stamp 2. The stamp measures the time it takes for the current from the sensor to charge a capacitor up to the switching threshold of the Stamp input pin. Details for both configurations follow:

1) Using the Stamp RCtime command with the AD590.
 +5 to + 15 volts ----------------------;  +
                                       AD590
                         ;--------------'  -
                         |
     stamp P5 ---/\/\----|
                 100     |
                        ---   0.1uF
                        ---
                         |
      common ------------'

The AD590 connects from the + power supply to the input pin. The 0.1 uF capacitor connects from the pin to common. The 100 ohm resistor is there to protect the stamp input pin from insults that might come down the sensor line, and to limit the capacitor discharge current. In operation, the pin starts out as an output, and the capacitor is discharged to zero volts. When the RCtime command operates, the pin switches to in input and the capacitor charges at a rate determined by the AD590 temperature. The RCtime command measures the time necessary for the voltage to rise from zero up to the 1.3 volt pin threshold. Then the pin is turned around to be an output again, and the process repeats the next time the program commands it. The 100 ohm resistor introduces a small scale error, because the current from the AD590 passes through that resistor while the capacitor is discharging. This will cancel out during the calibration procedure.

cal    con  64020    ' calibration constant to be determined
X      var  word     ' raw count from RCtime, 2uS resolution
kelvin var  word     ' kelvin temperature
degC   var  word     ' temperature in 'C
degF   var  word     ' degrees Fahrenheit
low 5         ' initial discharge the capacitor on p5
loop:
RCtime 5,0,X       ' get charging time
  low 5            ' discharge the capacitor
  Kal = X*273
  kelvin = cal/X
  degC = kelvin-273    ' calculate temperature
  degF = kelvin *9/5 - 460
  debug cls,? X,? Kal,? kelvin,? degC, ? degF 
                   ' show raw count, and temperatures (positive display only)
pause 2000         ' 2 second delay for demo
goto loop

To calibrate the sensor, put it in ice water (in a thermos bottle if possible!), allow it to equilibrate, and read the value of X. Multiply that times 273. This is the number you should substitute for the constant "cal" in the program. If, for example, you read X=230 with the probe in an ice bath, use 230*273=58695 in the program instead of 62790. The program shows you the value of Kal. Once you substitute the new value, the temperature should read correct (+/- 1 degree C), for any value of temperature.

The theoretical charging time is given by:

2*rct = 1.3 * 106 * C / K

where

  2*rct = time as measured in microseconds (2*rct)
                         or in RCtime count (rct)
        The RCtime command counts in units of 2 microseconds
  1.3 = the triggering threshold for RCtime, in volts.
        the threshold has a small negative temperature coefficient.
  C = capacitance in microfarads
  K = temperature in Kelvin
   

Combining the constants, and assuming C=0.1 microfarad:

rct = 65000/K

This assumes that the constants all have their nominal values. In actual situations, the capacitor will not be exactly 0.1 microfarad, the PIC threshold will not be exactly 1.3 volts, and the AD590 response will not be exactly 1 microamp per Kelvin. But in any case, the response is given by

rct = constant/K

And the constant can be determined by one calibration point for reasonable accuracy commensurate with 1 degree Celsius resolution. The value of rct will be about 238 when the temperature is 273 Kelvin (0 degrees Celsius). So each change in rct value amounts to a little more than one degree Celsius.

You can improve the resolution considerably by increasing the value of the capacitor to 0.22 uF or 0.33 uF. The numbers returned by RCtime will be larger, and there will be more steps (more resolution) over a given termperature range.

Suppose that you use a 0.22uf capacitor, and at 273 Kelvin (0 degrees C) you find a number from RCtime of 497. Then 273*497=135681. (The theoretical value is 143000.) This number is larger than the stamp can deal with in one word. The above program will not give the correct result. To compute this, you can use extended division:

Kelvin = 13568/X*10+(13568//X*10+1/X)     ' Kelvin
                                     ' resolution 1.0 Kelvin
degC = Kelvin - 273                    ' degrees Celsius
degF = Kelvin * 9/5 -460                ' Fahrenheit
   

This is a a kind of long division. The five most significant digits (13568) appear in two places, in a first division, (13568/X) to determine the most significant digits of the quotient, and then in the remainder term, (13568//X). The least significant digit is added onto the remainder, (13568//X*10+1/X) in a second division that determines the least significant figure of the quotient.

The above formula resolves the result to 1 degree. Use the following formula to resolve to 0.5 degree:

Kelvin = 13568/X*20+(13568//X*10+1*2/X)*5   ' Kelvin
                                       ' resolution 0.5 Kelvin
degC = Kelvin - 2730                      ' Celsius * 10 to units of 0.5 degree 
degF = Kelvin * 9 +25 /50 -460                ' Fahrenheit rounded off to 1 degree
   

There is a limit to the accuracy though, using the RCtime command, due to thermal drift in the PIC pin threshold, and noise.

In some cases it may be desireable to implement automatic calibration, where the user can press a button or enter a special routine that determines the calibration constant. All that is required is that the sensor be held at a reference temperature. This can be an ice bath a 273 Kelvin, or it can be a temperature bath being monitored by a reference thermometer being read by the BASIC Stamp. Call this Tref. The count returned by the RCtime at that temperature is rct. For the best accuracy, the calibration constant will in general be a double precision value, for example, 273*497=135681. What we need are the two values that appear in the equation just above. The easiest way is to rearrange the calculation as follows:

273*497 = 273*(49*10+7)           X=497         X/10=49     X//10=7
        = 273*49*10 + 273*7           
        = 13377*10 +1911          X/10*273=13377     X//10*273=1911
        = 13377*10 +191*10 +1     X//10*273/10=191  X//10*273//10=1
        = 13568*10 +1             X/10*273+(X//10*273/10)=13568
          ^^^^^     ^
          Kal1    Kal0

The following program starts off with a certain calibration constant in the data memory. The program reads the calibration constant and uses it to show the temperature in Kelvin and in degrees Celsius. Suppose you equilibrate the probe in an ice reference bath, and then push a button, which is the event that causes the program to branch to the "calibrate" routine. There the program calculates a new calibration constant, based on the assumption that the current temperature is equal to the reference temperature. New values of the calibration constants are written into the data memory. The program then continues, now using the new constants. The program shows how to read and write a word+ value in the data memory, as well as how to calculate the calibration value on the fly.

Tref   con   273         ' reference temperature for calibration
eKal1  data  word 13568  ' calibration constant most significant digits
eKal0  data  1           ' ditto, least significant digit
Kal1   var  word         ' for calibration
Kal0   var  nib          ' ditto  
X      var  word         ' raw count from RCtime, 2uS resolution
degC   var  word         ' temperature in 'C
K      var  word         ' temperature in Kelvin
   
dirs=$0000               ' initial discharge the capacitor
loop:
  RCtime 5,0,X           ' get charging time
  low 5                  ' discharge the capacitor
    read eKal0,Kal0          ' get calibration factor, ones digit
    read eKal1,Kal1.byte0    ' calibration factor, byte0 of word
    read eKal1+1,Kal1.byte1  ' ditton, byte 1 of word
    K = Kal1/X*10+(Kal1//X*10+Kal0/X)     ' Kelvin
    degC = K-273    ' degrees Celsius     ' degrees Celsius
    debug home,dec? X,dec? K,sdec? degC   ' show count & temperatures
  debug dec5 Kal1, dec1? Kal0           ' show calibration constants
  pause 500                       ' .5 second delay for demo
  if event then calibrate         ' write new calibration on event
goto loop                         ' continue the demo
   
calibrate:                    ' write the new calibration constants.
  Kal1=X/10*Tref+(X//10*Tref/10)        ' new calibration constants
  Kal0=X//10*Tref//10
  debug dec5 Kal1, dec1? Kal0     ' show new calibration constants 
  write eKal0,Kal0
  write eKal1,KAl1.byte0
  write eKal1+1, Kal1.byte1
goto loop
 
2) Using the OWL2c (or other) 12 bit or better A/D converter with the AD590.

On the OWL2c, with the AD590, a 10k½ termination resistor, a >9 volt power supply, and a 12 bit A/D converter referenced to 5.12 volts, it is possible to get a resolution of 1/8'C for temperatures up to 100'C. With a 6 volt supply and a 4.99kohm termination, the resolution is limited to 1/4'C. The termination resistor is limited by the requirement of keeping at least 4 volts across the AD590 sensor element.

 +5 to + 15 volts ----------------------;  +
                                       AD590
                         ;--------------'  -
                         |
    ADC input -;-/\/\----|
               | 100     |
               |         \
              ---  .1    /  4.99kohm
              ---        \
               |         |
      common --'---------'

 

The output across the 4.99k resistor is 5 millivolts per Kelvin. The resistor value can be trimmed for the specific sensor, or each sensor can be provided with its own calibration constant to be entered into software.

Calibration of the resistor: Equilibrate the sensor in an ice bath, and then trim the resistor value so that the program outputs zero degrees C, or 273 Kelvin.

ADch=5
gosub ADread0  ' get count, 1 count=1.25 millivolts=0.25 Kelvin
degC=result*25-27300
debug dec degC/100,".",dec2 degC," degrees Celsius"

Calibration in software. The factor Kal is the correction factor, expressed as Kal/65536. For example, 0.987 is approximated as 64684/65536. Or 1.022 would be 1 + 1442/65536

ADch=5
gosub ADread0  ' get count, 1 count=1.25 millivolts=0.25 Kelvin
degC=result**64684*25-27300     ' example where correction is *0.097
'degC=result**1442+result-27300 ' example where correction is *1.022
debug dec degC/100,".",dec2 degC," degrees Celsius"

          

This shows the result to a resolution of 0.25 degrees C. It is possible to calculate and store these calibration factors in memory automatically, in a manner similar to the case of RCtime. For example, if the reference temperature is 273 Kelvin, and the uncorrected reading is 274.25 Kelvin, then the calibration constant is:

274.25 * (Kal/65536) = 273
Kal=27300 * 65536 / 27425

This must be calculated using long division. Note that our binary long division routine automatically includes the factor of 65536. Once the Kal factor is determined, it can be written to the data memory.

In many cases it may be desireable to have one side of the temperature sensor grounded. The OWL2c provides a reference voltage output of 5.12 volts, and the sense resistor can be returned to that point:

 +5.120 volts -,---------,----------
               |         |
               |         |
               |         \
              ---  .1    /  4.99kohm
              ---        \
               |  100    |
    ADC input -;-/\/\----'---------*******
                                   *AD590*
     common -----------------------*******

The signals are now all referenced to the 4095 count at 5.120 volts:

ADch=5
gosub ADread0         ' get count, 1 count=1.25 millivolts=0.25 Kelvin
result=4096-result    ' invert sense of result
degC=result*25-27300
debug dec degC/100,".",dec2 degC," degrees Celsius"


 .<top> <index> <home> logo < mailto:info@emesystems.com >