Further improvement to prevent potential LA related hang #25696
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
#25557 fixed a problem where a division by zero in the 32 bit code for
Stepper::calc_timer_interval()
resulted inla_interval == 0
which caused an infinite loop in the stepper ISR.There remains a potential edge case where
Stepper::calc_timer_interval()
is passed a very lowstep_rate
which results in a return value that is larger than can fit intohal_timer_t
. In the very edgiest case it could even be a number that truncates to zero when converted to typehal_timer_t
, also causing a hang. But even in the more general edge case it will result in a smaller value forla_interval
than is correct.This PR introduces an analogy to the 8 bit code which tests for
min_step_rate
and returns a fixed large number ifstep_rate
is too small.In addition, whilst working on this, I realised that if
la_interval
ends up being a large number (becausestep_rate
is really low) then the E steps will freeze untilla_interval
has expired. Butstep_rate
will only ever be really low momentarily (at the point where the E stepper reverses during a deceleration ramp due to linear advance). Long beforela_interval
has expired, it will receive a new, smaller value which should be honoured to avoid missed E steps. So there is a correction for this as well.Requirements
Enable
LIN_ADVANCE
.Benefits
Removes a potential edge case hang and potential lost E steps.
Related Issues
#25553
#25557