Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Closed
ekozlenko wants to merge 3 commits into arduino:master from ekozlenko:patch-1

Conversation

Copy link
Contributor

@ekozlenko ekozlenko commented Nov 26, 2013

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.

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.
Copy link

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

Copy link
Contributor Author

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.

@ffissore ffissore added New and removed New labels Feb 27, 2014
Copy link
Contributor

Can I build this pull request?

Copy link
Contributor Author

Yes you can. It's been ready a while now.

Copy link
Contributor

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

Copy link
Contributor Author

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).

Copy link
Contributor

Can one of the admins verify this patch?

Copy link
Contributor Author

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?

@cmaglie cmaglie added Library: Stepper The Stepper Arduino library feature request A request to make an enhancement (not a bug fix) and removed Component: Core Related to the code for the standard Arduino API labels Apr 15, 2015
Copy link
Member

cmaglie commented May 28, 2015

I've picked this change in #3246, please follow up there.

@ffissore ffissore added this to the Release 1.6.5 milestone May 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
No reviews
Labels
feature request A request to make an enhancement (not a bug fix) Library: Stepper The Stepper Arduino library
Projects
None yet
Milestone
Release 1.6.5
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /