mikrokontrollersystemer-pro.../prosjekt.X/thermistor-temp.c
Elp03 849c719b59 Change error temp
Make it able to innputt a chosen max temp
2024-03-20 11:06:46 +01:00

40 lines
972 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;
}
// returns error message if the messured thermistor temp is higher than
// Choosen max_temp
bool error_message(float thermistor_temp, uint8_t max_temp){
// Return true if temp is higher then max value
if (thermistor_temp >= max_temp){
printf("Error");
return true;
}
else {
return false;
}
}