49 lines
1.3 KiB
C
49 lines
1.3 KiB
C
#include "themistor-temp.h"
|
|
|
|
|
|
void init_alarm_gpio(){
|
|
PORTB.DIRSET = ALERT_PIN;
|
|
}
|
|
|
|
float calculate_thermistor_temp(float thermistor_voltage){
|
|
float R_thermistor;
|
|
float V_1;
|
|
float ln;
|
|
float T_thermistor;
|
|
float V_thermistor;
|
|
#define V_TOT 3.3
|
|
// Calculate Voltage over thermistor
|
|
V_thermistor = (V_TOT/1024)*thermistor_voltage;
|
|
|
|
// Voltage accross R_1
|
|
V_1 = V_TOT - V_thermistor;
|
|
|
|
// Calculate Thermistor resistanse
|
|
R_thermistor = (V_thermistor)/ (V_1 / R_1);
|
|
|
|
// Steinhart-Harts formula
|
|
ln = log(R_thermistor/R_T0);
|
|
T_thermistor = (1/ ((ln/B) + (1/T_0)));
|
|
|
|
// Temperatur in celcius
|
|
T_thermistor -= 273.15;
|
|
|
|
return T_thermistor;
|
|
}
|
|
|
|
// returns error message if the messured thermistor temp is higher than
|
|
// Choosen max_temp
|
|
bool voltage_threshold_bool(float thermistor_temp, uint8_t max_temp){
|
|
// Return true if temp is higher then max value
|
|
return (thermistor_temp >= max_temp);
|
|
}
|
|
|
|
//print if the maximum threshold is exceeded.
|
|
void alert_voltage_threshold_exceeded(bool voltage_threshold_bool){
|
|
if (voltage_threshold_bool){
|
|
//printf("Error: maximum temperature exceeded");
|
|
PORTB.OUTSET = ALERT_PIN;
|
|
} else{
|
|
PORTB.OUTCLR = ALERT_PIN;
|
|
}
|
|
} |