Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:examples:sensor:thermistor [2010/02/10 18:38] priitjen:examples:sensor:thermistor [2020/07/20 09:00] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== Thermistor ====== ====== Thermistor ======
  
-//Necessary knowledge: [HW] [[en:hardware:homelab:sensor]], [HW] [[en:hardware:homelab:lcd]], [ELC] [[en:electronics:voltage_divider]], [AVR] [[en:avr:adc]], [LIB] [[en:software:homelab:library:adc]], [LIB] [[en:software:homelab:library:module:lcd_alphanumeric]], [LIB] [[en:software:homelab:library:module:sensor]]//+//Necessary knowledge:  
 +[HW] [[en:hardware:homelab:digi]],  
 +[ELC] [[en:electronics:voltage_divider]],  
 +[AVR] [[en:avr:adc]],  
 +[LIB] [[en:software:homelab:library:adc]], [LIB] [[en:software:homelab:library:module:lcd_graphic]], [LIB] [[en:software:homelab:library:module:sensor]]//
  
 ===== Theory ===== ===== Theory =====
  
-[{{  :examples:sensor:thermistor:sensor_thermistor_ntc_picture.jpg?80|NTC thermistor}}]+[{{  ::examples:sensor:thermistor:ntc.jpg?300|NTC thermistor}}]
  
