Skip to content

Commit

Permalink
Added Stepstick Lookup Table and Config Reference
Browse files Browse the repository at this point in the history
Rebased to master, removed conflicts
  • Loading branch information
lraithel15133 committed Jul 18, 2024
1 parent a945c63 commit eb212a4
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 13 deletions.
50 changes: 41 additions & 9 deletions docs/Config_Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -3866,8 +3866,14 @@ run_current:
# The amount of time (in seconds) to wait after changing homing current.
# The default is 0.5 seconds.
#sense_resistor: 0.110
# The resistance (in ohms) of the motor sense resistor. The default
# is 0.110 ohms.
# The resistance (in ohms) of the motor sense resistor. Overwrites
# value defined by stepstick_type. The default is 0.110 ohms.
#stepstick_type:
# Here, you will input the name of your stepper driver. This is used
# to define a more accurate max current, and also the proper sense
# resistor value. sense_resistor config entry overwrites a sense
# resistor value defined by this entry.
# (See the Stepstick_Types.md document for more details on each driver)
#stealthchop_threshold: 0
# The velocity (in mm/s) to set the "stealthChop" threshold to. When
# set, "stealthChop" mode will be enabled if the stepper motor
Expand Down Expand Up @@ -3977,8 +3983,14 @@ run_current:
# The amount of time (in seconds) to wait after changing homing current.
# The default is 0.5 seconds.
#sense_resistor: 0.110
# The resistance (in ohms) of the motor sense resistor. The default
# is 0.110 ohms.
# The resistance (in ohms) of the motor sense resistor. Overwrites
# value defined by stepstick_type. The default is 0.110 ohms.
#stepstick_type:
# Here, you will input the name of your stepper driver. This is used
# to define a more accurate max current, and also the proper sense
# resistor value. sense_resistor config entry overwrites a sense
# resistor value defined by this entry.
# (See the Stepstick_Types.md document for more details on each driver)
#stealthchop_threshold: 0
# The velocity (in mm/s) to set the "stealthChop" threshold to. When
# set, "stealthChop" mode will be enabled if the stepper motor
Expand Down Expand Up @@ -4022,6 +4034,14 @@ run_current:
#home_current:
#current_change_dwell_time:
#sense_resistor: 0.110
# The resistance (in ohms) of the motor sense resistor. Overwrites
# value defined by stepstick_type. The default is 0.110 ohms.
#stepstick_type:
# Here, you will input the name of your stepper driver. This is used
# to define a more accurate max current, and also the proper sense
# resistor value. sense_resistor config entry overwrites a sense
# resistor value defined by this entry.
# (See the Stepstick_Types.md document for more details on each driver)
#stealthchop_threshold: 0
# See the "tmc2208" section for the definition of these parameters.
#coolstep_threshold:
Expand Down Expand Up @@ -4103,8 +4123,14 @@ run_current:
# The amount of time (in seconds) to wait after changing homing current.
# The default is 0.5 seconds.
#sense_resistor:
# The resistance (in ohms) of the motor sense resistor. This
# parameter must be provided.
# The resistance (in ohms) of the motor sense resistor. Overwrites
# value defined by stepstick_type. The default is 0.110 ohms.
#stepstick_type:
# Here, you will input the name of your stepper driver. This is used
# to define a more accurate max current, and also the proper sense
# resistor value. sense_resistor config entry overwrites a sense
# resistor value defined by this entry.
# (See the Stepstick_Types.md document for more details on each driver)
#idle_current_percent: 100
# The percentage of the run_current the stepper driver will be
# lowered to when the idle timeout expires (you need to set up the
Expand Down Expand Up @@ -4328,8 +4354,14 @@ run_current:
# The amount of time (in seconds) to wait after changing homing current.
# The default is 0.5 seconds.
#sense_resistor: 0.075
# The resistance (in ohms) of the motor sense resistor. The default
# is 0.075 ohms.
# The resistance (in ohms) of the motor sense resistor. Overwrites
# value defined by stepstick_type. The default is 0.075 ohms.
#stepstick_type:
# Here, you will input the name of your stepper driver. This is used
# to define a more accurate max current, and also the proper sense
# resistor value. sense_resistor config entry overwrites a sense
# resistor value defined by this entry.
# (See the Stepstick_Types.md document for more details on each driver)
#stealthchop_threshold: 0
# The velocity (in mm/s) to set the "stealthChop" threshold to. When
# set, "stealthChop" mode will be enabled if the stepper motor
Expand Down Expand Up @@ -5725,4 +5757,4 @@ via the `i2c_speed` parameter. All other Klipper micro-controllers use a
# The Klipper implementation on most micro-controllers is hard-coded
# to 100000 and changing this value has no effect. The default is
# 100000. Linux, RP2040 and ATmega support 400000.
```
```
63 changes: 63 additions & 0 deletions docs/Stepstick_Types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Stepstick Type Definitions

