-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Update stepper library: High-speed stepping mod and timer rollover fix #1701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
When using the stepper library with a 1.8 degrees per step motor, and at high angular speeds, the current Stepper library leads to really loud and jittery rotation. This is due to the fact that the timing is calculated in milliseconds, and the delay length between steps is only 2.5 milliseconds when trying to spin at 120 rpm. Since only integer math is performed, you end up actually bouncing between different step delays, and thus speeds, from step to step instead of giving the motor a constant input. Which causes the motor to freak out. Changing the library to calculate the step delays in micros() solves that problem for any speed you can reasonably demand from your stepper motor. The down side is that the micros() counter rolls over every hour or so, and any move you perform after that point will hang your code. Easy fix for that is to add an || micros() - this->last_step_time < 0 to the while loop if statement in Stepper.cpp.
RobTillaart
commented
Nov 26, 2013
One problem I noticed in the code is that
long last_step_time; // in stepper.h
is wrong, should be unsigned long as it should hold the output of millis();
Fixing that might solve the overflow issue (do not have a stepper to try ;)
Good catch. Also mixing the signed and unsigned math can be easily avoided by changing "|| micros() - this->last_step_time < 0" to "|| micros() < this->last_step_time".
Now I just need to figure out how to work the changes into the pull request.
Can I build this pull request?
Yes you can. It's been ready a while now.
sorry for the comment from arduinobot. we are setting up automated build of all PRs, so that we can provide a downloadable version of the patched IDE
Federico,
So does that mean that this pull request will not be built? It's fully
debugged and ready to go, as far as I understand the process. Is there
something else I should do to get it included in the main trunk or whatever
the proper terminology is?
It fixes a flaw that crops up whenever anyone tries to use a large step
per revolution stepper motor, and prevents smooth rotation and cuts down on
torque.
Thanks,
Eugene
On Mon, Aug 25, 2014 at 3:33 AM, Federico Fissore notifications@github.com
wrote:
sorry for the comment from arduinobot. we are setting up automated build
of all PRs, so that we can provide a downloadable version of the patched IDE—
Reply to this email directly or view it on GitHub
#1701 (comment).
Can one of the admins verify this patch?
Anyone? This Patch has been sitting here for over a year, waiting to be verified and pulled. I have no doubts that in the mean time, literally several people have been frustrated with the lackluster performance of their stepper motors when using the built-in stepper library. Have you no mercy?
57dcf07
to
5a68e34
Compare
I've picked this change in #3246, please follow up there.
When using the stepper library with a 1.8 degrees per step motor, and at high angular speeds, the current Stepper library leads to really loud and jittery rotation. This is due to the fact that the timing is calculated in milliseconds, and the delay length between steps is only 2.5 milliseconds when trying to spin at 120 rpm. Since only integer math is performed, you end up actually bouncing between different step delays, and thus speeds, from step to step instead of giving the motor a constant input. Which causes the motor to freak out.
Changing the library to calculate the step delays in micros() solves that problem for any speed you can reasonably demand from your stepper motor. The down side is that the micros() counter rolls over every hour or so, and any move you perform after that point will hang your code. Easy fix for that is to add an || micros() - this->last_step_time < 0 to the while loop if statement in Stepper.cpp.