mikrokontrollersystemer-pro.../prosjekt.X/thermistor-temp.c
2024-03-13 13:07:29 +01:00

37 lines
805 B
C

#include "themistor-temp.h"
float calculate_thermistor_temp(float readValue){
float R_therm;
float V_1;
float ln;
float T_therm;
float V_therm;
uint8_t V_tot = 5;
// Calculate Voltage over thermistor
V_therm = (V_tot/1024)*readValue;
// 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;
}
bool error_message(float thermistor_temp){
int high_temp = 0;
if (thermistor_temp > high_temp){
return true;
}
else {
return false;
}
}