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

Namespaces

namespace  ChipVersion
 TMC chip version constants.
 
namespace  ClockFreq
 TMC51x0 clock frequency constants.
 
namespace  MathConstants
 Mathematical constants.
 
namespace  MotorCalcConstants
 
namespace  RegisterConstants
 Register conversion constants.
 
namespace  Registers
 TMC51x0 register addresses.
 

Classes

struct  AccelerationValue
 Self-describing acceleration value with explicit unit. More...
 
union  CHOPCONF_Register
 Chopper and driver configuration register (CHOPCONF) More...
 
struct  ChopperConfig
 Chopper configuration structure. More...
 
class  CommInterface
 CRTP-based communication interface for register read/write operations. More...
 
class  ConfigBuilder
 Fluent configuration builder for DriverConfig. More...
 
union  COOLCONF_Register
 coolStep smart current control and stallGuard2 configuration register (COOLCONF) More...
 
struct  CoolStepConfig
 CoolStep configuration structure. More...
 
union  DCCTRL_Register
 dcStep automatic commutation configuration register (DCCTRL) More...
 
struct  DcStepConfig
 DcStep configuration structure. More...
 
struct  Diag0Config
 DIAG0 pin configuration structure. More...
 
struct  Diag1Config
 DIAG1 pin configuration structure. More...
 
struct  DriverConfig
 Driver initialization configuration structure. More...
 
union  DRV_CONF_Register
 Driver configuration register (DRV_CONF) More...
 
union  DRV_STATUS_Register
 stallGuard2 value and driver error flags register (DRV_STATUS) More...
 
union  ENC_STATUS_Register
 Encoder status register (ENC_STATUS) More...
 
union  ENCMODE_Register
 Encoder configuration register (ENCMODE) More...
 
struct  EncoderConfig
 Encoder configuration structure. More...
 
struct  ExternalClockConfig
 External clock configuration structure. More...
 
union  GCONF_Register
 General configuration register (GCONF) More...
 
struct  GlobalConfig
 Global configuration (GCONF) structure. More...
 
union  GSTAT_Register
 Global status register (GSTAT) More...
 
struct  HomingSettingsCache
 Cached settings for homing operations. More...
 
union  IHOLD_IRUN_Register
 Driver current control register (IHOLD_IRUN) More...
 
struct  InputStatus
 Input pin status structure. More...
 
union  IOIN_Register
 Input pin register (IOIN) - Read-only at address 0x04. More...
 
struct  MechanicalSystem
 Mechanical system configuration structure. More...
 
struct  MicrostepChangeOptions
 Options for changing microstep resolution (CHOPCONF.MRES) More...
 
struct  MotorSpec
 Motor specification structure. More...
 
union  MSCURACT_Register
 Actual microstep current register (MSCURACT) More...
 
union  MSLUTSEL_Register
 Microstep lookup table segmentation definition register (MSLUTSEL) More...
 
union  NODECONF_Register
 UART node address configuration register (NODECONF) More...
 
union  OFFSET_READ_Register
 Offset calibration result register (OFFSET_READ) More...
 
union  OTP_PROG_Register
 OTP programming register (OTP_PROG) More...
 
union  OTP_READ_Register
 OTP read register (OTP_READ) More...
 
struct  PinActiveLevels
 Pin active level configuration structure. More...
 
struct  PowerStageParameters
 Power stage parameters structure. More...
 
union  PWM_AUTO_Register
 stealthChop automatically generated values read out register (PWM_AUTO) More...
 
union  PWM_SCALE_Register
 Results of stealthChop amplitude regulator register (PWM_SCALE) More...
 
union  PWMCONF_Register
 stealthChop voltage PWM mode chopper configuration register (PWMCONF) More...
 
union  RAMP_STAT_Register
 Ramp status and switch event status register (RAMP_STAT) More...
 
struct  RampConfig
 Ramp configuration structure. More...
 
struct  ReferenceSwitchConfig
 Reference switch configuration structure. More...
 
class  Result
 Result type for operations that return a value. More...
 
class  Result< void >
 Result type for operations that don't return a value. More...
 
union  SHORT_CONF_Register
 Short detector configuration register (SHORT_CONF) More...
 
struct  SpiCommand
 TMC5160 SPI command structure with union-based frame representation. More...
 
class  SpiCommInterface
 CRTP-based SPI implementation of TMC5160CommInterface. More...
 
struct  SpiResponse
 TMC5160 SPI response structure. More...
 
struct  SpiStatus
 SPI_STATUS structure - status flags returned with each SPI datagram. More...
 
struct  StallGuardConfig
 StallGuard2 configuration structure. More...
 
struct  StallGuardTuningResult
 Result structure for StallGuard2 threshold (SGT) tuning. More...
 
struct  StealthChopConfig
 StealthChop configuration structure. More...
 
union  SW_MODE_Register
 Switch mode configuration register (SW_MODE) More...
 
class  TMC51x0
 Main class representing a TMC51x0 stepper motor driver (TMC5130 & TMC5160) More...
 
class  TMC51x0DaisyChain
 High-level manager for multiple TMC51x0 drivers in a daisy-chain configuration. More...
 
class  TMC51x0MultiNode
 High-level manager for multiple TMC51x0 drivers in a UART multi-node configuration. More...
 
struct  TMC51x0PinConfig
 TMC51x0 GPIO pin configuration structure. More...
 
class  UartCommInterface
 CRTP-based UART implementation of TMC5160CommInterface. More...
 
struct  UartConfig
 UART communication configuration structure. More...
 
struct  UartFrame
 TMC5160 UART command/response frame structure with built-in CRC8. More...
 
struct  VelocityValue
 Self-describing velocity value with explicit unit. More...
 

Typedefs

using ResultVoid = Result<void>
 

Enumerations

enum class  RampMode : uint8_t { POSITIONING = 0x00 , VELOCITY_POS = 0x01 , VELOCITY_NEG = 0x02 , HOLD = 0x03 }
 Ramp mode enumeration values. More...
 
enum class  PWMFreewheel : uint8_t { NORMAL = 0x00 , ENABLED = 0x01 , SHORT_LS = 0x02 , SHORT_HS = 0x03 }
 PWM freewheel mode enumeration values. More...
 
enum class  EncoderSensitivity : uint8_t { NO_EDGE = 0x00 , RISING_EDGE = 0x01 , FALLING_EDGE = 0x02 , BOTH_EDGES }
 Encoder N channel sensitivity enumeration values. More...
 
enum class  LogLevel : uint8_t {
  Error = 0 , Warn = 1 , Info = 2 , Debug = 3 ,
  Verbose = 4
}
 Driver-native log levels for debug output. More...
 
enum class  CommMode : uint8_t { SPI , UART }
 Supported physical communication modes for TMC51x0. More...
 
enum class  TMC51x0CtrlPin : uint8_t {
  EN , DIR , STEP , REFL_STEP ,
  REFR_DIR , DIAG0 , DIAG1 , ENCA ,
  ENCB , ENCN , DCEN , DCIN ,
  DCO , CLK , SPI_MODE , SD_MODE
}
 TMC51x0 control pin identifiers with board-agnostic naming. More...
 
enum class  GpioSignal : uint8_t { INACTIVE = 0 , ACTIVE = 1 }
 GPIO signal states with board-agnostic naming. More...
 
enum class  UartFrameType : uint8_t { WriteAccess , ReadRequest , ReadReply }
 TMC5160 UART frame types. More...
 
enum class  ErrorCode : uint8_t {
  OK = 0 , NOT_INITIALIZED , COMM_ERROR , INVALID_VALUE ,
  INVALID_STATE , TIMEOUT , CANCELLED , HARDWARE_ERROR ,
  SHORT_CIRCUIT , OPEN_LOAD , OVERTEMP_WARNING , OVERTEMP_SHUTDOWN ,
  UNSUPPORTED
}
 Error codes for TMC51x0 operations. More...
 
