diff --git a/prosjekt.X/main.c b/prosjekt.X/main.c index 5483a2b..6058f74 100644 --- a/prosjekt.X/main.c +++ b/prosjekt.X/main.c @@ -11,42 +11,8 @@ #include #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; -} - +#include +#include "themistor-temp.h" int main() { init_uart((uint16_t)9600); diff --git a/prosjekt.X/nbproject/configurations.xml b/prosjekt.X/nbproject/configurations.xml index 322cc4c..208dedf 100644 --- a/prosjekt.X/nbproject/configurations.xml +++ b/prosjekt.X/nbproject/configurations.xml @@ -5,6 +5,7 @@ displayName="Header Files" projectFiles="true"> uart.h + themistor-temp.h +#include +#include +#include +#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); + diff --git a/prosjekt.X/thermistor-temp.c b/prosjekt.X/thermistor-temp.c index 8b13789..4aa1e41 100644 --- a/prosjekt.X/thermistor-temp.c +++ b/prosjekt.X/thermistor-temp.c @@ -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; +}