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

Chopper configuration structure. More...

#include <tmc51x0_types.hpp>

Public Member Functions

 ChopperConfig ()=default
 Default constructor.
 
 ChopperConfig (uint8_t off_time, uint8_t blank_time=2, uint8_t hysteresis_start=4, uint8_t hysteresis_end=0, MicrostepResolution microstep_res=MicrostepResolution::MRES_256)
 Helper constructor for SpreadCycle mode.
 
 ChopperConfig (uint8_t off_time, uint8_t fast_decay_time, uint8_t sine_offset, uint8_t blank_time=2, bool disable_comparator=false, MicrostepResolution microstep_res=MicrostepResolution::MRES_16)
 Helper constructor for Classic mode.
 

Public Attributes

ChopperMode mode {ChopperMode::SPREAD_CYCLE}
 Chopper mode selection.
 
uint8_t toff {5}
 Off time (slow decay time) setting.
 
uint8_t tbl {2}
 Comparator blank time.
 
uint8_t hstrt {4}
 Hysteresis start value (SpreadCycle mode only)
 
uint8_t hend {0}
 Hysteresis end value (SpreadCycle mode) or Sine wave offset (Classic mode)
 
uint8_t tfd {0}
 Fast decay time (Classic mode only)
 
bool disfdcc {false}
 Disable fast decay comparator (Classic mode only)
 
uint8_t tpfd {0}
 Passive fast decay time.
 
MicrostepResolution mres {MicrostepResolution::MRES_256}
 Microstep resolution.
 
bool intpol {true}
 Enable interpolation to 256 microsteps.
 
bool dedge {false}
 Enable double edge step pulses.
 
bool vhighfs {false}
 High velocity fullstep selection.
 
bool vhighchm {false}
 High velocity chopper mode.
 
bool diss2g {false}
 Short to GND protection disable.
 
bool diss2vs {false}
 Short to supply protection disable.
 

Detailed Description

Chopper configuration structure.

User-friendly configuration for SpreadCycle and Classic chopper modes. SpreadCycle is a cycle-by-cycle current control providing superior microstepping quality. Classic mode is an alternative constant off-time chopper algorithm.

The chopper frequency is an important parameter. Most motors work optimally in 16-30kHz range. Frequency is influenced by TOFF, TBL, hysteresis settings, motor inductance, and supply voltage.

Note
TOFF=0 completely disables all driver transistors (motor can free-wheel).
For StealthChop operation, TOFF is required to enable motor but not used for chopping.
TOFF=1 requires TBL ≥ 2.
SpreadCycle mode (recommended) provides superior microstepping quality with default settings.
See also
Datasheet section 8: SpreadCycle and Classic Chopper

Constructor & Destructor Documentation

◆ ChopperConfig() [1/3]

tmc51x0::ChopperConfig::ChopperConfig ( )
default

Default constructor.

Initializes with recommended default values for SpreadCycle mode:

  • mode: SPREAD_CYCLE (recommended)
  • toff: 5 (typical for 16-30kHz chopper frequency)
  • tbl: 2 (36 clocks, typical)
  • hstrt: 4 (effective hysteresis = 4)
  • hend: 0 (effective end = -3)
  • mres: MRES_256 (256 microsteps)
  • intpol: true (enable interpolation)

◆ ChopperConfig() [2/3]

tmc51x0::ChopperConfig::ChopperConfig ( uint8_t off_time,
uint8_t blank_time = 2,
uint8_t hysteresis_start = 4,
uint8_t hysteresis_end = 0,
MicrostepResolution microstep_res = MicrostepResolution::MRES_256 )
inline

Helper constructor for SpreadCycle mode.

Creates a SpreadCycle configuration with typical settings.

Parameters
off_timeOff time setting (0=disabled, 1-15, 5=typical)
blank_timeBlank time (ChopperBlankTime enum or 0-3, TBL_36CLK=typical)
hysteresis_startHysteresis start (0-7, 4=typical)
hysteresis_endHysteresis end (0-15 encoded, 0=typical)
microstep_resMicrostep resolution (MicrostepResolution enum, MRES_256=typical)

◆ ChopperConfig() [3/3]

tmc51x0::ChopperConfig::ChopperConfig ( uint8_t off_time,
uint8_t fast_decay_time,
uint8_t sine_offset,
uint8_t blank_time = 2,
bool disable_comparator = false,
MicrostepResolution microstep_res = MicrostepResolution::MRES_16 )
inline

Helper constructor for Classic mode.

Creates a Classic constant off-time chopper configuration.

Parameters
off_timeOff time setting (0=disabled, 1-15, 5=typical)
fast_decay_timeFast decay time (0-15, similar to off_time)
sine_offsetSine wave offset (0-15 encoded, 4-6=typical positive offset)
blank_timeBlank time (ChopperBlankTime enum or 0-3, TBL_36CLK=typical)
disable_comparatorDisable fast decay comparator (false=enable, true=time only)
microstep_resMicrostep resolution (MicrostepResolution enum, MRES_16=typical)

