Protect pulse generation timing by disabling interrupts for longer #27131
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
Protect pulse generation timing by disabling interrupts within
Stepper::isr()
for longer.This is a mitigation for the stepper isr jitter seen in #27115 and other sources of stepper isr jitter on other platforms. On microcontrollers with ISR prioritization, note that only higher priority ISRs can ever interrupt the stepper ISR.
Benefits
More consistent pulse timings. I've tested on LPC176x and here's some before/after logic analyzer captures:
Before:
![jitter-interrupt-before](https://private-user-images.githubusercontent.com/299015/334075616-4180f188-36b7-49de-b25d-b43e7f847ab0.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU1NjAxMzQsIm5iZiI6MTcyNTU1OTgzNCwicGF0aCI6Ii8yOTkwMTUvMzM0MDc1NjE2LTQxODBmMTg4LTM2YjctNDlkZS1iMjVkLWI0M2U3Zjg0N2FiMC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwOTA1JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDkwNVQxODEwMzRaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT02ODFkZjc2YmQ3NDMxYzI2YjJjYWFhYjdmODFhNDEwMGZhNmIyYmU5ZDEzYjFiZjJhMGQ4ODBlYTY2OWY1YTEzJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.WsnSj6kgOB-fTcC-wU75nl0ubvDytdUWaaEP3LGsQIg)
After (edit, recaptured due to forgotten local changes):
![jitter-interrupt-after](https://private-user-images.githubusercontent.com/299015/334157314-d44697ef-2196-4921-b2fd-307f45b27d4a.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU1NjAxMzQsIm5iZiI6MTcyNTU1OTgzNCwicGF0aCI6Ii8yOTkwMTUvMzM0MTU3MzE0LWQ0NDY5N2VmLTIxOTYtNDkyMS1iMmZkLTMwN2Y0NWIyN2Q0YS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwOTA1JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDkwNVQxODEwMzRaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1mY2I2NzE5YzA4ZGIwZDdmMzhhNmRhNzIzZWFjZTAwZjE2NjJkYjhkMmMzZjQwYWQ3ZThmZmMyYmE4NGJhOWE1JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.HPLtA_wqDScaqDDh1MLf3B4-xlan0C_rdRUGPYp-g5s)
Basically no improvements in actual printing quality/noise unless
ADAPTIVE_STEP_SMOOTHING
is enabled sinceADAPTIVE_STEP_SMOOTHING
reduces a larger source of speed jitter, namely bresenham aliasing for the minor axes.Related Issues
Mostly mitigates #27115