From 1671476f4191dab5c9fbcbb3b0d3276aa7d717e7 Mon Sep 17 00:00:00 2001 From: "Sebastian H. Gabrielli" Date: Tue, 30 Apr 2024 11:11:32 +0200 Subject: [PATCH] Move index incrementation over storage This avoids the problem where the current index has outdated data. It does however mean the first piece of stored data is empty, but it is a worthwile tradeoff. --- prosjekt.X/fan_speeeed.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/prosjekt.X/fan_speeeed.c b/prosjekt.X/fan_speeeed.c index 21d0850..db41f07 100644 --- a/prosjekt.X/fan_speeeed.c +++ b/prosjekt.X/fan_speeeed.c @@ -99,10 +99,6 @@ ISR(AC1_AC_vect){ // AC1 vec flag ISR (TCA0_OVF_vect) { cli(); - // 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++; @@ -116,6 +112,10 @@ ISR (TCA0_OVF_vect) { fan2_history_index = 0; } + // 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); + // Reset the edge counter fan1_edge_counter = 0; fan2_edge_counter = 0;