Fix variable name and led

This commit is contained in:
Elp03 2024-04-16 17:24:54 +02:00
parent 9f27bc8454
commit 933949dcff
2 changed files with 28 additions and 21 deletions

View File

@ -18,10 +18,12 @@ extern "C" {
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include <math.h> #include <math.h>
#define R_t0 10000 #include <avr/io.h>
#define R_T0 10000
#define T_0 298.15 #define T_0 298.15
#define B 3950 #define B 3950
#define R_1 1000 #define R_1 1000
#define ledpin PIN3_bm
// Takes inn messured value // Takes inn messured value
// Calculates the temperature in celcius // Calculates the temperature in celcius
@ -32,8 +34,10 @@ float calculate_thermistor_temp(float readValue);
// Returns true if temperatur is higher than max_temp // Returns true if temperatur is higher than max_temp
bool voltage_threshold_bool(float thermistor_temp, uint8_t max_temp); bool voltage_threshold_bool(float thermistor_temp, uint8_t max_temp);
void voltage_threshold_exceeded(bool voltage_threshold_bool); void alert_voltage_threshold_exceeded(bool voltage_threshold_bool);
// Initialise led
void init_led();
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

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