tmc2209: Initial support for tmc2209 stepper driver

Signed-off-by: Stephan Oelze <stephan.oelze@gmail.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Stephan Oelze 2019-06-18 19:43:18 +00:00 committed by Kevin O'Connor
parent c3467f5b35
commit ec9fad758a
3 changed files with 113 additions and 3 deletions

96
klippy/extras/tmc2209.py Normal file
View File

@ -0,0 +1,96 @@
# TMC2209 configuration
#
# Copyright (C) 2019 Stephan Oelze <stephan.oelze@gmail.com>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import tmc2208, tmc2130, tmc, tmc_uart
TMC_FREQUENCY=12000000.
Registers = dict(tmc2208.Registers)
Registers.update({
"TCOOLTHRS": 0x14,
"COOLCONF": 0x42,
"SGTHRS": 0x40,
"SG_RESULT": 0x41
})
ReadRegisters = tmc2208.ReadRegisters + ["SG_RESULT"]
Fields = dict(tmc2208.Fields)
Fields["COOLCONF"] = {
"semin": 0x0F << 0,
"seup": 0x03 << 5,
"semax": 0x0F << 8,
"sedn": 0x03 << 13,
"seimin": 0x01 << 15
}
Fields["IOIN"] = {
"ENN": 0x01 << 0,
"MS1": 0x01 << 2,
"MS2": 0x01 << 3,
"DIAG": 0x01 << 4,
"PDN_UART": 0x01 << 6,
"STEP": 0x01 << 7,
"SPREAD_EN": 0x01 << 8,
"DIR": 0x01 << 9,
"VERSION": 0xff << 24
}
Fields["SGTHRS"] = {
"SGTHRS": 0xFF << 0
}
Fields["SG_RESULT"] = {
"SG_RESULT": 0x3FF << 0
}
Fields["TCOOLTHRS"] = {
"TCOOLTHRS": 0xfffff
}
FieldFormatters = dict(tmc2208.FieldFormatters)
######################################################################
# TMC2209 printer object
######################################################################
class TMC2209:
def __init__(self, config):
# Setup mcu communication
self.fields = tmc.FieldHelper(Fields, tmc2208.SignedFields,
FieldFormatters)
self.mcu_tmc = tmc_uart.MCU_TMC_uart(config, Registers, self.fields)
# Register commands
cmdhelper = tmc.TMCCommandHelper(config, self.mcu_tmc)
cmdhelper.setup_register_dump(self.query_registers)
# Setup basic register values
self.fields.set_field("pdn_disable", True)
self.fields.set_field("mstep_reg_select", True)
self.fields.set_field("multistep_filt", True)
tmc2130.TMCCurrentHelper(config, self.mcu_tmc)
mh = tmc.TMCMicrostepHelper(config, self.mcu_tmc)
self.get_microsteps = mh.get_microsteps
self.get_phase = mh.get_phase
tmc.TMCStealthchopHelper(config, self.mcu_tmc, TMC_FREQUENCY)
# Allow other registers to be set from the config
set_config_field = self.fields.set_config_field
set_config_field(config, "toff", 3)
set_config_field(config, "hstrt", 5)
set_config_field(config, "hend", 0)
set_config_field(config, "TBL", 2)
set_config_field(config, "intpol", True, "interpolate")
set_config_field(config, "IHOLDDELAY", 8)
set_config_field(config, "TPOWERDOWN", 20)
set_config_field(config, "PWM_OFS", 36)
set_config_field(config, "PWM_GRAD", 14)
set_config_field(config, "pwm_freq", 1)
set_config_field(config, "pwm_autoscale", True)
set_config_field(config, "pwm_autograd", True)
set_config_field(config, "PWM_REG", 8)
set_config_field(config, "PWM_LIM", 12)
set_config_field(config, "SGTHRS", 0)
def query_registers(self, print_time=0.):
return [(reg_name, self.mcu_tmc.get_register(reg_name))
for reg_name in ReadRegisters]
def load_config_prefix(config):
return TMC2209(config)

View File

