Arduino stepper motor Speed fluctuations

It shouldn’t be needed, but if your testing indicates it is, and to remove any doubt, you can change things a bit. Create a top-level (global) boolean variable such as stepNeeded. Be sure to declare it as volatile. In the interrupt service routine there is just one line of code to set this variable to true. In the main loop, immediately after calling the timer run method, test stepNeeded and if it’s true do the stepper stepping and reset stepNeeded to false. That way the ISR takes almost no time to execute, and any delays in the step cannot affect it.

1 Like