Exemplo n.º 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)
Exemplo n.º 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()
Exemplo n.º 3
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, 0, default_speed=4000000)
        # Add SET_CURRENT and DUMP_TMC commands
        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 driver registers
        self.regs = collections.OrderedDict()
        self.fields = tmc2130.FieldHelper(Fields, SignedFields,
                                          FieldFormatters, self.regs)
        set_config_field = self.fields.set_config_field

        # DRVCTRL
        steps = {
            '256': 0,
            '128': 1,
            '64': 2,
            '32': 3,
            '16': 4,
            '8': 5,
            '4': 6,
            '2': 7,
            '1': 8
        }
        self.driver_mres = config.getchoice('microsteps', steps)
        self.fields.set_field("MRES", self.driver_mres)
        set_config_field(config, "DEDGE", 0)
        set_config_field(config, "INTPOL", True, 'interpolate')
        # CHOPCONF
        set_config_field(config, "TBL", 2)
        set_config_field(config, "RNDTF", 0)
        set_config_field(config, "HDEC", 0)
        set_config_field(config, "CHM", 0)
        set_config_field(config, "HEND", 3)
        set_config_field(config, "HSTRT", 3)
        set_config_field(config, "TOFF", 4)
        if not self.fields.get_field("CHM"):
            if (self.fields.get_field("HSTRT") +
                    self.fields.get_field("HEND")) > 15:
                raise config.error("driver_HEND + driver_HSTRT must be <= 15")
        # SMARTEN
        set_config_field(config, "SEIMIN", 0)
        set_config_field(config, "SEDN", 0)
        set_config_field(config, "SEMAX", 0)
        set_config_field(config, "SEUP", 0)
        set_config_field(config, "SEMIN", 0)

        # SGSCONF
        set_config_field(config, "SFILT", 1)
        set_config_field(config, "SGT", 0)
        self.current = config.getfloat('run_current', minval=0.1, maxval=2.4)
        self.sense_resistor = config.getfloat('sense_resistor')
        (self.driver_cs,
         self.driver_vsense) = get_config_current(self.current,
                                                  self.sense_resistor)
        self.fields.set_field("CS", self.driver_cs)

        # DRVCONF
        set_config_field(config, "SLPH", 0)
        set_config_field(config, "SLPL", 0)
        set_config_field(config, "DISS2G", 0)
        set_config_field(config, "TS2G", 3)
        self.fields.set_field("VSENSE", self.driver_vsense)
        self.fields.set_field("RDSEL", 0)  # needed for phase calculations
        self.fields.set_field("SDOFF", 0)  # only step/dir mode supported

        # Init Registers
        self._init_registers(self)

        # Register ready/printing handlers
        self.idle_current_percentage = config.getint('idle_current_percent',
                                                     default=100,
                                                     minval=0,
                                                     maxval=100)
        if self.idle_current_percentage < 100:
            self.printer.register_event_handler("idle_timeout:printing",
                                                self.handle_printing)
            self.printer.register_event_handler("idle_timeout:ready",
                                                self.handle_ready)
Exemplo n.º 4
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.field_helper = tmc2130.FieldHelper(
         Fields, FieldFormatters, self.regs)
     self.field_helper.set_field("pdn_disable", True)
     self.field_helper.set_field("mstep_reg_select", True)
     self.field_helper.set_field("multistep_filt", True)
     steps = {'256': 0, '128': 1, '64': 2, '32': 3, '16': 4,
              '8': 5, '4': 6, '2': 7, '1': 8}
     mres = config.getchoice('microsteps', steps)
     self.field_helper.set_field("MRES", mres)
     # Calculate current
     vsense = False
     run_current = config.getfloat('run_current', above=0., maxval=2.)
     hold_current = config.getfloat('hold_current', run_current,
                                    above=0., maxval=2.)
     sense_resistor = config.getfloat('sense_resistor', 0.110, above=0.)
     irun = self.current_bits(run_current, sense_resistor, vsense)
     ihold = self.current_bits(hold_current, sense_resistor, vsense)
     if irun < 16 and ihold < 16:
         vsense = True
         irun = self.current_bits(run_current, sense_resistor, vsense)
         ihold = self.current_bits(hold_current, sense_resistor, vsense)
     self.field_helper.set_field("vsense", vsense)
     self.field_helper.set_field("IHOLD", ihold)
     self.field_helper.set_field("IRUN", irun)
     # Setup stealthchop
     sc_velocity = config.getfloat('stealthchop_threshold', 0., minval=0.)
     sc_threshold = self.velocity_to_clock(config, sc_velocity, mres)
     self.field_helper.set_field("en_spreadCycle", not sc_velocity)
     self.field_helper.set_field("TPWMTHRS", sc_threshold)
     # Allow other registers to be set from the config
     set_config_field = self.field_helper.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)
Exemplo n.º 5
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=100000)
        # Allow virtual endstop to be created
        self.diag1_pin = config.get('diag1_pin', None)
        ppins = self.printer.lookup_object("pins")
        ppins.register_chip("tmc5160_" + self.name, self)
        # 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.regs = collections.OrderedDict()
        self.fields = tmc2130.FieldHelper(fields, SignedFields,
                                          FieldFormatters, self.regs)
        irun, ihold, self.sense_resistor = get_config_current(config)
        msteps, en_pwm, thresh = \
            tmc2130.get_config_stealthchop(config, TMC_FREQUENCY)
        set_config_field = self.fields.set_config_field
        #   CHOPCONF
        set_config_field(config, "toff", 3)
        set_config_field(config, "hstrt", 5)
        set_config_field(config, "hend", 2)
        set_config_field(config, "fd3", 0)
        set_config_field(config, "disfdcc", 0)
        set_config_field(config, "chm", 0)
        set_config_field(config, "tbl", 2)
        set_config_field(config, "vhighfs", 0)
        set_config_field(config, "vhighchm", 0)
        set_config_field(config, "tpfd", 4)
        self.fields.set_field("mres", msteps)  # microsteps
        set_config_field(config, "intpol", True, "interpolate")
        set_config_field(config, "dedge", 0)
        set_config_field(config, "diss2g", 0)
        set_config_field(config, "diss2vs", 0)
        #   COOLCONF
        set_config_field(config, "semin", 0)  # page 52
        set_config_field(config, "seup", 0)
        set_config_field(config, "semax", 0)
        set_config_field(config, "sedn", 0)
        set_config_field(config, "seimin", 0)
        set_config_field(config, "sgt", 0)
        set_config_field(config, "sfilt", 0)
        #   GCONF
        self.fields.set_field("en_pwm_mode", en_pwm)
        #   IHOLDIRUN
        self.fields.set_field("IHOLD", ihold)
        self.fields.set_field("IRUN", irun)
        set_config_field(config, "IHOLDDELAY", 6)
        #   PWMCONF
        set_config_field(config, "PWM_OFS", 30)
        set_config_field(config, "PWM_GRAD", 0)
        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, "freewheel", 0)
        set_config_field(config, "PWM_REG", 4)
        set_config_field(config, "PWM_LIM", 12)
        #   TPWMTHRS
        self.fields.set_field("TPWMTHRS", thresh)
        #   TPOWERDOWN
        set_config_field(config, "TPOWERDOWN", 10)

        self._init_registers()