tmc5160: diag0 support (#3159)

Allow for diag0 only hardware to use sensorless homing.

Signed-off-by:  Trevor Jones <trevorjones141@gmail.com>
This commit is contained in:
Trevor Jones 2020-08-09 06:17:51 -06:00 committed by GitHub
parent ea5e76746a
commit efebbb9a2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 36 additions and 24 deletions

View File

@ -1436,14 +1436,16 @@
# chip. This may be used to set custom motor parameters. The
# defaults for each parameter are next to the parameter name in the
# above list.
#diag0_pin:
#diag1_pin:
# The micro-controller pin attached to the DIAG1 line of the TMC2130
# chip. Setting this creates a "tmc2130_stepper_x:virtual_endstop"
# virtual pin which may be used as the stepper's endstop_pin. Doing
# this enables "sensorless homing". (Be sure to also set driver_SGT
# to an appropriate sensitivity value.) The default is to not enable
# sensorless homing. See docs/Sensorless_Homing.md for details on how
# to configure this.
# The micro-controller pin attached to one of the DIAG lines of the
# TMC2130 chip. Only a single diag pin should be specified.
# Setting this creates a "tmc2130_stepper_x:virtual_endstop" virtual
# pin which may be used as the stepper's endstop_pin. Doing this
# enables "sensorless homing". (Be sure to also set driver_SGT to an
# appropriate sensitivity value.) The default is to not enable
# sensorless homing. See docs/Sensorless_Homing.md for details on
# how to configure this.
# Configure a TMC2208 (or TMC2224) stepper motor driver via single
# wire UART. To use this feature, define a config section with a
@ -1691,14 +1693,16 @@
# chip. This may be used to set custom motor parameters. The
# defaults for each parameter are next to the parameter name in the
# above list.
#diag0_pin:
#diag1_pin:
# The micro-controller pin attached to the DIAG1 line of the TMC5160
# chip. Setting this creates a "tmc5160_stepper_x:virtual_endstop"
# virtual pin which may be used as the stepper's endstop_pin. Doing
# this enables "sensorless homing". (Be sure to also set driver_SGT
# to an appropriate sensitivity value.) The default is to not enable
# sensorless homing. See docs/Sensorless_Homing.md for details on how
# to configure this.
# The micro-controller pin attached to one of the DIAG lines of the
# TMC5160 chip. Only a single diag pin should be specified.
# Setting this creates a "tmc5160_stepper_x:virtual_endstop" virtual
# pin which may be used as the stepper's endstop_pin. Doing this
# enables "sensorless homing". (Be sure to also set driver_SGT to an
# appropriate sensitivity value.) The default is to not enable
# sensorless homing. See docs/Sensorless_Homing.md for details on
# how to configure this.
######################################################################

View File

@ -59,6 +59,8 @@ homing_retract_dist: 0
The name of the virtual end stop pin is derived from the name of the TMC2130 section. The `homing_retract_dist` setting should be set to zero to disable the second homing move as a second pass is not needed, and attempts to do so are error prone.
The TMC2130 and TMC5160 have both a `diag0_pin` and `diag1_pin` in most known hardware the `diag1_pin` is appropriate. In order for klipper to correctly configure the driver for sensorless homing, the correct configuration property name `diag0_pin` or `diag1_pin` must be used. Which is used is determined by which driver pin is connected to the MCU pin.
ATTENTION: This guide only mentions the mandatory parameters and the ones needed to set up sensorless homing. There are many other options to configure on a TMC2130, make sure to take a look at `config/example-extras.cfg` for all the available options.
## Testing of SPI/UART communication

View File

@ -182,11 +182,20 @@ class TMCCommandHelper:
# Helper class for "sensorless homing"
class TMCVirtualPinHelper:
def __init__(self, config, mcu_tmc, diag_pin):
def __init__(self, config, mcu_tmc):
self.printer = config.get_printer()
self.mcu_tmc = mcu_tmc
self.fields = mcu_tmc.get_fields()
self.diag_pin = diag_pin
if self.fields.lookup_register('diag0_stall') is not None:
if config.get('diag0_pin', None) is not None:
self.diag_pin = config.get('diag0_pin')
self.diag_pin_field = 'diag0_stall'
else:
self.diag_pin = config.get('diag1_pin', None)
self.diag_pin_field = 'diag1_stall'
else:
self.diag_pin = config.get('diag_pin', None)
self.diag_pin_field = None
self.mcu_endstop = None
self.en_pwm = False
self.pwmthrs = 0
@ -228,7 +237,7 @@ class TMCVirtualPinHelper:
else:
# On earlier drivers, "stealthchop" must be disabled
self.fields.set_field("en_pwm_mode", 0)
val = self.fields.set_field("diag1_stall", 1)
val = self.fields.set_field(self.diag_pin_field, 1)
self.mcu_tmc.set_register("GCONF", val)
self.mcu_tmc.set_register("TCOOLTHRS", 0xfffff)
def handle_homing_move_end(self, endstops):
@ -240,7 +249,7 @@ class TMCVirtualPinHelper:
val = self.fields.set_field("en_spreadCycle", not self.en_pwm)
else:
self.fields.set_field("en_pwm_mode", self.en_pwm)
val = self.fields.set_field("diag1_stall", 0)
val = self.fields.set_field(self.diag_pin_field, 0)
self.mcu_tmc.set_register("GCONF", val)
self.mcu_tmc.set_register("TCOOLTHRS", 0)

View File

@ -210,8 +210,7 @@ class TMC2130:
self.fields = tmc.FieldHelper(Fields, SignedFields, FieldFormatters)
self.mcu_tmc = MCU_TMC_SPI(config, Registers, self.fields)
# Allow virtual pins to be created
diag1_pin = config.get('diag1_pin', None)
tmc.TMCVirtualPinHelper(config, self.mcu_tmc, diag1_pin)
tmc.TMCVirtualPinHelper(config, self.mcu_tmc)
# Register commands
cmdhelper = tmc.TMCCommandHelper(config, self.mcu_tmc)
cmdhelper.setup_register_dump(ReadRegisters)

View File

@ -60,8 +60,7 @@ class TMC2209:
FieldFormatters)
self.mcu_tmc = tmc_uart.MCU_TMC_uart(config, Registers, self.fields, 3)
# Allow virtual pins to be created
diag_pin = config.get('diag_pin', None)
tmc.TMCVirtualPinHelper(config, self.mcu_tmc, diag_pin)
tmc.TMCVirtualPinHelper(config, self.mcu_tmc)
# Register commands
cmdhelper = tmc.TMCCommandHelper(config, self.mcu_tmc)
cmdhelper.setup_register_dump(ReadRegisters)

View File

@ -309,8 +309,7 @@ class TMC5160:
self.fields = tmc.FieldHelper(Fields, SignedFields, FieldFormatters)
self.mcu_tmc = tmc2130.MCU_TMC_SPI(config, Registers, self.fields)
# Allow virtual pins to be created
diag1_pin = config.get('diag1_pin', None)
tmc.TMCVirtualPinHelper(config, self.mcu_tmc, diag1_pin)
tmc.TMCVirtualPinHelper(config, self.mcu_tmc)
# Register commands
cmdhelper = tmc.TMCCommandHelper(config, self.mcu_tmc)
cmdhelper.setup_register_dump(ReadRegisters)