Skip to content

tmc: Fix stepper enable time for tmc virtual enable#7245

Open
MRX8024 wants to merge 1 commit intoKlipper3d:masterfrom
MRX8024:fix-tmc-virtual-en
Open

tmc: Fix stepper enable time for tmc virtual enable#7245
MRX8024 wants to merge 1 commit intoKlipper3d:masterfrom
MRX8024:fix-tmc-virtual-en

Conversation

@MRX8024
Copy link
Copy Markdown
Contributor

@MRX8024 MRX8024 commented Apr 2, 2026

When using the "Enabling TMC virtual enable for ..." function, motor activation is controlled by the toff register. On motor enable, the toff register value is sent to the tmc via _do_enable()-->_init_registers(), which occurs with print_time=None. Because of this, actual motor activation may occur earlier, up to ~1 second earlier.

For example:

G4 P1000
SET_STEPPER_ENABLE STEPPER=stepper_x ENABLE=1

Which will cause the motor to turn on immediately.

The change consists of moving the sending of the toff register to the required print_time, while the other registers continue to be initialized in advance. Since every on/off operation happens with mutex, everything should be fine.

Signed-off-by: Maksim Bolgov <maksim8024@gmail.com>
@KevinOConnor
Copy link
Copy Markdown
Collaborator

Thanks. However, sending the motor enable well in advance of the command is the intended behavior. We want to make sure the motor is enabled prior to any upcoming movement commands. Applying a print_time to a TMC register update only ensures the update does not occur before the provided time and there isn't a good way to ensure the update is fully processed by a given time.

Is there some problem resulting from turning on the motor power slightly in advance?

-Kevin

@MRX8024
Copy link
Copy Markdown
Contributor Author

MRX8024 commented Apr 8, 2026

Honestly, I don't know where the typical user might encounter problems with this. I'm supporting a project for Klipper that helps AWD printer users synchronize their motors; the algorithm works with motor enable and requires relatively precise timings. Unfortunately, the current behavior of virtual enable breaks it, and I thought it would be more appropriate to try to improve it here. I understand that print_time isn't a complete guarantee, but at least I haven't had any issues with it. We could have activated the motor a little earlier, say 20-50ms, but activating it earlier by up to 1s ~300ms is too much; I believe this is incorrect behavior.

Any thoughts?

@KevinOConnor
Copy link
Copy Markdown
Collaborator

Any thoughts?

That sounds challenging. Out of curiosity, could you explain why the enable timing is critical to the calibration? Maybe there is an alternative. Not sure.

For what it is worth, I'm not sure how one would go about ensuring precise timing of TMC messages in general. For example, the TMC UART code is not very fast, there could be host<->mcu message retransmits, and line noise could result in mcu<->driver retransmits. So, having confidence in even a 200ms time window would seem challenging. I suppose one could try for a time, check afterwards if the goal was met, and cancel the test otherwise. Not sure.

-Kevin

@MRX8024
Copy link
Copy Markdown
Contributor Author

MRX8024 commented Apr 10, 2026

Out of curiosity, could you explain why the enable timing is critical to the calibration? Maybe there is an alternative.

Without going into too much detail, the algorithm measures the impact value created by the motor upon activation using an accelerometer/encoder. The analyzed range is quite large, 200 ms, with the spike occurring near the center of range. However, given the current behavior with virual-en, the motor activates outside (before) the measured range.

I can actually find various hacks to make it work, but I was interested in a mainline solution.

I would suggest adding a pause before/after activating the motor, but it seems like turn-on callback is already a post-factum of steps flush, so we can't just add a time offset to next moves.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants