Klipper has a motan subsystem to analyze internal behavior and gather data.
What metric step_phase show?
./scripts/motan/motan_graph.py -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:
DUMP_TMC STEPPER=stepper_x REGISTER=MSCNT
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.
-Kevin
I fear I may have goofed in the motan code. Does the following change improve the results for you?
--- a/scripts/motan/readlog.py
+++ b/scripts/motan/readlog.py
@@ -293,7 +293,7 @@ class HandleStepPhase:
self._pull_block(req_time)
continue
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]
-Kevin
Yep, that simple fix does the trick, thanks!
mscnt, phase
...
155 868 # last pair
# 1023-155 = 868
DUMP_TMC STEPPER=stepper_x REGISTER=MSCNT
MSCNT: 0000009b mscnt=155