Motion analysis: stepper phase what is it?

Klipper has a motan subsystem to analyze internal behavior and gather data.
What metric step_phase show?

./scripts/motan/ -s 0 -d 20 ./log-file -g '[["step_phase(tmc5160 stepper_x,microstep)"], ["step_phase(tmc5160 stepper_x)"]]'

I start data logging, home head, move it - and stop logging.

Both motors at this time use 256 micro-stepping, so there are 1024 positions in 4 full steps.

The last value according to the graph is 864.
Because toolhead is at a standstill there, I query the driver:

MSCNT: 00000172 mscnt=370

Values do not match, is that expected?

The motan step_phase is intended to show a statistic similar to mscnt, but with a few notable differences. The step_phase increments between 0 - (microsteps*4-1) (whereas mscnt increments between 0 - 1023). The step_phase should always increment while the nominal stepper position increments (whereas mscnt may increment or decrement depending on the dir_pin polarity).

The two values don’t necessarily match, but it does seem like something went wrong with the values that you are reporting.


I fear I may have goofed in the motan code. Does the following change improve the results for you?

--- a/scripts/motan/
+++ b/scripts/motan/
@@ -293,7 +293,7 @@ class HandleStepPhase:
             step_pos = step_data[data_pos][1]
-            return (step_pos - self.mcu_phase_offset) % self.phases
+            return (step_pos + self.mcu_phase_offset) % self.phases
     def _pull_block(self, req_time):
         step_data = self.step_data
         del step_data[:-1]


1 Like

Yep, that simple fix does the trick, thanks!

mscnt, phase
155 868 # last pair
# 1023-155 = 868
MSCNT: 0000009b mscnt=155

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.