tmc2130: Configure stealthchop velocity limit
Change stealhchop config option to a stealthchop_threshold configuration option. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
739d37feac
commit
3799f40f29
|
@ -424,9 +424,11 @@
|
||||||
# default is to not scale the 'channel_x' parameters.
|
# default is to not scale the 'channel_x' parameters.
|
||||||
|
|
||||||
|
|
||||||
# Configure a TMC2130 stepper motor driver (one may define any number
|
# Configure a TMC2130 stepper motor driver via SPI bus. To use this
|
||||||
# of sections with a "tmc2130" prefix).
|
# feature, define a config section with a "tmc2130" prefix followed by
|
||||||
#[tmc2130 my_name]
|
# the name of the corresponding stepper config section (for example,
|
||||||
|
# "[tmc2130 stepper_x]").
|
||||||
|
#[tmc2130 stepper_x]
|
||||||
#cs_pin:
|
#cs_pin:
|
||||||
# The pin corresponding to the TMC2130 chip select line. This pin
|
# The pin corresponding to the TMC2130 chip select line. This pin
|
||||||
# will be set to low at the start of SPI messages and raised to high
|
# will be set to low at the start of SPI messages and raised to high
|
||||||
|
@ -448,8 +450,11 @@
|
||||||
#sense_resistor: 0.110
|
#sense_resistor: 0.110
|
||||||
# The resistance (in ohms) of the motor sense resistor. The default
|
# The resistance (in ohms) of the motor sense resistor. The default
|
||||||
# is 0.110 ohms.
|
# is 0.110 ohms.
|
||||||
#stealthchop: False
|
#stealthchop_threshold: 0
|
||||||
# Enable "stealthChop" mode. The default is False.
|
# The velocity (in mm/s) to set the "stealthChop" threshold to. When
|
||||||
|
# set, "stealthChop" mode will be enabled if the stepper motor
|
||||||
|
# velocity is below this value. The default is 0, which disables
|
||||||
|
# "stealthChop" mode.
|
||||||
#driver_IHOLDDELAY: 8
|
#driver_IHOLDDELAY: 8
|
||||||
#driver_TPOWERDOWN: 0
|
#driver_TPOWERDOWN: 0
|
||||||
#driver_BLANK_TIME_SELECT: 1
|
#driver_BLANK_TIME_SELECT: 1
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
# This file may be distributed under the terms of the GNU GPLv3 license.
|
# This file may be distributed under the terms of the GNU GPLv3 license.
|
||||||
import math
|
import math
|
||||||
|
|
||||||
|
TMC_FREQUENCY=13200000.
|
||||||
|
|
||||||
class tmc2130:
|
class tmc2130:
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
printer = config.get_printer()
|
printer = config.get_printer()
|
||||||
|
@ -26,9 +28,10 @@ class tmc2130:
|
||||||
sense_resistor = config.getfloat('sense_resistor', 0.110, above=0.)
|
sense_resistor = config.getfloat('sense_resistor', 0.110, above=0.)
|
||||||
steps = {'256': 0, '128': 1, '64': 2, '32': 3, '16': 4,
|
steps = {'256': 0, '128': 1, '64': 2, '32': 3, '16': 4,
|
||||||
'8': 5, '4': 6, '2': 7, '1': 8}
|
'8': 5, '4': 6, '2': 7, '1': 8}
|
||||||
microsteps = config.getchoice('microsteps', steps)
|
self.mres = config.getchoice('microsteps', steps)
|
||||||
interpolate = config.getboolean('interpolate', True)
|
interpolate = config.getboolean('interpolate', True)
|
||||||
stealthchop = config.getboolean('stealthchop', False)
|
sc_velocity = config.getfloat('stealthchop_threshold', 0., minval=0.)
|
||||||
|
sc_threshold = self.velocity_to_clock(config, sc_velocity)
|
||||||
iholddelay = config.getint('driver_IHOLDDELAY', 8, minval=0, maxval=15)
|
iholddelay = config.getint('driver_IHOLDDELAY', 8, minval=0, maxval=15)
|
||||||
tpowerdown = config.getint('driver_TPOWERDOWN', 0, minval=0, maxval=255)
|
tpowerdown = config.getint('driver_TPOWERDOWN', 0, minval=0, maxval=255)
|
||||||
blank_time_select = config.getint('driver_BLANK_TIME_SELECT', 1,
|
blank_time_select = config.getint('driver_BLANK_TIME_SELECT', 1,
|
||||||
|
@ -45,15 +48,17 @@ class tmc2130:
|
||||||
irun = self.current_bits(run_current, sense_resistor, vsense)
|
irun = self.current_bits(run_current, sense_resistor, vsense)
|
||||||
ihold = self.current_bits(hold_current, sense_resistor, vsense)
|
ihold = self.current_bits(hold_current, sense_resistor, vsense)
|
||||||
# configure GCONF
|
# configure GCONF
|
||||||
self.add_config_cmd(0x00, stealthchop << 2)
|
self.add_config_cmd(0x00, (sc_velocity > 0.) << 2)
|
||||||
# configure CHOPCONF
|
# configure CHOPCONF
|
||||||
self.add_config_cmd(
|
self.add_config_cmd(
|
||||||
0x6c, toff | (hstrt << 4) | (hend << 7) | (blank_time_select << 15)
|
0x6c, toff | (hstrt << 4) | (hend << 7) | (blank_time_select << 15)
|
||||||
| (vsense << 17) | (microsteps << 24) | (interpolate << 28))
|
| (vsense << 17) | (self.mres << 24) | (interpolate << 28))
|
||||||
# configure IHOLD_IRUN
|
# configure IHOLD_IRUN
|
||||||
self.add_config_cmd(0x10, ihold | (irun << 8) | (iholddelay << 16))
|
self.add_config_cmd(0x10, ihold | (irun << 8) | (iholddelay << 16))
|
||||||
# configure TPOWERDOWN
|
# configure TPOWERDOWN
|
||||||
self.add_config_cmd(0x11, tpowerdown)
|
self.add_config_cmd(0x11, tpowerdown)
|
||||||
|
# configure TPWMTHRS
|
||||||
|
self.add_config_cmd(0x13, max(0, min(0xfffff, sc_threshold)))
|
||||||
def add_config_cmd(self, addr, val):
|
def add_config_cmd(self, addr, val):
|
||||||
self.mcu.add_config_cmd("spi_send oid=%d data=%02x%08x" % (
|
self.mcu.add_config_cmd("spi_send oid=%d data=%02x%08x" % (
|
||||||
self.oid, (addr | 0x80) & 0xff, val & 0xffffffff), is_init=True)
|
self.oid, (addr | 0x80) & 0xff, val & 0xffffffff), is_init=True)
|
||||||
|
@ -65,6 +70,14 @@ class tmc2130:
|
||||||
cs = int(32. * current * sense_resistor * math.sqrt(2.) / vsense
|
cs = int(32. * current * sense_resistor * math.sqrt(2.) / vsense
|
||||||
- 1. + .5)
|
- 1. + .5)
|
||||||
return max(0, min(31, cs))
|
return max(0, min(31, cs))
|
||||||
|
def velocity_to_clock(self, config, velocity):
|
||||||
|
if not velocity:
|
||||||
|
return 0
|
||||||
|
stepper_name = config.get_name().split()[1]
|
||||||
|
stepper_config = config.getsection(stepper_name)
|
||||||
|
step_dist = stepper_config.getfloat('step_distance')
|
||||||
|
step_dist_256 = step_dist / (1 << self.mres)
|
||||||
|
return int(TMC_FREQUENCY * step_dist_256 / velocity + .5)
|
||||||
|
|
||||||
def load_config_prefix(config):
|
def load_config_prefix(config):
|
||||||
return tmc2130(config)
|
return tmc2130(config)
|
||||||
|
|
Loading…
Reference in New Issue