|
HF-TMC51x0 Driver (TMC5130 & TMC5160) 0.1.0-dev
Hardware Agnostic C++ Driver for the TMC51x0 (TMC5130 & TMC5160)
|
Status / monitoring subsystem (read-only) More...
#include <tmc51x0.hpp>
Public Member Functions | |
| Status (TMC51x0 &driver) noexcept | |
| Construct diagnostics subsystem. | |
| DriverStatus | GetStatus () noexcept |
| Get driver status. | |
| Result< bool > | GetGlobalStatus (bool &drv_err, bool &uv_cp) noexcept |
| Get global status flags (GSTAT) | |
| Result< void > | ClearGlobalStatus (bool clear_reset=true, bool clear_drv_err=true, bool clear_uv_cp=true) noexcept |
| Clear global status flags (GSTAT) | |
| Result< uint32_t > | GetDriverStatusRegister () noexcept |
| Get driver status register value. | |
| Result< bool > | IsOpenLoadA () noexcept |
| Check if open load is detected on phase A. | |
| Result< bool > | IsOpenLoadB () noexcept |
| Check if open load is detected on phase B. | |
| Result< bool > | CheckOpenLoad (bool &phase_a, bool &phase_b) noexcept |
| Check if open load is detected on either phase. | |
| Result< bool > | IsOvertemperature () noexcept |
| Check if overtemperature shutdown is active. | |
| Result< bool > | IsOvertempWarning () noexcept |
| Check if overtemperature pre-warning is active. | |
| Result< void > | GetTemperatureStatus (bool &overtemp, bool &prewarning) noexcept |
| Get both temperature status flags at once. | |
| Result< bool > | IsStealthChopActive () noexcept |
| Check if StealthChop mode is currently active. | |
| Result< bool > | IsFullstepActive () noexcept |
| Check if fullstep mode is currently active. | |
| Result< uint8_t > | GetActualCurrentScale () noexcept |
| Get actual motor current scale (CS_ACTUAL) | |
| Result< void > | IsShortToSupply (bool &phase_a, bool &phase_b) noexcept |
| Check for short to supply (VS) condition. | |
| Result< void > | IsShortToGround (bool &phase_a, bool &phase_b) noexcept |
| Check for short to ground (GND) condition. | |
| Result< void > | GetShortCircuitStatus (bool &s2vs_a, bool &s2vs_b, bool &s2g_a, bool &s2g_b) noexcept |
| Get all short circuit status flags at once. | |
| Result< uint32_t > | GetRampStatusRegister () noexcept |
| Get ramp status register value. | |
| Result< uint32_t > | GetLostSteps () noexcept |
| Get lost steps counter. | |
| Result< uint32_t > | GetTimeBetweenMicrosteps () noexcept |
| Get actual time between microsteps. | |
| Result< uint16_t > | GetMicrostepCounter () noexcept |
| Get microstep counter. | |
| Result< int16_t > | GetMicrostepCurrent (int16_t &phase_b) noexcept |
| Get microstep current. | |
| Result< uint8_t > | GetPwmScale (int16_t &pwm_scale_auto) noexcept |
| Get PWM scale results. | |
| Result< uint8_t > | GetPwmAuto (uint8_t &pwm_grad_auto) noexcept |
| Get automatically determined PWM values. | |
| Result< uint8_t > | ReadFactoryConfig () noexcept |
| Read factory configuration. | |
| Result< uint8_t > | ReadOtpConfig (bool &otp_s2_level, bool &otp_bbm, bool &otp_tbl) noexcept |
| Read OTP configuration. | |
| Result< uint8_t > | GetUartTransmissionCount () noexcept |
| Get UART transmission counter. | |
| Result< uint8_t > | ReadOffsetCalibration (uint8_t &phase_b) noexcept |
| Read offset calibration results. | |
| Result< void > | VerifySetup () noexcept |
| Run comprehensive startup verification. | |
| uint8_t | GetChipVersion () const noexcept |
| Get detected chip version. | |
| Result< void > | ProgramOtpBit (uint8_t byte_index, uint8_t bit_index, bool confirm_permanent) noexcept |
| Program a single OTP bit (PERMANENT - USE WITH EXTREME CAUTION!) | |
| Result< void > | ProgramOtpFclktrim (uint8_t fclktrim, bool confirm_permanent) noexcept |
| Program OTP FCLKTRIM value (PERMANENT - USE WITH EXTREME CAUTION!) | |
| Result< void > | ProgramOtpS2Level (bool high_level, bool confirm_permanent) noexcept |
| Program OTP short detection level default (PERMANENT!) | |
| Result< void > | ProgramOtpBbm (bool short_bbm, bool confirm_permanent) noexcept |
| Program OTP BBM (break-before-make) default (PERMANENT!) | |
| Result< void > | ProgramOtpTbl (bool short_tbl, bool confirm_permanent) noexcept |
| Program OTP TBL (blank time) default (PERMANENT!) | |
Private Attributes | |
| TMC51x0 & | driver_ |
| Reference to parent driver instance. | |
Status / monitoring subsystem (read-only)
Provides methods for reading status/telemetry and configuration/OTP info.
|
inlineexplicitnoexcept |
Construct diagnostics subsystem.
| driver | Reference to parent TMC51x0 driver instance |
|
noexcept |
Check if open load is detected on either phase.
| phase_a | Reference to store phase A status (true if open load detected) |
| phase_b | Reference to store phase B status (true if open load detected) |
Convenience method to check both phases at once.
|
noexcept |
Clear global status flags (GSTAT)
| clear_reset | Clear the reset flag (IC was reset since last read) |
| clear_drv_err | Clear the driver error flag (short/overtemp occurred) |
| clear_uv_cp | Clear the undervoltage charge pump flag |
GSTAT is a write-1-to-clear (W1C) register. Writing '1' to a bit clears that flag. Use this after handling a fault to acknowledge it.
|
noexcept |
Get actual motor current scale (CS_ACTUAL)
Returns the actual current scaling being applied to the motor, which may differ from IRUN due to:
To convert to actual current: I = (CS_ACTUAL + 1) / 32 * I_max
|
inlinenoexcept |
Get detected chip version.
|
noexcept |
Get driver status register value.
| status | Reference to store the DRV_STATUS register value |
|
noexcept |
Get global status flags (GSTAT)
| reset | Reference to store reset flag |
| drv_err | Reference to store driver error flag |
| uv_cp | Reference to store undervoltage charge pump flag |
|
noexcept |
Get lost steps counter.
| steps | Reference to store the number of lost steps |
Only valid when dcStep mode is enabled (SD_MODE = 1).
|
noexcept |
Get microstep counter.
| counter | Reference to store actual position in microstep table (0-1023) |
Read-only register showing actual position in the microstep table.
|
noexcept |
Get microstep current.
| phase_a | Reference to store phase A current (signed, -256 to 255) |
| phase_b | Reference to store phase B current (signed, -256 to 255) |
Read-only register showing actual microstep current for both phases. Values are signed 9-bit as read from MSLUT (not scaled by current).
|
noexcept |
Get automatically determined PWM values.
| pwm_ofs_auto | Reference to store auto-determined offset (0-255) |
| pwm_grad_auto | Reference to store auto-determined gradient (0-255) |
Read-only register showing automatically determined PWM configuration values.
|
noexcept |
Get PWM scale results.
| pwm_scale_sum | Reference to store actual PWM duty cycle (0-255) |
| pwm_scale_auto | Reference to store automatic regulation result (signed -255...+255) |
Read-only register showing stealthChop PWM scale results.
|
noexcept |
Get ramp status register value.
| status | Reference to store the RAMP_STAT register value |
|
noexcept |
Get all short circuit status flags at once.
| s2vs_a | Short to VS on phase A |
| s2vs_b | Short to VS on phase B |
| s2g_a | Short to GND on phase A |
| s2g_b | Short to GND on phase B |
More efficient than calling individual short check methods separately.
|
noexcept |
Get driver status.
|
noexcept |
Get both temperature status flags at once.
| overtemp | Reference to store overtemperature shutdown status |
| prewarning | Reference to store pre-warning status |
More efficient than calling IsOvertemperature() and IsOvertempWarning() separately as it only requires one register read.
|
noexcept |
Get actual time between microsteps.
| time | Reference to store time between microsteps in clock cycles |
Read-only register showing actual time between microsteps.
|
noexcept |
Get UART transmission counter.
Returns the number of UART transmissions since last read.
|
noexcept |
Check if fullstep mode is currently active.
Fullstep becomes active when:
In fullstep mode, the motor runs at native full steps (not microstepping).
|
noexcept |
Check if open load is detected on phase A.
Open load detection indicates an interrupted cable or connector issue.
|
noexcept |
Check if open load is detected on phase B.
Open load detection indicates an interrupted cable or connector issue.
|
noexcept |
Check if overtemperature shutdown is active.
When true, the bridge drivers are disabled due to excessive die temperature. The motor will not be driven until temperature drops below the threshold.
|
noexcept |
Check if overtemperature pre-warning is active.
Pre-warning typically activates ~20°C before shutdown. Use this to implement thermal management (reduce current, add cooling, slow motion).
|
noexcept |
Check for short to ground (GND) condition.
| phase_a | Reference to store phase A short-to-GND status |
| phase_b | Reference to store phase B short-to-GND status |
Short to GND occurs when a high-side FET output is unexpectedly low. This can indicate:
|
noexcept |
Check for short to supply (VS) condition.
| phase_a | Reference to store phase A short-to-VS status |
| phase_b | Reference to store phase B short-to-VS status |
Short to VS occurs when a low-side FET output is unexpectedly high. This can indicate:
|
noexcept |
Check if StealthChop mode is currently active.
StealthChop is active when:
|
noexcept |
Program OTP BBM (break-before-make) default (PERMANENT!)
| short_bbm | true for BBMCLKS=2 (shorter), false for BBMCLKS=4 |
| confirm_permanent | Must be true to confirm permanent operation |
WARNING: This permanently changes the reset default for BBMCLKS. Once set to short (1), it cannot be changed back.
|
noexcept |
Program a single OTP bit (PERMANENT - USE WITH EXTREME CAUTION!)
| byte_index | OTP byte index (0 only for TMC5160) |
| bit_index | Bit index within the byte (0-7) |
| confirm_permanent | Must be true to confirm permanent operation |
CRITICAL WARNING: OTP memory can only be programmed ONCE. Bits can only be set (0→1), never cleared. This operation is IRREVERSIBLE.
OTP bit mapping for byte 0 (TMC5160):
|
noexcept |
Program OTP FCLKTRIM value (PERMANENT - USE WITH EXTREME CAUTION!)
| fclktrim | Clock trim value (0-31, affects internal oscillator) |
| confirm_permanent | Must be true to confirm permanent operation |
CRITICAL WARNING: This permanently changes the internal clock frequency. The factory already programs this for 12MHz. Only use if you need a different clock frequency AND understand the implications.
|
noexcept |
Program OTP short detection level default (PERMANENT!)
| high_level | true for level=12 (less sensitive), false for level=6 |
| confirm_permanent | Must be true to confirm permanent operation |
WARNING: This permanently changes the reset default for S2G_LEVEL and S2VS_LEVEL. Once set to high (1), it cannot be changed back.
|
noexcept |
Program OTP TBL (blank time) default (PERMANENT!)
| short_tbl | true for TBL=1 (~2µs), false for TBL=2 (~3µs) |
| confirm_permanent | Must be true to confirm permanent operation |
WARNING: This permanently changes the reset default for TBL. Once set to short (1), it cannot be changed back.
|
noexcept |
Read factory configuration.
| fclktrim | Reference to store FCLKTRIM value (0-31) |
Reads the factory configuration/clock trim value.
|
noexcept |
Read offset calibration results.
| phase_a | Reference to store phase A offset (0-255) |
| phase_b | Reference to store phase B offset (0-255) |
Reads the results from offset calibration procedure.
|
noexcept |
Read OTP configuration.
| otp_fclktrim | Reference to store OTP FCLKTRIM (0-31) |
| otp_s2_level | Reference to store OTP S2 level (0-1) |
| otp_bbm | Reference to store OTP BBM (0-1) |
| otp_tbl | Reference to store OTP TBL (0-1) |
Reads the one-time programmable configuration memory.
|
noexcept |
Run comprehensive startup verification.
Performs a full verification of the driver setup including:
Logs all findings using the system logger.
|
private |
Reference to parent driver instance.