HF-TMC51x0 Driver (TMC5130 & TMC5160) 0.1.0-dev
Hardware Agnostic C++ Driver for the TMC51x0 (TMC5130 & TMC5160)
Loading...
Searching...
No Matches
tmc51x0::DriverConfig Struct Reference

Driver initialization configuration structure. More...

#include <tmc51x0_types.hpp>

Collaboration diagram for tmc51x0::DriverConfig:
[legend]

Public Member Functions

 DriverConfig () noexcept
 Default constructor.
 

Public Attributes

MotorSpec motor_spec {}
 Motor specifications (physical parameters for automatic current calculation)
 
PowerStageParameters power_stage {}
 Power stage configuration (includes short protection)
 
MechanicalSystem mechanical {}
 Mechanical system configuration (gearing, leadscrew, etc.) for unit conversions.
 
MotorDirection direction {MotorDirection::NORMAL}
 Motor direction (normal or inverse)
 
ChopperConfig chopper {}
 Chopper configuration (SpreadCycle or Classic mode)
 
StealthChopConfig stealthchop {}
 StealthChop configuration.
 
GlobalConfig global_config {}
 Global configuration (GCONF register)
 
RampConfig ramp_config {}
 Ramp generator configuration (with unit support)
 
ExternalClockConfig external_clk_config {}
 External clock configuration (0 = use internal 12 MHz, >0 = external clock frequency)
 
StallGuardConfig stallguard {}
 StallGuard2 configuration (defaults: threshold=0, disabled)
 
CoolStepConfig coolstep {}
 CoolStep configuration (defaults: lower_threshold_sg=0, disabled)
 
DcStepConfig dcstep {}
 DcStep configuration (defaults: min_velocity=0, disabled)
 
ReferenceSwitchConfig reference_switch_config {}
 Reference switch configuration (defaults: stop disabled, latching disabled)
 
EncoderConfig encoder_config {}
 Encoder configuration (includes pulses per rev, invert direction, deviation)
 
UartConfig uart_config {}
 UART communication configuration (node address, send delay)
 

Detailed Description

Driver initialization configuration structure.

Complete configuration structure for initializing the TMC5160 driver. Contains all necessary parameters for power stage, motor, and driver operation.

Automatic Current Calculation

IRUN, IHOLD, and GLOBAL_SCALER are automatically calculated from motor_spec parameters during Initialize(). These values are stored internally and NOT in motor_spec.

Required Parameters for automatic calculation:

  • motor_spec.sense_resistor_mohm (e.g., 50 for 0.05Ω) - MUST be non-zero
  • motor_spec.supply_voltage_mv (e.g., 24000 for 24V) - MUST be non-zero
  • motor_spec.rated_current_ma or motor_spec.run_current_ma (if run_current_ma=0, uses rated_current_ma)

Optional Parameters:

  • motor_spec.winding_resistance_mohm (for StealthChop lower limit validation)
  • motor_spec.winding_inductance_mh (for motor characterization)
  • motor_spec.hold_current_ma (if 0, auto-calculates as 30% of run current)
  • motor_spec.scaler_adjustment_percent, irun_adjustment_percent, ihold_adjustment_percent (for fine-tuning)

DO NOT manually set IRUN, IHOLD, or GLOBAL_SCALER - they are calculated automatically.

Clock Configuration

f_clk is automatically calculated from external_clk_config during Initialize(). The actual clock frequency used for timing calculations (f_clk) is determined internally:

  • If external_clk_config.frequency_hz > 0: f_clk = external_clk_config.frequency_hz (external clock)
  • If external_clk_config.frequency_hz == 0: f_clk = 12 MHz (internal clock, default)

Clock Mode Selection:

  • Internal Clock (default): Set external_clk_config.frequency_hz = 0 (or leave default)
    • CLK pin must be tied to GND (near the IC) to enable internal oscillator
    • Factory-trimmed on-chip oscillator provides ~12 MHz
    • Velocity precision: approximately ±4% (sufficient for most applications)
    • f_clk = 12 MHz (used for all timing calculations)
    • No external clock source required
  • External Clock: Set external_clk_config.frequency_hz to desired frequency
    • CLK pin receives clock signal from external source
    • Recommended frequency: 10-16 MHz for optimum performance
    • Up to 18 MHz can be used with 50% duty cycle
    • Clock source must supply clean CMOS output logic levels and steep slopes
    • External clock is enabled with the second positive polarity seen on CLK input
    • Internal watchdog switches back to internal clock if external signal is missing for >32 internal clock cycles
    • f_clk = external_clk_config.frequency_hz (used for all timing calculations)
    • Provides more precise timing reference for deterministic results

DO NOT manually set f_clk - it is calculated automatically from external_clk_config.

ESP32 Platform Configuration

For ESP32 examples, use helper functions from esp32_tmc5160_test_config.hpp:

  • ConfigureDriverFromMotor_17HS4401S_Gearbox(cfg)
  • ConfigureDriverFromMotor_17HS4401S_Direct(cfg)
  • ConfigureDriverFromMotor_AppliedMotion_5034(cfg)

These functions automatically configure all parameters from compile-time motor/platform specifications.

See tmc5160_motor_calc.hpp for calculation details. See docs/configuration.md for configuration guide.

Constructor & Destructor Documentation

◆ DriverConfig()

tmc51x0::DriverConfig::DriverConfig ( )
inlinenoexcept

Default constructor.

Initializes with recommended default values. Motor current settings (IRUN, IHOLD, GLOBAL_SCALER) are calculated automatically during Initialize() if motor_spec.sense_resistor_mohm and motor_spec.supply_voltage_mv are set.

All configurations use safe defaults (disabled/not configured where applicable).

Member Data Documentation

◆ chopper

ChopperConfig tmc51x0::DriverConfig::chopper {}

Chopper configuration (SpreadCycle or Classic mode)

◆ coolstep

CoolStepConfig tmc51x0::DriverConfig::coolstep {}

CoolStep configuration (defaults: lower_threshold_sg=0, disabled)

◆ dcstep

DcStepConfig tmc51x0::DriverConfig::dcstep {}

DcStep configuration (defaults: min_velocity=0, disabled)

◆ direction

MotorDirection tmc51x0::DriverConfig::direction {MotorDirection::NORMAL}

Motor direction (normal or inverse)

◆ encoder_config

EncoderConfig tmc51x0::DriverConfig::encoder_config {}

Encoder configuration (includes pulses per rev, invert direction, deviation)

◆ external_clk_config

ExternalClockConfig tmc51x0::DriverConfig::external_clk_config {}

External clock configuration (0 = use internal 12 MHz, >0 = external clock frequency)

◆ global_config

GlobalConfig tmc51x0::DriverConfig::global_config {}

Global configuration (GCONF register)

◆ mechanical

MechanicalSystem tmc51x0::DriverConfig::mechanical {}

Mechanical system configuration (gearing, leadscrew, etc.) for unit conversions.

◆ motor_spec

MotorSpec tmc51x0::DriverConfig::motor_spec {}

Motor specifications (physical parameters for automatic current calculation)

◆ power_stage

PowerStageParameters tmc51x0::DriverConfig::power_stage {}

Power stage configuration (includes short protection)

◆ ramp_config

RampConfig tmc51x0::DriverConfig::ramp_config {}

Ramp generator configuration (with unit support)

◆ reference_switch_config

ReferenceSwitchConfig tmc51x0::DriverConfig::reference_switch_config {}

Reference switch configuration (defaults: stop disabled, latching disabled)

◆ stallguard

StallGuardConfig tmc51x0::DriverConfig::stallguard {}

StallGuard2 configuration (defaults: threshold=0, disabled)

◆ stealthchop

StealthChopConfig tmc51x0::DriverConfig::stealthchop {}

StealthChop configuration.

◆ uart_config

UartConfig tmc51x0::DriverConfig::uart_config {}

UART communication configuration (node address, send delay)


The documentation for this struct was generated from the following file: