add calculating code
This commit is contained in:
parent
d84c565985
commit
555d3efde4
@ -12,6 +12,42 @@
|
|||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
#include <util/delay.h>
|
#include <util/delay.h>
|
||||||
|
|
||||||
|
#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() {
|
int main() {
|
||||||
init_uart((uint16_t)9600);
|
init_uart((uint16_t)9600);
|
||||||
stdout = &USART_stream;
|
stdout = &USART_stream;
|
||||||
|
|||||||
@ -15,6 +15,7 @@
|
|||||||
projectFiles="true">
|
projectFiles="true">
|
||||||
<itemPath>main.c</itemPath>
|
<itemPath>main.c</itemPath>
|
||||||
<itemPath>uart.c</itemPath>
|
<itemPath>uart.c</itemPath>
|
||||||
|
<itemPath>thermistor-temp.c</itemPath>
|
||||||
</logicalFolder>
|
</logicalFolder>
|
||||||
<logicalFolder name="ExternalFiles"
|
<logicalFolder name="ExternalFiles"
|
||||||
displayName="Important Files"
|
displayName="Important Files"
|
||||||
|
|||||||
23
prosjekt.X/themistor-temp.h
Normal file
23
prosjekt.X/themistor-temp.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* File: themistor-temp.h
|
||||||
|
* Author: athamantis
|
||||||
|
*
|
||||||
|
* Created on 08 March 2024, 11:46
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef THEMISTOR_TEMP_H
|
||||||
|
#define THEMISTOR_TEMP_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* THEMISTOR_TEMP_H */
|
||||||
|
|
||||||
1
prosjekt.X/thermistor-temp.c
Normal file
1
prosjekt.X/thermistor-temp.c
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user