-A thermistor is a type of resistor whose resistance varies with temperature. There two types of thermistors: positive temperature coefficient of resistance and negative temperature coefficient of resistance. The resistance of thermistors with positive temperature coefficient of resistance is growing when the temperature grows and negative’s resistance dropsThey are abbreviated as PTC (//positive temperature coefficient//) and NTC (//negative temperature coefficient//).+A thermistor is a type of resistor which resistance varies with temperature. There are two types of thermistors: positive temperature coefficient of resistance and negative temperature coefficient of resistance. The resistance of thermistors with positive temperature coefficient of resistance is increasing when the temperature grows and with negative the resistance decreasesThe respective abbreviations are PTC (//positive temperature coefficient//) and NTC (//negative temperature coefficient//).
  
-The tricky part of using thermistors is that their resistance’s dependence of the temperature is not linear. It is linear only in small temperature ranges. For accurate temperature measurements in wider temperature flotation the Steinhart-Hart third-order exponential equation can be used. For NTC thermistors the following simplified Steinhart-Hart equation with B-parameter exists:+The thermistors resistances' dependence of the temperature is not linear and this complicates the usage of it. For accurate temperature measurements in wider temperature flotation the Steinhart-Hart third-order exponential equation is used as the thermistors resistance is linear only in small temperature range. The following simplified Steinhart-Hart equation with B-parameter exists for NTC thermistors:
  
  
Line 19: Line 23:
   * B   - parameter B.   * B   - parameter B.
  
-Parameter B is a coefficient, which is usually given in the datasheet of the thermistor. But it is enough stable constant only in a certain ranges of temperature, for example at ranges 25–50 °C or 25–85 °C. If the temperature range measured is wider the equation given (if it is there) in the datasheet should be used.+Parameter B is a coefficient, which is usually given in the datasheet of the thermistor. But it is stable enough constant only in a certain ranges of temperature, for example at ranges 25–50 °C or 25–85 °C. If the temperature range measured is wider the data sheet should be used for retrieving the equation.
  
    
-For measuring the resistance of a thermistor usually a voltage-divider is used, where one resistor is replaced with a thermistor and the input voltage is constant. The output voltage of the voltage-divider is measured, which changes with the change of the resistance of the thermistor. If the voltage is applied, current goes through the thermistor which heats up the thermistor due to thermistors resistance and therefore alters again the resistance. The  fault caused by heating up of the thermistor can be compensated with calculations, but it is easier to use a thermistor that has higher resistance and therefore heats up less.+Usually a voltage-divider is used for measuring the resistance of a thermistor, where one resistor is replaced with a thermistor and the input voltage is constant. The output voltage of the voltage-divider is measured, which changes according to the change of the resistance of the thermistor. If the voltage is applied, current goes through the thermistor which heats up the thermistor due to thermistors resistance and therefore alters again the resistance. The  fault caused by heating up of the thermistor can be compensated with calculations, but it is easier to use a thermistor that has higher resistance and therefore heats up less.
  
-When having to use restricted resources and not having to have very high demands on accuracy, previously calculated charts and tables for temperatures are used. Generally in such tables are ranges of temperatures and the values of resistance, voltage or analogue-digital converters which are corresponding to the temperature ranges given. All exponential calculation is done and all the user has to do is to search up the correct row and read the temperature written on this+With restricted resources and with less demands on accuracy, previously calculated charts and tables for temperatures are used. Generally the tables have ranges of temperatures and respective values of resistance, voltage or analogue-digital converters. All exponential calculations are already done and the user needs to only find the correct row and read the temperature given
  
  
 ===== Practice ===== ===== Practice =====
  
-The module of the home lab is equipped with a NTC type thermistor which has 10 kΩ nominal resistance. At temperatures 25-50 °C the parameter B of the thermistor is 3900. One pin of the thermistor is connected to +5 V supply and the other one is connected to the channel 2 (pin number PF2) of the analogue-digital converter. With the same pin of the micro controller and earth is also connected a usual 10 kΩ resistor, which form a voltage divider with the thermistor. Since we are dealing with a NTC thermistor, which’s resistance reduces when the temperature grows; the output voltage of the voltage divider is growing also when the temperature grows.+The Sensor module of the HomeLab is equipped with a NTC type thermistor which has 10 kΩ nominal resistance. At temperatures 25-50 °C the parameter B of the thermistor is 3900. One pin of the thermistor is connected to supply and the other one is connected to the analogue-digital converter (HomeLab II channel 2 and HomeLab III channel 14)A typical 10 kΩ resistor is also connected with the same pin of the microcontroller and earth and together with the thermistor forms a voltage divider. Since we are dealing with a NTC thermistor, which resistance decreases as the temperature grows; the output voltage of the voltage divider is increasing repectively with growing temperature.
  
-It is wise to use a conversion table of values of temperature and analogue-digital converter to find the correct temperature when using the AVR. It is wise to find corresponding value of analogue-digital converter for each temperature degree of desired range of temperature because reverse table will be too large due to the amount of 10 bit ADC values. It is recommended to use some spreadsheet program (MS Excel, Openoffice Calc, etc.) to make the table. //Steinhart-Hart// formula which is customized for the mentioned NTC thermistors allows finding the resistance of the thermistor which corresponds to the temperature. Then using the resistance, it is possible to calculate the output voltage of the voltage divider and then using this output voltage it is possible to calculate the value of the ADC. Calculated values can be inserted to the program as follows:    +While using the AVR it is practical to use a conversion table of values of temperature and analogue-digital converter to find the correct temperature. It is wise to find corresponding value of analogue-digital converter for each temperature degree of desired range of temperature because reverse table will be too large due to the amount of 10 bit ADC values. It is recommended to use any kind of spreadsheet program (MS Excel, LibreOffice Calc, etc.) to make the table. //Steinhart-Hart// formula which is customized for the mentioned NTC thermistors able's to find the resistance of the thermistor which corresponds to the temperature. Derived from the resistance, is possible to calculate the output voltage of the voltage divider and using this output voltage to calculate the value of the ADC. Calculated values can be inserted to the program as follows:    
  
  
 <code c> <code c>
-// +// Table for converting temperature values to ADC values 
-// Table for converting temperature values to ADC values. +// Every element of the array marks one Celsius degree 
-// Every element of the array marks one Celsius degree. +// Elements begin from -20 degree and end at 100 degree 
-// Elements begin from -20 degree and end at 100 degree. +// There are 121 elements in the array
-// There are 121 elements in the array+
-//+
 const signed short min_temp = -20; const signed short min_temp = -20;
 const signed short max_temp = 100; const signed short max_temp = 100;
Line 60: Line 62:
 </code> </code>
  
-Following algorithm may be used to find the temperature that corresponds to the parameters of the ADC:+Following algorithm may be used to find the temperature which corresponds to the parameters of the ADC:
  
 <code c> <code c>
-// 
 // Converting the ADC values to Celsius degrees: // Converting the ADC values to Celsius degrees:
-// 
 signed short thermistor_calculate_celsius(unsigned short adc_value) signed short thermistor_calculate_celsius(unsigned short adc_value)
 { {
Line 74: Line 74:
  {  {
  // If the value in the table is the same or higher than measured   // If the value in the table is the same or higher than measured 
- // value, then the temperature is at least the same high as the temperature + // value, then the temperature is at least as high as the  
- // corresponding to the element.+ // temperature corresponding to the element
  if (adc_value >= conversion_table[celsius]))  if (adc_value >= conversion_table[celsius]))
  {  {
- // Since the table begins with 0 but values from -20, the value + // Since the table begins with 0 but values of the elements  
- // must be shifted.+ // from -20, the value must be shifted
  return celsius + min_temp;  return celsius + min_temp;
  }  }
  }  }
  
- // If the value was not found the minimal temperature is returned.+ // If the value was not found the minimal temperature is returned
  return min_temp;  return min_temp;
 } }
 </code> </code>