Member Data Documentation

◆ dedge

bool tmc51x0::ChopperConfig::dedge {false}

Enable double edge step pulses.

Enables step impulse at each step edge (both rising and falling).

  • false: Normal step pulses (single edge)
  • true: Double edge step pulses
Note
Typically not needed for most applications. Enable double edge step pulses (typically false)

◆ disfdcc

bool tmc51x0::ChopperConfig::disfdcc {false}

Disable fast decay comparator (Classic mode only)

Controls whether current comparator can terminate fast decay cycle.

  • false: Enable comparator termination (fast decay ends when current reaches higher negative value)
  • true: End fast decay by time only (fixed duration)
Note
Only used in Classic mode (chm=1).
In SpreadCycle mode, this field is not used. Disable fast decay comparator (Classic mode only)

◆ diss2g

bool tmc51x0::ChopperConfig::diss2g {false}

Short to GND protection disable.

Controls whether short to GND protection is enabled.

  • false: Short to GND protection is ON (recommended)
  • true: Short to GND protection is DISABLED (use with caution)
Note
Protection is configured via SHORT_CONF register (s2g_level).
This bit only disables the protection feature entirely.
Bit 30 in CHOPCONF register.
Warning
Disabling protection can lead to driver damage in case of faults. Short to GND protection disable (false=protection ON, true=protection OFF)

◆ diss2vs

bool tmc51x0::ChopperConfig::diss2vs {false}

Short to supply protection disable.

Controls whether short to VS (supply) protection is enabled.

  • false: Short to VS protection is ON (recommended)
  • true: Short to VS protection is DISABLED (use with caution)
Note
Protection is configured via SHORT_CONF register (s2vs_level).
This bit only disables the protection feature entirely.
Bit 31 in CHOPCONF register.
Warning
Disabling protection can lead to driver damage in case of faults. Short to supply protection disable (false=protection ON, true=protection OFF)

◆ hend

uint8_t tmc51x0::ChopperConfig::hend {0}

Hysteresis end value (SpreadCycle mode) or Sine wave offset (Classic mode)

SpreadCycle mode (chm=0): Hysteresis end value after decrements.

  • Encoded: 0-2 = negative (-3 to -1), 3 = zero, 4-15 = positive (1 to 12)
  • Effective hysteresis = HSTRT + HEND (with encoding)
  • Typical: 0 (effective end = -3, start = HSTRT+1-3 = HSTRT-2)

Classic mode (chm=1): Sine wave offset for zero crossing correction.

  • Encoded: 0-2 = negative (-3 to -1), 3 = zero, 4-15 = positive (1 to 12)
  • Positive offset corrects for zero crossing error (typically required)
  • Typical: 4-6 (positive offset 1-3) for smoothest operation
Note
Sum HSTRT+HEND must be ≤16 for SpreadCycle (at CS ≤ 30).
HSTRT=0 and HEND=0 disables hysteresis (not recommended). Hysteresis end (SpreadCycle) or offset (Classic), encoded 0-15

◆ hstrt

uint8_t tmc51x0::ChopperConfig::hstrt {4}

Hysteresis start value (SpreadCycle mode only)

Adds to hysteresis end value to create effective hysteresis start. Forces minimum current ripple into motor coils for best microstepping results.

Range: 0-7 (adds 1-8 to HEND)

  • Lower values: Less current ripple (may reduce microstep accuracy)
  • Higher values: More current ripple (may increase chopper noise)
  • Typical: 4 (effective hysteresis = 4 when HEND=0)

Effective hysteresis = HSTRT + HEND (with encoding)

Note
Only used in SpreadCycle mode (chm=0).
In Classic mode, this field controls fast decay time (TFD) instead.
Too low: Reduced microstep accuracy, humming/vibration at medium velocities.
Too high: Reduced chopper frequency, increased noise, no benefit.
Start from low setting (HSTRT=0, HEND=0) and increase until motor runs smoothly. Hysteresis start (0-7, adds 1-8 to HEND, 4=typical)

◆ intpol

bool tmc51x0::ChopperConfig::intpol {true}

Enable interpolation to 256 microsteps.

Extrapolates MRES setting to 256 microsteps for smoother motion.

  • true (recommended): Enable interpolation (smoother motion)
  • false: Use native MRES resolution only
Note
Interpolation works regardless of MRES setting.
Recommended for best microstepping quality. Enable interpolation to 256 microsteps (recommended)

◆ mode

ChopperMode tmc51x0::ChopperConfig::mode {ChopperMode::SPREAD_CYCLE}

Chopper mode selection.

  • SPREAD_CYCLE (recommended): Patented high-performance algorithm with superior microstepping quality. Automatically determines optimum fast-decay phase length. Provides best results with default settings.
  • CLASSIC: Constant off-time chopper mode. Alternative algorithm, requires more tuning.
