Skip to content

Comments

[2.0.x] Always honor minimum period on stepper pulse generation, and fix timing calculations#11004

Merged
thinkyhead merged 2 commits intoMarlinFirmware:bugfix-2.0.xfrom
ejtagle:always_honor_maximum_step_rate
Jun 13, 2018
Merged

[2.0.x] Always honor minimum period on stepper pulse generation, and fix timing calculations#11004
thinkyhead merged 2 commits intoMarlinFirmware:bugfix-2.0.xfrom
ejtagle:always_honor_maximum_step_rate

Conversation

@ejtagle
Copy link
Contributor

@ejtagle ejtagle commented Jun 12, 2018

If MINIMUM_STEPPER_PULSE_TIME was 0, then the minimum period was ignored. Enforce respecting the maximum stepper rate always.

Also fix the improper calculations of timer counts to enforce that maximum stepper rate: Timer counts are not the same as instruction cycle count, so we must convert it using the pulse timer prescaler define

@ejtagle ejtagle changed the title Always honor minimum period on stepper pulse generation, and fix timing calculations [2.0.x] Always honor minimum period on stepper pulse generation, and fix timing calculations Jun 12, 2018
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise. If MINIMUM_STEPPER_PULSE isn't defined, this won't compile either.

@thinkyhead
Copy link
Member

thinkyhead commented Jun 12, 2018

If MINIMUM_STEPPER_PULSE_TIME was 0, then the minimum period was ignored. Enforce respecting the maximum stepper rate always.

I assumed we would ensure a maximum stepper rate by limiting the frequency of the ISR (giving time back to the main loop) not by adding a pulse delay even when MINIMUM_STEPPER_PULSE_TIME is 0 or undefined. On AVR I assume most of the time there won't be any added delay, but on 32-bit platforms we probably do have the luxury of just limiting the ISR rate.

Anyway, as I've pointed out above, if MINIMUM_STEPPER_PULSE_TIME is undefined then some of this code won't compile. So I've added a conditional to set it to 0 if not defined.

@ejtagle
Copy link
Contributor Author

ejtagle commented Jun 12, 2018

Yes, @thinkyhead : The problem happens when multistepping (DISABLE_MULTI_STEPPING disabled, and that is the default) with multistepping, when on the same stepper ISR we send more than one step pulse. When that happens, and MINIMUM_STEPPER_PULSE_TIME == 0, previously the multistepping was done at the maximum rate possible, with no delays at all!

Very dangerous, as there are stepper drivers that will simply ignore the stepping pulses ... 👎

@thinkyhead
Copy link
Member

The problem happens with multistepping

Yeah, I just noticed that. So, most of the time for 32-bit multi-stepping probably won't be invoked, so not a big deal.

@ejtagle
Copy link
Contributor Author

ejtagle commented Jun 12, 2018

Initially i thought that, but it´s not the case. Z axis usually has a high number of pulses per mm (in my case, 4000) so it happens to be invoked more often than thought initially ;)

@ejtagle
Copy link
Contributor Author

ejtagle commented Jun 12, 2018

And on AVR it is even worse, and manifests itself as losing steps when going too fast ... Does it sound familiar to you ? ;)

@ejtagle
Copy link
Contributor Author

ejtagle commented Jun 12, 2018

Even if the drivers support the associated stepping rate, the mechanical hardware could lose steps. The situation worsens as soon as you start increasing microstepping.
Better play safe, and always enforce it! 👍

@thinkyhead
Copy link
Member

And on AVR it is even worse, and manifests itself as losing steps when going too fast ... Does it sound familiar to you ? ;)

Yes, but in real-world terms it seems to be absent until sometime after 1.1.8…

@ejtagle
Copy link
Contributor Author

ejtagle commented Jun 12, 2018

I´d say... Luckily it is absent... 👍 ... Something i have noticed lately is that everything seems to be settling down nicely. Less and less reports of layer shifts, people that say latest bugfix seems to be solving their issues... Very nice! 👍

@ejtagle
Copy link
Contributor Author

ejtagle commented Jun 12, 2018

Theoretically ADDED_STEP_DELAY will always be > 0, as the pulse width is always <= 0.5* pulse period, and pulse period is always > 0

@thinkyhead
Copy link
Member

Luckily…

By rubber-bands and duct tape.

…everything seems to be settling down nicely…

I'm sure we're getting much closer to the ideal!

@thinkyhead
Copy link
Member

Theoretically ADDED_STEP_DELAY will always be > 0…

Makes sense. But someone might decide to set MINIMUM_STEPPER_PULSE_TIME to some large value, and in that case it'll be good to leave out the other delay code.

@ejtagle
Copy link
Contributor Author

ejtagle commented Jun 12, 2018

If it tries, then an error should be printed. Again, no driver allows that. Pulse is always recommended to be 50% of the period or less. An incorrect value will most of the time mean badly configured Marlin and bug reports you probably don´t want (I call it: Defensive programming!)

Of course, i am the culprit of some of the bugs that we are fixing... But not all of them... For example, the serial errors were my fault, as some of the stepper and endstops...

@ejtagle
Copy link
Contributor Author

ejtagle commented Jun 12, 2018

Now, rechecking this, ADDED_STEP_DELAY could become negative if the MINIMUM__STEP_PULSE > 1/MAXIMUM_STEPPER_RATE ..

Trust me, i`d cause a compilation error on that case ;)

@ejtagle
Copy link
Contributor Author

ejtagle commented Jun 12, 2018

The only case where i would leave out the timing code is if the user did not define any limits at all... And in such case, i'd personally just disallow compilation - That is asking for trouble!

@thinkyhead
Copy link
Member

Some HALs use a static function to define HAL_TIMER_RATE so unfortunately we can't catch the error at compile time.

@ejtagle
Copy link
Contributor Author

ejtagle commented Jun 13, 2018

Yes, that is right

thinkyhead and others added 2 commits June 12, 2018 21:16
Always honor minimum period on stepper pulse generation, and fix timing calculations

Signed-off-by: etagle <ejtagle@hotmail.com>
@thinkyhead thinkyhead merged commit 81edbfa into MarlinFirmware:bugfix-2.0.x Jun 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants