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

StallGuard2 configuration structure. More...

#include <tmc51x0_types.hpp>

Public Member Functions

 StallGuardConfig ()=default
 Default constructor.
 
 StallGuardConfig (int8_t sgt_threshold, bool enable_filt=false, float min_vel=0.0F, float max_vel=0.0F, Unit vel_unit=Unit::RevPerSec, bool stop_on_stall=false)
 Helper constructor for quick setup.
 
 StallGuardConfig (StallGuardSensitivity sensitivity, bool enable_filt=false, float min_vel=0.0F, float max_vel=0.0F, Unit vel_unit=Unit::Steps, bool stop_on_stall=false)
 Helper constructor using sensitivity enum.
 

Public Attributes

int8_t threshold {0}
 StallGuard2 threshold value.
 
bool enable_filter {false}
 Enable StallGuard2 filter.
 
float min_velocity {0.0F}
 Lower velocity threshold for StallGuard2 operation.
 
float max_velocity {0.0F}
 Upper velocity threshold for StallGuard2 operation.
 
Unit velocity_unit {Unit::Steps}
 Unit for velocity thresholds.
 
bool stop_on_stall {false}
 Stop motor when stall detected.
 

Detailed Description

StallGuard2 configuration structure.

User-friendly configuration for StallGuard2 load measurement and stall detection. StallGuard2 provides accurate measurement of motor load and can detect stalls. It's used for sensorless homing, CoolStep load-adaptive current reduction, and diagnostics.

Note
StallGuard2 requires SpreadCycle mode (StealthChop must be disabled).
StallGuard2 measurement is updated with each fullstep (or every 4 fullsteps if filter enabled).
SGT threshold should be tuned for your specific motor and operating conditions.
See also
Datasheet section 13: StallGuard2 Load Measurement

Constructor & Destructor Documentation

◆ StallGuardConfig() [1/3]

tmc51x0::StallGuardConfig::StallGuardConfig ( )
default

Default constructor.

Initializes with recommended default values:

  • threshold: 0 (starting value, works with most motors)
  • enable_filter: false (faster response)
  • stop_on_stall: false (don't stop on stall)

◆ StallGuardConfig() [2/3]

tmc51x0::StallGuardConfig::StallGuardConfig ( int8_t sgt_threshold,
bool enable_filt = false,
float min_vel = 0.0F,
float max_vel = 0.0F,
Unit vel_unit = Unit::RevPerSec,
bool stop_on_stall = false )
inline

Helper constructor for quick setup.

Creates a StallGuard2 configuration with typical settings.

Parameters
sgt_thresholdStallGuard2 threshold (-64 to +63, 0 = starting value)
enable_filtEnable filter for smoother readings
min_velMinimum velocity for StallGuard2 operation
max_velMaximum velocity for StallGuard2 operation (0 = no limit)
vel_unitUnit for velocity thresholds
stop_on_stallStop motor when stall detected

◆ StallGuardConfig() [3/3]

tmc51x0::StallGuardConfig::StallGuardConfig ( StallGuardSensitivity sensitivity,
bool enable_filt = false,
float min_vel = 0.0F,
float max_vel = 0.0F,
Unit vel_unit = Unit::Steps,
bool stop_on_stall = false )
inline

Helper constructor using sensitivity enum.

Creates a StallGuard2 configuration using intuitive sensitivity levels.

Member Data Documentation

◆ enable_filter

bool tmc51x0::StallGuardConfig::enable_filter {false}

Enable StallGuard2 filter.

Filter reduces measurement rate to one measurement per electrical period (4 fullsteps). Compensates for motor construction variations (e.g., misalignment of phase magnets).

  • Enabled: More precise measurement, smoother readings (recommended for CoolStep)
  • Disabled: Faster response, higher time resolution (recommended for sensorless homing)
Note
Filter should be enabled when high-precision measurement is required.
Filter should be disabled for rapid response and best sensorless homing results. Enable StallGuard2 filter (reduces measurement rate 4x)

◆ max_velocity

float tmc51x0::StallGuardConfig::max_velocity {0.0F}

Upper velocity threshold for StallGuard2 operation.

StallGuard2 may not operate reliably above this velocity. Set to match the upper limit of velocity range where StallGuard2 gives stable results.

Note
Unit is specified by velocity_unit field.
Set to 0 for no upper limit (StallGuard2 active at all velocities above min_velocity). Maximum velocity for StallGuard2 (0 = no upper limit)

◆ min_velocity

float tmc51x0::StallGuardConfig::min_velocity {0.0F}

Lower velocity threshold for StallGuard2 operation.

StallGuard2 is disabled below this velocity. Set to match the lower limit of velocity range where StallGuard2 gives stable results.

Note
Unit is specified by velocity_unit field.
Set to match your typical operating velocity range.
For sensorless homing, set to match search speed. Minimum velocity for StallGuard2 (0 = no lower limit)

◆ stop_on_stall

bool tmc51x0::StallGuardConfig::stop_on_stall {false}

Stop motor when stall detected.

If true, motor stops (VACTUAL = 0) when stall is detected. Motor remains stopped until RAMP_STAT.event_stop_sg flag is read.

Note
Requires StallGuard2 to be properly tuned (threshold set correctly).
Requires min_velocity to be set (TCOOLTHRS must be configured).
Motor can be restarted by reading/writing RAMP_STAT register or disabling sg_stop. Stop motor when stall detected

◆ threshold

int8_t tmc51x0::StallGuardConfig::threshold {0}

StallGuard2 threshold value.

Controls StallGuard2 sensitivity for stall detection and sets optimum measurement range.

Range: -64 to +63

  • Lower values (-64 to 0): Higher sensitivity (detects stalls easier, more false positives)
  • Higher values (0 to +63): Lower sensitivity (requires more torque to detect stall, fewer false positives)
  • Zero (0): Starting value, works with most motors

Tuning: Adjust until SG_RESULT is between 0-100 at maximum load before stall.

Note
Can be set directly as int8_t or use sensitivity enum for convenience. StallGuard2 threshold (-64 to +63, 0 = starting value)

◆ velocity_unit

Unit tmc51x0::StallGuardConfig::velocity_unit {Unit::Steps}

Unit for velocity thresholds.

Specifies the unit used for min_velocity and max_velocity fields. Unit for velocity thresholds


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