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.
This commit is contained in:
Sebastian H. Gabrielli 2024-04-30 11:11:32 +02:00
parent bcd631001b
commit 1671476f41

View File

@ -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;