HF-TMC51x0 Driver (TMC5130 & TMC5160) 0.1.0-dev
Hardware Agnostic C++ Driver for the TMC51x0 (TMC5130 & TMC5160)
Loading...
Searching...
No Matches
tmc51x0_types.hpp
Go to the documentation of this file.
1
6#pragma once
7#include <cstdint>
9
10namespace tmc51x0 {
11
15namespace ClockFreq {
16constexpr uint32_t DEFAULT_F_CLK = 12000000U;
17constexpr uint32_t MIN_F_CLK = 8000000U;
18constexpr uint32_t MAX_F_CLK = 16000000U;
19} // namespace ClockFreq
20
24namespace ChipVersion {
25constexpr uint8_t TMC5130 = 0x11;
26constexpr uint8_t TMC5160 = 0x30;
27} // namespace ChipVersion
28
34namespace RegisterConstants {
35constexpr float TPOWERDOWN_DIVISOR = 262144.0F;
36constexpr float MS_PER_SEC = 1e3F;
37constexpr float US_PER_SEC = 1e6F;
38constexpr float NS_PER_SEC = 1e9F;
39constexpr float ENC_DECIMAL_MULTIPLIER = 1e4F;
40constexpr uint32_t ENC_BINARY_MULTIPLIER = 65536U;
41} // namespace RegisterConstants
42
46namespace MathConstants {
47constexpr float PI = 3.14159265359F;
48constexpr float TWO_PI = 2.0F * PI;
49constexpr float DEGREES_PER_REV = 360.0F;
50} // namespace MathConstants
51
52
53//===============================================================================================================
54//===============================================================================================================
55// ENUMERATIONS
56//===============================================================================================================
57//===============================================================================================================
58
82enum class ChipCommMode : uint8_t {
84 0,
87 2,
89 3
90};
91
95enum class MotorDirection : uint8_t {
96 NORMAL = 0,
97 INVERSE = 1
98};
99
103inline constexpr const char* ToString(MotorDirection d) noexcept {
104 switch (d) {
106 return "NORMAL";
108 return "INVERSE";
109 default:
110 return "Unknown";
111 }
112}
113
132enum class MotorType : uint8_t {
133 STEPPER = 0,
134 DC_MOTOR_SINGLE = 1,
135 DC_MOTOR_DUAL = 2,
136 SOLENOID_SINGLE = 3,
137 SOLENOID_DUAL = 4
138};
139
143inline constexpr const char* ToString(MotorType t) noexcept {
144 switch (t) {
146 return "STEPPER";
148 return "DC_MOTOR_SINGLE";
150 return "DC_MOTOR_DUAL";
152 return "SOLENOID_SINGLE";
154 return "SOLENOID_DUAL";
155 default:
156 return "Unknown";
157 }
158}
159
176enum class Unit : uint8_t {
177 Steps,
178 Rad,
179 Deg,
180 Mm,
181 RPM,
182 RevPerSec
183};
184
188inline constexpr const char* ToString(Unit u) noexcept {
189 switch (u) {
190 case Unit::Steps:
191 return "Steps";
192 case Unit::Rad:
193 return "Rad";
194 case Unit::Deg:
195 return "Deg";
196 case Unit::Mm:
197 return "Mm";
198 case Unit::RPM:
199 return "RPM";
200 case Unit::RevPerSec:
201 return "RevPerSec";
202 default:
203 return "Unknown";
204 }
205}
206
213enum class DriverStatus : uint8_t {
214 OK,
215 CP_UV,
216 S2VSA,
217 S2VSB,
218 S2GA,
219 S2GB,
220 OT,
221 OTHER_ERR,
222 OTPW
223};
224
225//===============================================================================================================
226//===============================================================================================================
227// RESPONSE STRUCTURES
228//===============================================================================================================
229//===============================================================================================================
230
237 bool refl_step{false};
238 bool refr_dir{false};
239 bool encb_dcen_cfg4{false};
240 bool enca_dcin_cfg5{false};
241 bool drv_enn{false};
242 bool enc_n_dco_cfg6{false};
243 bool sd_mode{false};
244 bool swcomp_in{false};
245 uint8_t version{0};
246};
247
248//===============================================================================================================
249//===============================================================================================================
250// HIGHER LEVEL - MECHANICAL SYSTEM CONFIGURATION STRUCTURES
251//===============================================================================================================
252//===============================================================================================================
253
259enum class MechanicalSystemType : uint8_t {
261 LeadScrew,
262 BeltDrive,
263 Gearbox
264};
265
269inline constexpr const char* ToString(MechanicalSystemType type) noexcept {
270 switch (type) {
272 return "DirectDrive";
274 return "LeadScrew";
276 return "BeltDrive";
278 return "Gearbox";
279 default:
280 return "Unknown";
281 }
282}
283
305
306//===============================================================================================================
307//===============================================================================================================
308// MOTOR SPECIFICATION STRUCTURE
309//===============================================================================================================
310//===============================================================================================================
311
322struct MotorSpec {
323 // Motor type (for documentation and configuration purposes)
327
328 // Motor electrical specifications
329 uint16_t steps_per_rev{200};
331 uint16_t rated_current_ma{1500};
334
335 // Desired current settings (used for calculation, not stored as register values)
336 uint16_t run_current_ma{0};
337 uint16_t hold_current_ma{0};
338
339 // Driver hardware configuration (required for automatic current calculation)
340 uint32_t sense_resistor_mohm{50};
341 uint32_t supply_voltage_mv{24000};
342
356
370
384
444 float iholddelay_ms{100.0F};
446
455 MotorSpec() = default;
456};
457
458//===============================================================================================================
459//===============================================================================================================
460// GATE DRIVER - POWER STAGE CONFIGURATION STRUCTURE
461//===============================================================================================================
462//===============================================================================================================
463
471enum class SenseFilterTime : uint8_t {
472 T100ns = 0,
473 T200ns = 1,
474 T300ns = 2,
475 T400ns = 3
476};
477
486enum class OverTempProtection : uint8_t {
487 Temp150C = 0,
488 Temp143C = 1,
489 Temp136C = 2,
490 Temp120C = 3
491};
492
659
660//===============================================================================================================
661//===============================================================================================================
662// CHOPPER CONFIGURATION STRUCTURE
663//===============================================================================================================
664//===============================================================================================================
665
671enum class ChopperMode : bool {
672 SPREAD_CYCLE = false,
673 CLASSIC = true
674};
675
679inline constexpr const char* ToString(ChopperMode m) noexcept {
680 return (m == ChopperMode::SPREAD_CYCLE) ? "SPREAD_CYCLE" : "CLASSIC";
681}
682
692enum class ChopperBlankTime : uint8_t {
693 TBL_16CLK = 0,
694 TBL_24CLK = 1,
695 TBL_36CLK = 2,
696 TBL_54CLK = 3
697};
698
707enum class MicrostepResolution : uint8_t {
708 MRES_256 = 0,
709 MRES_128 = 1,
710 MRES_64 = 2,
711 MRES_32 = 3,
712 MRES_16 = 4,
713 MRES_8 = 5,
714 MRES_4 = 6,
715 MRES_2 = 7,
716 FULLSTEP = 8
717};
718
722inline constexpr const char* ToString(MicrostepResolution mres) noexcept {
723 switch (mres) {
725 return "MRES_256";
727 return "MRES_128";
729 return "MRES_64";
731 return "MRES_32";
733 return "MRES_16";
735 return "MRES_8";
737 return "MRES_4";
739 return "MRES_2";
741 return "FULLSTEP";
742 default:
743 return "Unknown";
744 }
745}
746
752inline constexpr uint16_t MicrostepsPerFullStep(MicrostepResolution mres) noexcept {
753 const uint8_t enc = static_cast<uint8_t>(mres);
754 const uint8_t clamped = (enc > 8U) ? 8U : enc;
755 return static_cast<uint16_t>(256U >> clamped);
756}
757
767enum class MicrostepLutPreset : uint8_t {
774 DEFAULT_SINE = 0,
775
782 PURE_SINE = 1
783};
784
788inline constexpr const char* ToString(MicrostepLutPreset preset) noexcept {
789 switch (preset) {
791 return "DEFAULT_SINE";
793 return "PURE_SINE";
794 default:
795 return "Unknown";
796 }
797}
798
821
829
836 bool rescale_encoder{true};
837};
838
868
891 uint8_t toff{5};
892
908 uint8_t tbl{2};
909
929 uint8_t hstrt{4};
930
947 uint8_t hend{0};
948
964 uint8_t tfd{0};
965
977 bool disfdcc{false};
978
991 uint8_t tpfd{0};
992
1007
1019 bool intpol{true};
1020
1031 bool dedge{false};
1032
1047 bool vhighfs{false};
1048
1064 bool vhighchm{false};
1065
1079 bool diss2g{false};
1080
1094 bool diss2vs{false};
1095
1108 ChopperConfig() = default;
1109
1121 ChopperConfig(uint8_t off_time, uint8_t blank_time = 2, uint8_t hysteresis_start = 4, uint8_t hysteresis_end = 0,
1123 : toff(off_time), tbl(blank_time), hstrt(hysteresis_start), hend(hysteresis_end), mres(microstep_res) {}
1124
1137 ChopperConfig(uint8_t off_time, uint8_t fast_decay_time, uint8_t sine_offset, uint8_t blank_time = 2,
1138 bool disable_comparator = false, MicrostepResolution microstep_res = MicrostepResolution::MRES_16)
1139 : mode(ChopperMode::CLASSIC), toff(off_time), tbl(blank_time), hstrt(0) // Not used in Classic mode
1140 ,
1141 hend(sine_offset) // Used as OFFSET in Classic mode
1142 ,
1143 tfd(fast_decay_time), disfdcc(disable_comparator), mres(microstep_res) {}
1144};
1145
1146//===============================================================================================================
1147//===============================================================================================================
1148// STEALTHCHOP CONFIGURATION STRUCTURE
1149//===============================================================================================================
1150//===============================================================================================================
1151
1168enum class StealthChopPwmFreq : uint8_t {
1169 PWM_FREQ_0 = 0,
1170 PWM_FREQ_1 = 1,
1171 PWM_FREQ_2 = 2,
1172 PWM_FREQ_3 = 3
1173};
1174
1187enum class StealthChopRegulationSpeed : uint8_t {
1188 VERY_SLOW = 1,
1189 SLOW = 2,
1190 MODERATE = 4,
1191 FAST = 8,
1192 VERY_FAST = 15
1193};
1194
1205enum class StealthChopJerkReduction : uint8_t {
1206 MAXIMUM = 8,
1207 HIGH = 10,
1208 MODERATE = 12,
1209 LOW = 14,
1210 MINIMUM = 15
1211};
1212
1256 uint8_t pwm_ofs{30};
1257
1273 uint8_t pwm_grad{0};
1274
1293 uint8_t pwm_freq{1};
1294
1314 bool pwm_autoscale{true};
1315
1332 bool pwm_autograd{true};
1333
1356 uint8_t pwm_reg{4};
1357
1375 uint8_t pwm_lim{12};
1376
1394
1411
1418
1434
1446 StealthChopConfig(uint8_t pwm_frequency, uint8_t pwm_offset = 30, uint8_t pwm_gradient = 0,
1447 uint8_t regulation_speed = 4, uint8_t jerk_reduction = 12)
1448 : pwm_ofs(pwm_offset), pwm_grad(pwm_gradient), pwm_freq(pwm_frequency), pwm_reg(regulation_speed),
1449 pwm_lim(jerk_reduction) {}
1450
1465 uint8_t pwm_offset = 30, uint8_t pwm_gradient = 0)
1466 : pwm_ofs(pwm_offset), pwm_grad(pwm_gradient), pwm_freq(static_cast<uint8_t>(pwm_frequency)),
1467 pwm_reg(static_cast<uint8_t>(regulation_speed)), pwm_lim(static_cast<uint8_t>(jerk_reduction)) {}
1468
1479 StealthChopConfig(uint8_t pwm_frequency, uint8_t pwm_offset, uint8_t pwm_gradient)
1480 : pwm_ofs(pwm_offset), pwm_grad(pwm_gradient), pwm_freq(pwm_frequency), pwm_autoscale(false), // Manual mode
1481 pwm_autograd(false) // Manual mode
1482 {}
1483};
1484
1485//===============================================================================================================
1486//===============================================================================================================
1487// STALLGUARD CONFIGURATION STRUCTURE
1488//===============================================================================================================
1489//===============================================================================================================
1490
1498enum class StallGuardSensitivity : int8_t {
1499 VERY_HIGH = -32,
1500 HIGH = -16,
1501 MODERATE = 0,
1502 LOW = 16,
1503 VERY_LOW = 32
1504};
1505
1534 int8_t threshold{0};
1535
1548 bool enable_filter{false};
1549
1560 float min_velocity{0.0F};
1561
1571 float max_velocity{0.0F};
1572
1579
1590 bool stop_on_stall{false};
1591
1600 StallGuardConfig() = default;
1601
1614 StallGuardConfig(int8_t sgt_threshold, bool enable_filt = false, float min_vel = 0.0F, float max_vel = 0.0F,
1615 Unit vel_unit = Unit::RevPerSec, bool stop_on_stall = false)
1616 : threshold(sgt_threshold), enable_filter(enable_filt), min_velocity(min_vel), max_velocity(max_vel),
1618
1624 StallGuardConfig(StallGuardSensitivity sensitivity, bool enable_filt = false, float min_vel = 0.0F,
1625 float max_vel = 0.0F, Unit vel_unit = Unit::Steps, bool stop_on_stall = false)
1626 : threshold(static_cast<int8_t>(sensitivity)), enable_filter(enable_filt), min_velocity(min_vel),
1627 max_velocity(max_vel), velocity_unit(vel_unit), stop_on_stall(stop_on_stall) {}
1628};
1629
1655 int8_t optimal_sgt{0};
1656
1663 bool tuning_success{false};
1664
1675
1683
1694
1702
1714
1726
1736
1744
1752
1759};
1760
1761//===============================================================================================================
1762//===============================================================================================================
1763// SELF-DESCRIBING VALUE TYPES WITH UNITS
1764//===============================================================================================================
1765//===============================================================================================================
1766
1779 float value{0.0f};
1781
1785 VelocityValue() = default;
1786
1790 constexpr VelocityValue(float v, Unit u) noexcept : value(v), unit(u) {}
1791
1792 // Factory methods for common units
1793 static constexpr VelocityValue FromSteps(float v) noexcept { return {v, Unit::Steps}; }
1794 static constexpr VelocityValue FromRPM(float v) noexcept { return {v, Unit::RPM}; }
1795 static constexpr VelocityValue FromRevPerSec(float v) noexcept { return {v, Unit::RevPerSec}; }
1796 static constexpr VelocityValue FromRad(float v) noexcept { return {v, Unit::Rad}; }
1797 static constexpr VelocityValue FromDeg(float v) noexcept { return {v, Unit::Deg}; }
1798 static constexpr VelocityValue FromMm(float v) noexcept { return {v, Unit::Mm}; }
1799};
1800
1813 float value{0.0f};
1815
1820
1824 constexpr AccelerationValue(float v, Unit u) noexcept : value(v), unit(u) {}
1825
1826 // Factory methods for common units
1827 static constexpr AccelerationValue FromSteps(float v) noexcept { return {v, Unit::Steps}; }
1828 static constexpr AccelerationValue FromRevPerSec(float v) noexcept { return {v, Unit::RevPerSec}; }
1829 static constexpr AccelerationValue FromRad(float v) noexcept { return {v, Unit::Rad}; }
1830 static constexpr AccelerationValue FromDeg(float v) noexcept { return {v, Unit::Deg}; }
1831 static constexpr AccelerationValue FromMm(float v) noexcept { return {v, Unit::Mm}; }
1832};
1833
1834//===============================================================================================================
1835//===============================================================================================================
1836// RAMP CONFIGURATION STRUCTURE
1837//===============================================================================================================
1838//===============================================================================================================
1839
1856 // Velocity parameters (self-describing with explicit units)
1861
1862 // Acceleration parameters (self-describing with explicit units)
1867
1868 // Timing parameters (in milliseconds, automatically converted to register values)
1869 float tpowerdown_ms{437.0F};
1873
1919 0.0F};
1920
1936 RampConfig() = default;
1937};
1938
1939//===============================================================================================================
1940//===============================================================================================================
1941// COOLSTEP CONFIGURATION STRUCTURE
1942//===============================================================================================================
1943//===============================================================================================================
1944
1951enum class CoolStepIncrementStep : uint8_t {
1952 STEP_1 = 0,
1953 STEP_2 = 1,
1954 STEP_4 = 2,
1955 STEP_8 = 3
1956};
1957
1964enum class CoolStepDecrementSpeed : uint8_t {
1965 EVERY_32 = 0,
1966 EVERY_8 = 1,
1967 EVERY_2 = 2,
1968 EVERY_1 = 3
1969};
1970
1976enum class CoolStepMinCurrent : uint8_t {
1977 HALF_IRUN = 0,
1978 QUARTER_IRUN = 1
1979};
1980
2004
2016
2017 // Step size configuration (using enums for clarity)
2020
2021 // Minimum current configuration
2023
2024 // Filter configuration
2025 bool enable_filter{false};
2026
2027 // Velocity thresholds (with unit support)
2037 float min_velocity{0.0F};
2038
2047 float max_velocity{0.0F};
2048
2055
2062 CoolStepConfig() = default;
2063
2079 CoolStepConfig(uint16_t lower_sg, uint16_t upper_sg, float min_vel, float max_vel, Unit vel_unit = Unit::RevPerSec)
2080 : lower_threshold_sg(lower_sg), upper_threshold_sg(upper_sg), min_velocity(min_vel), max_velocity(max_vel),
2081 velocity_unit(vel_unit) {}
2082};
2083
2084//===============================================================================================================
2085//===============================================================================================================
2086// DCSTEP CONFIGURATION STRUCTURE
2087//===============================================================================================================
2088//===============================================================================================================
2089
2096enum class DcStepStallSensitivity : uint8_t {
2097 DISABLED = 0,
2098 LOW = 1,
2099 MODERATE = 2,
2100 HIGH = 3
2101};
2102
2134 float min_velocity{0.0F};
2135
2142
2160 float pwm_on_time_us{0.0F};
2161
2172
2182 bool stop_on_stall{false};
2183
2190 DcStepConfig() = default;
2191
2204 DcStepConfig(float min_vel, Unit vel_unit = Unit::RevPerSec, float pwm_time_us = 0.0F,
2206 : min_velocity(min_vel), velocity_unit(vel_unit), pwm_on_time_us(pwm_time_us), stall_sensitivity(sensitivity) {}
2207};
2208
2209//===============================================================================================================
2210//===============================================================================================================
2211// REFERENCE SWITCHES CONFIGURATION STRUCTURE
2212//===============================================================================================================
2213//===============================================================================================================
2214
2225enum class ReferenceSwitchActiveLevel : uint8_t {
2226 ACTIVE_LOW,
2233};
2234
2238inline constexpr const char* ToString(ReferenceSwitchActiveLevel a) noexcept {
2239 switch (a) {
2241 return "ACTIVE_LOW";
2243 return "ACTIVE_HIGH";
2244 default:
2245 return "Unknown";
2246 }
2247}
2248
2255enum class ReferenceLatchMode : uint8_t {
2256 DISABLED,
2257 ACTIVE_EDGE,
2261 BOTH_EDGES
2263};
2264
2268inline constexpr const char* ToString(ReferenceLatchMode m) noexcept {
2269 switch (m) {
2271 return "DISABLED";
2273 return "ACTIVE_EDGE";
2275 return "INACTIVE_EDGE";
2277 return "BOTH_EDGES";
2278 default:
2279 return "Unknown";
2280 }
2281}
2282
2288enum class ReferenceStopMode : uint8_t {
2289 HARD_STOP,
2292 SOFT_STOP
2295};
2296
2300inline constexpr const char* ToString(ReferenceStopMode m) noexcept {
2301 switch (m) {
2303 return "HARD_STOP";
2305 return "SOFT_STOP";
2306 default:
2307 return "Unknown";
2308 }
2309}
2310
2328 // Switch active level configuration (determines polarity)
2329 // Active level must always be specified (ACTIVE_LOW or ACTIVE_HIGH)
2330 // Use stop_enable to control whether switch stops the motor (allows real-time enable/disable)
2339
2340 // Motor stop enable configuration (independent of active level)
2341 // Allows enabling/disabling motor stop in real-time while keeping polarity configured
2343 false};
2346 false};
2348
2349 // Stop configuration
2352 bool swap_left_right{false};
2353
2354 // Position latching configuration
2357 bool en_latch_encoder{false};
2358
2369};
2370
2371//===============================================================================================================
2372//===============================================================================================================
2373// ENCODER FEEDBACK CONFIGURATION STRUCTURE
2374//===============================================================================================================
2375//===============================================================================================================
2376
2383enum class EncoderNSensitivity : uint8_t {
2384 ACTIVE_LEVEL,
2386 RISING_EDGE,
2388 FALLING_EDGE,
2390 BOTH_EDGES
2392};
2393
2397inline constexpr const char* ToString(EncoderNSensitivity s) noexcept {
2398 switch (s) {
2400 return "ACTIVE_LEVEL";
2402 return "RISING_EDGE";
2404 return "FALLING_EDGE";
2406 return "BOTH_EDGES";
2407 default:
2408 return "Unknown";
2409 }
2410}
2411
2417enum class EncoderClearMode : uint8_t {
2418 DISABLED,
2420 ONCE,
2423 CONTINUOUS
2425};
2426
2430inline constexpr const char* ToString(EncoderClearMode m) noexcept {
2431 switch (m) {
2433 return "DISABLED";
2435 return "ONCE";
2437 return "CONTINUOUS";
2438 default:
2439 return "Unknown";
2440 }
2441}
2442
2448enum class EncoderPrescalerMode : uint8_t {
2449 BINARY,
2451 DECIMAL
2453};
2454
2458inline constexpr const char* ToString(EncoderPrescalerMode m) noexcept {
2459 switch (m) {
2461 return "BINARY";
2463 return "DECIMAL";
2464 default:
2465 return "Unknown";
2466 }
2467}
2468
2480 // N channel configuration (shares ReferenceSwitchActiveLevel enum)
2481 // Note: Default initialization done in constructor since enum is forward-declared
2483 ReferenceSwitchActiveLevel::
2484 ACTIVE_LOW};
2486
2487 // A/B polarity requirements for N channel validation
2488 bool require_a_high{false};
2490 bool require_b_high{false};
2494
2495 // N channel event detection
2498
2499 // Clear/latch mode
2501
2502 // Additional encoder features
2507
2508 // Prescaler mode
2511
2529 0};
2530
2543 uint16_t pulses_per_rev{0};
2544
2555 bool invert_direction{false};
2556
2569 EncoderConfig() = default;
2570};
2571
2572//===============================================================================================================
2573//===============================================================================================================
2574// DIAGNOSTIC PIN CONFIGURATION STRUCTURES
2575//===============================================================================================================
2576//===============================================================================================================
2577
2589 bool error{false};
2590 bool otpw{false};
2592 false};
2593 bool pushpull{false};
2594
2600 Diag0Config() = default;
2601};
2602
2614 bool stall_dir{false};
2615 bool index{false};
2616 bool onstate{false};
2617 bool steps_skipped{false};
2618 bool pushpull{false};
2619
2627 Diag1Config() = default;
2628};
2629
2630//===============================================================================================================
2631//===============================================================================================================
2632// EXTERNAL CLOCK CONFIGURATION STRUCTURE
2633//===============================================================================================================
2634//===============================================================================================================
2635
2669 uint32_t frequency_hz{0};
2670
2678};
2679
2680//===============================================================================================================
2681//===============================================================================================================
2682// UART CONFIGURATION STRUCTURE
2683//===============================================================================================================
2684//===============================================================================================================
2685
2710 uint8_t node_address{0};
2711
2726 uint8_t send_delay{0};
2727
2735 UartConfig() = default;
2736};
2737
2738//===============================================================================================================
2739//===============================================================================================================
2740// GLOBAL CONFIGURATION STRUCTURE
2741//===============================================================================================================
2742//===============================================================================================================
2743
2799
2800//===============================================================================================================
2801//===============================================================================================================
2802// DRIVER CONFIGURATION STRUCTURE
2803//===============================================================================================================
2804//===============================================================================================================
2805
2874
2880
2881 // Clock configuration
2884
2885 // Advanced feature configurations (defaults are safe/disabled)
2889
2890 // Sensor configurations (defaults are safe/disabled)
2891 // These are typically set by test rig/platform configuration helpers
2892 // Defaults are safe: switches don't stop motor, encoder clear mode is disabled
2896
2897 // UART communication configuration (only used in UART mode)
2899
2909 DriverConfig() noexcept {}
2910};
2911
2924 // StealthChop state (must be disabled for StallGuard)
2927
2928 // SW_MODE register (modified by both homing methods)
2929 SW_MODE_Register cached_sw_mode{}; // Full register value before homing
2931
2932 // Ramp settings (modified by both homing methods)
2934 float cached_max_speed = 0.0f;
2937 float cached_vstart = 0.0f;
2938 float cached_vstop = 0.0f;
2939 float cached_v1 = 0.0f;
2941
2942 bool is_valid = false; // True if cache has been populated
2943};
2944
2945} // namespace tmc51x0
constexpr uint8_t TMC5160
TMC5160 chip version.
Definition tmc51x0_types.hpp:26
constexpr uint8_t TMC5130
TMC5130 chip version.
Definition tmc51x0_types.hpp:25
constexpr uint32_t MIN_F_CLK
Minimum clock frequency in Hz.
Definition tmc51x0_types.hpp:17
constexpr uint32_t MAX_F_CLK
Maximum clock frequency in Hz.
Definition tmc51x0_types.hpp:18
constexpr uint32_t DEFAULT_F_CLK
Typical internal clock frequency in Hz (12 MHz)
Definition tmc51x0_types.hpp:16
constexpr float PI
π (pi) constant
Definition tmc51x0_types.hpp:47
constexpr float TWO_PI
2π (two pi)
Definition tmc51x0_types.hpp:48
constexpr float DEGREES_PER_REV
Degrees per revolution.
Definition tmc51x0_types.hpp:49
constexpr float TPOWERDOWN_DIVISOR
2^18, used for TPOWERDOWN and TZEROWAIT register conversion
Definition tmc51x0_types.hpp:35
constexpr float ENC_DECIMAL_MULTIPLIER
Multiplier for encoder decimal mode (fractional part)
Definition tmc51x0_types.hpp:39
constexpr float MS_PER_SEC
Milliseconds per second (used for ms to seconds conversion)
Definition tmc51x0_types.hpp:36
constexpr float NS_PER_SEC
Nanoseconds per second (used for ns to seconds conversion)
Definition tmc51x0_types.hpp:38
constexpr float US_PER_SEC
Microseconds per second (used for us to seconds conversion)
Definition tmc51x0_types.hpp:37
constexpr uint32_t ENC_BINARY_MULTIPLIER
Multiplier for encoder binary mode (2^16)
Definition tmc51x0_types.hpp:40
Definition tmc51x0_register_defs.cpp:10
CoolStepMinCurrent
CoolStep minimum current percentage enumeration.
Definition tmc51x0_types.hpp:1976
@ QUARTER_IRUN
Minimum current is 25% of IRUN (1/4)
@ HALF_IRUN
Minimum current is 50% of IRUN (1/2)
MicrostepResolution
Microstep resolution enumeration.
Definition tmc51x0_types.hpp:707
@ FULLSTEP
Full step (no microstepping)
@ MRES_16
16 microsteps per full step (typical)
@ MRES_4
4 microsteps per full step
@ MRES_64
64 microsteps per full step
@ MRES_32
32 microsteps per full step
@ MRES_128
128 microsteps per full step
@ MRES_2
2 microsteps per full step
@ MRES_8
8 microsteps per full step
@ MRES_256
256 microsteps per full step (highest resolution)
OverTempProtection
Over-temperature protection level enumeration.
Definition tmc51x0_types.hpp:486
@ Temp136C
136°C threshold (more protection)
@ Temp143C
143°C threshold
@ Temp150C
150°C threshold (lowest protection, highest temperature)
@ Temp120C
120°C threshold (highest protection, lowest temperature)
ChopperBlankTime
Comparator blank time enumeration.
Definition tmc51x0_types.hpp:692
@ TBL_54CLK
54 clock cycles (~4.5µs @ 12MHz, for high capacitive loads)
@ TBL_36CLK
36 clock cycles (~3.0µs @ 12MHz, typical)
@ TBL_24CLK
24 clock cycles (~2.0µs @ 12MHz)
@ TBL_16CLK
16 clock cycles (~1.33µs @ 12MHz)
EncoderNSensitivity
Encoder N channel sensitivity enumeration.
Definition tmc51x0_types.hpp:2383
EncoderClearMode
Encoder clear mode enumeration.
Definition tmc51x0_types.hpp:2417
MechanicalSystemType
Mechanical system type enumeration.
Definition tmc51x0_types.hpp:259
@ Gearbox
Gearbox reduction.
@ LeadScrew
Lead screw drive.
@ BeltDrive
Belt drive with pulleys.
@ DirectDrive
Direct drive (motor shaft directly connected)
constexpr const char * ToString(MotorDirection d) noexcept
Convert MotorDirection to human-readable string.
Definition tmc51x0_types.hpp:103
ReferenceStopMode
Stop mode enumeration.
Definition tmc51x0_types.hpp:2288
ReferenceLatchMode
Position latching mode enumeration.
Definition tmc51x0_types.hpp:2255
@ DISABLED
No position latching (latch disabled)
MotorType
Motor type enumeration.
Definition tmc51x0_types.hpp:132
@ STEPPER
Stepper motor (default, typically uses step/dir or internal ramp generator)
@ DC_MOTOR_SINGLE
Single DC motor (typically uses direct mode, coil A only)
@ SOLENOID_SINGLE
Single solenoid/actuator (typically uses direct mode, coil A only)
@ SOLENOID_DUAL
Two solenoids/actuators (typically uses direct mode, coil A and B)
@ DC_MOTOR_DUAL
Two DC motors (typically uses direct mode, coil A and B)
DcStepStallSensitivity
DcStep stall detection sensitivity enumeration.
Definition tmc51x0_types.hpp:2096
@ DISABLED
Stall detection disabled (dc_sg = 0)
@ MODERATE
Moderate sensitivity - balanced (dc_sg ≈ dc_time / 16, recommended)
StealthChopJerkReduction
StealthChop mode switching jerk reduction enumeration.
Definition tmc51x0_types.hpp:1205
@ MAXIMUM
Maximum jerk reduction (smoothest switching)
@ MODERATE
Moderate jerk reduction (default, balanced)
@ HIGH
High jerk reduction.
@ MINIMUM
Minimum jerk reduction (fastest switching, may cause spikes)
@ OK
Operation succeeded.
constexpr uint16_t MicrostepsPerFullStep(MicrostepResolution mres) noexcept
Get microsteps-per-full-step for an MRES value.
Definition tmc51x0_types.hpp:752
Unit
Unit enumeration.
Definition tmc51x0_types.hpp:176
@ Mm
Millimeters (linear only)
@ Rad
Radians (per second for velocity, per second^2 for accel)
@ RevPerSec
Revolutions per Second (recommended default for velocity)
@ Deg
Degrees (per second for velocity, per second^2 for accel)
@ Steps
Steps (see notes above; float APIs treat this as full-steps, register units are microsteps)
@ RPM
Revolutions per Minute (Velocity only, typically)
MotorDirection
Motor direction enumeration.
Definition tmc51x0_types.hpp:95
@ INVERSE
Inverse motor direction.
@ NORMAL
Normal motor direction.
@ BOTH_EDGES
N channel active on N event activation and de-activation.
@ FALLING_EDGE
N channel active when the N event is de-activated.
@ RISING_EDGE
N channel active when the N event is activated.
EncoderPrescalerMode
Encoder prescaler mode enumeration.
Definition tmc51x0_types.hpp:2448
CoolStepDecrementSpeed
CoolStep current decrement speed enumeration.
Definition tmc51x0_types.hpp:1964
@ EVERY_32
Decrement every 32 measurements (slowest reduction, most stable)
@ EVERY_2
Decrement every 2 measurements.
@ EVERY_1
Decrement every measurement (fastest reduction)
@ EVERY_8
Decrement every 8 measurements.
ReferenceSwitchActiveLevel
Reference switch active level enumeration.
Definition tmc51x0_types.hpp:2225
RampMode
Ramp mode enumeration values.
Definition tmc51x0_registers.hpp:32
@ POSITIONING
Positioning mode using all A, D and V parameters.
StealthChopPwmFreq
StealthChop PWM frequency enumeration.
Definition tmc51x0_types.hpp:1168
@ PWM_FREQ_0
fPWM = 2/1024 * fCLK (~23.4kHz @ 12MHz)
@ PWM_FREQ_1
fPWM = 2/683 * fCLK (~35.1kHz @ 12MHz, recommended)
@ PWM_FREQ_3
fPWM = 2/410 * fCLK (~58.5kHz @ 12MHz)
@ PWM_FREQ_2
fPWM = 2/512 * fCLK (~46.9kHz @ 12MHz)
SenseFilterTime
Sense amplifier filter time constant enumeration.
Definition tmc51x0_types.hpp:471
@ T100ns
~100ns (reset default)
StealthChopRegulationSpeed
StealthChop regulation speed enumeration.
Definition tmc51x0_types.hpp:1187
@ SLOW
1 increment per half wave
@ VERY_SLOW
0.5 increments per half wave (slowest, most stable)
@ MODERATE
2 increments per half wave (default, balanced)
@ VERY_FAST
7.5 increments per half wave (fastest, may be less stable)
@ FAST
4 increments per half wave
CoolStepIncrementStep
CoolStep current increment step width enumeration.
Definition tmc51x0_types.hpp:1951
@ STEP_8
Increment by 8 steps per measurement (fastest response)
@ STEP_2
Increment by 2 steps per measurement.
@ STEP_4
Increment by 4 steps per measurement.
@ STEP_1
Increment by 1 step per measurement (slowest, smoothest)
ChipCommMode
Chip communication and motion control mode configuration.
Definition tmc51x0_types.hpp:82
@ SPI_EXTERNAL_STEPDIR
SPI_MODE=HIGH, SD_MODE=HIGH - SPI interface with external step/dir inputs.
@ STANDALONE_EXTERNAL_STEPDIR
SPI_MODE=LOW, SD_MODE=HIGH - Standalone Step/Dir mode (no SPI/UART, CFG pins configure driver)
@ SPI_INTERNAL_RAMP
SPI_MODE=HIGH, SD_MODE=LOW - SPI interface with internal ramp generator (motion controller)
@ UART_INTERNAL_RAMP
SPI_MODE=LOW, SD_MODE=LOW - UART interface with internal ramp generator (motion controller)
StallGuardSensitivity
StallGuard2 sensitivity enumeration.
Definition tmc51x0_types.hpp:1498
@ VERY_HIGH
Very high sensitivity (SGT = -32) - detects stalls very easily.
@ VERY_LOW
Very low sensitivity (SGT = 32) - requires significant torque to detect stall.
PWMFreewheel
PWM freewheel mode enumeration values.
Definition tmc51x0_registers.hpp:42
@ NORMAL
Normal operation.
ChopperMode
Chopper mode enumeration.
Definition tmc51x0_types.hpp:671
@ CLASSIC
Classic constant off-time mode - alternative chopper algorithm.
@ SPREAD_CYCLE
SpreadCycle mode (recommended) - superior microstepping quality.
MicrostepLutPreset
Microstep lookup table preset waveforms.
Definition tmc51x0_types.hpp:767
@ PURE_SINE
Mathematical pure sine wave.
@ DEFAULT_SINE
TMC5160 power-on default (slightly modified sine)
DriverStatus
Driver status enumeration.
Definition tmc51x0_types.hpp:213
@ OT
Overtemperature (error)
@ OTHER_ERR
GSTAT drv_err is set but none of the above conditions is found.
@ S2VSB
Short to supply phase B.
@ CP_UV
Charge pump undervoltage.
@ S2GB
Short to ground phase B.
@ OTPW
Overtemperature pre-warning.
@ S2GA
Short to ground phase A.
@ S2VSA
Short to supply phase A.
Self-describing acceleration value with explicit unit.
Definition tmc51x0_types.hpp:1812
float value
Acceleration magnitude.
Definition tmc51x0_types.hpp:1813
Unit unit
Acceleration unit (per second²)
Definition tmc51x0_types.hpp:1814
constexpr AccelerationValue(float v, Unit u) noexcept
Construct with value and unit.
Definition tmc51x0_types.hpp:1824
static constexpr AccelerationValue FromSteps(float v) noexcept
Definition tmc51x0_types.hpp:1827
static constexpr AccelerationValue FromDeg(float v) noexcept
Definition tmc51x0_types.hpp:1830
static constexpr AccelerationValue FromRevPerSec(float v) noexcept
Definition tmc51x0_types.hpp:1828
static constexpr AccelerationValue FromMm(float v) noexcept
Definition tmc51x0_types.hpp:1831
AccelerationValue()=default
Default constructor.
static constexpr AccelerationValue FromRad(float v) noexcept
Definition tmc51x0_types.hpp:1829
Chopper configuration structure.
Definition tmc51x0_types.hpp:856
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.
Definition tmc51x0_types.hpp:1121
bool diss2vs
Short to supply protection disable.
Definition tmc51x0_types.hpp:1094
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.
Definition tmc51x0_types.hpp:1137
bool diss2g
Short to GND protection disable.
Definition tmc51x0_types.hpp:1079
ChopperMode mode
Chopper mode selection.
Definition tmc51x0_types.hpp:867
bool vhighfs
High velocity fullstep selection.
Definition tmc51x0_types.hpp:1047
uint8_t hend
Hysteresis end value (SpreadCycle mode) or Sine wave offset (Classic mode)
Definition tmc51x0_types.hpp:947
bool intpol
Enable interpolation to 256 microsteps.
Definition tmc51x0_types.hpp:1019
uint8_t toff
Off time (slow decay time) setting.
Definition tmc51x0_types.hpp:891
uint8_t hstrt
Hysteresis start value (SpreadCycle mode only)
Definition tmc51x0_types.hpp:929
bool dedge
Enable double edge step pulses.
Definition tmc51x0_types.hpp:1031
uint8_t tfd
Fast decay time (Classic mode only)
Definition tmc51x0_types.hpp:964
uint8_t tpfd
Passive fast decay time.
Definition tmc51x0_types.hpp:991
bool vhighchm
High velocity chopper mode.
Definition tmc51x0_types.hpp:1064
bool disfdcc
Disable fast decay comparator (Classic mode only)
Definition tmc51x0_types.hpp:977
ChopperConfig()=default
Default constructor.
MicrostepResolution mres
Microstep resolution.
Definition tmc51x0_types.hpp:1006
uint8_t tbl
Comparator blank time.
Definition tmc51x0_types.hpp:908
CoolStep configuration structure.
Definition tmc51x0_types.hpp:1992
float max_velocity
Upper velocity threshold for CoolStep activation.
Definition tmc51x0_types.hpp:2047
uint16_t upper_threshold_sg
Upper StallGuard2 threshold for current decrease.
Definition tmc51x0_types.hpp:2015
bool enable_filter
Enable StallGuard2 filter (reduces measurement rate by 4x)
Definition tmc51x0_types.hpp:2025
CoolStepMinCurrent min_current
Minimum current percentage.
Definition tmc51x0_types.hpp:2022
CoolStepConfig(uint16_t lower_sg, uint16_t upper_sg, float min_vel, float max_vel, Unit vel_unit=Unit::RevPerSec)
Helper constructor for common configuration.
Definition tmc51x0_types.hpp:2079
CoolStepIncrementStep increment_step
Current increment step width.
Definition tmc51x0_types.hpp:2018
uint16_t lower_threshold_sg
Lower StallGuard2 threshold for current increase.
Definition tmc51x0_types.hpp:2003
CoolStepConfig()=default
Default constructor.
CoolStepDecrementSpeed decrement_speed
Current decrement speed.
Definition tmc51x0_types.hpp:2019
Unit velocity_unit
Unit for velocity thresholds.
Definition tmc51x0_types.hpp:2054
float min_velocity
Lower velocity threshold for CoolStep activation.
Definition tmc51x0_types.hpp:2037
DcStep configuration structure.
Definition tmc51x0_types.hpp:2122
DcStepConfig()=default
Default constructor.
float min_velocity
Minimum velocity threshold for DcStep activation.
Definition tmc51x0_types.hpp:2134
DcStepConfig(float min_vel, Unit vel_unit=Unit::RevPerSec, float pwm_time_us=0.0F, DcStepStallSensitivity sensitivity=DcStepStallSensitivity::MODERATE)
Helper constructor for quick setup.
Definition tmc51x0_types.hpp:2204
DcStepStallSensitivity stall_sensitivity
Stall detection sensitivity.
Definition tmc51x0_types.hpp:2171
Unit velocity_unit
Unit for velocity threshold.
Definition tmc51x0_types.hpp:2141
bool stop_on_stall
Enable stop on stall.
Definition tmc51x0_types.hpp:2182
float pwm_on_time_us
PWM on-time limit for commutation (user-friendly)
Definition tmc51x0_types.hpp:2160
DIAG0 pin configuration structure.
Definition tmc51x0_types.hpp:2588
bool pushpull
Bit 12: Output mode (false=open collector active low, true=push pull active high)
Definition tmc51x0_types.hpp:2593
bool error
Bit 5: Enable DIAG0 on driver errors (OT, S2G, UV_CP) - SD_MODE=1 only.
Definition tmc51x0_types.hpp:2589
Diag0Config()=default
Default constructor.
bool otpw
Bit 6: Enable DIAG0 on overtemperature prewarning - SD_MODE=1 only.
Definition tmc51x0_types.hpp:2590
bool stall_step
Bit 7: (SD_MODE=1) DIAG0 on stall, (SD_MODE=0) DIAG0 as STEP output (half frequency,...
Definition tmc51x0_types.hpp:2591
DIAG1 pin configuration structure.
Definition tmc51x0_types.hpp:2613
bool pushpull
Bit 13: Output mode (false=open collector active low, true=push pull active high)
Definition tmc51x0_types.hpp:2618
bool stall_dir
Bit 8: (SD_MODE=1) DIAG1 on stall, (SD_MODE=0) DIAG1 as DIR output.
Definition tmc51x0_types.hpp:2614
bool index
Bit 9: Enable DIAG1 on index position (microstep LUT position 0) - SD_MODE=1 only.
Definition tmc51x0_types.hpp:2615
bool onstate
Bit 10: Enable DIAG1 when chopper is on (second half of fullstep) - SD_MODE=1 only.
Definition tmc51x0_types.hpp:2616
Diag1Config()=default
Default constructor.
bool steps_skipped
Bit 11: Enable output toggle when steps skipped in dcStep mode - SD_MODE=1 only.
Definition tmc51x0_types.hpp:2617
Driver initialization configuration structure.
Definition tmc51x0_types.hpp:2870
RampConfig ramp_config
Ramp generator configuration (with unit support)
Definition tmc51x0_types.hpp:2879
StallGuardConfig stallguard
StallGuard2 configuration (defaults: threshold=0, disabled)
Definition tmc51x0_types.hpp:2886
ExternalClockConfig external_clk_config
External clock configuration (0 = use internal 12 MHz, >0 = external clock frequency)
Definition tmc51x0_types.hpp:2883
UartConfig uart_config
UART communication configuration (node address, send delay)
Definition tmc51x0_types.hpp:2898
CoolStepConfig coolstep
CoolStep configuration (defaults: lower_threshold_sg=0, disabled)
Definition tmc51x0_types.hpp:2887
GlobalConfig global_config
Global configuration (GCONF register)
Definition tmc51x0_types.hpp:2878
ReferenceSwitchConfig reference_switch_config
Reference switch configuration (defaults: stop disabled, latching disabled)
Definition tmc51x0_types.hpp:2894
MotorDirection direction
Motor direction (normal or inverse)
Definition tmc51x0_types.hpp:2875
MotorSpec motor_spec
Motor specifications (physical parameters for automatic current calculation)
Definition tmc51x0_types.hpp:2871
DcStepConfig dcstep
DcStep configuration (defaults: min_velocity=0, disabled)
Definition tmc51x0_types.hpp:2888
DriverConfig() noexcept
Default constructor.
Definition tmc51x0_types.hpp:2909
EncoderConfig encoder_config
Encoder configuration (includes pulses per rev, invert direction, deviation)
Definition tmc51x0_types.hpp:2895
PowerStageParameters power_stage
Power stage configuration (includes short protection)
Definition tmc51x0_types.hpp:2872
MechanicalSystem mechanical
Mechanical system configuration (gearing, leadscrew, etc.) for unit conversions.
Definition tmc51x0_types.hpp:2873
ChopperConfig chopper
Chopper configuration (SpreadCycle or Classic mode)
Definition tmc51x0_types.hpp:2876
StealthChopConfig stealthchop
StealthChop configuration.
Definition tmc51x0_types.hpp:2877
Encoder configuration structure.
Definition tmc51x0_types.hpp:2479
bool ignore_ab_polarity
Definition tmc51x0_types.hpp:2492
uint16_t pulses_per_rev
Encoder pulses per revolution.
Definition tmc51x0_types.hpp:2543
EncoderPrescalerMode prescaler_mode
Encoder prescaler divisor mode (enc_sel_decimal)
Definition tmc51x0_types.hpp:2509
bool invert_direction
Invert encoder direction.
Definition tmc51x0_types.hpp:2555
bool require_a_high
Definition tmc51x0_types.hpp:2488
int32_t allowed_deviation_steps
Allowed encoder deviation in steps.
Definition tmc51x0_types.hpp:2528
ReferenceSwitchActiveLevel n_channel_active
Definition tmc51x0_types.hpp:2482
EncoderClearMode clear_mode
Clear mode for encoder counter on N events.
Definition tmc51x0_types.hpp:2500
bool require_b_high
Definition tmc51x0_types.hpp:2490
EncoderConfig()=default
Default constructor.
EncoderNSensitivity n_sensitivity
N channel event sensitivity (edge/level detection)
Definition tmc51x0_types.hpp:2496
bool clear_enc_x_on_event
Definition tmc51x0_types.hpp:2503
bool latch_xactual_with_enc
Definition tmc51x0_types.hpp:2505
External clock configuration structure.
Definition tmc51x0_types.hpp:2646
ExternalClockConfig()=default
Default constructor.
uint32_t frequency_hz
External clock frequency in Hz.
Definition tmc51x0_types.hpp:2669
Global configuration (GCONF) structure.
Definition tmc51x0_types.hpp:2750
bool en_stealthchop_step_filter
Definition tmc51x0_types.hpp:2759
bool en_stealthchop_mode
Definition tmc51x0_types.hpp:2757
bool enca_dcin_sequencer_stop
Definition tmc51x0_types.hpp:2773
bool invert_direction
Definition tmc51x0_types.hpp:2763
bool en_short_standstill_timeout
Definition tmc51x0_types.hpp:2752
bool direct_mode
Definition tmc51x0_types.hpp:2778
Diag0Config diag0
DIAG0 pin configuration (bits 5, 6, 7, 12)
Definition tmc51x0_types.hpp:2766
bool recalibrate
Bit 0: Zero crossing recalibration during driver disable.
Definition tmc51x0_types.hpp:2751
Diag1Config diag1
DIAG1 pin configuration (bits 8, 9, 10, 11, 13)
Definition tmc51x0_types.hpp:2767
GlobalConfig()=default
Default constructor.
bool en_small_step_frequency_hysteresis
Definition tmc51x0_types.hpp:2769
Cached settings for homing operations.
Definition tmc51x0_types.hpp:2923
bool cached_stealthchop_enabled
Definition tmc51x0_types.hpp:2925
bool ramp_settings_were_modified
Definition tmc51x0_types.hpp:2940
float cached_max_speed
Definition tmc51x0_types.hpp:2934
bool stealthchop_was_modified
Definition tmc51x0_types.hpp:2926
bool sw_mode_was_modified
Definition tmc51x0_types.hpp:2930
SW_MODE_Register cached_sw_mode
Definition tmc51x0_types.hpp:2929
RampMode cached_ramp_mode
Definition tmc51x0_types.hpp:2933
float cached_vstop
Definition tmc51x0_types.hpp:2938
float cached_acceleration
Definition tmc51x0_types.hpp:2935
bool is_valid
Definition tmc51x0_types.hpp:2942
float cached_vstart
Definition tmc51x0_types.hpp:2937
float cached_v1
Definition tmc51x0_types.hpp:2939
float cached_deceleration
Definition tmc51x0_types.hpp:2936
Input pin status structure.
Definition tmc51x0_types.hpp:236
bool sd_mode
SD_MODE pin (1=External step and dir source)
Definition tmc51x0_types.hpp:243
bool refr_dir
Reference right / direction input.
Definition tmc51x0_types.hpp:238
bool drv_enn
Driver enable (inverted)
Definition tmc51x0_types.hpp:241
uint8_t version
IC version (0x11 for TMC5130, 0x30 for TMC5160)
Definition tmc51x0_types.hpp:245
bool enca_dcin_cfg5
Encoder A / DCIN / CFG5.
Definition tmc51x0_types.hpp:240
bool refl_step
Reference left / step input.
Definition tmc51x0_types.hpp:237
bool encb_dcen_cfg4
Encoder B / DCEN / CFG4.
Definition tmc51x0_types.hpp:239
bool swcomp_in
Software comparator input.
Definition tmc51x0_types.hpp:244
bool enc_n_dco_cfg6
Encoder N / DCO / CFG6.
Definition tmc51x0_types.hpp:242
Mechanical system configuration structure.
Definition tmc51x0_types.hpp:290
MechanicalSystem()=default
Default constructor.
float belt_pitch_mm
Belt pitch in mm (for BeltDrive)
Definition tmc51x0_types.hpp:294
uint16_t belt_pulley_teeth
Number of teeth on motor pulley (for BeltDrive)
Definition tmc51x0_types.hpp:293
MechanicalSystemType system_type
Type of mechanical system.
Definition tmc51x0_types.hpp:291
float gear_ratio
Gear ratio (output/input, for Gearbox)
Definition tmc51x0_types.hpp:295
float lead_screw_pitch_mm
Lead screw pitch in mm (for LeadScrew)
Definition tmc51x0_types.hpp:292
Options for changing microstep resolution (CHOPCONF.MRES)
Definition tmc51x0_types.hpp:810
bool preserve_physical_units
Preserve physical meaning of position and motion profile on MRES change.
Definition tmc51x0_types.hpp:820
bool require_standstill
Require standstill before changing MRES.
Definition tmc51x0_types.hpp:828
bool rescale_encoder
Reapply encoder scaling after MRES change (if encoder is configured)
Definition tmc51x0_types.hpp:836
Motor specification structure.
Definition tmc51x0_types.hpp:322
uint16_t steps_per_rev
Definition tmc51x0_types.hpp:329
uint32_t supply_voltage_mv
Motor supply voltage in millivolts (e.g., 24000 for 24V, 0 = not specified)
Definition tmc51x0_types.hpp:341
uint32_t sense_resistor_mohm
Sense resistor value in milliohms (e.g., 50 for 0.05Ω, 0 = not specified)
Definition tmc51x0_types.hpp:340
uint16_t hold_current_ma
Desired hold current in milliamps (0 = auto-calculate as 30% of run)
Definition tmc51x0_types.hpp:337
uint16_t run_current_ma
Desired run current in milliamps (0 = use rated_current_ma)
Definition tmc51x0_types.hpp:336
float irun_adjustment_percent
Percentage adjustment for IRUN calculation.
Definition tmc51x0_types.hpp:369
uint32_t winding_resistance_mohm
Winding resistance in milliohms (required for StealthChop lower limit calc)
Definition tmc51x0_types.hpp:332
float ihold_adjustment_percent
Percentage adjustment for IHOLD calculation.
Definition tmc51x0_types.hpp:383
float scaler_adjustment_percent
Percentage adjustment for GLOBAL_SCALER calculation.
Definition tmc51x0_types.hpp:355
float iholddelay_ms
Total motor power down delay time (IHOLDDELAY)
Definition tmc51x0_types.hpp:444
MotorType motor_type
Definition tmc51x0_types.hpp:324
float winding_inductance_mh
Winding inductance in millihenries (optional, 0 = not specified) (for StealthChop)
Definition tmc51x0_types.hpp:333
MotorSpec()=default
Default constructor.
uint16_t rated_current_ma
Rated motor current in milliamps (RMS)
Definition tmc51x0_types.hpp:331
Power stage parameters structure.
Definition tmc51x0_types.hpp:500
float mosfet_miller_charge_nc
MOSFET Miller charge in nanocoulombs (used to calculate DRVSTRENGTH)
Definition tmc51x0_types.hpp:519
OverTempProtection over_temp_protection
Over-temperature protection level for bridge disable.
Definition tmc51x0_types.hpp:569
uint16_t s2vs_voltage_mv
Short to VS detector voltage threshold in millivolts.
Definition tmc51x0_types.hpp:588
uint32_t bbm_time_ns
Break Before Make time in nanoseconds.
Definition tmc51x0_types.hpp:549
SenseFilterTime sense_filter
Sense amplifier filter time constant.
Definition tmc51x0_types.hpp:559
PowerStageParameters()=default
Default constructor.
uint16_t s2g_voltage_mv
Short to GND detector voltage threshold in millivolts.
Definition tmc51x0_types.hpp:608
uint8_t shortfilter
Spike filtering bandwidth for short detection (0-3)
Definition tmc51x0_types.hpp:619
uint8_t short_detection_delay_us_x10
Short detection delay in microseconds (0.1µs resolution)
Definition tmc51x0_types.hpp:638
Ramp configuration structure.
Definition tmc51x0_types.hpp:1855
RampConfig()=default
Default constructor.
VelocityValue vstart
Start velocity (0 = can be set to zero if not used)
Definition tmc51x0_types.hpp:1857
AccelerationValue dmax
Maximum deceleration (used above V1, 0 = uses AMAX value)
Definition tmc51x0_types.hpp:1865
float tzerowait_ms
Velocity-zero wait time (TZEROWAIT)
Definition tmc51x0_types.hpp:1918
AccelerationValue a1
First acceleration (used between VSTART and V1, 0 = use AMAX)
Definition tmc51x0_types.hpp:1864
float tpowerdown_ms
Definition tmc51x0_types.hpp:1869
AccelerationValue amax
Maximum acceleration (used above V1, 0 = must be set via SetAcceleration() before motion)
Definition tmc51x0_types.hpp:1863
VelocityValue v1
Transition velocity (switches between A1/AMAX and D1/DMAX, 0 = disabled)
Definition tmc51x0_types.hpp:1860
VelocityValue vstop
Stop velocity (must be >= VSTART, minimum 1 recommended)
Definition tmc51x0_types.hpp:1858
VelocityValue vmax
Maximum velocity (0 = must be set via SetMaxSpeed() before motion)
Definition tmc51x0_types.hpp:1859
AccelerationValue d1
First deceleration (used between VSTOP and V1, must not be 0 in positioning mode)
Definition tmc51x0_types.hpp:1866
Reference switch configuration structure.
Definition tmc51x0_types.hpp:2327
ReferenceSwitchConfig()=default
Default constructor.
ReferenceStopMode stop_mode
Stop mode (hard or soft) - only applies if stop is enabled.
Definition tmc51x0_types.hpp:2350
bool en_latch_encoder
Latch encoder position on switch event (for encoder N-channel as third switch)
Definition tmc51x0_types.hpp:2357
ReferenceLatchMode latch_right
Right switch latching mode (must be explicitly set)
Definition tmc51x0_types.hpp:2356
ReferenceLatchMode latch_left
Left switch latching mode (must be explicitly set)
Definition tmc51x0_types.hpp:2355
ReferenceSwitchActiveLevel right_switch_active
Definition tmc51x0_types.hpp:2335
bool right_switch_stop_enable
Definition tmc51x0_types.hpp:2345
ReferenceSwitchActiveLevel left_switch_active
Definition tmc51x0_types.hpp:2331
bool swap_left_right
Swap left and right switch inputs (useful for reversed wiring)
Definition tmc51x0_types.hpp:2352
bool left_switch_stop_enable
Definition tmc51x0_types.hpp:2342
StallGuard2 configuration structure.
Definition tmc51x0_types.hpp:1519
StallGuardConfig()=default
Default constructor.
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.
Definition tmc51x0_types.hpp:1624
bool enable_filter
Enable StallGuard2 filter.
Definition tmc51x0_types.hpp:1548
float min_velocity
Lower velocity threshold for StallGuard2 operation.
Definition tmc51x0_types.hpp:1560
bool stop_on_stall
Stop motor when stall detected.
Definition tmc51x0_types.hpp:1590
Unit velocity_unit
Unit for velocity thresholds.
Definition tmc51x0_types.hpp:1578
float max_velocity
Upper velocity threshold for StallGuard2 operation.
Definition tmc51x0_types.hpp:1571
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.
Definition tmc51x0_types.hpp:1614
int8_t threshold
StallGuard2 threshold value.
Definition tmc51x0_types.hpp:1534
Result structure for StallGuard2 threshold (SGT) tuning.
Definition tmc51x0_types.hpp:1644
StallGuardTuningResult()=default
Default constructor.
int8_t max_velocity_sgt
SGT value that works at maximum velocity (if requested)
Definition tmc51x0_types.hpp:1693
float actual_min_velocity
Actual minimum velocity that works with optimal SGT.
Definition tmc51x0_types.hpp:1713
bool max_velocity_success
Whether max velocity verification succeeded.
Definition tmc51x0_types.hpp:1701
int8_t optimal_sgt
Optimal SGT value found at target velocity.
Definition tmc51x0_types.hpp:1655
uint16_t min_velocity_sg_result
SG_RESULT value at min velocity (if verified)
Definition tmc51x0_types.hpp:1743
float actual_max_velocity
Actual maximum velocity that works with optimal SGT.
Definition tmc51x0_types.hpp:1725
uint16_t max_velocity_sg_result
SG_RESULT value at max velocity (if verified)
Definition tmc51x0_types.hpp:1751
bool tuning_success
Whether tuning succeeded at target velocity.
Definition tmc51x0_types.hpp:1663
uint16_t target_velocity_sg_result
SG_RESULT value at target velocity with optimal SGT.
Definition tmc51x0_types.hpp:1735
bool min_velocity_success
Whether min velocity verification succeeded.
Definition tmc51x0_types.hpp:1682
int8_t min_velocity_sgt
SGT value that works at minimum velocity (if requested)
Definition tmc51x0_types.hpp:1674
StealthChop configuration structure.
Definition tmc51x0_types.hpp:1234
uint8_t pwm_ofs
PWM amplitude offset.
Definition tmc51x0_types.hpp:1256
Unit velocity_threshold_unit
Unit for velocity threshold.
Definition tmc51x0_types.hpp:1417
uint8_t pwm_grad
PWM amplitude gradient.
Definition tmc51x0_types.hpp:1273
StealthChopConfig(uint8_t pwm_frequency, uint8_t pwm_offset, uint8_t pwm_gradient)
Helper constructor for manual mode.
Definition tmc51x0_types.hpp:1479
float velocity_threshold
StealthChop velocity threshold (TPWMTHRS)
Definition tmc51x0_types.hpp:1410
StealthChopConfig()=default
Default constructor.
bool pwm_autoscale
Enable automatic current scaling.
Definition tmc51x0_types.hpp:1314
uint8_t pwm_freq
PWM frequency selection.
Definition tmc51x0_types.hpp:1293
uint8_t pwm_reg
Regulation speed.
Definition tmc51x0_types.hpp:1356
PWMFreewheel freewheel
Freewheeling mode when I_HOLD=0.
Definition tmc51x0_types.hpp:1393
StealthChopConfig(StealthChopPwmFreq pwm_frequency, StealthChopRegulationSpeed regulation_speed=StealthChopRegulationSpeed::MODERATE, StealthChopJerkReduction jerk_reduction=StealthChopJerkReduction::MODERATE, uint8_t pwm_offset=30, uint8_t pwm_gradient=0)
Helper constructor using enums (most intuitive)
Definition tmc51x0_types.hpp:1462
StealthChopConfig(uint8_t pwm_frequency, uint8_t pwm_offset=30, uint8_t pwm_gradient=0, uint8_t regulation_speed=4, uint8_t jerk_reduction=12)
Helper constructor for automatic tuning mode.
Definition tmc51x0_types.hpp:1446
uint8_t pwm_lim
Mode switching jerk reduction.
Definition tmc51x0_types.hpp:1375
bool pwm_autograd
Enable automatic gradient adaptation.
Definition tmc51x0_types.hpp:1332
UART communication configuration structure.
Definition tmc51x0_types.hpp:2695
uint8_t node_address
UART node address.
Definition tmc51x0_types.hpp:2710
uint8_t send_delay
UART send delay.
Definition tmc51x0_types.hpp:2726
UartConfig()=default
Default constructor.
Self-describing velocity value with explicit unit.
Definition tmc51x0_types.hpp:1778
static constexpr VelocityValue FromSteps(float v) noexcept
Definition tmc51x0_types.hpp:1793
static constexpr VelocityValue FromRPM(float v) noexcept
Definition tmc51x0_types.hpp:1794
static constexpr VelocityValue FromRevPerSec(float v) noexcept
Definition tmc51x0_types.hpp:1795
float value
Velocity magnitude.
Definition tmc51x0_types.hpp:1779
static constexpr VelocityValue FromDeg(float v) noexcept
Definition tmc51x0_types.hpp:1797
VelocityValue()=default
Default constructor.
static constexpr VelocityValue FromMm(float v) noexcept
Definition tmc51x0_types.hpp:1798
static constexpr VelocityValue FromRad(float v) noexcept
Definition tmc51x0_types.hpp:1796
constexpr VelocityValue(float v, Unit u) noexcept
Construct with value and unit.
Definition tmc51x0_types.hpp:1790
Unit unit
Velocity unit.
Definition tmc51x0_types.hpp:1780
Register definitions and bitfield structures for TMC51x0 stepper motor.
Switch mode configuration register (SW_MODE)
Definition tmc51x0_registers.hpp:490