|
HF-TMC51x0 Driver (TMC5130 & TMC5160) 0.1.0-dev
Hardware Agnostic C++ Driver for the TMC51x0 (TMC5130 & TMC5160)
|
Motor control subsystem. More...
#include <tmc51x0.hpp>
Public Member Functions | |
| MotorControl (TMC51x0 &driver) noexcept | |
| Construct motor control subsystem. | |
| Result< void > | Enable () noexcept |
| Enable the motor driver. | |
| Result< void > | Disable () noexcept |
| Disable the motor driver. | |
| Result< void > | SetCurrent (uint8_t irun, uint8_t ihold) noexcept |
| Set motor run and hold current. | |
| Result< void > | ConfigureChopper (const ChopperConfig &config) noexcept |
| Configure chopper settings. | |
| Result< void > | SetMicrostepResolution (MicrostepResolution mres, const MicrostepChangeOptions &opts=MicrostepChangeOptions{}) noexcept |
| Change microstep resolution (CHOPCONF.MRES) | |
| Result< void > | ConfigureStealthChop (const StealthChopConfig &config) noexcept |
| Configure stealthChop settings. | |
| Result< void > | ConfigureMotorCurrent (const MotorSpec &motor_spec) noexcept |
| Configure motor current from motor specifications. | |
| Result< void > | SetGlobalScaler (uint16_t scaler) noexcept |
| Set global current scaler. | |
| Result< GlobalConfig > | GetGlobalConfig () noexcept |
| Get global configuration. | |
| Result< void > | ConfigureCoolStep (const CoolStepConfig &config) noexcept |
| Configure CoolStep current reduction. | |
| Result< void > | ConfigureDcStep (const DcStepConfig &config) noexcept |
| Configure dcStep automatic commutation. | |
| Result< void > | SetMicrostepLookupTable (uint8_t index, uint32_t value) noexcept |
| Set microstep lookup table entry. | |
| Result< void > | SetMicrostepLookupTableSegmentation (uint8_t width_sel_0, uint8_t width_sel_1, uint8_t width_sel_2, uint8_t width_sel_3, uint8_t lut_seg_start1, uint8_t lut_seg_start2, uint8_t lut_seg_start3) noexcept |
| Set microstep lookup table segmentation. | |
| Result< void > | SetMicrostepLookupTableStart (uint16_t start_current) noexcept |
| Set microstep lookup table start current. | |
| Result< void > | ConfigureMicrostepLutPreset (MicrostepLutPreset preset) noexcept |
| Configure microstep lookup table with a preset waveform. | |
| Result< void > | ConfigureMicrostepLutCustom (const uint32_t lut[8], uint8_t w0, uint8_t w1, uint8_t w2, uint8_t w3, uint8_t x1, uint8_t x2, uint8_t x3, uint8_t start_sin, uint8_t start_sin90) noexcept |
| Configure microstep lookup table from raw data. | |
| Result< void > | SetupMotorFromSpec (const MotorSpec &motor_spec, const MechanicalSystem *mechanical_system=nullptr) noexcept |
| Setup motor from high-level specifications. | |
| Result< void > | ConfigureGlobalConfig (const GlobalConfig &config) noexcept |
| Configure global configuration (GCONF register) | |
| Result< void > | SetStealthChopEnabled (bool enabled) noexcept |
| Enable/Disable StealthChop (PWM mode) | |
| Result< ChopperConfig > | GetChopperConfig () noexcept |
| Get chopper configuration. | |
| Result< bool > | IsEnabled () noexcept |
| Check if motor driver is enabled. | |
| Result< bool > | IsStealthChopEnabled () noexcept |
| Check if StealthChop is enabled. | |
| Result< bool > | IsStealthChopCalibrated () noexcept |
| Check if StealthChop is calibrated and working. | |
| Result< Diag0Config > | GetDiag0Config () noexcept |
| Get DIAG0 pin configuration. | |
| Result< void > | SetDiag0Config (const Diag0Config &config) noexcept |
| Set DIAG0 pin configuration. | |
| Result< Diag1Config > | GetDiag1Config () noexcept |
| Get DIAG1 pin configuration. | |
| Result< void > | SetDiag1Config (const Diag1Config &config) noexcept |
| Set DIAG1 pin configuration. | |
| Result< void > | SetCoilCurrents (int16_t coil_a, int16_t coil_b) noexcept |
| Set coil currents for direct mode operation. | |
| Result< void > | SetIholdDelayMs (float total_delay_ms) noexcept |
| Set motor power down delay (IHOLDDELAY) in milliseconds. | |
Private Attributes | |
| TMC51x0 & | driver_ |
| Reference to parent driver instance. | |
Motor control subsystem.
Provides methods for controlling motor current, chopper configuration, and stealthChop operation.
|
inlineexplicitnoexcept |
Construct motor control subsystem.
| driver | Reference to parent TMC51x0 driver instance |
|
noexcept |
Configure chopper settings.
| config | Chopper configuration structure |
|
noexcept |
Configure CoolStep current reduction.
| config | CoolStep configuration structure |
|
noexcept |
Configure dcStep automatic commutation.
| config | dcStep configuration structure |
|
noexcept |
Configure global configuration (GCONF register)
| config | Global configuration structure |
|
noexcept |
Configure microstep lookup table from raw data.
| lut | Array of 8 uint32_t values for MSLUT0-7 |
| w0 | Width select for segment 0 (0-3) |
| w1 | Width select for segment 1 (0-3) |
| w2 | Width select for segment 2 (0-3) |
| w3 | Width select for segment 3 (0-3) |
| x1 | Segment 1 start (0-255) |
| x2 | Segment 2 start (0-255) |
| x3 | Segment 3 start (0-255) |
| start_sin | Start sine value at entry 0 (0-255) |
| start_sin90 | Sine value at entry 256 / 90° (0-255) |
Programs all MSLUT registers with custom values for advanced waveform shaping. Use this for custom motor characteristics or torque ripple compensation.
|
noexcept |
Configure microstep lookup table with a preset waveform.
| preset | Waveform preset (DEFAULT_SINE, PURE_SINE, etc.) |
Programs all MSLUT registers (MSLUT0-7, MSLUTSEL, MSLUTSTART) with optimized values for the selected waveform type.
Available presets:
|
noexcept |
Configure motor current from motor specifications.
| motor_spec | Motor specifications including current, sense resistor, supply voltage |
Automatically calculates and sets IRUN, IHOLD, and GLOBAL_SCALER from motor specifications. Also sets IHOLDDELAY if configured in motor_spec.
|
noexcept |
Configure stealthChop settings.
| config | StealthChop configuration structure |
|
noexcept |
Disable the motor driver.
|
noexcept |
Enable the motor driver.
|
noexcept |
Get chopper configuration.
| config | Reference to store current ChopperConfig |
|
noexcept |
Get DIAG0 pin configuration.
| config | Reference to store current Diag0Config |
Reads DIAG0 configuration from GCONF register using read-modify-write pattern.
|
noexcept |
Get DIAG1 pin configuration.
| config | Reference to store current Diag1Config |
Reads DIAG1 configuration from GCONF register using read-modify-write pattern.
|
noexcept |
Get global configuration.
| config | Reference to store current GlobalConfig |
|
noexcept |
Check if motor driver is enabled.
|
noexcept |
Check if StealthChop is calibrated and working.
StealthChop requires calibration to work properly. If not calibrated, the motor may not move or may have poor performance.
|
noexcept |
Check if StealthChop is enabled.
|
noexcept |
Set coil currents for direct mode operation.
| coil_a | Coil A current target (signed, range ±248 recommended for safe operation) |
| coil_b | Coil B current target (signed, range ±248 recommended for safe operation) |
Sets coil current targets directly via XTARGET register when direct_mode is enabled. In direct mode, XTARGET controls coil currents instead of position:
Current is scaled by IHOLD setting. The STEP/DIR inputs and motion controller are not used in direct mode.
|
noexcept |
Set motor run and hold current.
| irun | Run current (0-31, where 31 = 100% of global scaler) |
| ihold | Hold current (0-31, where 31 = 100% of global scaler) |
|
noexcept |
Set DIAG0 pin configuration.
| config | Diag0Config structure with DIAG0 settings |
Writes DIAG0 configuration to GCONF register using read-modify-write pattern. Preserves all other GCONF bits.
|
noexcept |
Set DIAG1 pin configuration.
| config | Diag1Config structure with DIAG1 settings |
Writes DIAG1 configuration to GCONF register using read-modify-write pattern. Preserves all other GCONF bits.
|
noexcept |
Set global current scaler.
| scaler | Global scaler value (32-256) |
|
noexcept |
Set motor power down delay (IHOLDDELAY) in milliseconds.
| total_delay_ms | Total motor power down delay time in milliseconds (0.0 = instant, automatically calculated to register value 0-15) |
Sets the total delay time for motor power down after motion as soon as standstill is detected (stst=1) and TPOWERDOWN has expired. The smooth transition avoids a motor jerk upon power down.
The delay is automatically calculated from the desired total delay time, clock frequency, and the number of current reduction steps (IRUN - IHOLD).
Calculation: IHOLDDELAY = round((total_delay_ms / (IRUN - IHOLD)) × f_clk / (1000 × 2^18)) Total delay = (IRUN - IHOLD) × IHOLDDELAY × (2^18 / f_clk)
|
noexcept |
Set microstep lookup table entry.
| index | Lookup table index (0-7) |
| value | Lookup table value (32-bit) |
|
noexcept |
Set microstep lookup table segmentation.
| width_sel_0 | Width selection for segment 0 (0-3) |
| width_sel_1 | Width selection for segment 1 (0-3) |
| width_sel_2 | Width selection for segment 2 (0-3) |
| width_sel_3 | Width selection for segment 3 (0-3) |
| lut_seg_start1 | Start position for segment 1 (0-255) |
| lut_seg_start2 | Start position for segment 2 (0-255) |
| lut_seg_start3 | Start position for segment 3 (0-255) |
|
noexcept |
Set microstep lookup table start current.
| start_current | Start current value (0-255) |
|
noexcept |
Change microstep resolution (CHOPCONF.MRES)
| mres | New microstep resolution |
| opts | Options controlling rescaling behavior |
By default, this preserves physical meaning across the MRES change:
If the motor is not in standstill and opts.require_standstill is true (default), the operation fails with INVALID_STATE.
|
noexcept |
Enable/Disable StealthChop (PWM mode)
| enabled | true to enable StealthChop, false for SpreadCycle |
|
noexcept |
Setup motor from high-level specifications.
| motor_spec | Motor specification structure |
| mechanical_system | Optional mechanical system configuration |
Automatically calculates and sets motor current, chopper configuration, and other parameters based on motor specifications.
|
private |
Reference to parent driver instance.