This page contains information to assist in defining the `stepstick_type` config entry.

In stock Klipper behavior, selecting a driver automatically uses the TMC definitions' default sense resistor. While this is usually fine, it can cause issues with driver boards that have unconventional sense resistor sizes, leading to incorrect current values being set.

The goal of these changes to DangerKlipper is to allow you to set custom sense resistor and max current values for your stepper drivers. This results in more accurate configurations for your setup and enhances safety.


## Use
In practice, you should set your driver using `stepstick_type`. If you need to override the default value, you can then use `sense_resistor`. Additionally, `stepstick_type` is not required to use `sense_resistor`. If neither `stepstick_type` or `sense_resistor` is set, the default
Klipper behavior of using the TMC default value will be used (i.e. 0.075 for 5160).

> [!NOTE]
> Drivers with variable sense resistors (such as the FYSETC EXT2160) have not been defined and have been left out of the table intentionally. You must set sense resistor for them manually.

| Stepstick Type | Config Name | Sense Resistor | Max Current |
|-----------------------------------------|-------------------------|----------------|-------------|
| BTT Kraken S1-4 | KRAKEN_2160_8A | 0.022 | 8 |
| BTT Kraken S5-8 | KRAKEN_2160_3A | 0.022 | 3 |
| LDO Leviathan HV0,HV1 | LEVIATHAN_5160 | 0.075 | 3 |
| LDO Leviathan S0-4 | LEVIATHAN_2209 | 0.11 | 2 |
| BTT TMC2208 | BTT_2208 | 0.11 | 2 |
| BTT TMC2209 | BTT_2209 | 0.11 | 2 |
| BTT TMC2240 | BTT_2240 | 0.11 | 2.1 |
| BTT TMC5160T Pro | BTT_5160 | 0.075 | 3 |
| BTT EZ2130 | BTT_EZ_2130 | 0.11 | 2 |
| BTT EZ2208 | BTT_EZ_2208 | 0.11 | 2 |
| BTT EZ2209 | BTT_EZ_2209 | 0.11 | 2 |
| BTT EZ2225 | BTT_EZ_2225 | 0.11 | 2 |
| BTT EZ2226 | BTT_EZ_2226 | 0.11 | 2 |
| BTT EZ5160 Pro | BTT_EZ_5160_PRO | 0.075 | 2.5 |
| BTT EZ5160 RGB | BTT_EZ_5160_RGB | 0.05 | 4.7 |
| BTT EZ6609 | BTT_EZ_6609 | 0.11 | 2 |
| BTT TMC5160T Plus | BTT_EXT_5160 | 0.022 | 10.6 |
| FLY HV-TMC5160 Pro | MELLOW_FLY_HV_5160_Pro | 0.033 | 6 |
| COREVUS TMC2209 | COREVUS_2209 | 0.1 | 3 |
| COREVUS TMC2160 OLD | COREVUS_2160_OLD | 0.03 | 3 |
| COREVUS TMC2160 5A | COREVUS_2160_5A | 0.03 | 5 |
| COREVUS TMC2160 | COREVUS_2160 | 0.05 | 3 |
| Watterott SilentStepStick TMC2100 | WATTEROTT_2100 | 0.11 | 1.2 |
| Watterott SilentStepStick TMC2130 | WATTEROTT_2130 | 0.11 | 1.2 |
| Watterott SilentStepStick TMC2208 | WATTEROTT_2208 | 0.11 | 1.2 |
| Watterott SilentStepStick TMC2209 | WATTEROTT_2209 | 0.11 | 1.7 |
| Watterott SilentStepStick TMC5160 | WATTEROTT_5160 | 0.075 | 3 |
| Watterott SilentStepStick TMC5160HV | WATTEROTT_5160_HV | 0.075 | 3 |
| FYSETC TMC2100 | FYSETC_2100 | 0.11 | 1.2 |
| FYSETC TMC2130 | FYSETC_2130 | 0.11 | 1.2 |
| FYSETC TMC2208 | FYSETC_2208 | 0.11 | 1.2 |
| FYSETC TMC2209 | FYSETC_2209 | 0.11 | 1.7 |
| FYSETC TMC2225 | FYSETC_2225 | 0.11 | 1.4 |
| FYSETC TMC2226 | FYSETC_2226 | 0.11 | 2 |
| FYSETC HV5160 | FYSETC_HV5160 | 0.075 | 3 |
| FYSETC QHV5160 | FYSETC_QHV5160 | 0.075 | 3 |
| FYSETC Silent5161 | FYSETC_5161 | 0.06 | 3.5 |
| MKS GC6609 | MKS_GC6609 | 0.11 | 2 |
| MKS 2130 | MKS_2130 | 0.11 | 2 |
| MKS 2208 | MKS_2208 | 0.11 | 2 |
| MKS 2209 | MKS_2209 | 0.11 | 2 |
| MKS 2225 | MKS_2225 | 0.11 | 2 |
| MKS 2226 | MKS_2226 | 0.17 | 2.5 |
| MKS 2240 | MKS_2240 | 0.11 | 2.1 |
46 changes: 46 additions & 0 deletions klippy/extras/stepstick_defs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
STEPSTICK_DEFS = {
"KRAKEN_2160_8A": (0.022, 8),
"KRAKEN_2160_3A": (0.022, 3),
"LEVIATHAN_5160": (0.075, 3),
"LEVIATHAN_2209": (0.11, 2),
"BTT_2208": (0.11, 2),
"BTT_2209": (0.11, 2),
"BTT_2240": (0.11, 2.1),
"BTT_5160": (0.075, 3),
"BTT_EZ_2130": (0.11, 2),
"BTT_EZ_2208": (0.11, 2),
"BTT_EZ_2209": (0.11, 2),
"BTT_EZ_2225": (0.11, 2),
"BTT_EZ_2226": (0.11, 2),
"BTT_EZ_5160_PRO": (0.075, 2.5),
"BTT_EZ_5160_RGB": (0.05, 4.7),
"BTT_EZ_6609": (0.11, 2),
"BTT_5160T": (0.022, 10.6),
"MELLOW_FLY_HV_5160_Pro": (0.033, 6),
"COREVUS_2209": (0.1, 3),
"COREVUS_2160_OLD": (0.03, 3),
"COREVUS_2160_5A": (0.03, 5),
"COREVUS_2160": (0.05, 3),
"WATTEROTT_2100": (0.11, 1.2),
"WATTEROTT_2130": (0.11, 1.2),
"WATTEROTT_2208": (0.11, 1.2),
"WATTEROTT_2209": (0.11, 1.7),
"WATTEROTT_5160": (0.075, 3),
"WATTEROTT_5160_HV": (0.075, 3),
"FYSETC_2100": (0.11, 1.2),
"FYSETC_2130": (0.11, 1.2),
"FYSETC_2208": (0.11, 1.2),
"FYSETC_2209": (0.11, 1.7),
"FYSETC_2225": (0.11, 1.4),
"FYSETC_2226": (0.11, 2),
"FYSETC_HV5160": (0.075, 3),
"FYSETC_QHV5160": (0.075, 3),
"FYSETC_5161": (0.06, 3.5),
"MKS_GC6609": (0.11, 2),
"MKS_2130": (0.11, 2),
"MKS_2208": (0.11, 2),
"MKS_2209": (0.11, 2),
"MKS_2225": (0.11, 2),
"MKS_2226": (0.17, 2.5),
"MKS_2240": (0.11, 2.1),
}
36 changes: 36 additions & 0 deletions klippy/extras/tmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# This file may be distributed under the terms of the GNU GPLv3 license.
import logging, collections
import stepper
from . import stepstick_defs