Note
SpreadCycle cycles: on → slow decay → fast decay → slow decay
Classic cycles: on → fast decay → slow decay Chopper mode (SPREAD_CYCLE recommended)

◆ mres

MicrostepResolution tmc51x0::ChopperConfig::mres {MicrostepResolution::MRES_256}

Microstep resolution.

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

Uses MicrostepResolution enum for type safety.

Typical: MRES_256 (256 microsteps) for balanced performance.

Note
Interpolation can be enabled to extrapolate to 256 microsteps regardless of MRES.
Higher resolution = smoother motion but lower max velocity. Microstep resolution (MRES_256 = 256 microsteps typical)

◆ tbl

uint8_t tmc51x0::ChopperConfig::tbl {2}

Comparator blank time.

Masks comparator input to block spikes from parasitic capacitances during switching. Typically 1-2 microseconds. Longer blank time provides more protection but may limit frequency.

Can be specified as:

  • uint8_t (0-3): Raw register value
  • ChopperBlankTime enum: More intuitive (recommended)

Recommended: TBL_36CLK (~3.0µs @ 12MHz) for most applications.

Note
For highly capacitive loads (filter networks), use TBL_36CLK or TBL_54CLK.
Lower blank time allows lower StealthChop current limit. Blank time (0-3 or ChopperBlankTime enum, 2=typical)

◆ tfd

uint8_t tmc51x0::ChopperConfig::tfd {0}

Fast decay time (Classic mode only)

Sets fixed fast decay time following each on phase in Classic mode. Should be long enough to follow falling slope but not cause excess ripple.

Range: 0-15 (uses hstrt_tfd bits + tfd_3 bit)

  • 0: Slow decay only
  • 1-15: Fast decay time duration
  • Typical: Similar to slow decay time (TOFF) setting
Note
Only used in Classic mode (chm=1).
In SpreadCycle mode, this field is controlled by hstrt instead.
Tune using oscilloscope or motor smoothness at different velocities. Fast decay time (Classic mode only, 0-15, 0=slow decay only)

◆ toff

uint8_t tmc51x0::ChopperConfig::toff {5}

Off time (slow decay time) setting.

Sets the slow decay time and limits maximum chopper frequency. Higher values increase slow decay time and reduce chopper frequency.

Range: 0-15

  • 0: Chopper off (driver disabled, motor can free-wheel)
  • 1: Minimum off time (requires TBL ≥ 2)
  • 2-15: Off time setting (typical: 3-5 for 16-30kHz chopper frequency)

Calculation for target chopper frequency: t_OFF = (1 / f_chopper) * (slow_decay_percent / 100) * (1 / 2) TOFF = (t_OFF * f_CLK - 12) / 32

Example (25kHz target, 50% slow decay, 12MHz clock): t_OFF = (1/25000) * 0.5 * 0.5 = 10µs TOFF = (10µs * 12MHz - 12) / 32 ≈ 3.0 → use 3

Note
For StealthChop operation, any setting is OK (not used for chopping).
Higher motor velocities may benefit from TOFF=2 or 3 with short TBL=1 or 2. Off time setting (0=disabled, 1-15=off time, 5=typical)

◆ tpfd

uint8_t tmc51x0::ChopperConfig::tpfd {0}

Passive fast decay time.

Adds passive fast decay time after bridge polarity change. Helps reduce mid-range resonances.

Range: 0-15

  • 0: Disabled
  • 1-15: Fast decay time in multiples of 128 clocks (~10µs per unit @ 12MHz)
Note
Starting from 0, increase value if motor suffers from mid-range resonances. Passive fast decay time (0=disabled, 1-15=time in 128 clock units)

◆ vhighchm

bool tmc51x0::ChopperConfig::vhighchm {false}

High velocity chopper mode.

Enables switching to chm=1 (Classic mode) and fd=0 when VHIGH is exceeded. This way, a higher velocity can be achieved.

  • false: Normal chopper mode operation
  • true: Switch to Classic mode (chm=1) with fd=0 at high velocity
Note
Can be combined with vhighfs for maximum velocity.
If set, the TOFF setting automatically becomes doubled during high velocity operation in order to avoid doubling of the chopper frequency.
Automatically set to true when DcStep is configured.
Bit 19 in CHOPCONF register. High velocity chopper mode (false=normal, true=Classic mode at high velocity)

◆ vhighfs

bool tmc51x0::ChopperConfig::vhighfs {false}

High velocity fullstep selection.

Enables switching to fullstep when VHIGH is exceeded. Switching takes place only at 45° position. The fullstep target current uses the current value from the microstep table at the 45° position.

  • false: Normal microstepping operation
  • true: Switch to fullstep at high velocity (VHIGH threshold)
Note
Can be combined with vhighchm for maximum velocity.
Automatically set to true when DcStep is configured.
Bit 18 in CHOPCONF register. High velocity fullstep selection (false=normal, true=fullstep at high velocity)

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