Thermistor and usage example

Lecture



  Thermistor and usage example

NTC thermistor A thermistor is a resistor whose resistance varies with temperature. Thermistors are of two types: positive and negative temperature coefficient. In a thermistor with a positive coefficient, with increasing temperature, the resistance increases, and with a negative coefficient it decreases. Their abbreviations in English: PTC ( positive temperature coefficient ) and NTC ( negative temperature coefficient ).

The use of a thermistor complicates the non-linearity of the temperature dependence of its resistance. The dependence is linear only in small limits; an exponential third-order Steinhart-Hart equation is suitable for calculating several tens of degrees and a larger measurement limit. For NTC thermistors, there is the following simplified equation with a B-parameter:

  Thermistor and usage example

Where:

  • T0 is the nominal temperature, for example 25 ° C.

  • R0 is the resistance at nominal temperature.

  • B - B – parameter.

B - parameter is a coefficient, which is usually given in the thermistor specification. At the same time, it is fairly constant only in known temperature ranges, for example, 25–50 ° C or 25–85 ° C. If the measured temperature interval is larger, then, if possible, use the equation in the specification.

The resistance of the thermistor is measured indirectly by a voltage divider, where instead of one resistor a thermistor is installed and the input voltage is constant. The output voltage of the voltage divider is measured, which changes as the resistance of the thermistor changes. When a voltage is applied, an electric current passes through the thermistor, which heats the thermistor due to its resistance and thus changes the resistance. The error occurring when the thermistor is heated can be compensated computationally, but it is easier to use a thermistor with higher resistance, which heats up less.

Due to the limited resource and the lack of need for high accuracy, pre-calculated tables of interdependent temperature and resistance are used. In the table, in general, recorded temperature readings with accurate intervals, in accordance with the resistance of the sensor, voltage or value of the analog-digital converter. For the table, all the exponential calculation is done in advance and in the program you only need to find the series corresponding to the measured parameter and read the temperature.

Practice

The motherboard's “Sensors” module board is equipped with an NTC thermistor with a nominal resistance of 10 kΩ. At a temperature of 25-50 ° CB, the parameter is equal to 3900. One output of the thermistor is connected to the power supply +5 V and the other to channel 2 (output PF2) of the analog-digital converter of the microcontroller. The usual 10 kΩ resistor is connected to the same microcontroller output and the ground, which together with the thermistor forms a voltage divider. Since there is an NTC thermistor, the resistance of which decreases with increasing temperature, then at the same time the output voltage of the voltage divider rises.

To search for temperature, it is advisable to use a table for converting temperature values ​​and an analog-digital converter. It is reasonable for each degree to find the corresponding value of the analog-digital converter from the desired temperature range, because the opposite table will be too large due to the number of 10-bit ADC values. To create a table, it is desirable to use any program for calculating tables (MS Excel, Openoffice Calc or others). Using the above Steinhart-Hart equation, adapted for NTC thermistors, it is possible to find the temperature resistance of the thermistor. From the resistance, you can calculate the output voltage of the voltage divider and in turn from it - the value of ADC. The found values ​​can be written to the program as follows:

 //
 // Table for converting temperature to ADC value.
 // Each element of the array represents one degree Celsius.
 // Elements start at -20 degrees and end at 100 degrees.
 // In general, the array 121 elements.
 //
 const signed short min_temp = -20;
 const signed short max_temp = 100;

 const unsigned short conversion_table [] =
 {                           
	 91.96,102,107,113,119,125,132,139,146,153,
	 160,168,176,184,192,201,210,219,228,238,247,
	 257,267,277,288,298,309,319,330,341,352,364,
	 375,386,398,409,421,432,444,455,467,478,489,
	 501,512,523,534,545,556,567,578,588,599,609,
	 619,629,639,649,658,667,677,685,694,703,711,
	 720,728,736,743,751,758,766,773,780,786,793,
	 799,805,811,817,823,829,834,839,844,849,854,
	 859,863,868,872,876,880,884,888,892,896,899,
	 903,906,909,912,915,918,921,924,927,929,932,
	 934,937,939,941,943,945,947,949,951,953,955
 }; 

In order to find the temperature in the table by the value of ADC, you can use the following algorithm:

 //
 // Converting ADC value to Celsius degree.
 //
 signed short thermistor_calculate_celsius (unsigned short adc_value)
 {
	 signed short celsius;

	 // Passing the table in reverse
	 for (celsius = max_temp - min_temp; celsius> = 0; celsius--)
	 {
		 // If the value of the table is the same or greater than the measured result,
		 // then the temperature is about as high
		 // as the temperature corresponding to the elements.
		 if (adc_value> = conversion_table [celsius])
		 {
			 // Since the table starts from zero,
			 // and the value of the element is 20 degrees, then you have to shift the value
			 return celsius + min_temp;
		 }
	 }

	 // If no value is found, then the minimum temperature is returned.
	 return min_temp;
 } 

The algorithm searches the table for the interval in which the ADC value is located, and recognizes the lower limit of the sequence number of the interval. The sequence number denotes degrees, to which it is necessary only to add the initial temperature, and thus the temperature accuracy of 1 degree is obtained.

The above translation table and function are already available in the HomeLab library, so in this exercise you don’t have to write them yourself. The conversion function in the library has the name thermistor_calculate_celsius . It should be borne in mind that the conversion is suitable only for a thermistor located in the Sensors module of the Home Laboratory. To use other thermistors you will have to create the translation table yourself and use the complex functions described in the library instructions. In the exercise for the example program, there is a thermometer that measures the temperature in Celsius and displays it on an alphanumeric LCD screen.

 //
 // An example of the thermistor program of the “Sensors” module of the Home Laboratory.
 // LCD displays temperature in degrees.
 //
 #include 
 #include 
 #include 
 #include 

 //
 // Main program
 //
 int main (void)
 {
	 unsigned short value;
	 signed short temperature;	
	 char text [16];

	 // Setting the LCD screen
	 lcd_alpha_init (LCD_ALPHA_DISP_ON);

	 // Clear LCD Screen
	 lcd_alpha_clear ();

	 // The name of the program
	 lcd_alpha_write_string ("Thermometer");

	 // Configure the ADC converter
	 adc_init (ADC_REF_AVCC, ADC_PRESCALE_8);

	 // Endless cycle
	 while (true)
	 {
		 // Reading the thermistor voltage value, rounded 4 times
		 value = adc_get_average_value (2, 4);

		 // Recalculate ADC value in degrees
		 temperature = thermistor_calculate_celsius (value);

		 // Converting temperature to text
		 // To display the sign of the degree octane number 337
		 sprintf (text, "% d \ 337C", temperature);

		 // Display text at the beginning of the second row of LCD
		 lcd_alpha_goto_xy (0, 1);
		 lcd_alpha_write_string (text);
	 }
 } 

Comments


To leave a comment
If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Sensors

Terms: Sensors