######################################################################
Expand Down Expand Up @@ -766,10 +767,45 @@ def TMCStealthchopHelper(config, mcu_tmc, tmc_freq):
class BaseTMCCurrentHelper:
def __init__(self, config, mcu_tmc, max_current):
self.printer = config.get_printer()
self.config_file = self.printer.lookup_object("configfile")
self.name = config.get_name().split()[-1]
self.mcu_tmc = mcu_tmc
self.fields = mcu_tmc.get_fields()

stepper_driver_type = config.get("stepstick_type", None)
sense_resistor_from_driver, step_driver_max_current = (
stepstick_defs.STEPSTICK_DEFS.get(stepper_driver_type, (None, None))
)

override_sense_resistor = config.getfloat(
"sense_resistor",
None,
minval=0.0,
)
if (
override_sense_resistor is None
and sense_resistor_from_driver is None
):
logging.warning(
"No sense resistor or driver type defined for %s", self.name
)
self.sense_resistor = self.DEFAULT_SENSE_RESISTOR
self.config_file.warn(
"config",
f"[{self.name}] 'stepper_driver_type' or 'sense_resistor' is not defined, Using default value of {self.sense_resistor} ohm sense resistor. If this is incorrect, your drivers or board may be damaged.",
"sense_resistor",
)