enum class  ChipCommMode : uint8_t { SPI_INTERNAL_RAMP , SPI_EXTERNAL_STEPDIR = 1 , UART_INTERNAL_RAMP , STANDALONE_EXTERNAL_STEPDIR }
 Chip communication and motion control mode configuration. More...
 
enum class  MotorDirection : uint8_t { NORMAL = 0 , INVERSE = 1 }
 Motor direction enumeration. More...
 
enum class  MotorType : uint8_t {
  STEPPER = 0 , DC_MOTOR_SINGLE = 1 , DC_MOTOR_DUAL = 2 , SOLENOID_SINGLE = 3 ,
  SOLENOID_DUAL = 4
}
 Motor type enumeration. More...
 
enum class  Unit : uint8_t {
  Steps , Rad , Deg , Mm ,
  RPM , RevPerSec
}
 Unit enumeration. More...
 
enum class  DriverStatus : uint8_t {
  OK , CP_UV , S2VSA , S2VSB ,
  S2GA , S2GB , OT , OTHER_ERR ,
  OTPW
}
 Driver status enumeration. More...
 
enum class  MechanicalSystemType : uint8_t { DirectDrive , LeadScrew , BeltDrive , Gearbox }
 Mechanical system type enumeration. More...
 
enum class  SenseFilterTime : uint8_t { T100ns = 0 , T200ns = 1 , T300ns = 2 , T400ns = 3 }
 Sense amplifier filter time constant enumeration. More...
 
enum class  OverTempProtection : uint8_t { Temp150C = 0 , Temp143C = 1 , Temp136C = 2 , Temp120C = 3 }
 Over-temperature protection level enumeration. More...
 
enum class  ChopperMode : bool { SPREAD_CYCLE = false , CLASSIC = true }
 Chopper mode enumeration. More...
 
enum class  ChopperBlankTime : uint8_t { TBL_16CLK = 0 , TBL_24CLK = 1 , TBL_36CLK = 2 , TBL_54CLK = 3 }
 Comparator blank time enumeration. More...
 
enum class  MicrostepResolution : uint8_t {
  MRES_256 = 0 , MRES_128 = 1 , MRES_64 = 2 , MRES_32 = 3 ,
  MRES_16 = 4 , MRES_8 = 5 , MRES_4 = 6 , MRES_2 = 7 ,
  FULLSTEP = 8
}
 Microstep resolution enumeration. More...
 
enum class  MicrostepLutPreset : uint8_t { DEFAULT_SINE = 0 , PURE_SINE = 1 }
 Microstep lookup table preset waveforms. More...
 
enum class  StealthChopPwmFreq : uint8_t { PWM_FREQ_0 = 0 , PWM_FREQ_1 = 1 , PWM_FREQ_2 = 2 , PWM_FREQ_3 = 3 }
 StealthChop PWM frequency enumeration. More...
 
enum class  StealthChopRegulationSpeed : uint8_t {
  VERY_SLOW = 1 , SLOW = 2 , MODERATE = 4 , FAST = 8 ,
  VERY_FAST = 15
}
 StealthChop regulation speed enumeration. More...
 
enum class  StealthChopJerkReduction : uint8_t {
  MAXIMUM = 8 , HIGH = 10 , MODERATE = 12 , LOW = 14 ,
  MINIMUM = 15
}
 StealthChop mode switching jerk reduction enumeration. More...
 
enum class  StallGuardSensitivity : int8_t {
  VERY_HIGH = -32 , HIGH = -16 , MODERATE = 0 , LOW = 16 ,
  VERY_LOW = 32
}
 StallGuard2 sensitivity enumeration. More...
 
enum class  CoolStepIncrementStep : uint8_t { STEP_1 = 0 , STEP_2 = 1 , STEP_4 = 2 , STEP_8 = 3 }
 CoolStep current increment step width enumeration. More...
 
enum class  CoolStepDecrementSpeed : uint8_t { EVERY_32 = 0 , EVERY_8 = 1 , EVERY_2 = 2 , EVERY_1 = 3 }
 CoolStep current decrement speed enumeration. More...
 
enum class  CoolStepMinCurrent : uint8_t { HALF_IRUN = 0 , QUARTER_IRUN = 1 }
 CoolStep minimum current percentage enumeration. More...
 
enum class  DcStepStallSensitivity : uint8_t { DISABLED = 0 , LOW = 1 , MODERATE = 2 , HIGH = 3 }
 DcStep stall detection sensitivity enumeration. More...
 
enum class  ReferenceSwitchActiveLevel : uint8_t { ACTIVE_LOW , ACTIVE_HIGH }
 Reference switch active level enumeration. More...
 
enum class  ReferenceLatchMode : uint8_t { DISABLED , ACTIVE_EDGE , INACTIVE_EDGE , BOTH_EDGES }
 Position latching mode enumeration. More...
 
enum class  ReferenceStopMode : uint8_t { HARD_STOP , SOFT_STOP }
 Stop mode enumeration. More...
 
enum class  EncoderNSensitivity : uint8_t { ACTIVE_LEVEL , RISING_EDGE , FALLING_EDGE , BOTH_EDGES }
 Encoder N channel sensitivity enumeration. More...
 
enum class  EncoderClearMode : uint8_t { DISABLED , ONCE , CONTINUOUS }
 Encoder clear mode enumeration. More...
 
enum class  EncoderPrescalerMode : uint8_t { BINARY , DECIMAL }
 Encoder prescaler mode enumeration. More...
 

Functions

const char * GetRegisterDef (uint8_t address)
 
bool CalculateMotorCurrent (const MotorSpec &motor_spec, uint32_t sense_resistor_mohm, uint32_t supply_voltage_mv, uint16_t run_current_ma, uint16_t hold_current_ma, uint8_t &irun, uint8_t &ihold, uint16_t &global_scaler) noexcept
 Calculate motor current settings from physical parameters.
 
uint16_t CalculateStealthChopLowerLimit (const MotorSpec &motor_spec, uint32_t supply_voltage_mv, uint8_t tbl, uint8_t pwm_freq, uint32_t f_clk=12000000U) noexcept
 Calculate StealthChop lower current limit.
 
uint16_t CalculateMaxCurrentForSenseResistor (uint32_t sense_resistor_mohm) noexcept
 Calculate maximum RMS current for a given sense resistor.
 
uint8_t CalculateS2VSLevel (uint16_t voltage_mv) noexcept
 Calculate S2VS_LEVEL register value from voltage threshold.
 
uint8_t CalculateS2GLevel (uint16_t voltage_mv, uint32_t supply_voltage_mv=0) noexcept
 Calculate S2G_LEVEL register value from voltage threshold.
 
uint8_t CalculateShortDelay (uint8_t delay_us_x10) noexcept
 Calculate shortdelay register bit from detection delay time.
 
constexpr float StepsToMm (int32_t steps, float steps_per_rev, float lead_screw_pitch_mm) noexcept
 Convert steps to millimeters.
 
constexpr int32_t MmToSteps (float mm, float steps_per_rev, float lead_screw_pitch_mm) noexcept
 Convert millimeters to steps.
 
constexpr float StepsToDegrees (int32_t steps, float steps_per_rev) noexcept
 Convert steps to degrees.
 
constexpr int32_t DegreesToSteps (float degrees, float steps_per_rev) noexcept
 Convert degrees to steps.
 
constexpr float RpmToStepsPerSec (float rpm, float steps_per_rev) noexcept
 Convert RPM to steps per second.
 
constexpr float StepsPerSecToRpm (float steps_per_sec, float steps_per_rev) noexcept
 Convert steps per second to RPM.
 
