Recently, I received a question about the Passive Breaking feature in TMC.
The main use is to prevent Z from falling down on the motor disable.
Passive breaking can be used only on an enabled driver.
Only in StealthChop mode.
It will short out coils and prevent the motor from spinning freely.
Most TMC drivers used in Klipper support it.
Before it is implemented in code, I think it would be useful to have a macro to test that functionality and play with it.
It is required that in the config, there is a 0 or greater value, or we will need to modify more registers (en_pwm_mode or en_spreadcycle):
[tmc2209 stepper_z]
stealthchop_threshold: 0
First, we need to know the current values, specifically the hold current and stealth threshold:
$ DUMP_TMC STEPPER=stepper_z REGISTER=IHOLD_IRUN
IHOLD_IRUN: 04061f1f ihold=31 irun=31 iholddelay=6 irundelay=4
$ DUMP_TMC STEPPER=stepper_z REGISTER=TPWMTHRS
// TPWMTHRS: 000fffff tpwmthrs=1048575
In my case ihold is 31, and tpwmths (stealth threshold) is 1048575, so effectively disabled.
In case you have set stealthchop_threshold
to a value > 0 mm/s in a config, it simplifies the next macro.
SET_KINEMATIC_POSITION CLEAR=Z
# Only needed if stealthchop_threshold = 0
SET_TMC_FIELD STEPPER=stepper_z FIELD=TPWMTHRS VALUE=1 # some value lower than disabled
SET_TMC_FIELD STEPPER=stepper_z FIELD=IHOLD VALUE=0 # zero is required
# Some drivers support the default value passed from the config
# If so, it is also not required
SET_TMC_FIELD STEPPER=stepper_z FIELD=FREEWHEEL VALUE=2 # 2 or 3
To revert back, we simply restore previous values:
# Only needed if stealthchop_threshold = 0
SET_TMC_FIELD STEPPER=stepper_z FIELD=TPWMTHRS VALUE=1048575
SET_TMC_FIELD STEPPER=stepper_z FIELD=IHOLD VALUE=31
So, the idle_timeout automation will look like:
[idle_timeout]
gcode:
{% if 'heaters' in printer %}
TURN_OFF_HEATERS
{% endif %}
# M84
SET_STEPPER_ENABLE STEPPER=stepper_x ENABLE=0
SET_STEPPER_ENABLE STEPPER=stepper_y ENABLE=0
SET_STEPPER_ENABLE STEPPER=extruder ENABLE=0
SET_KINEMATIC_POSITION CLEAR=Z
SET_TMC_FIELD STEPPER=stepper_z FIELD=TPWMTHRS VALUE=1
SET_TMC_FIELD STEPPER=stepper_z FIELD=IHOLD VALUE=0
SET_TMC_FIELD STEPPER=stepper_z FIELD=FREEWHEEL VALUE=2
SET_TMC_FIELD STEPPER=stepper_z1 FIELD=TPWMTHRS VALUE=1
SET_TMC_FIELD STEPPER=stepper_z1 FIELD=IHOLD VALUE=0
SET_TMC_FIELD STEPPER=stepper_z1 FIELD=FREEWHEEL VALUE=2
# ... etc
Those can be further automated by referencing the config values for specified steppers and the use of additional:
SET_TMC_CURRENT STEPPER=<name> CURRENT=<amps> HOLDCURRENT=<amps>
The SET_TMC_CURRENT
will only be valid for restore, because it is forbidden to set the current to 0.
SET_TMC_FIELD STEPPER=<name> FIELD=TPWMTHRS VELOCITY=<value>
Hope that helps someone.
Freewheel possible values:
%00: Normal operation
%01: Freewheeling
%10: Coil shorted using LS drivers #2, 4 motor pins tied to GND
%11: Coil shorted using HS drivers #3, 4 motor pins tied to Vmotor (12V, 24V, 36V, 48V generally)
It should be possible to validate behaviour on your machine and with your drivers.
With ihold: 1
(low non-zero value) you will be able to rotate the motor only by skipping 4 full steps. You can feel it by hand.
With ihold: 0 freewheel: 0|2|3
it should rotate slowly, like when you “mix” the “dough”.
With ihold: 0 freewheel: 1
, it will act like a disabled driver, easy to spin.
I did some tests with TMC2226 (2209), TMC2240, and TMC5160.
I cannot notice any usable difference between FreeWheel 0, 2, and 3.
With freewheel: 0
looks like coils are shorted inside the driver, to some middle point, with 24V power, I measure 12V between GND and coils, with 48V → 24V.