@ -19,7 +19,6 @@ diag1_pin: !PK2
[stepper_x1] [stepper_x1]
step_pin: PC3 step_pin: PC3
dir_pin: PL6 dir_pin: PL6
enable_pin: !PA4
step_distance: .005 step_distance: .005
endstop_pin: ^PB6 endstop_pin: ^PB6
@ -33,7 +32,6 @@ diag1_pin: !PK2
[stepper_y] [stepper_y]
step_pin: PC1 step_pin: PC1
dir_pin: !PL1 dir_pin: !PL1
enable_pin: !PA6
step_distance: .005 step_distance: .005
endstop_pin: tmc5160_stepper_y:virtual_endstop endstop_pin: tmc5160_stepper_y:virtual_endstop
position_endstop: 0 position_endstop: 0
@ -46,10 +44,20 @@ run_current: .5
sense_resistor: 0.220 sense_resistor: 0.220
diag1_pin: !PK7 diag1_pin: !PK7
[stepper_y1]
step_pin: PA4
dir_pin: PA6
step_distance: .005
[tmc2209 stepper_y1]
uart_pin: PA5
microsteps: 16
run_current: .5
sense_resistor: 0.075
[stepper_z] [stepper_z]
step_pin: PC2 step_pin: PC2
dir_pin: PL2 dir_pin: PL2
enable_pin: !PA5
step_distance: .0025 step_distance: .0025
endstop_pin: ^PB4 endstop_pin: ^PB4
position_endstop: 0.5 position_endstop: 0.5
@ -83,3 +91,5 @@ max_velocity: 300
max_accel: 3000 max_accel: 3000
max_z_velocity: 5 max_z_velocity: 5
max_z_accel: 100 max_z_accel: 100
[endstop_phase]

View File

@ -16,6 +16,7 @@ G1 Y1
DUMP_TMC STEPPER=stepper_x DUMP_TMC STEPPER=stepper_x
DUMP_TMC STEPPER=stepper_x1 DUMP_TMC STEPPER=stepper_x1
DUMP_TMC STEPPER=stepper_y DUMP_TMC STEPPER=stepper_y
DUMP_TMC STEPPER=stepper_y1
DUMP_TMC STEPPER=stepper_z DUMP_TMC STEPPER=stepper_z
DUMP_TMC STEPPER=stepper_z1 DUMP_TMC STEPPER=stepper_z1
@ -23,6 +24,7 @@ DUMP_TMC STEPPER=stepper_z1
INIT_TMC STEPPER=stepper_x INIT_TMC STEPPER=stepper_x
INIT_TMC STEPPER=stepper_x1 INIT_TMC STEPPER=stepper_x1
INIT_TMC STEPPER=stepper_y INIT_TMC STEPPER=stepper_y
INIT_TMC STEPPER=stepper_y1
INIT_TMC STEPPER=stepper_z INIT_TMC STEPPER=stepper_z
INIT_TMC STEPPER=stepper_z1 INIT_TMC STEPPER=stepper_z1
@ -30,6 +32,7 @@ INIT_TMC STEPPER=stepper_z1
SET_TMC_CURRENT STEPPER=stepper_x CURRENT=.7 SET_TMC_CURRENT STEPPER=stepper_x CURRENT=.7
SET_TMC_CURRENT STEPPER=stepper_x1 CURRENT=.7 SET_TMC_CURRENT STEPPER=stepper_x1 CURRENT=.7
SET_TMC_CURRENT STEPPER=stepper_y CURRENT=.7 SET_TMC_CURRENT STEPPER=stepper_y CURRENT=.7
SET_TMC_CURRENT STEPPER=stepper_y1 CURRENT=.7
SET_TMC_CURRENT STEPPER=stepper_z CURRENT=.7 SET_TMC_CURRENT STEPPER=stepper_z CURRENT=.7
SET_TMC_CURRENT STEPPER=stepper_z1 CURRENT=.7 SET_TMC_CURRENT STEPPER=stepper_z1 CURRENT=.7
@ -37,5 +40,6 @@ SET_TMC_CURRENT STEPPER=stepper_z1 CURRENT=.7
SET_TMC_CURRENT STEPPER=stepper_x FIELD=intpol VALUE=0 SET_TMC_CURRENT STEPPER=stepper_x FIELD=intpol VALUE=0
SET_TMC_CURRENT STEPPER=stepper_x1 FIELD=intpol VALUE=0 SET_TMC_CURRENT STEPPER=stepper_x1 FIELD=intpol VALUE=0
SET_TMC_CURRENT STEPPER=stepper_y FIELD=intpol VALUE=0 SET_TMC_CURRENT STEPPER=stepper_y FIELD=intpol VALUE=0
SET_TMC_CURRENT STEPPER=stepper_y1 FIELD=intpol VALUE=0
SET_TMC_CURRENT STEPPER=stepper_z FIELD=intpol VALUE=0 SET_TMC_CURRENT STEPPER=stepper_z FIELD=intpol VALUE=0
SET_TMC_CURRENT STEPPER=stepper_z1 FIELD=intpol VALUE=0 SET_TMC_CURRENT STEPPER=stepper_z1 FIELD=intpol VALUE=0