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:
parent
bcd631001b
commit
1671476f41
@ -99,10 +99,6 @@ ISR(AC1_AC_vect){ // AC1 vec flag
|
|||||||
ISR (TCA0_OVF_vect) {
|
ISR (TCA0_OVF_vect) {
|
||||||
cli();
|
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
|
// Increment the index, or reset if it is at the top
|
||||||
if (fan1_history_index < 512) {
|
if (fan1_history_index < 512) {
|
||||||
fan1_history_index++;
|
fan1_history_index++;
|
||||||
@ -116,6 +112,10 @@ ISR (TCA0_OVF_vect) {
|
|||||||
fan2_history_index = 0;
|
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
|
// Reset the edge counter
|
||||||
fan1_edge_counter = 0;
|
fan1_edge_counter = 0;
|
||||||
fan2_edge_counter = 0;
|
fan2_edge_counter = 0;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user