From 63aa397b784880497e5df96976456cb31582c65a Mon Sep 17 00:00:00 2001 From: Inamr Date: Tue, 9 Apr 2024 16:17:34 +0200 Subject: [PATCH] testing with hardware cli and function names --- prosjekt.X/fan_speeeed.c | 20 +- prosjekt.X/fan_speeeed.h | 7 +- prosjekt.X/main.c | 5 +- prosjekt.X/nbproject/configurations.xml | 459 ++++++++++++++---------- 4 files changed, 293 insertions(+), 198 deletions(-) diff --git a/prosjekt.X/fan_speeeed.c b/prosjekt.X/fan_speeeed.c index f60d65b..26c7292 100644 --- a/prosjekt.X/fan_speeeed.c +++ b/prosjekt.X/fan_speeeed.c @@ -1,6 +1,10 @@ #include "fan_speeeed.h" #include "uart.h" +uint16_t timer_period_ms = 1; +uint16_t fan_speed; +volatile uint16_t falling_edge_counter = 0; + void TCA0_init() { TCA0.SINGLE.INTCTRL = TCA_SINGLE_OVF_bm ; TCA0.SINGLE.CTRLA = TCA_SINGLE_ENABLE_bm | TCA_SINGLE_CLKSEL_DIV1024_gc ; /* Sysclk /1024 */ @@ -8,13 +12,13 @@ TCA0.SINGLE.PERBUF = 0x0F42; } void TCA0_update_period_ms() { -TCA0.SINGLE.PERBUF = (F_CPU*(1/timer_period)/1024); /* F_CPU * F_IRQ / TCA_prescaler */ +TCA0.SINGLE.PERBUF = (F_CPU*(1/timer_period_ms)/1024); /* F_CPU * F_IRQ / TCA_prescaler */ } -int read_input_get_RPM() { - - fan_speed=(voltage_value_counter/timer_period)*6000*3; - voltage_value_counter = 0; +uint16_t RPM_calculation() { + fan_speed = (falling_edge_counter/timer_period_ms)*6000*3; + falling_edge_counter= 0; + printf("%u", fan_speed); return fan_speed; } @@ -25,12 +29,14 @@ void PORT_init(){ ISR ( TCA0_OVF_vect ) { - read_input_get_RPM(); + cli(); + RPM_calculation(); TCA0.SINGLE.INTFLAGS = TCA_SINGLE_OVF_bm ; + sei(); } ISR(PORTB_PORT_vect){ PORTB.INTFLAGS = PIN2_bm; - voltage_value_counter ++; + falling_edge_counter ++; } diff --git a/prosjekt.X/fan_speeeed.h b/prosjekt.X/fan_speeeed.h index 476d539..337e034 100644 --- a/prosjekt.X/fan_speeeed.h +++ b/prosjekt.X/fan_speeeed.h @@ -23,17 +23,12 @@ extern "C" { #include #include #include - - volatile uint16_t voltage_value_counter = 0; - int timer_period = 1; - int fan_speed; void TCA0_init (); void PORT_init(); void TCA0_update_period_ms (); - int read_input_get_RPM(); - int interrpt(); + uint16_t RPM_calculation(); #ifdef __cplusplus } #endif diff --git a/prosjekt.X/main.c b/prosjekt.X/main.c index ab8146f..9c5b6af 100644 --- a/prosjekt.X/main.c +++ b/prosjekt.X/main.c @@ -27,10 +27,13 @@ int main() { - read_input_get_RPM(); + + sei(); init_uart((uint16_t)9600); stdout = &USART_stream; + TCA0_init (); + PORT_init(); while (1) { ; diff --git a/prosjekt.X/nbproject/configurations.xml b/prosjekt.X/nbproject/configurations.xml index 534a367..8884ea2 100644 --- a/prosjekt.X/nbproject/configurations.xml +++ b/prosjekt.X/nbproject/configurations.xml @@ -1,184 +1,275 @@ - - - - - uart.h - voltage.h - fan_speeeed.h - themistor-temp.h - - - - - main.c - uart.c - voltage.c - fan_speeeed.c - thermistor-temp.c - - - Makefile - - - Makefile - - - - localhost - AVR128DB48 - - - nEdbgTool - XC8 - 2.45 - 2 - - - - - - - - - - - - - - - false - false - - - - - - - false - false - - false - - false - false - false - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + uart.h + voltage.h + fan_speeeed.h + themistor-temp.h + + + Makefile + + + + + main.c + uart.c + voltage.c + fan_speeeed.c + thermistor-temp.c + + + Makefile + + + + localhost + AVR128DB48 + + + nEdbgTool + XC8 + 2.46 + 3 + + + + + + + + + + + + + + + false + false + + + + + + + false + false + + false + + false + false + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +