This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
de:examples:sensor:thermistor [2010/09/09 16:17] – angelegt Wember | de: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: | + | //Notwendiges Wissen: [HW] [[en: |
===== Theorie ===== | ===== Theorie ===== | ||
- | [{{ : | + | [{{ : |
- | Ein Thermistor ist ein Typ von Widerstand, dessen Widerstand sich mit der Temperatur verändert. Es gibt zwei Typen von Thermistoren: Welche | + | Ein Thermistor ist temperaturabhängiger |
- | Die dazugehörigen Abkürzungen sind PTC(// | + | |
- | + | ||
- | + | ||
- | The thermistors resistances' | + | |
+ | Die Temperaturabhängigkeit des Widerstands verläuft nicht linear zu der Temperatur, was die Nutzung erschwert. Für genaue Temperaturmessungen bei größeren Temperaturschwankungen wird die exponentielle Steinhart-Hart Gleichung dritter Ordnung genutzt, da der Thermistorwiderstand nur innerhalb kleiner Temperaturbereiche linear ist. Für NTC Thermistoren gibts es folgende vereinfachte Steinhart-Hart-Gleichung mit dem Parameter B: | ||
{{: | {{: | ||
- | where:\\ | + | mit:\\ |
- | * T< | + | * T< |
- | * R< | + | * R< |
- | * B | + | * B |
- | 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 | + | Der Parameter B ist ein Koeffizient, welcher normalerweise im Datenblatt des Thermistors vorgegeben ist. Aber er ist nur in bestimmten Temperaturbereichen ausreichend konstant, z.B. in Bereichen zwischen |
- | + | Normalerweise wird ein Spannungsteiler genutzt, um den Widerstand eines Thermistors zu messen. Dabei wird ein Widerstand durch einen Thermistor ausgetauscht wird und die Inputspannung ist konstant. Es wird die Outputspannung des Spannungsteilers gemessen, welche sich in Abhängigkeit der Widerstandsänderung des Thermistors verändert. Wenn Spannung anliegt, fließt Strom durch den Thermistor, wodurch sich dieser bedingt durch den Thermistorwiderstand aufheizt und damit den Widerstand verändert. Der durch das Aufheizen entstehende Fehler kann berechnet werden, jedoch ist es einfacher einen Thermistor zu nutzen, welcher einen hohen Widerstand hat und sich nicht so viel aufheizt. | |
- | 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. | + | |
- | 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. | + | Bei begrenzten Ressourcen und geringerem Anspruch auf Genauigkeit, werden zuvor errechnete Diagramme und Tabellen für die Temperaturen genutzt. Normalerweise enthalten die Tabellen Temperaturbereiche und die entsprechenden Werte für Widerstand, Spannung und ADC. Alle exponentiellen Berechnungen wurden bereits durchgeführt sodass der Nutzer nur noch die entsprechende Reihe finden und die Werte auslesen muss. |
+ | ===== Übung ===== | ||
- | ===== Practice ===== | + | Das Sensormodul des HomeLab |
- | + | Ein Pin des Thermistors ist an die +5 V Betriebsspannung angeschlossen der andere an Kanal 2 (Pin PF2). Ein typischer | |
- | The Sensor module of the HomeLab | + | |
- | + | ||
- | 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, Openoffice Calc, etc.) to make the table. // | + | |
+ | Während der Nutzung des AVR ist es nützlich, eine Tabelle mit den Temperaturwerten und den Werten des ADC zu verwenden, um die korrekte Temperatur zu finden. Es ist sinnvoll, für jede Gradzahl der gewünschten Temperaturstufe des Messbereichs den korrespondierenden ADC Wert aus der Tabelle herauszusuchen, | ||
<code c> | <code c> | ||
// | // | ||
- | // Table for converting temperature values to ADC values. | + | // Tabelle zur Konvertierung von Temperaturwerten ind ADC Werte. |
- | // Every element of the array marks one Celsius | + | // Jedes Element des Arrays kennzeichnet ein Grad Celsius. |
- | // Elements begin from -20 degree and end at 100 degree. | + | // Die Elemente beginnen bei -20 Grad und enden bei 100 Grad. |
- | // There are 121 elements in the array. | + | // Ein Array enthält |
// | // | ||
const signed short min_temp = -20; | const signed short min_temp = -20; | ||
Line 62: | Line 57: | ||
</ | </ | ||
- | Following algorithm may be used to find the temperature which corresponds to the parameters of the ADC: | + | Folgender Algorithmus kann genutzt werden um die mit den ADC Parametern korrespondierende Temperatur zu finden: |
<code c> | <code c> | ||
// | // | ||
- | // Converting the ADC values to Celsius | + | // Konvertierung der ACD Werte in Grad Celsius: |
// | // | ||
signed short thermistor_calculate_celsius(unsigned short adc_value) | signed short thermistor_calculate_celsius(unsigned short adc_value) | ||
Line 72: | Line 67: | ||
signed short celsius; | signed short celsius; | ||
- | // Covering the table backwards: | + | // Tabelle von hinten beginnend durchgehen: |
for (celsius = max_temp - min_temp; celsius >= 0; celsius--) | for (celsius = max_temp - min_temp; celsius >= 0; celsius--) | ||
{ | { | ||
- | // If the value in the table is the same or higher than measured | + | // Ist der Wert aus der Tabelle gleich oder höher dem gemessenen |
- | // value, then the temperature is at least as high as the temperature | + | // Wert, ist die Temperatur mindestens so hoch wie die mit dem Element |
- | // corresponding to the element. | + | // korrespondierende Temperatur. |
if (adc_value >= conversion_table[celsius])) | if (adc_value >= conversion_table[celsius])) | ||
{ | { | ||
- | // Since the table begins with 0 but values of the elements from -20, | + | // Da die Tabelle mit 0 beginnt, die Werte der Elemente jedoch mit -20, |
- | // the value must be shifted. | + | // muss der Wert geshiftet werden. |
return celsius + min_temp; | return celsius + min_temp; | ||
} | } | ||
} | } | ||
- | // If the value was not found the minimal temperature is returned. | + | // Wurde der Wert nicht gefunden, wird die minimale Temperaur ausgegeben. |
return min_temp; | return min_temp; | ||
} | } | ||
</ | </ | ||
- | 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. | ||
- | This conversion table and function are already | + | Der Algorithmus sucht den Bereich aus der Tabelle |
+ | |||
+ | Umrechnungstabelle und Funktion sind schon in der HomeLab | ||
<code c> | <code c> | ||
// | // | ||
- | // Example program of the thermistor of Sensors module. | + | // Beispielprogramm des Thermistors des Sensormoduls. |
- | // The temperature is displayed on the LCD. | + | // Die Temperatur wird auf dem LCD angezeigt. |
// | // | ||
#include < | #include < | ||
Line 106: | Line 102: | ||
// | // | ||
- | // Main program | + | // Hauptprogramm |
// | // | ||
int main(void) | int main(void) | ||
Line 114: | Line 110: | ||
char text[16]; | char text[16]; | ||
- | // Setting the LCD | + | // Einrichten des LCD |
lcd_alpha_init(LCD_ALPHA_DISP_ON); | lcd_alpha_init(LCD_ALPHA_DISP_ON); | ||
- | // Cleaning the LCD | + | // Löschen des LCD |
lcd_alpha_clear(); | lcd_alpha_clear(); | ||
- | // Name of the program | + | // Name des Programms |
lcd_alpha_write_string(" | lcd_alpha_write_string(" | ||
- | // Setting the ADC | + | // Einrichten des ADC |
adc_init(ADC_REF_AVCC, | adc_init(ADC_REF_AVCC, | ||
- | // Endless loop | + | // Endlosschleife |
while (true) | while (true) | ||
{ | { | ||
- | // Reading the 4 times rounded values of the voltage of the thermistor | + | // Auslesen der 4-fach gerundeten Spannungswerte aus dem Thermistor |
value = adc_get_average_value(2, | value = adc_get_average_value(2, | ||
- | // Converting the values of ADC into celsius scale | + | // Konvertieren der ADC Werte in Grad Celsius |
temperature = thermistor_calculate_celsius(value); | temperature = thermistor_calculate_celsius(value); | ||
- | // Converting the temperature | + | // Konvertieren der Temperatur |
// To display the degree sign, the octal variable is 337. | // To display the degree sign, the octal variable is 337. | ||
sprintf(text, | sprintf(text, | ||
- | // Displaying the text in the beginning of the second row of the LCD. | + | // Anzeige des Textes am Anfang der zweiten Zeile des LCDs. |
lcd_alpha_goto_xy(0, | lcd_alpha_goto_xy(0, | ||
lcd_alpha_write_string(text); | lcd_alpha_write_string(text); | ||
Line 148: | Line 144: | ||
===== Extra ===== | ===== Extra ===== | ||
- | * {{: | + | * {{: |