constexpr float MmPerSecToStepsPerSec (float mm_per_sec, float steps_per_rev, float lead_screw_pitch_mm) noexcept
 Convert millimeters per second to steps per second.
 
constexpr float StepsPerSecToMmPerSec (float steps_per_sec, float steps_per_rev, float lead_screw_pitch_mm) noexcept
 Convert steps per second to millimeters per second.
 
constexpr float AccelerationMmToSteps (float accel_mm_per_sec2, float steps_per_rev, float lead_screw_pitch_mm) noexcept
 Convert acceleration from mm/s² to steps/s²
 
constexpr float AccelerationStepsToMm (float accel_steps_per_sec2, float steps_per_rev, float lead_screw_pitch_mm) noexcept
 Convert acceleration from steps/s² to mm/s²
 
constexpr int32_t BeltTeethToSteps (uint32_t teeth, float steps_per_rev, uint16_t belt_pulley_teeth) noexcept
 Convert belt drive distance (teeth) to steps.
 
constexpr float StepsToBeltTeeth (int32_t steps, float steps_per_rev, uint16_t belt_pulley_teeth) noexcept
 Convert steps to belt drive distance (teeth)
 
const char * GetDriverVersion () noexcept
 
static constexpr uint8_t calculateCrc8 (const uint8_t *data, size_t length) noexcept
 Calculate CRC8 checksum for UART communication.
 
const char * ErrorMessage (ErrorCode code)
 Get human-readable error message.
 
template<std::size_t N, typename T >
decltype(auto) get (Result< T > &r) noexcept
 Tuple-like access for structured bindings (C++17)
 
template<std::size_t N, typename T >
decltype(auto) get (const Result< T > &r) noexcept
 
template<std::size_t N, typename T >
decltype(auto) get (Result< T > &&r) noexcept
 
template<std::size_t N>
std::enable_if_t< N==0, ErrorCodeget (Result< void > &r) noexcept
 
template<std::size_t N>
std::enable_if_t< N==0, ErrorCodeget (const Result< void > &r) noexcept
 
template<std::size_t N>
std::enable_if_t< N==0, ErrorCodeget (Result< void > &&r) noexcept
 
constexpr const char * ToString (MotorDirection d) noexcept
 Convert MotorDirection to human-readable string.
 
constexpr const char * ToString (MotorType t) noexcept
 Convert MotorType to human-readable string.
 
constexpr const char * ToString (Unit u) noexcept
 Convert Unit to human-readable string.
 
constexpr const char * ToString (MechanicalSystemType type) noexcept
 Convert MechanicalSystemType to human-readable string.
 
constexpr const char * ToString (ChopperMode m) noexcept
 Convert ChopperMode to human-readable string.
 
constexpr const char * ToString (MicrostepResolution mres) noexcept
 Convert MicrostepResolution to human-readable string.
 
constexpr uint16_t MicrostepsPerFullStep (MicrostepResolution mres) noexcept
 Get microsteps-per-full-step for an MRES value.
 
constexpr const char * ToString (MicrostepLutPreset preset) noexcept
 Convert MicrostepLutPreset to human-readable string.
 
constexpr const char * ToString (ReferenceSwitchActiveLevel a) noexcept
 Convert ReferenceSwitchActiveLevel to human-readable string.
 
constexpr const char * ToString (ReferenceLatchMode m) noexcept
 Convert ReferenceLatchMode to human-readable string.
 
constexpr const char * ToString (ReferenceStopMode m) noexcept
 Convert ReferenceStopMode to human-readable string.
 
constexpr const char * ToString (EncoderNSensitivity s) noexcept
 Convert EncoderNSensitivity to human-readable string.
 
constexpr const char * ToString (EncoderClearMode m) noexcept
 Convert EncoderClearMode to human-readable string.
 
constexpr const char * ToString (EncoderPrescalerMode m) noexcept
 Convert EncoderPrescalerMode to human-readable string.
 

Typedef Documentation

◆ ResultVoid

using tmc51x0::ResultVoid = Result<void>

Enumeration Type Documentation

◆ ChipCommMode

enum class tmc51x0::ChipCommMode : uint8_t
strong

Chip communication and motion control mode configuration.

This enumeration represents the combination of SPI_MODE and SD_MODE pins that determine the TMC51x0 operating mode. These pins are typically hardwired and read at startup, but can be controlled via GPIO if connected.

WARNING: Changing the mode requires a chip reset to take effect. The mode pins are read at startup, so any changes must be followed by a reset cycle (power cycle since TMC51x0 has no reset pin).

Note
These modes correspond to the hardware pin configuration:
  • SPI_MODE (pin 22): HIGH=SPI, LOW=UART/Standalone
  • SD_MODE (pin 21): HIGH=External step/dir, LOW=Internal ramp generator
Complete mode mapping:
SD_MODE SPI_MODE Mode Description
LOW (0) HIGH (1) SPI_INTERNAL_RAMP SPI + internal ramp generator (motion controller)
HIGH (1) HIGH (1) SPI_EXTERNAL_STEPDIR SPI + external Step/Dir inputs
LOW (0) LOW (0) UART_INTERNAL_RAMP UART + internal ramp generator (motion controller)
HIGH (1) LOW (0) STANDALONE_EXTERNAL_STEPDIR Standalone Step/Dir (no SPI/UART, CFG pins configure driver)
Enumerator
SPI_INTERNAL_RAMP 

SPI_MODE=HIGH, SD_MODE=LOW - SPI interface with internal ramp generator (motion controller)

SPI_EXTERNAL_STEPDIR 

SPI_MODE=HIGH, SD_MODE=HIGH - SPI interface with external step/dir inputs.

UART_INTERNAL_RAMP 

SPI_MODE=LOW, SD_MODE=LOW - UART interface with internal ramp generator (motion controller)

STANDALONE_EXTERNAL_STEPDIR 

SPI_MODE=LOW, SD_MODE=HIGH - Standalone Step/Dir mode (no SPI/UART, CFG pins configure driver)

◆ ChopperBlankTime

enum class tmc51x0::ChopperBlankTime : uint8_t
strong

Comparator blank time enumeration.

Blank time masks comparator input to block spikes from parasitic capacitances during switching. Longer blank time provides more protection but may limit chopper frequency.

Note
For most applications, TBL_24CLK or TBL_36CLK is good.
For highly capacitive loads (e.g., filter networks), TBL_36CLK or TBL_54CLK may be required.
Enumerator
TBL_16CLK 

16 clock cycles (~1.33µs @ 12MHz)

TBL_24CLK 

24 clock cycles (~2.0µs @ 12MHz)

TBL_36CLK 

36 clock cycles (~3.0µs @ 12MHz, typical)

TBL_54CLK 

54 clock cycles (~4.5µs @ 12MHz, for high capacitive loads)

◆ ChopperMode

enum class tmc51x0::ChopperMode : bool
strong

Chopper mode enumeration.

Selects between SpreadCycle (patented high-performance algorithm) and Classic constant off-time chopper.

Enumerator
SPREAD_CYCLE 

SpreadCycle mode (recommended) - superior microstepping quality.

CLASSIC 

Classic constant off-time mode - alternative chopper algorithm.

◆ CommMode

enum class tmc51x0::CommMode : uint8_t
strong

Supported physical communication modes for TMC51x0.

Enumerator
SPI 

SPI (Serial Peripheral Interface) mode - 4-wire synchronous communication

UART 

UART (Universal Asynchronous Receiver-Transmitter) mode - 2-wire asynchronous communication

◆ CoolStepDecrementSpeed

enum class tmc51x0::CoolStepDecrementSpeed : uint8_t
strong

CoolStep current decrement speed enumeration.

Defines how many StallGuard2 measurements above threshold before decrementing current. Higher values provide slower current reduction, preventing rapid oscillations.

Enumerator
EVERY_32 

