Fix source files

This commit is contained in:
Elp03 2024-03-13 10:25:36 +01:00
parent 555d3efde4
commit 5e22a493e2
4 changed files with 44 additions and 36 deletions

View File

@ -11,42 +11,8 @@
#include <stdlib.h> #include <stdlib.h>
#include "uart.h" #include "uart.h"
#include <util/delay.h> #include <util/delay.h>
#include <stdint.h>
#define R_t0 10000 #include "themistor-temp.h"
#define T_0 298.15
#define B 3950
#define R_1 1000
float R_therm;
float V_1;
float ln;
float T_therm;
float V_therm;
// Takes inn messured value
// Calculates the temperature in celcius
// Returns the themperature
float calculate_thermistor_temp(float readValue){
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;
}
int main() { int main() {
init_uart((uint16_t)9600); init_uart((uint16_t)9600);

View File

@ -5,6 +5,7 @@
displayName="Header Files" displayName="Header Files"
projectFiles="true"> projectFiles="true">
<itemPath>uart.h</itemPath> <itemPath>uart.h</itemPath>
<itemPath>themistor-temp.h</itemPath>
</logicalFolder> </logicalFolder>
<logicalFolder name="LinkerScript" <logicalFolder name="LinkerScript"
displayName="Linker Files" displayName="Linker Files"

View File

@ -11,6 +11,21 @@
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <math.h>
#define R_t0 10000
#define T_0 298.15
#define B 3950
#define R_1 1000
// Takes inn messured value
// Calculates the temperature in celcius
// Returns the themperature
float calculate_thermistor_temp(float readValue);

View File

@ -1 +1,27 @@
#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;
}