2024-03-06 11:34:22 +00:00
|
|
|
/*
|
|
|
|
|
* File: main.c
|
|
|
|
|
* Author: Sebastian H. Gabrielli
|
|
|
|
|
*
|
|
|
|
|
* Created on March 6, 2024, 12:34 PM
|
|
|
|
|
*/
|
|
|
|
|
|
2024-03-06 14:36:24 +00:00
|
|
|
#define F_CPU 4E6
|
|
|
|
|
|
2024-03-06 11:34:22 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
2024-03-06 14:36:24 +00:00
|
|
|
#include "uart.h"
|
|
|
|
|
#include <util/delay.h>
|
2024-03-06 11:34:22 +00:00
|
|
|
|
2024-03-08 10:48:49 +00:00
|
|
|
#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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-03-06 14:36:24 +00:00
|
|
|
int main() {
|
|
|
|
|
init_uart((uint16_t)9600);
|
|
|
|
|
stdout = &USART_stream;
|
2024-03-06 11:34:22 +00:00
|
|
|
|
2024-03-06 14:36:24 +00:00
|
|
|
while (1) {
|
|
|
|
|
printf("Hello, world!\n");
|
|
|
|
|
_delay_ms(500);
|
|
|
|
|
}
|
|
|
|
|
}
|