|
HF-TMC51x0 Driver (TMC5130 & TMC5160) 0.1.0-dev
Hardware Agnostic C++ Driver for the TMC51x0 (TMC5130 & TMC5160)
|
Fluent configuration builder for DriverConfig. More...
#include <tmc51x0_config_builder.hpp>
Public Member Functions | |
| ConfigBuilder ()=default | |
| Default constructor. | |
| ConfigBuilder (const DriverConfig &cfg) | |
| Construct from existing config. | |
| ConfigBuilder & | WithMotorMa (uint16_t steps_per_rev, uint16_t rated_current_ma) |
| Configure motor specifications. | |
| ConfigBuilder & | WithRunCurrentMa (uint16_t run_current_ma) |
| Set run current value. | |
| ConfigBuilder & | WithHoldCurrentMa (uint16_t hold_current_ma) |
| Set hold current value. | |
| ConfigBuilder & | WithSupplyVoltageMv (uint32_t voltage_mv) |
| Set supply voltage value. | |
| ConfigBuilder & | WithSenseResistorMohm (uint32_t resistance_mohm) |
| Set sense resistor value. | |
| ConfigBuilder & | WithWindingResistanceMohm (uint32_t resistance_mohm) |
| Set winding resistance value. | |
| ConfigBuilder & | WithWindingInductanceMh (float inductance_mh) |
| Set winding inductance value. | |
| ConfigBuilder & | WithMotorPowerDownDelayMs (float delay_ms) |
| Set motor power down delay time. | |
| ConfigBuilder & | WithStepsPerRevolution (uint16_t steps) |
| Set steps per revolution. | |
| ConfigBuilder & | WithMosfetMillerChargeNc (float charge_nc) |
| Set MOSFET Miller charge. | |
| ConfigBuilder & | WithBbmTimeNs (uint32_t time_ns) |
| Set Break Before Make time. | |
| ConfigBuilder & | WithSenseFilter (SenseFilterTime filter_time) |
| Set sense amplifier filter time. | |
| ConfigBuilder & | WithOverTempProtection (OverTempProtection protection) |
| Set over-temperature protection level. | |
| ConfigBuilder & | WithS2vsVoltageMv (uint16_t voltage_mv) |
| Set short to VS detector voltage threshold. | |
| ConfigBuilder & | WithS2gVoltageMv (uint16_t voltage_mv) |
| Set short to GND detector voltage threshold. | |
| ConfigBuilder & | WithShortFilter (uint8_t filter) |
| Set short detection filter bandwidth. | |
| ConfigBuilder & | WithShortDetectionDelayUsX10 (uint8_t delay_us_x10) |
| Set short detection delay. | |
| ConfigBuilder & | WithChopperMode (ChopperMode mode) |
| Set chopper mode. | |
| ConfigBuilder & | WithChopperToff (uint8_t toff) |
| Set chopper off-time (TOFF) | |
| ConfigBuilder & | WithChopperBlankTime (ChopperBlankTime blank_time) |
| Set chopper blank time. | |
| ConfigBuilder & | WithHysteresisStart (uint8_t hstrt) |
| Set hysteresis start value (SpreadCycle mode) | |
| ConfigBuilder & | WithHysteresisEnd (uint8_t hend) |
| Set hysteresis end value (SpreadCycle mode) | |
| ConfigBuilder & | WithFastDecayTime (uint8_t tfd) |
| Set fast decay time (Classic mode only) | |
| ConfigBuilder & | WithPassiveFastDecayTime (uint8_t tpfd) |
| Set passive fast decay time. | |
| ConfigBuilder & | WithMicrostepResolution (MicrostepResolution mres) |
| Set microstep resolution. | |
| ConfigBuilder & | WithInterpolation (bool enable) |
| Enable/disable interpolation. | |
| ConfigBuilder & | WithStealthChop (bool enable) |
| Enable/disable StealthChop. | |
| ConfigBuilder & | WithStealthChopThreshold (const VelocityValue &velocity) |
| Set StealthChop threshold velocity. | |
| ConfigBuilder & | WithStealthChopPwmFreq (uint8_t freq) |
| Set StealthChop PWM frequency. | |
| ConfigBuilder & | WithStealthChopPwmOfs (uint8_t ofs) |
| Set StealthChop PWM offset. | |
| ConfigBuilder & | WithStealthChopAutoscale (bool enable) |
| Enable/disable StealthChop PWM autoscale. | |
| ConfigBuilder & | WithStealthChopAutograd (bool enable) |
| Enable/disable StealthChop PWM autograd. | |
| ConfigBuilder & | WithStallGuardThreshold (int8_t threshold) |
| Set StallGuard2 threshold (SGT) | |
| ConfigBuilder & | WithStallGuardFilter (bool enable) |
| Enable/disable StallGuard2 filter. | |
| ConfigBuilder & | WithStallGuardMinVelocity (float velocity, Unit unit=Unit::RPM) |
| Set StallGuard2 minimum velocity threshold. | |
| ConfigBuilder & | WithStallGuardMaxVelocity (float velocity, Unit unit=Unit::RPM) |
| Set StallGuard2 maximum velocity threshold. | |
| ConfigBuilder & | WithStallGuard (const StallGuardConfig &sg_config) |
| Configure StallGuard2 with a complete config struct. | |
| ConfigBuilder & | WithRecalibration (bool enable) |
| Enable/disable recalibration. | |
| ConfigBuilder & | WithShortStandstillTimeout (bool enable) |
| Enable/disable short standstill timeout. | |
| ConfigBuilder & | WithStealthChopStepFilter (bool enable) |
| Enable/disable StealthChop step filter. | |
| ConfigBuilder & | WithMaxSpeed (const VelocityValue &velocity) |
| Set maximum velocity. | |
| ConfigBuilder & | WithAcceleration (const AccelerationValue &acceleration) |
| Set maximum acceleration. | |
| ConfigBuilder & | WithDeceleration (const AccelerationValue &deceleration) |
| Set maximum deceleration. | |
| ConfigBuilder & | WithStartSpeed (const VelocityValue &velocity) |
| Set start velocity. | |
| ConfigBuilder & | WithStopSpeed (const VelocityValue &velocity) |
| Set stop velocity. | |
| ConfigBuilder & | WithVelocityThreshold (const VelocityValue &velocity) |
| Set velocity threshold for acceleration/deceleration phase transition. | |
| ConfigBuilder & | WithFirstAcceleration (const AccelerationValue &acceleration) |
| Set first acceleration phase. | |
| ConfigBuilder & | WithFirstDeceleration (const AccelerationValue &deceleration) |
| Set first deceleration phase. | |
| ConfigBuilder & | WithRampPowerDownDelayMs (float delay_ms) |
| Set ramp power down delay. | |
| ConfigBuilder & | WithZeroWaitTimeMs (float wait_ms) |
| Set zero velocity wait time. | |
| ConfigBuilder & | WithInternalClock () |
| Use internal clock (12MHz) | |
| ConfigBuilder & | WithExternalClockHz (uint32_t frequency_hz) |
| Use external clock. | |
| ConfigBuilder & | WithDirectDrive () |
| Configure direct drive system. | |
| ConfigBuilder & | WithGearbox (float gear_ratio) |
| Configure gearbox system. | |
| ConfigBuilder & | WithLeadScrew (float pitch_mm) |
| Configure lead screw system. | |
| ConfigBuilder & | WithBeltDrive (uint16_t pulley_teeth, float belt_pitch_mm) |
| Configure belt drive system. | |
| ConfigBuilder & | WithDirection (MotorDirection direction) |
| Set motor direction. | |
| DriverConfig | Build () const |
| Build the final configuration. | |
| DriverConfig & | Config () |
| Get mutable reference to config for advanced customization. | |
| const DriverConfig & | Config () const |
| Get const reference to config. | |
Private Attributes | |
| DriverConfig | config_ |
Fluent configuration builder for DriverConfig.
Provides a user-friendly interface for building TMC51x0 configurations with automatic unit conversions. All motor-specific presets are removed to allow users full control over configuration.
The builder ensures all DriverConfig fields are properly initialized, following the same pattern as ESP32 test config initialization.
|
default |
Default constructor.
Creates a builder with default configuration values. All DriverConfig fields use their default constructors.
|
inlineexplicit |
Construct from existing config.
| cfg | Existing DriverConfig to start from |
|
inline |
Build the final configuration.
Returns a complete DriverConfig with all fields properly initialized. The configuration follows the same pattern as ESP32 test config:
|
inline |
Get mutable reference to config for advanced customization.
Allows direct access to the internal config for advanced use cases where the fluent interface doesn't provide enough control.
|
inline |
Get const reference to config.
|
inline |
Set maximum acceleration.
| acceleration | Self-describing acceleration with unit |
|
inline |
Set Break Before Make time.
| time_ns | BBM time in nanoseconds (0 = auto-calculate) |
|
inline |
Configure belt drive system.
| pulley_teeth | Number of pulley teeth |
| belt_pitch_mm | Belt pitch in mm (e.g., 2.0 for GT2) |
|
inline |
Set chopper blank time.
| blank_time | Blank time (TBL_36CLK typical) |
|
inline |
Set chopper mode.
| mode | Chopper mode (SPREAD_CYCLE recommended) |
|
inline |
Set chopper off-time (TOFF)
| toff | Off-time value (0-15, 0=driver disable, 5=typical) |
|
inline |
Set maximum deceleration.
| deceleration | Self-describing deceleration with unit |
|
inline |
Configure direct drive system.
|
inline |
Set motor direction.
| direction | Motor direction (NORMAL or INVERSE) |
|
inline |
Use external clock.
| frequency_hz | External clock frequency in Hz |
|
inline |
Set fast decay time (Classic mode only)
| tfd | Fast decay time (0-15, 0=slow decay only) |
|
inline |
Set first acceleration phase.
| acceleration | Self-describing acceleration with unit |
|
inline |
Set first deceleration phase.
| deceleration | Self-describing deceleration with unit |
|
inline |
Configure gearbox system.
| gear_ratio | Gear ratio (output/input, e.g., 5.18 for 5.18:1) |
|
inline |
Set hold current value.
| hold_current_ma | Hold current in milliamps (0 = auto-calculate as 30% of run) |
|
inline |
Set hysteresis end value (SpreadCycle mode)
| hend | Hysteresis end (0-15, 0=typical) |
|
inline |
Set hysteresis start value (SpreadCycle mode)
| hstrt | Hysteresis start (0-7, 4=typical) |
|
inline |
Use internal clock (12MHz)
|
inline |
Enable/disable interpolation.
| enable | True to enable interpolation to 256 microsteps |
|
inline |
Configure lead screw system.
| pitch_mm | Lead screw pitch in mm |
|
inline |
Set maximum velocity.
| velocity | Self-describing velocity with unit |
|
inline |
Set microstep resolution.
| mres | Microstep resolution (MRES_256 typical) |
|
inline |
Set MOSFET Miller charge.
Used to calculate DRVSTRENGTH register.
| charge_nc | MOSFET Miller charge in nanocoulombs (0 = auto-calculate) |
|
inline |
Configure motor specifications.
Sets basic motor parameters: steps per revolution and rated current.
| steps_per_rev | Steps per revolution (e.g., 200 for 1.8° motors) |
| rated_current_ma | Rated motor current in milliamps (e.g., 1500 for 1.5A) |
|
inline |
Set motor power down delay time.
Controls the total delay time for motor power down after standstill. This is the IHOLDDELAY setting that controls the smooth transition from run current to hold current.
| delay_ms | Total delay time in milliseconds (0 = instant) |
|
inline |
Set over-temperature protection level.
| protection | Over-temperature protection level |
|
inline |
Set passive fast decay time.
| tpfd | Passive fast decay time (0=disabled, 1-15) |
|
inline |
Set ramp power down delay.
Sets the TPOWERDOWN delay - time before motor power down after standstill. This is different from motor power down delay (IHOLDDELAY).
| delay_ms | Power down delay in milliseconds |
|
inline |
Enable/disable recalibration.
| enable | True to enable recalibration |
|
inline |
Set run current value.
| run_current_ma | Run current in milliamps (0 = use rated current) |
|
inline |
Set short to GND detector voltage threshold.
| voltage_mv | Voltage threshold in millivolts (0 = auto-calculate) |
|
inline |
Set short to VS detector voltage threshold.
| voltage_mv | Voltage threshold in millivolts (0 = auto-calculate) |
|
inline |
Set sense amplifier filter time.
| filter_time | Sense filter time constant |
|
inline |
Set sense resistor value.
Required for automatic current calculation.
| resistance_mohm | Sense resistor in milliohms (e.g., 50 for 0.05Ω) |
|
inline |
Set short detection delay.
| delay_us_x10 | Delay in 0.1µs units (0 = auto-calculate) |
|
inline |
Set short detection filter bandwidth.
| filter | Filter bandwidth (0-3, 0=lowest, 1=default) |
|
inline |
Enable/disable short standstill timeout.
| enable | True to enable short standstill timeout |
|
inline |
Configure StallGuard2 with a complete config struct.
Sets all StallGuard parameters at once.
| sg_config | Complete StallGuard configuration |
|
inline |
Enable/disable StallGuard2 filter.
Filter reduces measurement rate to one per electrical period (4 fullsteps).
| enable | True to enable filter (smoother, recommended for CoolStep), False to disable (faster response, recommended for homing) |
|
inline |
Set StallGuard2 maximum velocity threshold.
StallGuard is disabled above this velocity. Set to 0 to disable limit.
| velocity | Maximum velocity value (0 = no limit) |
| unit | Velocity unit (default: RPM) |
|
inline |
Set StallGuard2 minimum velocity threshold.
StallGuard readings are only valid above this velocity. Below this speed, stall detection is unreliable.
| velocity | Minimum velocity value |
| unit | Velocity unit (default: RPM) |
|
inline |
Set StallGuard2 threshold (SGT)
Controls StallGuard2 sensitivity for stall detection.
| threshold | SGT value (-64 to +63)
|
|
inline |
Set start velocity.
| velocity | Self-describing velocity with unit |
|
inline |
Enable/disable StealthChop.
| enable | True to enable StealthChop, false for SpreadCycle |
|
inline |
Enable/disable StealthChop PWM autograd.
| enable | True to enable automatic PWM gradient calibration |
|
inline |
Enable/disable StealthChop PWM autoscale.
| enable | True to enable automatic PWM amplitude calibration |
|
inline |
Set StealthChop PWM frequency.
| freq | PWM frequency (0-3, 1=~35kHz typical) |
|
inline |
Set StealthChop PWM offset.
| ofs | PWM offset (0-255, 20-40 typical) |
|
inline |
Enable/disable StealthChop step filter.
| enable | True to enable step filter for StealthChop |
|
inline |
Set StealthChop threshold velocity.
Velocity below which StealthChop is active, above which SpreadCycle is used.
| velocity | Threshold velocity with unit |
|
inline |
Set steps per revolution.
| steps | Steps per revolution (e.g., 200 for 1.8° motor) |
|
inline |
Set stop velocity.
| velocity | Self-describing velocity with unit |
|
inline |
Set supply voltage value.
| voltage_mv | Supply voltage in millivolts (e.g., 24000 for 24V) |
|
inline |
Set velocity threshold for acceleration/deceleration phase transition.
| velocity | Self-describing velocity with unit |
|
inline |
Set winding inductance value.
Used for StealthChop configuration.
| inductance_mh | Winding inductance in millihenries |
|
inline |
Set winding resistance value.
Required for StealthChop lower limit calculation.
| resistance_mohm | Winding resistance in milliohms |
|
inline |
Set zero velocity wait time.
| wait_ms | Wait time at zero velocity in milliseconds |
|
private |