Exemple #1
0
 def __init__(self, config):
     self.printer = config.get_printer()
     self.name = config.get_name().split()[-1]
     self.printer.register_event_handler("klippy:connect",
                                         self.handle_connect)
     # pin setup
     ppins = self.printer.lookup_object("pins")
     rx_pin_params = ppins.lookup_pin(
         config.get('uart_pin'), can_pullup=True)
     tx_pin_desc = config.get('tx_pin', None)
     if tx_pin_desc is None:
         tx_pin_params = rx_pin_params
     else:
         tx_pin_params = ppins.lookup_pin(tx_pin_desc)
     if rx_pin_params['chip'] is not tx_pin_params['chip']:
         raise ppins.error("TMC2208 rx and tx pins must be on the same mcu")
     self.mcu = rx_pin_params['chip']
     self.pullup = rx_pin_params['pullup']
     self.rx_pin = rx_pin_params['pin']
     self.tx_pin = tx_pin_params['pin']
     self.oid = self.mcu.create_oid()
     self.tmcuart_send_cmd = None
     self.mcu.register_config_callback(self.build_config)
     # Add DUMP_TMC command
     gcode = self.printer.lookup_object("gcode")
     gcode.register_mux_command(
         "DUMP_TMC", "STEPPER", self.name,
         self.cmd_DUMP_TMC, desc=self.cmd_DUMP_TMC_help)
     # Setup basic register values
     self.ifcnt = None
     self.regs = collections.OrderedDict()
     self.fields = tmc2130.FieldHelper(Fields, FieldFormatters, self.regs)
     self.fields.set_field("pdn_disable", True)
     self.fields.set_field("mstep_reg_select", True)
     self.fields.set_field("multistep_filt", True)
     vsense, irun, ihold = tmc2130.get_config_current(config)
     self.fields.set_field("vsense", vsense)
     self.fields.set_field("IHOLD", ihold)
     self.fields.set_field("IRUN", irun)
     mres, en, thresh = tmc2130.get_config_stealthchop(config, TMC_FREQUENCY)
     self.fields.set_field("MRES", mres)
     self.fields.set_field("en_spreadCycle", not en)
     self.fields.set_field("TPWMTHRS", thresh)
     # 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, "driver_BLANK_TIME_SELECT")
     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)
Exemple #2
0
    def __init__(self, config):
        self.printer = config.get_printer()
        self.name = config.get_name().split()[-1]
        self.spi = bus.MCU_SPI_from_config(config, 3, default_speed=4000000)
        self.gcode = self.printer.lookup_object("gcode")
        #
        self.gcode.register_mux_command("DUMP_TMC",
                                        "STEPPER",
                                        self.name,
                                        self.cmd_DUMP_TMC,
                                        desc=self.cmd_DUMP_TMC_help)
        #
        # Setup basic register values
        self.regs = collections.OrderedDict()
        self.fields = tmc2130.FieldHelper(fields, FieldFormatters, self.regs)
        vsense, irun, ihold, self.sense_resistor = tmc2130.get_config_current(
            config)
        #self.fields.set_field("vsense", vsense)
        self.fields.set_field("IHOLD", ihold)
        self.fields.set_field("IRUN", irun)
        mres, en_pwm, thresh = tmc2130.get_config_stealthchop(
            config, TMC_FREQUENCY)
        self.fields.set_field("MRES", mres)
        self.fields.set_field("en_pwm_mode", en_pwm)
        self.fields.set_field("TPWMTHRS", thresh)
        #
        #
        # 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", 4)
        set_config_field(config, "hend", 1)
        set_config_field(config, "TBL", 2)
        set_config_field(config, "intpol", True, "interpolate")
        set_config_field(config, "IHOLDDELAY", 6)
        set_config_field(config, "TPOWERDOWN", 10)
        set_config_field(config, "PWM_OFS", 128)  #
        set_config_field(config, "PWM_GRAD", 4)  #
        set_config_field(config, "pwm_freq", 1)
        set_config_field(config, "pwm_autoscale", True)
        sgt = config.getint('driver_SGT', 0, minval=-64, maxval=63) & 0x7f
        self.fields.set_field("sgt", sgt)
        set_config_field(config, "test_mode", 0)
        set_config_field(config, "direct_mode", 0)
        #
        set_config_field(config, "multistep_filt", 1)
        set_config_field(config, "chm", 0)

        #
        self._init_registers()
Exemple #3
0
 def __init__(self, config):
     self.printer = config.get_printer()
     self.name = config.get_name().split()[-1]
     self.printer.register_event_handler("klippy:connect",
                                         self._init_registers)
     # pin setup
     ppins = self.printer.lookup_object("pins")
     rx_pin_params = ppins.lookup_pin(
         config.get('uart_pin'), can_pullup=True)
     tx_pin_desc = config.get('tx_pin', None)
     if tx_pin_desc is None:
         tx_pin_params = rx_pin_params
     else:
         tx_pin_params = ppins.lookup_pin(tx_pin_desc)
     if rx_pin_params['chip'] is not tx_pin_params['chip']:
         raise ppins.error("TMC2208 rx and tx pins must be on the same mcu")
     self.mcu = rx_pin_params['chip']
     self.pullup = rx_pin_params['pullup']
     self.rx_pin = rx_pin_params['pin']
     self.tx_pin = tx_pin_params['pin']
     self.oid = self.mcu.create_oid()
     self.tmcuart_send_cmd = None
     self.mcu.register_config_callback(self.build_config)
     # Add DUMP_TMC, INIT_TMC command
     gcode = self.printer.lookup_object("gcode")
     gcode.register_mux_command(
         "SET_TMC_CURRENT", "STEPPER", self.name,
         self.cmd_SET_TMC_CURRENT, desc=self.cmd_SET_TMC_CURRENT_help)
     gcode.register_mux_command(
         "DUMP_TMC", "STEPPER", self.name,
         self.cmd_DUMP_TMC, desc=self.cmd_DUMP_TMC_help)
     gcode.register_mux_command(
         "SET_TMC_FIELD", "STEPPER", self.name,
         self.cmd_SET_TMC_FIELD, desc=self.cmd_SET_TMC_FIELD_help)
     gcode.register_mux_command(
         "INIT_TMC", "STEPPER", self.name,
         self.cmd_INIT_TMC, desc=self.cmd_INIT_TMC_help)
     # Setup basic register values
     self.ifcnt = None
     self.regs = collections.OrderedDict()
     self.fields = tmc2130.FieldHelper(Fields, FieldFormatters, self.regs)
     self.fields.set_field("pdn_disable", True)
     self.fields.set_field("mstep_reg_select", True)
     self.fields.set_field("multistep_filt", True)
     vsense, irun, ihold, self.sense_resistor = \
         tmc2130.get_config_current(config)
     self.fields.set_field("vsense", vsense)
     self.fields.set_field("IHOLD", ihold)
     self.fields.set_field("IRUN", irun)
     mres, en, thresh = tmc2130.get_config_stealthchop(config, TMC_FREQUENCY)
     self.fields.set_field("MRES", mres)
     self.fields.set_field("en_spreadCycle", not en)
     self.fields.set_field("TPWMTHRS", thresh)
     # 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)