From 555d3efde4134b768c3d1fc99c5431f8ffe59bce Mon Sep 17 00:00:00 2001 From: Elp03 Date: Fri, 8 Mar 2024 11:48:49 +0100 Subject: [PATCH] add calculating code --- prosjekt.X/main.c | 36 +++++++++++++++++++++++++ prosjekt.X/nbproject/configurations.xml | 1 + prosjekt.X/themistor-temp.h | 23 ++++++++++++++++ prosjekt.X/thermistor-temp.c | 1 + 4 files changed, 61 insertions(+) create mode 100644 prosjekt.X/themistor-temp.h create mode 100644 prosjekt.X/thermistor-temp.c diff --git a/prosjekt.X/main.c b/prosjekt.X/main.c index b42afa9..5483a2b 100644 --- a/prosjekt.X/main.c +++ b/prosjekt.X/main.c @@ -12,6 +12,42 @@ #include "uart.h" #include +#define R_t0 10000 +#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() { init_uart((uint16_t)9600); stdout = &USART_stream; diff --git a/prosjekt.X/nbproject/configurations.xml b/prosjekt.X/nbproject/configurations.xml index e8e1b9c..322cc4c 100644 --- a/prosjekt.X/nbproject/configurations.xml +++ b/prosjekt.X/nbproject/configurations.xml @@ -15,6 +15,7 @@ projectFiles="true"> main.c uart.c + thermistor-temp.c