Decrement every 32 measurements (slowest reduction, most stable)

EVERY_8 

Decrement every 8 measurements.

EVERY_2 

Decrement every 2 measurements.

EVERY_1 

Decrement every measurement (fastest reduction)

◆ CoolStepIncrementStep

enum class tmc51x0::CoolStepIncrementStep : uint8_t
strong

CoolStep current increment step width enumeration.

Defines how many current steps to increment per StallGuard2 measurement below threshold. Higher values provide faster response to increasing load but may cause oscillations.

Enumerator
STEP_1 

Increment by 1 step per measurement (slowest, smoothest)

STEP_2 

Increment by 2 steps per measurement.

STEP_4 

Increment by 4 steps per measurement.

STEP_8 

Increment by 8 steps per measurement (fastest response)

◆ CoolStepMinCurrent

enum class tmc51x0::CoolStepMinCurrent : uint8_t
strong

CoolStep minimum current percentage enumeration.

Defines the minimum motor current as a percentage of IRUN when CoolStep reduces current.

Enumerator
HALF_IRUN 

Minimum current is 50% of IRUN (1/2)

QUARTER_IRUN 

Minimum current is 25% of IRUN (1/4)

◆ DcStepStallSensitivity

enum class tmc51x0::DcStepStallSensitivity : uint8_t
strong

DcStep stall detection sensitivity enumeration.

Defines the sensitivity of stall detection in DcStep mode. Higher sensitivity detects stalls earlier but may trigger false positives.

Enumerator
DISABLED 

Stall detection disabled (dc_sg = 0)

LOW 

Low sensitivity - fewer false positives (dc_sg ≈ dc_time / 20)

MODERATE 

Moderate sensitivity - balanced (dc_sg ≈ dc_time / 16, recommended)

HIGH 

High sensitivity - detects stalls earlier (dc_sg ≈ dc_time / 12)

◆ DriverStatus

enum class tmc51x0::DriverStatus : uint8_t
strong

Driver status enumeration.

Indicates the current status of the TMC51x0 driver, including error conditions and warnings.

Enumerator
OK 

No error condition.

CP_UV 

Charge pump undervoltage.

S2VSA 

Short to supply phase A.

S2VSB 

Short to supply phase B.

S2GA 

Short to ground phase A.

S2GB 

Short to ground phase B.

OT 

Overtemperature (error)

OTHER_ERR 

GSTAT drv_err is set but none of the above conditions is found.

OTPW 

Overtemperature pre-warning.

◆ EncoderClearMode

enum class tmc51x0::EncoderClearMode : uint8_t
strong

Encoder clear mode enumeration.

Defines when and how the encoder counter is cleared on N channel events.

Enumerator
DISABLED 

No clearing or latching (clr_cont=0, clr_once=0) N channel events are ignored

ONCE 

Latch or latch and clear X_ENC on the next N event only (clr_once=1) Automatically disables after first N event Useful for encoders that give N signal once per revolution

CONTINUOUS 

Always latch or latch and clear X_ENC upon N event (clr_cont=1) Continuously monitors N channel and triggers on every event

◆ EncoderNSensitivity

enum class tmc51x0::EncoderNSensitivity : uint8_t
strong

Encoder N channel sensitivity enumeration.

Defines how the N channel event is detected (level-sensitive or edge-sensitive). Similar to ReferenceLatchMode but specifically for encoder N channel edge detection.

Enumerator
ACTIVE_LEVEL 

N channel event is active during active N level (level-sensitive) Register: pos_edge=0, neg_edge=0

RISING_EDGE 

N channel is valid upon active going edge (positive edge) Register: pos_edge=1, neg_edge=0

FALLING_EDGE 

N channel is valid upon inactive going edge (negative edge) Register: pos_edge=0, neg_edge=1

BOTH_EDGES 

N channel is valid upon both active and inactive going edges Register: pos_edge=1, neg_edge=1

◆ EncoderPrescalerMode

enum class tmc51x0::EncoderPrescalerMode : uint8_t
strong

Encoder prescaler mode enumeration.

Defines the encoder prescaler divisor mode for ENC_CONST calculation.

Enumerator
BINARY 

Binary mode - Counts ENC_CONST(fractional part) / 65536 Standard fixed-point 16.16 format

DECIMAL 

Decimal mode - Counts ENC_CONST(fractional part) / 10000 Decimal representation: FACTOR.DECIMALS (e.g., 25.6 = 0x0019.0x1770)

◆ EncoderSensitivity

enum class tmc51x0::EncoderSensitivity : uint8_t
strong

Encoder N channel sensitivity enumeration values.

Enumerator
NO_EDGE 

N channel active while the N event is valid.

RISING_EDGE 

N channel active when the N event is activated.

FALLING_EDGE 

N channel active when the N event is de-activated.

BOTH_EDGES 

N channel active on N event activation and de-activation.

◆ ErrorCode

enum class tmc51x0::ErrorCode : uint8_t
strong

Error codes for TMC51x0 operations.

Enumerator
OK 

Operation succeeded.

NOT_INITIALIZED 

Driver not initialized.

COMM_ERROR 

Communication interface error (SPI/UART)

INVALID_VALUE 

Invalid parameter value.

INVALID_STATE 

Operation not valid in current state.

TIMEOUT 

Operation timed out.

CANCELLED 

Operation cancelled by user/request.

HARDWARE_ERROR 

Hardware fault detected.

SHORT_CIRCUIT 

Short circuit detected.

OPEN_LOAD 

Open load detected.

OVERTEMP_WARNING 

Overtemperature warning threshold.

OVERTEMP_SHUTDOWN 

Overtemperature shutdown.

UNSUPPORTED 

Feature not supported by this chip variant.

◆ GpioSignal

enum class tmc51x0::GpioSignal : uint8_t
strong

GPIO signal states with board-agnostic naming.

Enumerator
INACTIVE 

Inactive signal state (logical low)

ACTIVE 

Active signal state (logical high)

◆ LogLevel

enum class tmc51x0::LogLevel : uint8_t
strong

Driver-native log levels for debug output.

These are intentionally numeric and stable so platform integrations can map them onto their own logging systems.

Convention:

  • Error (0): Serious failures / incorrect behavior
  • Warn (1): Unexpected but recoverable situations
  • Info (2): High-level informational messages (typical init/runtime logs)
  • Debug (3): Debug details (noisy)
  • Verbose (4): Very noisy trace
Enumerator
Error 
Warn 
Info 
Debug 
Verbose 

◆ MechanicalSystemType

enum class tmc51x0::MechanicalSystemType : uint8_t
strong

Mechanical system type enumeration.

Defines the type of mechanical system connected to the motor.

Enumerator
DirectDrive 

Direct drive (motor shaft directly connected)

LeadScrew 

Lead screw drive.

BeltDrive 

Belt drive with pulleys.

Gearbox 

Gearbox reduction.

◆ MicrostepLutPreset

enum class tmc51x0::MicrostepLutPreset : uint8_t
strong

Microstep lookup table preset waveforms.

Defines preset waveform configurations for the microstep lookup table (MSLUT). The lookup table defines the first quarter of the sine wave (0-90°); the driver mirrors it for the remaining three quarters.

See also
Datasheet Section 18: Microstep Lookup Table
Enumerator
DEFAULT_SINE 

TMC5160 power-on default (slightly modified sine)

Uses the factory default values programmed at reset. This provides a balanced tradeoff between smoothness and torque.

PURE_SINE 

Mathematical pure sine wave.

Provides the smoothest motion with minimal torque ripple. Best for applications where smooth motion is more important than maximum torque.

◆ MicrostepResolution

enum class tmc51x0::MicrostepResolution : uint8_t
strong

Microstep resolution enumeration.

Defines the number of microsteps per full step. Higher resolution provides smoother motion but may reduce maximum velocity.

