This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:iot-open:practical:hardware:itt:avr:thermistor [2025/08/26 08:15] – ingmar05 | en:iot-open:practical:hardware:itt:avr:thermistor [2025/09/02 09:45] (current) – raivo.sell | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | < | ||
| ====== Thermistor ====== | ====== Thermistor ====== | ||
| ===== Theory ===== | ===== Theory ===== | ||
| - | [{{ :: | + | [{{ :: |
| - | A thermistor is a type of resistor | + | A thermistor is a type of resistor |
| - | The thermistors resistances' dependence | + | The thermistor's resistance |
| - | {{: | + | {{: |
| where:\\ | where:\\ | ||
| Line 17: | Line 18: | ||
| * B - parameter B. | * B - parameter B. | ||
| - | Parameter B is a coefficient, | + | Parameter B is a coefficient, |
| - | 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 | + | 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 |
| - | + | ||
| - | 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 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 | + | The Sensor module of the HomeLab is equipped with an NTC-type thermistor, which has a 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 the supply, and the other one is connected to the analogue-digital converter channel |
| - | 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. // | + | While using the AVR, it is practical to use a conversion table of values of temperature and an analogue-digital converter to find the correct temperature. It is wise to find the corresponding value of an analogue-digital converter for each temperature degree of the desired range of temperature because |
| Line 35: | Line 34: | ||
| // 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 | + | // Elements begin from -20 degrees |
| // 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; | ||
| Line 56: | Line 55: | ||
| </ | </ | ||
| - | Following algorithm may be used to find the temperature which corresponds to the parameters of the ADC: | + | The conversion table and function are already in the library of the HomeLab. In the library, the conversion function is named // |
| - | + | ||
| - | <code c> | + | |
| - | // Converting the ADC values to Celsius degrees: | + | |
| - | signed short thermistor_calculate_celsius(unsigned short adc_value) | + | |
| - | { | + | |
| - | signed short celsius; | + | |
| - | + | ||
| - | // Covering the table backwards: | + | |
| - | for (celsius = max_temp - min_temp; celsius >= 0; celsius--) | + | |
| - | { | + | |
| - | // If the value in the table is the same or higher than measured | + | |
| - | // value, then the temperature is at least as high as the | + | |
| - | // temperature corresponding to the element | + | |
| - | if (adc_value >= conversion_table[celsius])) | + | |
| - | { | + | |
| - | // Since the table begins with 0 but values of the elements | + | |
| - | // from -20, the value must be shifted | + | |
| - | return celsius + min_temp; | + | |
| - | } | + | |
| - | } | + | |
| - | + | ||
| - | // If the value was not found the minimal temperature is returned | + | |
| - | 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 in the library of the HomeLab, therefore there is no need to write them for this exercise. In the library the conversion function is named // | + | |
| <code c> | <code c> | ||
| - | // Example program of the thermistor of Sensors module | ||
| // The temperature is displayed on the LCD | // The temperature is displayed on the LCD | ||
| #include < | #include < | ||
| Line 96: | Line 66: | ||
| #include < | #include < | ||
| - | // Robotic Homelab II | + | // Sensor |
| //#define ADC_CHANNEL 2 | //#define ADC_CHANNEL 2 | ||
| - | // Robotic Homelab III | ||
| - | #define ADC_CHANNEL 14 | ||
| - | |||
| // Main program | // Main program | ||
| int main(void) | int main(void) | ||
| Line 112: | Line 79: | ||
| lcd_gfx_init(); | lcd_gfx_init(); | ||
| - | // Clearing the LCD and setting backlight | + | // Clearing the LCD and setting |
| lcd_gfx_clear(); | lcd_gfx_clear(); | ||
| lcd_gfx_backlight(true); | lcd_gfx_backlight(true); | ||
| Line 130: | Line 97: | ||
| value = adc_get_average_value(ADC_CHANNEL, | value = adc_get_average_value(ADC_CHANNEL, | ||
| - | // Converting the values of ADC into celsius | + | // Converting the values of ADC into the Celsius |
| temperature = thermistor_calculate_celsius(value); | temperature = thermistor_calculate_celsius(value); | ||
| - | // Converting the temperature | + | // Converting the temperature |
| // To display the degree sign, the octal variable is 56 | // To display the degree sign, the octal variable is 56 | ||
| sprintf(text, | sprintf(text, | ||
| Line 146: | Line 113: | ||
| } | } | ||
| </ | </ | ||
| + | |||
| + | ==== Task to be implemented ==== | ||
| + | - Switch every 3 seconds the unit between Kelvin (K), Fahrenheit (F), and Celsius (C). The temperature must be displayed in correct values, units, and symbols. | ||
| + | |||