else:
self.sense_resistor = (
override_sense_resistor or sense_resistor_from_driver
)

logging.warning(self.sense_resistor)

if step_driver_max_current is not None:
max_current = step_driver_max_current

# config_{run|hold|home}_current
# represents an initial value set via config file
self.config_run_current = config.getfloat(
Expand Down
5 changes: 2 additions & 3 deletions klippy/extras/tmc2130.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,11 @@


class TMC2130CurrentHelper(tmc.BaseTMCCurrentHelper):
DEFAULT_SENSE_RESISTOR = 0.110

def __init__(self, config, mcu_tmc):
super().__init__(config, mcu_tmc, MAX_CURRENT)

self.sense_resistor = config.getfloat(
"sense_resistor", 0.110, above=0.0
)
vsense, irun, ihold = self._calc_current(
self.req_run_current, self.req_hold_current
)
Expand Down
5 changes: 4 additions & 1 deletion klippy/extras/tmc2660.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ def __init__(self, config, mcu_tmc):
super().__init__(config, mcu_tmc, MAX_CURRENT)

self.current = self.req_run_current
self.sense_resistor = config.getfloat("sense_resistor")

if self.sense_resistor is None:
self.sense_resistor = config.getfloat("sense_resistor")

vsense, cs = self._calc_current(self.req_run_current)
self.fields.set_field("cs", cs)
self.fields.set_field("vsense", vsense)
Expand Down
2 changes: 2 additions & 0 deletions klippy/extras/tmc5160.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@


class TMC5160CurrentHelper(tmc.BaseTMCCurrentHelper):
DEFAULT_SENSE_RESISTOR = 0.075

def __init__(self, config, mcu_tmc):
super().__init__(config, mcu_tmc, MAX_CURRENT)

Expand Down

0 comments on commit eb212a4

Please sign in to comment.