From dd53b4dbf228450154ec702741a6c5ad7547b5b1 Mon Sep 17 00:00:00 2001 From: "Sebastian H. Gabrielli" Date: Tue, 30 Apr 2024 11:08:03 +0200 Subject: [PATCH] Fan data is now saved in the array Closes #9 --- prosjekt.X/command-handler.h | 3 +++ prosjekt.X/fan_speeeed.c | 21 +++++++++++++++++++-- prosjekt.X/fan_speeeed.h | 6 ++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/prosjekt.X/command-handler.h b/prosjekt.X/command-handler.h index cf0f428..23ca9f8 100644 --- a/prosjekt.X/command-handler.h +++ b/prosjekt.X/command-handler.h @@ -66,6 +66,9 @@ typedef struct { // Fan history variables extern volatile uint16_t fan1_history[512]; extern volatile uint16_t fan2_history[512]; +// Fan history index variable +volatile uint16_t fan1_history_index = 0; +volatile uint16_t fan2_history_index = 0; // Config extern volatile config_t config; diff --git a/prosjekt.X/fan_speeeed.c b/prosjekt.X/fan_speeeed.c index 38540af..21d0850 100644 --- a/prosjekt.X/fan_speeeed.c +++ b/prosjekt.X/fan_speeeed.c @@ -98,8 +98,25 @@ ISR(AC1_AC_vect){ // AC1 vec flag // TIMER INTERUPT ISR (TCA0_OVF_vect) { cli(); - RPM_calculation(fan1_edge_counter,timer_period_ms); - RPM_calculation(fan2_edge_counter,timer_period_ms); + + // Calculate the fanspeed + fan1_history[fan1_history_index] = RPM_calculation(fan1_edge_counter,timer_period_ms); + fan2_history[fan2_history_index] = RPM_calculation(fan2_edge_counter,timer_period_ms); + + // Increment the index, or reset if it is at the top + if (fan1_history_index < 512) { + fan1_history_index++; + } else { + fan1_history_index = 0; + } + + if (fan2_history_index < 512) { + fan2_history_index++; + } else { + fan2_history_index = 0; + } + + // Reset the edge counter fan1_edge_counter = 0; fan2_edge_counter = 0; TCA0.SINGLE.INTFLAGS = TCA_SINGLE_OVF_bm ; diff --git a/prosjekt.X/fan_speeeed.h b/prosjekt.X/fan_speeeed.h index 160071d..dfe47a8 100644 --- a/prosjekt.X/fan_speeeed.h +++ b/prosjekt.X/fan_speeeed.h @@ -29,6 +29,12 @@ extern "C" { * and inspiration form practice 6 for TCA0 setup */ +// Fan history variables +extern volatile uint16_t fan1_history[512]; +extern volatile uint16_t fan2_history[512]; +// Fan history index variable +volatile uint16_t fan1_history_index = 0; +volatile uint16_t fan2_history_index = 0; // INITALICE TIMER COUNTER void init_TCA0();