Skip to content

Commit

Permalink
Merge pull request #74 from KaushikMalapati/responsive
Browse files Browse the repository at this point in the history
Fixing PPM indexing bug
  • Loading branch information
KaushikMalapati authored Oct 10, 2024
2 parents 696a827 + 74b1b96 commit 71ea120
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ IF rTrig_Background.Q OR bResetAutoBackground THEN
// Dump 5s worth of readings
IF udBackgroundVoltageBufferIndex > 6 THEN
FOR i := (udBackgroundVoltageBufferIndex - 5) TO (udBackgroundVoltageBufferIndex - 1) DO
fBackgroundVoltageSum := fBackgroundVoltageSum - fBackgroundVoltageBuffer[i MOD 100];
fBackgroundVoltageSum := fBackgroundVoltageSum - fBackgroundVoltageBuffer[((i-1) MOD 100) + 1];
END_FOR
udBackgroundVoltageBufferIndex := udBackgroundVoltageBufferIndex - 5;
IF udBackgroundVoltageBufferIndex <> 1 AND BACKGROUND_MODE = Passive THEN
Expand All @@ -233,8 +233,8 @@ ELSIF eEnumGet = E_PPM_States.OUT AND stYAxisState = 0 THEN
// Every second, move fBackgroundVoltageAcc into buffer and sum
IF tonBackgroundAutoCollecting.Q = TRUE THEN
tonBackgroundAutoCollecting( IN := FALSE);
fBackgroundVoltageStale := fBackgroundVoltageBuffer[udBackgroundVoltageBufferIndex MOD 100];
fBackgroundVoltageBuffer[udBackgroundVoltageBufferIndex MOD 100] := fBackgroundVoltageAcc / uAccCount;
fBackgroundVoltageStale := fBackgroundVoltageBuffer[((udBackgroundVoltageBufferIndex - 1) MOD 100) + 1];
fBackgroundVoltageBuffer[((udBackgroundVoltageBufferIndex - 1) MOD 100) + 1] := fBackgroundVoltageAcc / uAccCount;
// Remove overwritten voltage
IF udBackgroundVoltageBufferIndex > 100 THEN
fBackgroundVoltageSum := fBackgroundVoltageSum - fBackgroundVoltageStale;
Expand Down

0 comments on commit 71ea120

Please sign in to comment.