Skip to content

Stepper library improvements #3246

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

Merged
merged 6 commits into from
Jun 5, 2015
Merged

Conversation

cmaglie
Copy link
Member

@cmaglie cmaglie commented May 28, 2015

This pull request picks the improvements made on:

5 phase/5 wire stepper support - #61
hi-speed stepping and timer rollover fix - #1701 #1702

I've added a commit that should improve the timing calculations:
1c7d88a

/cc @ekozlenko @rdodesigns

@cmaglie cmaglie added this to the Release 1.6.5 milestone Jun 5, 2015
ekozlenko and others added 6 commits June 5, 2015 16:18
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.
micros() is now called only once per cycle (instead of 3).

The rollover check is superflous because the "last_step_time" field
is unsigned.
@cmaglie cmaglie force-pushed the stepper-improvements branch from b79e131 to f2a8f51 Compare June 5, 2015 14:19
@cmaglie cmaglie merged commit f2a8f51 into arduino:master Jun 5, 2015
@cmaglie cmaglie deleted the stepper-improvements branch June 5, 2015 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request A request to make an enhancement (not a bug fix) Library: Stepper The Stepper Arduino library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants