Change TMC Mode for sensorless homing

Is there a way to change from stealthchop mode for only homing and then set it to spreadcycle for printing? RepRap and Marlin use M569. I tried to change stealthchop_threshold in my homing_override area, but it gives and error.

Thanks for the help.

Found this on Klipper github issues from @mental405

 def handle_homing_move_begin(self, endstops):
        if self.mcu_endstop not in endstops:
            return
        reg = self.fields.lookup_register("en_pwm_mode", None)
        if reg is None:
            # On "stallguard4" drivers, "stealthchop" must be enabled
            self.mcu_tmc.set_register("TPWMTHRS", 0)
            val = self.fields.set_field("en_spreadCycle", 0)
        else:
            # On earlier drivers, "stealthchop" must be disabled
            self.fields.set_field("en_pwm_mode", 0)
            val = self.fields.set_field("diag1_stall", 1)
        self.mcu_tmc.set_register("GCONF", val)
        self.mcu_tmc.set_register("TCOOLTHRS", 0xfffff)

Not sure if this would be a method to do what I want or where this code would go. Any comments?

This means that Klipper is already doing the necessary steps / settings when in “homing mode” and reverts back to your selected default when in “printing mode”.
There is no need to do anything from a user perspective.

First Klipper install. It doesn’t seem like it is working on my install. When I set the driver settings to spread cycle, it stays in spread cycle while homing. When I put the drive settings into stealth chop, the motors are silent when homing and work better. Is there a certain setting in the config to ensure the above code kicks in for homing. Do you need to specify a particular tmc2209 in the config? I am using a BTT E3 Mini V3 board. Would it be better to just set the stealthchop_threshold to something like 25 so when I home at 20 it is in stealthchop so it homes well and print faster in spread cycle?

Please carefully work through TMC drivers - Klipper documentation

  • Mind the notes regarding stealthchop_threshold in general
  • Mind the differences between the driver types during tuning
  • Also check the macro to tune driver current suggested at the end

Thank you for the responses. I have read the document you linked several times. I started by using the recommendations in this document. Set drivers in spreadcycle mode, set homing speed, set retract distance to 0, no holding current, etc. Created a homing macro that reduces the run current for x/y motors, pause, homex, move away, pause, homey, move away, reset motor current. Tuned the sensitivity for the stall. This is where I am confused, based on your first response, Klipper should automatically change to stealthchop mode during homing based on the driver specified. It doesn’t seem to be doing that. If I set the drivers to stealthchop in the config, it homes in stealthchop. I used the Klipper config from BTT E3 mini V3 github as starting point point and revised for my printer specifics.

If Klipper is already configured to handle tmc2209 sensorless homing by putting it in the correct mode, how come it seems to not be doing it for me? It is fine if its not working automatically, if I can set it in my homing macro. Is there a Set_TMC_Field for spreadcycle enable that I can use in my macro? This seems like a simple thing. In RepRap and Marlin it can be done by mcode.

Thanks.

Well, I do not use sensorless homing myself but it is quite common here and typically working as expected.

With the SET_TMC_FIELD command you can directly manipulate the driver settings but unfortunately there is no SET_TMC_FIELD stealthchop=off. The driver registers you need to manipulate are tpwmthrs and en_pwm_mode and there is a math behind how they need to be calculated. And in addition this is exactly what the code above already does for you.

Thank you for the quick response.