mikrokontrollersystemer-pro.../prosjekt.X/thermistor-temp.c

46 lines
1.2 KiB
C
Raw Normal View History

2024-03-13 12:07:29 +00:00
#include "themistor-temp.h"
2024-04-16 13:56:51 +00:00
float calculate_thermistor_temp(float thermistor_voltage){
2024-03-13 12:07:29 +00:00
float R_therm;
float V_1;
float ln;
float T_therm;
float V_therm;
uint8_t V_tot = 5;
// Calculate Voltage over thermistor
2024-04-16 13:56:51 +00:00
V_therm = (V_tot/1024)*thermistor_voltage;
2024-03-13 12:07:29 +00:00
// Voltage accross R_1
V_1 = V_tot - V_therm;
// Calculate Thermistor resistanse
R_therm = (V_therm)/ (V_1 / R_1);
// Steinhart-Harts formula
ln = log(R_therm/R_t0);
T_therm = (1/ ((ln/B) + (1/T_0)));
// Temperatur in celcius
T_therm -= 273.15;
return T_therm;
}
// returns error message if the messured thermistor temp is higher than
// Choosen max_temp
2024-04-16 13:56:51 +00:00
bool voltage_threshold_bool(float thermistor_temp, uint8_t max_temp){
2024-03-13 12:16:16 +00:00
// Return true if temp is higher then max value
if (thermistor_temp >= max_temp){
2024-03-13 12:07:29 +00:00
return true;
}
else {
return false;
}
2024-04-16 13:56:51 +00:00
}
//print if the maximum threshold is exceeded.
void voltage_threshold_exceeded(bool voltage_threshold_bool){
if (voltage_threshold_bool){
printf("Error: maximum temperature exceeded");
}
2024-03-13 12:07:29 +00:00
}