-The algorithm searches range from the table where the ADC value suits and remembers the lower ranking number of this range. The ranking number marks degreesthe temperature with the accuracy of 1 degree is become when the original temperature is added to the ranking number.+The algorithm searches range from the table where the ADC value is and acquires the lower ranking number of this range. The ranking number marks degrees, adding the primary temperature to this a temperature with accuracy of 1 degree is reached.
  
-That conversion table and this function are already in the library of the home labin the exercise is no need to write them. The conversion function is named as nimeks //thermistor_calculate_celsius// in the libraryThe fact that the conversion is valid only when it is used on the thermistor on the module of sensors of the home lab, must be taken into accountIf using other thermistors,self made conversion table and some more complex functiondescribed in the manual of the librarymust be used. The example program of this exercise is a thermometer, which measures temperature in Celsius scale and displays it on an alphabetical LCD.  +This conversion table and function are already in the library of the HomeLabtherefore there is no need to write them for this exerciseIn the library the conversion function is named //thermistor_calculate_celsius//Must be considered, that the conversion is valid only when used on the thermistor on the Sensors module of the HomeLabFor using other thermistors, a conversion table needs to be created and more complex function described in the manual of the library must be used. Example program of this exercise is a thermometer, which measures temperature in Celsius scale and displays it on an alphabetical LCD.  
    
  
 <code c> <code c>
-// +// Example program of the thermistor of Sensors module 
-// Example program of the thermistor of module of sensors of home lab. +// The temperature is displayed on the LCD
-// The temperature is displayed on the LCD+
-//+
 #include <stdio.h> #include <stdio.h>
 #include <homelab/adc.h> #include <homelab/adc.h>
 #include <homelab/module/sensors.h> #include <homelab/module/sensors.h>
-#include <homelab/module/lcd_alpha.h>+#include <homelab/module/lcd_gfx.h> 
 +#include <homelab/delay.h> 
 + 
 +// Robotic Homelab II 
 +//#define ADC_CHANNEL 2 
 +  
 +// Robotic Homelab III 
 +#define ADC_CHANNEL 14
  
-// 
 // Main program // Main program
-// 
 int main(void) int main(void)
 { {
Line 112: Line 115:
  char text[16];  char text[16];
    
- // Setting the LCD + // Initialization of LCD 
- lcd_alpha_init(LCD_ALPHA_DISP_ON); + lcd_gfx_init();
-  +
- // Cleaning the LCD +
- lcd_alpha_clear();+
    
 + // Clearing the LCD and setting backlight
 + lcd_gfx_clear();
 +        lcd_gfx_backlight(true);
 +
  // Name of the program  // Name of the program
- lcd_alpha_write_string("Termomeeter");+        lcd_gfx_goto_char_xy(1, 1); 
 + lcd_gfx_write_string("Thermometer");
    
  // Setting the ADC  // Setting the ADC
Line 127: Line 132:
  while (true)  while (true)
  {  {
- // Reading the 4 times rounded values of the voltage of the thermistor + // Reading the 4 times rounded values of the voltage of the  
- value = adc_get_average_value(2, 4);+ // thermistor 
 + value = adc_get_average_value(ADC_CHANNEL, 4);
  
- // Conversing the values of ADC into celsius scale+ // Converting the values of ADC into celsius scale
  temperature = thermistor_calculate_celsius(value);  temperature = thermistor_calculate_celsius(value);
  
- // Conversing the temperature in to text. + // Converting the temperature in to text 
- // To display the degree sign, the octal variable is 337. + // To display the degree sign, the octal variable is 56 
- sprintf(text, "%d\337C   ", temperature);+ sprintf(text, "%d\56C   ", temperature);
  
- // Displaying the text in the beginning of the second row of the LCD. + // Displaying the text in the beginning of the third row of the LCD 
- lcd_alpha_goto_xy(01); + lcd_gfx_goto_char_xy(53); 
- lcd_alpha_write_string(text);+ lcd_gfx_write_string(text); 
 + 
 +                hw_delay_ms(1000);
  }  }
 +        return 0;
 } }
 </code> </code>
- 
-===== Extra ===== 
- 
-  * {{:examples:sensor:thermistor:ntc.xls|The diagram of temperature of a 10 kΩ NTC thermistor}} 
- 
en/examples/sensor/thermistor.1265827136.txt.gz · Last modified: 2020/07/20 09:00 (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0