From b6bf4551551e5a20cf420a1d3c5049d601d941c3 Mon Sep 17 00:00:00 2001 From: Florian Heilmann Date: Wed, 24 Oct 2018 22:01:12 +0200 Subject: [PATCH] tmc2660: Add endstop phase detection functionality to TMC2660 extra (#816) Signed-off-by: Florian Heilmann --- config/example-extras.cfg | 2 +- docs/Endstop_Phase.md | 6 +++--- klippy/extras/endstop_phase.py | 2 +- klippy/extras/tmc2660.py | 13 ++++++++++++- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/config/example-extras.cfg b/config/example-extras.cfg index 978a1a32..ac251512 100644 --- a/config/example-extras.cfg +++ b/config/example-extras.cfg @@ -333,7 +333,7 @@ # This specifies the number of phases of the given stepper motor # driver (which is the number of micro-steps multiplied by four). # This setting is automatically determined if one uses TMC2130, -# TMC2208, or TMC2224 drivers with run-time configuration. +# TMC2208, TMC2224 or TMC2660 drivers with run-time configuration. # Otherwise, this parameter must be provided. #endstop_accuracy: 0.200 # Sets the expected accuracy (in mm) of the endstop. This represents diff --git a/docs/Endstop_Phase.md b/docs/Endstop_Phase.md index 71a03f3e..9b7b4d74 100644 --- a/docs/Endstop_Phase.md +++ b/docs/Endstop_Phase.md @@ -26,9 +26,9 @@ the endstop trigger to improve the accuracy of the endstop. In order to use this functionality it is necessary to be able to identify the phase of the stepper motor. If one is using Trinamic -TMC2130, TMC2208, or TMC2224 drivers in run-time configuration mode -(ie, not stand-alone mode) then Klipper can query the stepper phase -from the driver. (It is also possible to use this system on +TMC2130, TMC2208, TMC2224 or TMC2660 drivers in run-time configuration +mode (ie, not stand-alone mode) then Klipper can query the stepper +phase from the driver. (It is also possible to use this system on traditional stepper drivers if one can reliably reset the stepper drivers - see below for details.) diff --git a/klippy/extras/endstop_phase.py b/klippy/extras/endstop_phase.py index 81d9b147..20ddd340 100644 --- a/klippy/extras/endstop_phase.py +++ b/klippy/extras/endstop_phase.py @@ -6,7 +6,7 @@ import math, logging import homing -TRINAMIC_DRIVERS = ["tmc2130", "tmc2208"] +TRINAMIC_DRIVERS = ["tmc2130", "tmc2208", "tmc2660"] class EndstopPhase: def __init__(self, config): diff --git a/klippy/extras/tmc2660.py b/klippy/extras/tmc2660.py index ec177efa..6f14f7ac 100644 --- a/klippy/extras/tmc2660.py +++ b/klippy/extras/tmc2660.py @@ -162,7 +162,7 @@ class TMC2660: self.driver_sdoff = False # since we don't support SPI mode yet, this has to be False vsense = {'low': 0, 'high': 1} self.driver_vsense = config.getchoice('driver_VSENSE', vsense, default='high') - self.driver_rdsel = 2 # stallguard2 and coolstep current level + self.driver_rdsel = 0 # Microsteps (used by endstop phase) # Build and send registers @@ -248,6 +248,17 @@ class TMC2660: self.is_idle = True return eventtime + 0.1 + def get_microsteps(self): + return 256 >> self.driver_mres + + def get_phase(self): + # Send DRVCTRL to get a response + reg_data = [(self.reg_drvctrl >> 16) & 0xff, (self.reg_drvctrl >> 8) & 0xff, self.reg_drvctrl & 0xff] + params = self.spi_transfer_cmd.send_with_response([self.oid, reg_data], 'spi_transfer_response', self.oid) + pr = bytearray(params['response']) + steps = (((pr[0] << 16) | (pr[1] << 8) | pr[2]) & READRSP['MSTEP'][1]) >> READRSP['MSTEP'][0] + return steps >> self.driver_mres + def set_current(self, current): self.driver_cs = current_to_reg(current) reg = self.reg_sgcsconf