Note
Interpolation can be enabled to extrapolate to 256 microsteps regardless of MRES setting.
Enumerator
MRES_256 

256 microsteps per full step (highest resolution)

MRES_128 

128 microsteps per full step

MRES_64 

64 microsteps per full step

MRES_32 

32 microsteps per full step

MRES_16 

16 microsteps per full step (typical)

MRES_8 

8 microsteps per full step

MRES_4 

4 microsteps per full step

MRES_2 

2 microsteps per full step

FULLSTEP 

Full step (no microstepping)

◆ MotorDirection

enum class tmc51x0::MotorDirection : uint8_t
strong

Motor direction enumeration.

Enumerator
NORMAL 

Normal motor direction.

INVERSE 

Inverse motor direction.

◆ MotorType

enum class tmc51x0::MotorType : uint8_t
strong

Motor type enumeration.

Defines the type of motor being controlled. This is primarily for documentation and configuration purposes. Direct mode can be used with any motor type.

  • STEPPER: Standard stepper motor (typically uses step/dir or internal ramp generator)
  • DC_MOTOR_SINGLE: Single DC motor (typically uses direct mode, coil A only)
  • DC_MOTOR_DUAL: Two DC motors (typically uses direct mode, coil A and B)
  • SOLENOID_SINGLE: Single solenoid/actuator (typically uses direct mode, coil A only)
  • SOLENOID_DUAL: Two solenoids/actuators (typically uses direct mode, coil A and B)
Note
Direct mode (global_config.direct_mode) can be enabled for any motor type. When enabled, coil currents are controlled directly via XTARGET register instead of using the ramp generator or step/dir inputs. The motor type enum helps document the intended use case but does not automatically configure direct_mode - that must be set explicitly in GlobalConfig.
Enumerator
STEPPER 

Stepper motor (default, typically uses step/dir or internal ramp generator)

DC_MOTOR_SINGLE 

Single DC motor (typically uses direct mode, coil A only)

DC_MOTOR_DUAL 

Two DC motors (typically uses direct mode, coil A and B)

SOLENOID_SINGLE 

Single solenoid/actuator (typically uses direct mode, coil A only)

SOLENOID_DUAL 

Two solenoids/actuators (typically uses direct mode, coil A and B)

◆ OverTempProtection

enum class tmc51x0::OverTempProtection : uint8_t
strong

Over-temperature protection level enumeration.

Selects the over-temperature level for bridge disable. Higher values provide more protection but trigger at lower temperatures.

Note
Based on DRV_CONF register: OTSELECT bits
Enumerator
Temp150C 

150°C threshold (lowest protection, highest temperature)

Temp143C 

143°C threshold

Temp136C 

136°C threshold (more protection)

Temp120C 

120°C threshold (highest protection, lowest temperature)

◆ PWMFreewheel

enum class tmc51x0::PWMFreewheel : uint8_t
strong

PWM freewheel mode enumeration values.

Enumerator
NORMAL 

Normal operation.

ENABLED 

Freewheeling.

SHORT_LS 

Coil shorted using LS drivers.

SHORT_HS 

Coil shorted using HS drivers.

◆ RampMode

enum class tmc51x0::RampMode : uint8_t
strong

Ramp mode enumeration values.

Enumerator
POSITIONING 

Positioning mode using all A, D and V parameters.

VELOCITY_POS 

Positive VMAX, using AMAX acceleration.

VELOCITY_NEG 

Negative VMAX, using AMAX acceleration.

HOLD 

Velocity remains unchanged, unless stop event occurs.

◆ ReferenceLatchMode

enum class tmc51x0::ReferenceLatchMode : uint8_t
strong

Position latching mode enumeration.

Defines when position should be latched (captured) on switch events. Used to simplify latching configuration instead of separate boolean flags.

Enumerator
DISABLED 

No position latching (latch disabled)

ACTIVE_EDGE 

Latch position on active edge (switch becomes active) Most common for homing - captures position when switch triggers

INACTIVE_EDGE 

Latch position on inactive edge (switch becomes inactive) Useful for capturing position when switch releases

BOTH_EDGES 

Latch position on both active and inactive edges Captures position on both switch activation and release

◆ ReferenceStopMode

enum class tmc51x0::ReferenceStopMode : uint8_t
strong

Stop mode enumeration.

Defines how the motor stops when a reference switch is triggered.

Enumerator
HARD_STOP 

Abrupt stop (immediate, no deceleration) Use for emergency stops and precise homing Motor stops exactly at switch position

SOFT_STOP 

Soft stop using deceleration ramp (DMAX, V1, D1) Use for normal operation to prevent mechanical shock Motor decelerates smoothly to zero velocity

◆ ReferenceSwitchActiveLevel

enum class tmc51x0::ReferenceSwitchActiveLevel : uint8_t
strong

Reference switch active level enumeration.

Defines the electrical signal level when the switch is active/triggered. Used to automatically configure polarity for proper switch detection.

Note
Active level must always be specified (ACTIVE_LOW or ACTIVE_HIGH). Use stop_enable to control whether the switch stops the motor. This allows configuring polarity while enabling/disabling stop functionality in real-time.
Enumerator
ACTIVE_LOW 

Switch is active when signal is LOW (GND) Typically used with pull-up resistors (switch connects to GND when active) Common for normally-closed switches and failsafe configurations Recommended for safety-critical applications (broken wire = HIGH = not active = safe)

ACTIVE_HIGH 

Switch is active when signal is HIGH (VCC) Typically used with pull-down resistors (switch connects to VCC when active) Common for normally-open switches and photo interrupters

◆ SenseFilterTime

enum class tmc51x0::SenseFilterTime : uint8_t
strong

Sense amplifier filter time constant enumeration.

Filter time constant of sense amplifier to suppress ringing and coupling from second coil operation. Increase setting if motor chopper noise occurs due to cross-coupling of both coils.

Enumerator
T100ns 

~100ns (reset default)

T200ns 

~200ns

T300ns 

~300ns

T400ns 

~400ns

◆ StallGuardSensitivity

enum class tmc51x0::StallGuardSensitivity : int8_t
strong

StallGuard2 sensitivity enumeration.

Provides intuitive sensitivity levels for StallGuard2 threshold tuning. Lower SGT values = higher sensitivity (detects stalls easier, more false positives). Higher SGT values = lower sensitivity (requires more torque to detect stall, fewer false positives).

Enumerator
VERY_HIGH 

Very high sensitivity (SGT = -32) - detects stalls very easily.

HIGH 

High sensitivity (SGT = -16) - detects stalls easily.

MODERATE 

Moderate sensitivity (SGT = 0) - starting value, works with most motors.

LOW 

Low sensitivity (SGT = 16) - requires more torque to detect stall.

VERY_LOW 

Very low sensitivity (SGT = 32) - requires significant torque to detect stall.

◆ StealthChopJerkReduction

enum class tmc51x0::StealthChopJerkReduction : uint8_t
strong

StealthChop mode switching jerk reduction enumeration.

Controls current jerk reduction when switching from SpreadCycle to StealthChop. Lower values reduce current spike during mode switching (smoother). Higher values allow faster switching but may cause more current jerk.

Note
Only affects switching from SpreadCycle to StealthChop.
Reduce value if experiencing current spikes during mode switching.
Enumerator
MAXIMUM 

Maximum jerk reduction (smoothest switching)

HIGH 

High jerk reduction.

MODERATE 

Moderate jerk reduction (default, balanced)

LOW 

Low jerk reduction.

MINIMUM 

Minimum jerk reduction (fastest switching, may cause spikes)

◆ StealthChopPwmFreq

enum class tmc51x0::StealthChopPwmFreq : uint8_t
strong

StealthChop PWM frequency enumeration.

