mirror of
https://github.com/QIDITECH/klipper.git
synced 2026-02-01 08:28:41 +03:00
plus4的klipper版本
This commit is contained in:
@@ -105,6 +105,13 @@ Fields["CHOPCONF"] = {
|
||||
"diss2g": 0x01 << 30,
|
||||
"diss2vs": 0x01 << 31
|
||||
}
|
||||
Fields["DRV_CONF"] = {
|
||||
"bbmtime": 0x1F << 0,
|
||||
"bbmclks": 0x0F << 8,
|
||||
"otselect": 0x03 << 16,
|
||||
"drvstrength": 0x03 << 18,
|
||||
"filt_isense": 0x03 << 20,
|
||||
}
|
||||
Fields["DRV_STATUS"] = {
|
||||
"sg_result": 0x3FF << 0,
|
||||
"s2vsa": 0x01 << 12,
|
||||
@@ -171,6 +178,27 @@ Fields["IOIN"] = {
|
||||
Fields["LOST_STEPS"] = {
|
||||
"lost_steps": 0xfffff << 0
|
||||
}
|
||||
Fields["MSLUT0"] = { "mslut0": 0xffffffff }
|
||||
Fields["MSLUT1"] = { "mslut1": 0xffffffff }
|
||||
Fields["MSLUT2"] = { "mslut2": 0xffffffff }
|
||||
Fields["MSLUT3"] = { "mslut3": 0xffffffff }
|
||||
Fields["MSLUT4"] = { "mslut4": 0xffffffff }
|
||||
Fields["MSLUT5"] = { "mslut5": 0xffffffff }
|
||||
Fields["MSLUT6"] = { "mslut6": 0xffffffff }
|
||||
Fields["MSLUT7"] = { "mslut7": 0xffffffff }
|
||||
Fields["MSLUTSEL"] = {
|
||||
"x3": 0xFF << 24,
|
||||
"x2": 0xFF << 16,
|
||||
"x1": 0xFF << 8,
|
||||
"w3": 0x03 << 6,
|
||||
"w2": 0x03 << 4,
|
||||
"w1": 0x03 << 2,
|
||||
"w0": 0x03 << 0,
|
||||
}
|
||||
Fields["MSLUTSTART"] = {
|
||||
"start_sin": 0xFF << 0,
|
||||
"start_sin90": 0xFF << 16,
|
||||
}
|
||||
Fields["MSCNT"] = {
|
||||
"mscnt": 0x3ff << 0
|
||||
}
|
||||
@@ -218,6 +246,10 @@ Fields["TSTEP"] = {
|
||||
SignedFields = ["cur_a", "cur_b", "sgt", "xactual", "vactual", "pwm_scale_auto"]
|
||||
|
||||
FieldFormatters = dict(tmc2130.FieldFormatters)
|
||||
FieldFormatters.update({
|
||||
"s2vsa": (lambda v: "1(ShortToSupply_A!)" if v else ""),
|
||||
"s2vsb": (lambda v: "1(ShortToSupply_B!)" if v else ""),
|
||||
})
|
||||
|
||||
|
||||
######################################################################
|
||||
@@ -225,7 +257,7 @@ FieldFormatters = dict(tmc2130.FieldFormatters)
|
||||
######################################################################
|
||||
|
||||
VREF = 0.325
|
||||
MAX_CURRENT = 3.000
|
||||
MAX_CURRENT = 10.000 # Maximum dependent on board, but 10 is safe sanity check
|
||||
|
||||
class TMC5160CurrentHelper:
|
||||
def __init__(self, config, mcu_tmc):
|
||||
@@ -239,19 +271,18 @@ class TMC5160CurrentHelper:
|
||||
above=0., maxval=MAX_CURRENT)
|
||||
self.req_hold_current = hold_current
|
||||
self.sense_resistor = config.getfloat('sense_resistor', 0.075, above=0.)
|
||||
self._set_globalscaler(run_current)
|
||||
irun, ihold = self._calc_current(run_current, hold_current)
|
||||
gscaler, irun, ihold = self._calc_current(run_current, hold_current)
|
||||
self.fields.set_field("globalscaler", gscaler)
|
||||
self.fields.set_field("ihold", ihold)
|
||||
self.fields.set_field("irun", irun)
|
||||
def _set_globalscaler(self, current):
|
||||
def _calc_globalscaler(self, current):
|
||||
globalscaler = int((current * 256. * math.sqrt(2.)
|
||||
* self.sense_resistor / VREF) + .5)
|
||||
globalscaler = max(32, globalscaler)
|
||||
if globalscaler >= 256:
|
||||
globalscaler = 0
|
||||
self.fields.set_field("globalscaler", globalscaler)
|
||||
def _calc_current_bits(self, current):
|
||||
globalscaler = self.fields.get_field("globalscaler")
|
||||
return globalscaler
|
||||
def _calc_current_bits(self, current, globalscaler):
|
||||
if not globalscaler:
|
||||
globalscaler = 256
|
||||
cs = int((current * 256. * 32. * math.sqrt(2.) * self.sense_resistor)
|
||||
@@ -259,9 +290,10 @@ class TMC5160CurrentHelper:
|
||||
- 1. + .5)
|
||||
return max(0, min(31, cs))
|
||||
def _calc_current(self, run_current, hold_current):
|
||||
irun = self._calc_current_bits(run_current)
|
||||
ihold = self._calc_current_bits(min(hold_current, run_current))
|
||||
return irun, ihold
|
||||
gscaler = self._calc_globalscaler(run_current)
|
||||
irun = self._calc_current_bits(run_current, gscaler)
|
||||
ihold = self._calc_current_bits(min(hold_current, run_current), gscaler)
|
||||
return gscaler, irun, ihold
|
||||
def _calc_current_from_field(self, field_name):
|
||||
globalscaler = self.fields.get_field("globalscaler")
|
||||
if not globalscaler:
|
||||
@@ -275,7 +307,9 @@ class TMC5160CurrentHelper:
|
||||
return run_current, hold_current, self.req_hold_current, MAX_CURRENT
|
||||
def set_current(self, run_current, hold_current, print_time):
|
||||
self.req_hold_current = hold_current
|
||||
irun, ihold = self._calc_current(run_current, hold_current)
|
||||
gscaler, irun, ihold = self._calc_current(run_current, hold_current)
|
||||
val = self.fields.set_field("globalscaler", gscaler)
|
||||
self.mcu_tmc.set_register("GLOBALSCALER", val, print_time)
|
||||
self.fields.set_field("ihold", ihold)
|
||||
val = self.fields.set_field("irun", irun)
|
||||
self.mcu_tmc.set_register("IHOLD_IRUN", val, print_time)
|
||||
@@ -289,7 +323,8 @@ class TMC5160:
|
||||
def __init__(self, config):
|
||||
# Setup mcu communication
|
||||
self.fields = tmc.FieldHelper(Fields, SignedFields, FieldFormatters)
|
||||
self.mcu_tmc = tmc2130.MCU_TMC_SPI(config, Registers, self.fields)
|
||||
self.mcu_tmc = tmc2130.MCU_TMC_SPI(config, Registers, self.fields,
|
||||
TMC_FREQUENCY)
|
||||
# Allow virtual pins to be created
|
||||
tmc.TMCVirtualPinHelper(config, self.mcu_tmc)
|
||||
# Register commands
|
||||
@@ -299,9 +334,12 @@ class TMC5160:
|
||||
self.get_phase_offset = cmdhelper.get_phase_offset
|
||||
self.get_status = cmdhelper.get_status
|
||||
# Setup basic register values
|
||||
tmc.TMCWaveTableHelper(config, self.mcu_tmc)
|
||||
tmc.TMCStealthchopHelper(config, self.mcu_tmc, TMC_FREQUENCY)
|
||||
# CHOPCONF
|
||||
set_config_field = self.fields.set_config_field
|
||||
# GCONF
|
||||
set_config_field(config, "multistep_filt", True)
|
||||
# CHOPCONF
|
||||
set_config_field(config, "toff", 3)
|
||||
set_config_field(config, "hstrt", 5)
|
||||
set_config_field(config, "hend", 2)
|
||||
@@ -322,6 +360,11 @@ class TMC5160:
|
||||
set_config_field(config, "seimin", 0)
|
||||
set_config_field(config, "sgt", 0)
|
||||
set_config_field(config, "sfilt", 0)
|
||||
# DRV_CONF
|
||||
set_config_field(config, "drvstrength", 0)
|
||||
set_config_field(config, "bbmclks", 4)
|
||||
set_config_field(config, "bbmtime", 0)
|
||||
set_config_field(config, "filt_isense", 0)
|
||||
# IHOLDIRUN
|
||||
set_config_field(config, "iholddelay", 6)
|
||||
# PWMCONF
|
||||
|
||||
Reference in New Issue
Block a user