2024-03-13 12:07:29 +00:00
|
|
|
#include "themistor-temp.h"
|
|
|
|
|
|
2024-04-16 15:24:54 +00:00
|
|
|
|
2024-04-30 09:37:21 +00:00
|
|
|
void init_alarm_gpio(){
|
|
|
|
|
PORTB.DIRSET = ALERT_PIN;
|
2024-04-16 15:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
2024-04-16 13:56:51 +00:00
|
|
|
float calculate_thermistor_temp(float thermistor_voltage){
|
2024-04-16 15:24:54 +00:00
|
|
|
float R_thermistor;
|
2024-03-13 12:07:29 +00:00
|
|
|
float V_1;
|
|
|
|
|
float ln;
|
2024-04-16 15:24:54 +00:00
|
|
|
float T_thermistor;
|
|
|
|
|
float V_thermistor;
|
2024-04-30 14:17:52 +00:00
|
|
|
#define V_TOT 3.3
|
2024-03-13 12:07:29 +00:00
|
|
|
// Calculate Voltage over thermistor
|
2024-04-16 15:24:54 +00:00
|
|
|
V_thermistor = (V_TOT/1024)*thermistor_voltage;
|
2024-03-13 12:07:29 +00:00
|
|
|
|
|
|
|
|
// Voltage accross R_1
|
2024-04-16 15:24:54 +00:00
|
|
|
V_1 = V_TOT - V_thermistor;
|
2024-03-13 12:07:29 +00:00
|
|
|
|
|
|
|
|
// Calculate Thermistor resistanse
|
2024-04-16 15:24:54 +00:00
|
|
|
R_thermistor = (V_thermistor)/ (V_1 / R_1);
|
2024-03-13 12:07:29 +00:00
|
|
|
|
|
|
|
|
// Steinhart-Harts formula
|
2024-04-16 15:24:54 +00:00
|
|
|
ln = log(R_thermistor/R_T0);
|
|
|
|
|
T_thermistor = (1/ ((ln/B) + (1/T_0)));
|
2024-03-13 12:07:29 +00:00
|
|
|
|
|
|
|
|
// Temperatur in celcius
|
2024-04-16 15:24:54 +00:00
|
|
|
T_thermistor -= 273.15;
|
2024-03-13 12:07:29 +00:00
|
|
|
|
2024-04-16 15:24:54 +00:00
|
|
|
return T_thermistor;
|
2024-03-13 12:07:29 +00:00
|
|
|
}
|
|
|
|
|
|
2024-03-20 10:06:46 +00:00
|
|
|
// 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
|
2024-04-16 15:24:54 +00:00
|
|
|
return (thermistor_temp >= max_temp);
|
2024-04-16 13:56:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//print if the maximum threshold is exceeded.
|
2024-04-16 15:24:54 +00:00
|
|
|
void alert_voltage_threshold_exceeded(bool voltage_threshold_bool){
|
2024-04-16 13:56:51 +00:00
|
|
|
if (voltage_threshold_bool){
|
|
|
|
|
printf("Error: maximum temperature exceeded");
|
2024-04-30 09:37:21 +00:00
|
|
|
PORTB.OUTSET = ALERT_PIN;
|
2024-04-16 15:24:54 +00:00
|
|
|
} else{
|
2024-04-30 09:37:21 +00:00
|
|
|
PORTB.OUTCLR = ALERT_PIN;
|
2024-04-16 15:24:54 +00:00
|
|
|
}
|
2024-03-13 12:07:29 +00:00
|
|
|
}
|