Provides PWM frequency selection options for StealthChop operation. Lower frequencies reduce current ripple but may limit high-velocity performance. Higher frequencies improve high-velocity performance but increase dynamic power dissipation.

Recommended range: 20-50kHz for most applications.

Note
Actual frequency depends on clock frequency (f_CLK).
For 12MHz internal clock:
  • PWM_FREQ_0: ~23.4kHz
  • PWM_FREQ_1: ~35.1kHz (recommended)
  • PWM_FREQ_2: ~46.9kHz
  • PWM_FREQ_3: ~58.5kHz
Enumerator
PWM_FREQ_0 

fPWM = 2/1024 * fCLK (~23.4kHz @ 12MHz)

PWM_FREQ_1 

fPWM = 2/683 * fCLK (~35.1kHz @ 12MHz, recommended)

PWM_FREQ_2 

fPWM = 2/512 * fCLK (~46.9kHz @ 12MHz)

PWM_FREQ_3 

fPWM = 2/410 * fCLK (~58.5kHz @ 12MHz)

◆ StealthChopRegulationSpeed

enum class tmc51x0::StealthChopRegulationSpeed : uint8_t
strong

StealthChop regulation speed enumeration.

Controls how fast the PWM amplitude regulation loop adapts to changes. Specifies maximum PWM amplitude change per half wave when using automatic scaling.

Lower values provide stable, soft regulation (slower response). Higher values provide faster adaptation but may be less stable.

Note
Optimize for fastest required acceleration/deceleration ramp.
Higher acceleration during AT#2 requires higher regulation speed.
Enumerator
VERY_SLOW 

0.5 increments per half wave (slowest, most stable)

SLOW 

1 increment per half wave

MODERATE 

2 increments per half wave (default, balanced)

FAST 

4 increments per half wave

VERY_FAST 

7.5 increments per half wave (fastest, may be less stable)

◆ TMC51x0CtrlPin

enum class tmc51x0::TMC51x0CtrlPin : uint8_t
strong

TMC51x0 control pin identifiers with board-agnostic naming.

These pin identifiers abstract the physical pin assignments to provide a consistent interface regardless of board implementation.

Pin functions depend on mode configuration (SPI_MODE, SD_MODE):

  • SPI_MODE=1, SD_MODE=0: Internal ramp generator mode (motion controller)
    • REFL_STEP, REFR_DIR: Reference switch inputs
    • ENCA, ENCB, ENCN: Encoder inputs
    • DIAG0, DIAG1: Diagnostic outputs
  • SPI_MODE=1, SD_MODE=1: External step/dir mode
    • REFL_STEP, REFR_DIR: STEP/DIR inputs (same physical pins)
    • DCEN, DCIN, DCO: DC Step control pins (same physical pins as ENCB, ENCA, ENCN)
    • DIAG0, DIAG1: Diagnostic outputs
  • SPI_MODE=0, SD_MODE=0: UART single wire interface mode
    • DIAG1_SWP (pin 27): Single wire I/O (positive) - Use SWP alone for single wire UART
    • DIAG0_SWN (pin 26): Single wire I/O (negative) - Use SWP+SWN for RS485 differential bus
    • SDI_CFG1 (pin 15): Next address input (NAI) for sequential addressing
    • SDO_CFG0 (pin 16): Next address output (NAO) for sequential addressing
    • CSN_CFG3, SCK_CFG2, ENCB_CFG4, ENCA_CFG5: Configuration inputs (CFG functions)
    • Other pins: Not used for communication in UART mode
Note
Some pins have multiple functions depending on mode. See datasheet section 2.2 for complete pin function descriptions.
Enumerator
EN 

Enable pin (DRV_ENN, pin 28) - Active HIGH disables power stage.

DIR 

Direction pin (REFR_DIR, pin 18) - DIR input when SD_MODE=1, Right reference when SD_MODE=0

STEP 

Step pin (REFL_STEP, pin 17) - STEP input when SD_MODE=1, Left reference when SD_MODE=0

REFL_STEP 

Left reference switch input (REFL_STEP, pin 17) - Used when SD_MODE=0

REFR_DIR 

Right reference switch input (REFR_DIR, pin 18) - Used when SD_MODE=0

DIAG0 

Diagnostic output 0 (DIAG0_SWN, pin 26) - Interrupt/STEP output when SD_MODE=0, SPI_MODE=1. Single wire I/O (negative) when SD_MODE=0, SPI_MODE=0 (UART mode). Use with DIAG1_SWP for RS485 bus.

DIAG1 

Diagnostic output 1 (DIAG1_SWP, pin 27) - Position-compare/DIR output when SD_MODE=0, SPI_MODE=1. Single wire I/O (positive) when SD_MODE=0, SPI_MODE=0 (UART mode). Use alone for single wire UART.

ENCA 

Encoder A-channel input (ENCA_DCIN_CFG5, pin 24) - Used when SD_MODE=0

ENCB 

Encoder B-channel input (ENCB_DCEN_CFG4, pin 23) - Used when SD_MODE=0

ENCN 

Encoder N-channel input (ENCN_DCO_CFG6, pin 25) - Used when SD_MODE=0

DCEN 

DC Step enable input (ENCB_DCEN_CFG4, pin 23) - Used when SD_MODE=1, SPI_MODE=1

DCIN 

DC Step gating input (ENCA_DCIN_CFG5, pin 24) - Used when SD_MODE=1, SPI_MODE=1

DCO 

DC Step ready output (ENCN_DCO_CFG6, pin 25) - Used when SD_MODE=1, SPI_MODE=1

CLK 

Clock input (CLK, pin 12) - External clock input (tie to GND for internal clock)

SPI_MODE 

SPI/UART mode select (pin 22) - HIGH=SPI, LOW=UART. Typically hardwired.

SD_MODE 

Step/Dir mode select (pin 21) - HIGH=External step/dir, LOW=Internal ramp. Typically hardwired.

◆ UartFrameType

enum class tmc51x0::UartFrameType : uint8_t
strong

TMC5160 UART frame types.

Enumerator
WriteAccess 

Write access datagram (8 bytes: 7 bytes + CRC)

ReadRequest 

Read access request datagram (4 bytes: 3 bytes + CRC)

ReadReply 

Read access reply datagram (8 bytes: 7 bytes + CRC)

◆ Unit

enum class tmc51x0::Unit : uint8_t
strong

Unit enumeration.

Defines the unit of measurement for position, velocity, and acceleration. Steps:

  • For float APIs (e.g. SetTargetPosition(float, Unit) / SetMaxSpeed(float, Unit)), Unit::Steps is treated as motor full-steps for convenience.
  • The TMC51x0 motion-controller position registers (XACTUAL/XTARGET/...) use microsteps internally. The driver converts full-steps ↔ microsteps using the current microstep resolution.
  • For raw register units, use the APIs that accept int32_t positions (these are microsteps). Rad: Radians (per second for velocity, per second^2 for accel) Deg: Degrees (per second for velocity, per second^2 for accel) Mm: Millimeters (linear only) RPM: Revolutions per Minute (Velocity only, typically) RevPerSec: Revolutions per Second (recommended default for velocity)
Enumerator
Steps 

Steps (see notes above; float APIs treat this as full-steps, register units are microsteps)

Rad 

Radians (per second for velocity, per second^2 for accel)

Deg 

Degrees (per second for velocity, per second^2 for accel)

Mm 

Millimeters (linear only)

RPM 

Revolutions per Minute (Velocity only, typically)

RevPerSec 

Revolutions per Second (recommended default for velocity)

Function Documentation

◆ AccelerationMmToSteps()

constexpr float tmc51x0::AccelerationMmToSteps ( float accel_mm_per_sec2,
float steps_per_rev,
float lead_screw_pitch_mm )
constexprnoexcept

