Skip to content

Conversation

kadirilkimen
Copy link
Contributor

@kadirilkimen kadirilkimen commented Jul 13, 2025

Description

Spindle Override

CNC-style realtime spindle override feature added, controlled via the new M222 command. For example, M222 S120 sets the spindle output to 120% of the configured RPM. If the spindle is set to 10,000 RPM, this command increases the output to 12,000 RPM without altering the original setting—allowing runtime adjustments.

Unrelated to the spindle override function, this commit also fixes a potential typo in the warnings.cpp file. The typo indicates that EDITABLE_STEPS_PER_UNIT is required for G92 command. But it is actually required for M92 command.

Ramping for P000 and R000

The original P000 stops the Stepper ISR abruptly, causing sudden stop and let inertia to become a dangerous problem. As the following, R000 performs a sudden start of move at the stopped feed rate without acceleration. Causing the motors to stall. Both actions results in lost position and safety problem with inertia.

To prevent this, ramping feature added to the Realtime Reporting Commands P000 and R000. It provides safe stopping by deceleration and resume by acceleration.

The feature tweaks the Stepper ISR call frequency to provide ramping. Therefore it doesn't alter planned motions and doesn't wait for the planned moves to be executed. It ramps down on and ramps up on the planned path at the exact call time of the commands.

Requirements

For Spindle Override

SPINDLE_FEATURE is required.

For Ramping

EMERGENCY_PARSER and REALTIME_REPORTING_COMMANDS

Benefits

##For Spindle Override
Adds a spindle override feature to the firmware, allowing real-time fine-tuning of spindle speed. Useful for custom machine builders who need dynamic spindle control during operation.

##For Ramping
It provides Industrial CNC like HOLD/RESUME with safe deceleration/acceleration without altering the planned motions.

Configurations

For Spindle Override

Only SPINDLE_FEATURE in the Configuration_adv.h needed.

For Ramping

The following definitions must be enabled for this feature to function correctly:

EMERGENCY_PARSER
REALTIME_REPORTING_COMMANDS
REALTIME_RAMPING (optional flag to enable or disable the ramping behavior)

Related Issues

Helpful with this feature request : #24845
Helpful with this issue : #27964

The compiler should throw a warning that EDITABLE_STEPS_PER_UNIT affects the M92 command, but the warning incorrectly states that it affects G92
Added a spindle override by percentage feature. It adjusts output RPM in real-time relative to the set RPM, not direct RPM control.

Made dir_state accessible for reporting/tracking spindle rotation direction.
Added a spindle override by percentage feature. It adjusts output RPM in real-time relative to the set RPM, not direct RPM control.

Made dir_state accessible for reporting/tracking spindle rotation direction.
Added MIN and MAX limit definitions for spindle override feature.
Added a new M command for the spindle override feature.
Added a new M command for the spindle override feature.
M222 command is added for the spindle override feature.
M222 command is added for the spindle override feature.
Added M222.cpp file
Defined the minimum and maximum spindle override percentages allowed, preventing the override value from going below or above these limits.
Spindle override limits are clamped with validation conditions.
The original P000 command stops the Stepper ISR abruptly, causing an immediate halt that can result in dangerous consequences due to machine inertia. Similarly, the R000 command resumes motion instantly at the last feedrate without applying acceleration, which may lead to motor stalls. Both behaviors can cause loss of position and pose safety risks.

To address this, a ramping mechanism has been added to the realtime commands P000 and R000. This feature enables controlled deceleration when stopping and smooth acceleration when resuming, ensuring safer transitions.

The implementation adjusts the Stepper ISR call frequency to achieve ramping. It does not interfere with planned motions or require them to complete before execution. Instead, it ramps down or up along the current path precisely at the moment these commands are issued.
@kadirilkimen kadirilkimen changed the title CNC-style realtime spindle override feature added CNC-style realtime spindle override and Ramping to Realtime Reporting Commands P000 and R000 Jul 13, 2025
@kadirilkimen
Copy link
Contributor Author

Please excuse my update to the pull request — I don’t have much experience with the PR workflow.
Therefore I accidentally added another unrelated update on my pull request.

I’ve been working on adding ramping support to the P000 and R000 Emergency Parser commands. I believe this feature could be a valuable addition to Marlin.

To implement it, I modified the Stepper ISR call frequency to enable controlled deceleration and acceleration. I’ve run extensive tests on a CNC router with a heavy gantry over several days with more than a hundred pause/resume cycles and found no issues so far — it has performed reliably under the conditions I tested.

That said, I’d appreciate it if someone more familiar with the ISR internals could review and confirm whether this approach is safe and compatible with the rest of Marlin's timing-sensitive systems.

@DerAndere1
Copy link
Contributor

DerAndere1 commented Jul 13, 2025

Cool! You can have a look at PR #27592. It adds deceleration to the freeze feature and also has code to deal with S_CURVE_ACELERATION. Maybe in the future both PRs can converge to use the same implementation for deceleration to hold with P000 and FREEZE_FEATURE. I am not qualified to decide which implementation is cleaner / works better, though.

@kadirilkimen
Copy link
Contributor Author

I reviewed PR #27592 but got a bit lost partway through.
Coding is not my primary profession. Therefore I lack experience in handling pull requests and hadn’t noticed this one earlier.

Happy to see more people involved with this realtime pause/resume improvement.
I hope any of our approach is good for Marlin and it gets the feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants