Measuring Temperature using a 10K NTC Thermistor

Copyright, Stacy Anderson, Baltimore, MD, Oct, '99


This routine illustrates how an inexpensive negative temperature thermistor (NTC) may be interfaced with an analog to digital converter to measure and display temperature. Note that this may be extended to logging the data to the BasicX's EEPROM or to an external 24LC256.

It is interesting to note the simplicity when compared with a Parallax Basic Stamp 2 which does not provide either floating point nor such math functions as log. This routine uses about 2K of program memory, but this is only 1/16th of the current capability of the BasicX.

Detailed Discussion

Consider a voltage divider consisting of V_ref (nominally 5.0 VDC), a 10K resistor (R1) and a nominal 10K NTC thermistor (R_therm) to ground. The node at R1 and R_therm is connected to the input of the A/D converter.

Thus the voltage is divided;

(1)	V_a_d = R_therm / (R1 + R_therm) * V_ref
In this example, an 8-bit A/D (ADC0831) was used. Thus the expanse of 0.0 to V_ref is quantized into 256 bands. Thus;
(2)	V_a_d = band / 256 * V_ref
Equating (1) and (2);
(3)  	band / 256 * V_ref = R_therm / (R1 + R_therm) * V_ref
It is interesting to note that V_ref cancels out.

Using a bit of algebra, R_therm may be expressed in terms of the quantizing band as;

(4)	R_therm = (R1 * band) / (256 - band)	
Thus, by knowing the quantizing band, the resistance of the thermistor (R_therm) may be calculated.

Knowing R_therm, the temperature in degrees Kelvin may be calculated using a two point model as;

(5)	T_K = 1 / (a + b * ln(R_therm))
The temperature in degrees F may then be calculated as;
(6)	T_F = (T_K - 273.15) * 1.8 + 32.0
In this routine, an inexpensive ADC0831 8-bit A/D was used. (Note that the BasicX24 provides eight on-board 10-bit A/Ds and the same technique might be used. Equation (4) would be modified;
(7)	R_therm = (R1 * band) / (1024 - band)
In controlling the ADC0831, CS is brought low, resetting the internal successive approximation circuitry. This is followed by single clock pulse. The eight data bits are then read, most significant bit first, by providing a clock pulse and reading the state of IN_D.
' ADC0831.Bas
' Uses an ADC0831 (8-bit A/D) to read the voltage at the node of 
' a fixed 10K resistor and a nominal 10K NTC thermistor and calculates
' R_thermistor.  The temperature in degrees is then calculated and 
' displayed
' Copyright, Stacy Anderson, Baltimore, MD, Oct, '99

Const CS as Byte = 37	' give the pins some meaningful designations
Const Clock as Byte = 38	
Const In_D as Byte = 39	

Const A as Single = 6.217335e-4	' constants used in 2-point model 
				' of NTC thermistor
Const B as Single = 2.972154e-4		

Sub Main()

   Dim Y as Byte
   Dim Band as Byte

   Dim N as Integer

   Dim R_TH as Single 
   Dim T_k as Single 
   Dim T_f as Single 
   Dim T_c as Single

   Call OpenSerialPort(2, 9600)	

   Do	' continually loop
      Call PutPin (In_D, 3)	' Make pin 39 an input

      Call PutPin (CS, 1)	' Initial States =>Clip Select is high
      Call PutPin (Clock, 0)	' Clock is low

      Call PutPin(CS, 0)  	' 1 to 0 transistion on CS

      Call PutPin (Clock, 1)	' Dummy Clock Pulse
      Call PutPin (Clock, 0)

      For N = 1 TO 8		' read the eight data bits
        Call PutPin (Clock, 1)	' clock pulse
        Call PutPin (Clock, 0)

	Y = GetPin (In_D)	' Read after negative clock
	Band = (Band * 2) OR Y	
	'Call Putb(Band)	' for debugging
      ' Band = 128		' used for debugging
      R_th = (1.0e4 * CSng(Band)) / (256.0 - CSng(Band))	
               ' Calculate R_thermistor
      If (R_th > 0.0) then	' avoid taking the log of 
				' a negative number

	' illustrates the power of the BasicX over the Basic Stamp
	T_k = 1.0 / (A+ (B* (log(R_th))))
	T_c = T_k - 273.15
	T_f = (1.8*(T_c))+ 32.0

 	Call PutS(T_F)	' display T_f
 	Call NewLine()

      End If

      Call Sleep (1.0)	' a bit of a delay

End Sub