Convert acceleration from mm/s² to steps/s²

Parameters
accel_mm_per_sec2Acceleration in millimeters per second squared
steps_per_revSteps per revolution of the motor
lead_screw_pitch_mmLead screw pitch in millimeters
Returns
Acceleration in steps per second squared

◆ AccelerationStepsToMm()

constexpr float tmc51x0::AccelerationStepsToMm ( float accel_steps_per_sec2,
float steps_per_rev,
float lead_screw_pitch_mm )
constexprnoexcept

Convert acceleration from steps/s² to mm/s²

Parameters
accel_steps_per_sec2Acceleration in steps per second squared
steps_per_revSteps per revolution of the motor
lead_screw_pitch_mmLead screw pitch in millimeters
Returns
Acceleration in millimeters per second squared

◆ BeltTeethToSteps()

constexpr int32_t tmc51x0::BeltTeethToSteps ( uint32_t teeth,
float steps_per_rev,
uint16_t belt_pulley_teeth )
constexprnoexcept

Convert belt drive distance (teeth) to steps.

Parameters
teethNumber of belt teeth
steps_per_revSteps per revolution of the motor
belt_pulley_teethNumber of teeth on the motor pulley
Returns
Number of steps

◆ calculateCrc8()

static constexpr uint8_t tmc51x0::calculateCrc8 ( const uint8_t * data,
size_t length )
staticconstexprnoexcept

Calculate CRC8 checksum for UART communication.

TMC5160 uses CRC8-ATM polynomial (x^8 + x^2 + x^1 + x^0 = 0x07) with initial value of zero. The CRC is applied LSB to MSB, including the sync- and addressing byte. The sync nibble is assumed to always be correct.

Algorithm per datasheet section 5.2: CRC = (CRC << 1) OR (CRC.7 XOR CRC.1 XOR CRC.0 XOR [new incoming bit])

Parameters
dataPointer to the data bytes to checksum
lengthNumber of bytes to include in the checksum calculation
Returns
8-bit CRC8 checksum value
Here is the caller graph for this function:

◆ CalculateMaxCurrentForSenseResistor()

uint16_t tmc51x0::CalculateMaxCurrentForSenseResistor ( uint32_t sense_resistor_mohm)
inlinenoexcept

Calculate maximum RMS current for a given sense resistor.

Parameters
sense_resistor_mohmSense resistor value in milliohms
Returns
Maximum RMS current in milliamps at full scale (GLOBAL_SCALER=256, CS=31)

◆ CalculateMotorCurrent()

bool tmc51x0::CalculateMotorCurrent ( const MotorSpec & motor_spec,
uint32_t sense_resistor_mohm,
uint32_t supply_voltage_mv,
uint16_t run_current_ma,
uint16_t hold_current_ma,
uint8_t & irun,
uint8_t & ihold,
uint16_t & global_scaler )
inlinenoexcept

Calculate motor current settings from physical parameters.

Calculates IRUN, IHOLD, and GLOBAL_SCALER based on:

  • Desired run current (typically motor rated current)
  • Sense resistor value
  • Supply voltage (for StealthChop lower limit calculation)
  • Motor winding resistance (for StealthChop lower limit)
Parameters
motor_specMotor specifications including rated current, resistance, etc.
sense_resistor_mohmSense resistor value in milliohms (e.g., 50 for 0.05Ω)
supply_voltage_mvSupply voltage in millivolts (e.g., 24000 for 24V)
run_current_maDesired run current in milliamps (default: motor rated current)
hold_current_maDesired hold current in milliamps (default: 30% of run current)
irunReference to store calculated IRUN value (0-31)
iholdReference to store calculated IHOLD value (0-31)
global_scalerReference to store calculated GLOBAL_SCALER value (32-256)
Returns
true if calculation successful, false if parameters invalid
Note
Based on datasheet equation: I_RMS = (GLOBAL_SCALER/256) * ((CS+1)/32) * (VFS/RSENSE) * (1/√2) Where VFS ≈ 325mV (0.325V, typical full-scale voltage) Calculations work directly in milliohms, millivolts, and milliamps
For best precision, IRUN will be constrained to 16-31 range
For automatic tuning compatibility, IRUN will be at least 8

◆ CalculateS2GLevel()

uint8_t tmc51x0::CalculateS2GLevel ( uint16_t voltage_mv,
uint32_t supply_voltage_mv = 0 )
inlinenoexcept

Calculate S2G_LEVEL register value from voltage threshold.

Converts user-friendly voltage threshold (mV) to S2G_LEVEL register value (2-15). Uses datasheet typical values for interpolation.

Parameters
voltage_mvVoltage threshold in millivolts (0 = auto-calculate to 625mV)
supply_voltage_mvSupply voltage in millivolts (for VS-dependent calculation)
Returns
S2G_LEVEL register value (2-15), or 0 if voltage out of range

Datasheet typical values (VS-dependent):

  • S2G_LEVEL=6 (VS<50V): 625mV
  • S2G_LEVEL=15 (VS<52V): 1560mV
  • S2G_LEVEL=15 (VS<55V): 850mV (minimum to prevent false triggers)
Note
For VS>52V, minimum recommended is 1200mV (S2G_LEVEL=12)

◆ CalculateS2VSLevel()

uint8_t tmc51x0::CalculateS2VSLevel ( uint16_t voltage_mv)
inlinenoexcept

Calculate S2VS_LEVEL register value from voltage threshold.

Converts user-friendly voltage threshold (mV) to S2VS_LEVEL register value (4-15). Uses datasheet typical values for interpolation.

Parameters
voltage_mvVoltage threshold in millivolts (0 = auto-calculate to 625mV)
Returns
S2VS_LEVEL register value (4-15), or 0 if voltage out of range

Datasheet typical values:

  • S2VS_LEVEL=6: 625mV
  • S2VS_LEVEL=15: 1560mV
Note
Linear interpolation between known points

◆ CalculateShortDelay()

uint8_t tmc51x0::CalculateShortDelay ( uint8_t delay_us_x10)
inlinenoexcept

Calculate shortdelay register bit from detection delay time.

Converts user-friendly delay time (µs in 0.1µs units) to shortdelay register bit (0-1).

Parameters
delay_us_x10Detection delay in 0.1µs units (0 = auto-calculate to 8.5 = 0.85µs)
Returns
shortdelay register bit (0 or 1), or 0 if delay out of range

Datasheet timing (typical values):

  • shortdelay=0: 0.5-0.85-1.1µs (normal)
  • shortdelay=1: 1.1-1.6-2.2µs (high delay)
Note
Threshold at ~1.0µs: below uses shortdelay=0, above uses shortdelay=1

◆ CalculateStealthChopLowerLimit()

uint16_t tmc51x0::CalculateStealthChopLowerLimit ( const MotorSpec & motor_spec,
uint32_t supply_voltage_mv,
uint8_t tbl,
uint8_t pwm_freq,
uint32_t f_clk = 12000000U )
inlinenoexcept

Calculate StealthChop lower current limit.

Calculates the minimum motor current that can be regulated in StealthChop mode based on blank time, PWM frequency, supply voltage, and motor resistance.

Parameters
motor_specMotor specifications including winding resistance
supply_voltage_mvSupply voltage in millivolts
tblBlank time setting (0-3, corresponds to 16, 24, 36, 54 clock cycles)
pwm_freqPWM frequency setting (0-3)
f_clkClock frequency in Hz (default: 12 MHz)
Returns
Lower current limit in milliamps, or 0 if calculation not possible
Note
Based on datasheet equation: I_Lower_Limit = t_BLANK * f_PWM * V_M / R_COIL Where t_BLANK depends on TBL setting

◆ DegreesToSteps()

constexpr int32_t tmc51x0::DegreesToSteps ( float degrees,
float steps_per_rev )
constexprnoexcept

Convert degrees to steps.

Parameters
degreesAngle in degrees
steps_per_revSteps per revolution of the motor
Returns
Number of steps

◆ ErrorMessage()

const char * tmc51x0::ErrorMessage ( ErrorCode code)
inline

Get human-readable error message.

Parameters
codeError code
Returns
Error message string
Here is the caller graph for this function:

◆ get() [1/6]

template<std::size_t N, typename T >
decltype(auto) tmc51x0::get ( const Result< T > & r)
noexcept

◆ get() [2/6]

template<std::size_t N>
std::enable_if_t< N==0, ErrorCode > tmc51x0::get ( const Result< void > & r)
noexcept
Here is the call graph for this function:

◆ get() [3/6]

template<std::size_t N, typename T >
decltype(auto) tmc51x0::get ( Result< T > && r)
noexcept

◆ get() [4/6]

template<std::size_t N, typename T >
decltype(auto) tmc51x0::get ( Result< T > & r)
noexcept

Tuple-like access for structured bindings (C++17)

Structured bindings use unqualified get<N>(obj) found via ADL for tuple-like types. These overloads make auto [err, value] = result; work reliably.

◆ get() [5/6]

template<std::size_t N>
std::enable_if_t< N==0, ErrorCode > tmc51x0::get ( Result< void > && r)
noexcept
Here is the call graph for this function:

◆ get() [6/6]

template<std::size_t N>
std::enable_if_t< N==0, ErrorCode > tmc51x0::get ( Result< void > & r)
noexcept
Here is the call graph for this function:

◆ GetDriverVersion()

const char * tmc51x0::GetDriverVersion ( )
inlinenoexcept
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetRegisterDef()

const char * tmc51x0::GetRegisterDef ( uint8_t address)

◆ MicrostepsPerFullStep()

constexpr uint16_t tmc51x0::MicrostepsPerFullStep ( MicrostepResolution mres)
inlineconstexprnoexcept

Get microsteps-per-full-step for an MRES value.

Note
Encoded: 0=256 ... 8=1 (fullstep). Values outside [0,8] are clamped.

◆ MmPerSecToStepsPerSec()

constexpr float tmc51x0::MmPerSecToStepsPerSec ( float mm_per_sec,
float steps_per_rev,
float lead_screw_pitch_mm )
constexprnoexcept

Convert millimeters per second to steps per second.

Parameters
mm_per_secSpeed in millimeters per second
steps_per_revSteps per revolution of the motor
lead_screw_pitch_mmLead screw pitch in millimeters
Returns
Speed in steps per second

◆ MmToSteps()

constexpr int32_t tmc51x0::MmToSteps ( float mm,
float steps_per_rev,
float lead_screw_pitch_mm )
constexprnoexcept

Convert millimeters to steps.

Parameters
mmDistance in millimeters
steps_per_revSteps per revolution of the motor
lead_screw_pitch_mmLead screw pitch in millimeters
Returns
Number of steps
Here is the caller graph for this function:

◆ RpmToStepsPerSec()

constexpr float tmc51x0::RpmToStepsPerSec ( float rpm,
float steps_per_rev )
constexprnoexcept

Convert RPM to steps per second.

Parameters
rpmRevolutions per minute
steps_per_revSteps per revolution of the motor
Returns
Speed in steps per second
Here is the caller graph for this function:

◆ StepsPerSecToMmPerSec()

constexpr float tmc51x0::StepsPerSecToMmPerSec ( float steps_per_sec,
float steps_per_rev,
float lead_screw_pitch_mm )
constexprnoexcept

Convert steps per second to millimeters per second.

Parameters
steps_per_secSpeed in steps per second
steps_per_revSteps per revolution of the motor
lead_screw_pitch_mmLead screw pitch in millimeters
Returns
Speed in millimeters per second

◆ StepsPerSecToRpm()

constexpr float tmc51x0::StepsPerSecToRpm ( float steps_per_sec,
float steps_per_rev )
constexprnoexcept

Convert steps per second to RPM.

Parameters
steps_per_secSpeed in steps per second
steps_per_revSteps per revolution of the motor
Returns
Speed in RPM

◆ StepsToBeltTeeth()

constexpr float tmc51x0::StepsToBeltTeeth ( int32_t steps,
float steps_per_rev,
uint16_t belt_pulley_teeth )
constexprnoexcept

Convert steps to belt drive distance (teeth)

Parameters
stepsNumber of steps
steps_per_revSteps per revolution of the motor
belt_pulley_teethNumber of teeth on the motor pulley
Returns
Number of belt teeth

◆ StepsToDegrees()

constexpr float tmc51x0::StepsToDegrees ( int32_t steps,
float steps_per_rev )
constexprnoexcept

Convert steps to degrees.

Parameters
stepsNumber of steps
steps_per_revSteps per revolution of the motor
Returns
Angle in degrees

◆ StepsToMm()

constexpr float tmc51x0::StepsToMm ( int32_t steps,
float steps_per_rev,
float lead_screw_pitch_mm )
constexprnoexcept

Convert steps to millimeters.

Parameters
stepsNumber of steps
steps_per_revSteps per revolution of the motor
lead_screw_pitch_mmLead screw pitch in millimeters (for lead screws)
Returns
Distance in millimeters

For lead screws: distance = (steps / steps_per_rev) * lead_screw_pitch_mm

◆ ToString() [1/13]

constexpr const char * tmc51x0::ToString ( ChopperMode m)
inlineconstexprnoexcept

Convert ChopperMode to human-readable string.

◆ ToString() [2/13]

constexpr const char * tmc51x0::ToString ( EncoderClearMode m)
inlineconstexprnoexcept

Convert EncoderClearMode to human-readable string.

◆ ToString() [3/13]

constexpr const char * tmc51x0::ToString ( EncoderNSensitivity s)
inlineconstexprnoexcept

Convert EncoderNSensitivity to human-readable string.

◆ ToString() [4/13]

constexpr const char * tmc51x0::ToString ( EncoderPrescalerMode m)
inlineconstexprnoexcept

Convert EncoderPrescalerMode to human-readable string.

◆ ToString() [5/13]

constexpr const char * tmc51x0::ToString ( MechanicalSystemType type)
inlineconstexprnoexcept

Convert MechanicalSystemType to human-readable string.

◆ ToString() [6/13]

constexpr const char * tmc51x0::ToString ( MicrostepLutPreset preset)
inlineconstexprnoexcept

Convert MicrostepLutPreset to human-readable string.

◆ ToString() [7/13]

constexpr const char * tmc51x0::ToString ( MicrostepResolution mres)
inlineconstexprnoexcept

Convert MicrostepResolution to human-readable string.

◆ ToString() [8/13]

constexpr const char * tmc51x0::ToString ( MotorDirection d)
inlineconstexprnoexcept

Convert MotorDirection to human-readable string.

◆ ToString() [9/13]

constexpr const char * tmc51x0::ToString ( MotorType t)
inlineconstexprnoexcept

Convert MotorType to human-readable string.

◆ ToString() [10/13]

constexpr const char * tmc51x0::ToString ( ReferenceLatchMode m)
inlineconstexprnoexcept

Convert ReferenceLatchMode to human-readable string.

◆ ToString() [11/13]

constexpr const char * tmc51x0::ToString ( ReferenceStopMode m)
inlineconstexprnoexcept

Convert ReferenceStopMode to human-readable string.

◆ ToString() [12/13]

constexpr const char * tmc51x0::ToString ( ReferenceSwitchActiveLevel a)
inlineconstexprnoexcept

Convert ReferenceSwitchActiveLevel to human-readable string.

◆ ToString() [13/13]

constexpr const char * tmc51x0::ToString ( Unit u)
inlineconstexprnoexcept

Convert Unit to human-readable string.