HF-TMC9660 Driver 0.1.0-dev
Hardware Agnostic C++ Driver for the TMC9660
Loading...
Searching...
No Matches
tmc9660.hpp
Go to the documentation of this file.
1
18#pragma once
19#include <array>
20#include <cmath>
21#include <cstdint>
22#include <cstdlib>
23#include <limits>
24#include <memory>
25#include <optional>
26#include <span>
27#include <variant>
28#include <vector>
29
31#include "tmc9660_version.h"
34
35namespace tmc9660 {
36
123template <typename CommType>
124class TMC9660 {
125public:
126 //================================================================================
127 // @name Core Initialization and Management
128 // @{
129 //================================================================================
130
137 TMC9660(CommType& comm, uint8_t address = 0,
138 const tmc9660::BootloaderConfig* bootCfg = nullptr) noexcept;
139
141 ~TMC9660() noexcept;
142
146 [[nodiscard]] CommType& comm() noexcept {
147 return comm_;
148 }
149
150 //============================================================================
151 // @name GPIO Helpers (driver-owned control)
152 // @{
153 //============================================================================
154
155 [[nodiscard]] bool GpioSet(TMC9660CtrlPin pin, GpioSignal signal) noexcept;
156 [[nodiscard]] bool GpioRead(TMC9660CtrlPin pin, GpioSignal& signal) noexcept;
157 [[nodiscard]] bool GpioSetActive(TMC9660CtrlPin pin) noexcept;
158 [[nodiscard]] bool GpioSetInactive(TMC9660CtrlPin pin) noexcept;
159
160 // @}
161
162 // @}
163
164 //================================================================================
165 // @name Bootloader Management
166 // @{
167 //================================================================================
168
173 Success,
174 NoConfig,
175 Failure
176 };
177
232 bool performReset = true,
233 bool retrieveBootloaderInfo = false,
234 bool failOnVerifyError = true) noexcept;
235
267 tmc9660::TMC9660Bootloader<CommType>* getBootloader() noexcept {
268 return bootloader_.get();
269 }
270
294 bool enterBootloaderMode() noexcept {
295 // Boot command with magic values per datasheet: TYPE=0x81, MOTOR/BANK=0x92, VALUE=0xA3B4C5D6
296 return sendCommand(tmc9660::tmcl::Op::Boot, 0x81, 0x92, 0xA3B4C5D6, nullptr);
297 }
298
299 // @}
300
301 //================================================================================
302 // @name Core Parameter Access
303 // @{
304 //================================================================================
305
315 [[nodiscard]] bool writeParameter(tmc9660::tmcl::Parameters id, uint32_t value,
316 uint8_t motorIndex = 0) noexcept;
317
325 [[nodiscard]] bool readParameter(tmc9660::tmcl::Parameters id, uint32_t& value,
326 uint8_t motorIndex = 0) noexcept;
327
328 // Variant type for global parameter banks (can be index or any bank enum)
330 std::variant<uint8_t, tmc9660::tmcl::GlobalParamBank0, tmc9660::tmcl::GlobalParamBank2,
331 tmc9660::tmcl::GlobalParamBank3>;
332
339 [[nodiscard]] bool writeGlobalParameter(GlobalParamBankVariant id, uint8_t bank,
340 uint32_t value) noexcept;
341
349 [[nodiscard]] bool readGlobalParameter(GlobalParamBankVariant id, uint8_t bank,
350 uint32_t& value) noexcept;
351
353 bool sendCommand(tmc9660::tmcl::Op opcode, uint16_t type = 0, uint8_t motor = 0,
354 uint32_t value = 0, uint32_t* reply = nullptr) noexcept;
355
356 // @}
357
358 //================================================================================
359 // @name Subsystem Interfaces
360 // @{
361 //================================================================================
362
380 struct MotorConfig {
394 bool setType(tmc9660::tmcl::MotorType type, uint8_t polePairs = 1) noexcept;
395
403 bool setDirection(tmc9660::tmcl::MotorDirection direction) noexcept;
404
410 bool setPWMFrequency(uint32_t frequency_hz) noexcept;
411
442 bool setCommutationMode(tmc9660::tmcl::CommutationMode mode) noexcept;
443
452 bool setOutputVoltageLimit(uint16_t limit) noexcept;
453
459 bool getOutputVoltageLimit(uint16_t& limit) noexcept;
460
471 bool setMaxTorqueCurrent(uint16_t milliamps) noexcept;
472
484 bool setMaxFluxCurrent(uint16_t milliamps) noexcept;
485
503 bool setPWMSwitchingScheme(tmc9660::tmcl::PwmSwitchingScheme scheme) noexcept;
504
594 bool setIdleMotorPWMBehavior(
595 tmc9660::tmcl::IdleMotorPwmBehavior pwmOffWhenIdle =
596 tmc9660::tmcl::IdleMotorPwmBehavior::PWM_OFF_WHEN_MOTOR_IDLE) noexcept;
597
598 //-------------------------------------------------------------------------
599 // Auto-Configuration
600 //-------------------------------------------------------------------------
601
608 // Required parameters
610 uint8_t polePairs;
615
616 // Optional parameters with defaults
618 tmc9660::tmcl::MotorDirection::FORWARD;
620 tmc9660::tmcl::PwmSwitchingScheme::SVPWM;
622 float maxFluxCurrent_A =
623 std::numeric_limits<float>::quiet_NaN();
626 uint16_t outputVoltageLimit =
627 8000;
629 tmc9660::tmcl::IdleMotorPwmBehavior::PWM_OFF_WHEN_MOTOR_IDLE;
631 std::optional<tmc9660::tmcl::CommutationMode>
635 };
636
658 bool configureAuto(const MotorProfile& profile) noexcept;
659
660 private:
661 friend class TMC9660;
662 explicit MotorConfig(TMC9660& parent) noexcept : driver(parent) {}
664 } motorConfig{*this};
665
666 //***************************************************************************
667 //** SUBSYSTEM: Current Measurement **//
668 //***************************************************************************
669
673
679
684 bool getShuntType(tmc9660::tmcl::AdcShuntType& shuntType) noexcept;
685
693 bool readRaw(int16_t& adc0, int16_t& adc1, int16_t& adc2, int16_t& adc3) noexcept;
694
702
710
718 tmc9660::tmcl::CsaFilter filter3) noexcept;
719
727 tmc9660::tmcl::CsaFilter& filter3) noexcept;
728
733 bool setScalingFactor(uint16_t scaling_factor) noexcept;
734
739 bool getScalingFactor(uint16_t& scaling_factor) noexcept;
740
751
762
771 bool setScalingFactors(uint16_t scale0, uint16_t scale1, uint16_t scale2,
772 uint16_t scale3) noexcept;
773
782 bool getScalingFactors(uint16_t& scale0, uint16_t& scale1, uint16_t& scale2,
783 uint16_t& scale3) noexcept;
784
795
806 tmc9660::tmcl::AdcInversion& inv3) noexcept;
807
816 bool setOffsets(int16_t offset0, int16_t offset1, int16_t offset2, int16_t offset3) noexcept;
817
826 bool getOffsets(int16_t& offset0, int16_t& offset1, int16_t& offset2,
827 int16_t& offset3) noexcept;
828
837 bool readScaledAndOffset(int16_t& adc0, int16_t& adc1, int16_t& adc2, int16_t& adc3) noexcept;
838
850 bool calibrateOffsets(bool waitForCompletion = false, uint32_t timeoutMs = 1000) noexcept;
851
857 bool getCalibrationStatus(bool& is_calibrated) noexcept;
858
859 //-------------------------------------------------------------------------
860 // Auto-Configuration
861 //-------------------------------------------------------------------------
888 struct AutoConfig {
889 // Required parameters
893
894 // Optional parameters with defaults
895 bool usePeakScaling =
896 true;
898 tmc9660::tmcl::AdcShuntType::BOTTOM_SHUNTS;
900 tmc9660::tmcl::CsaFilter::T_1_0_MICROSEC;
901
902 // Per-ADC actual shunt resistances (for automatic ADC_Ix_SCALE compensation)
903 // If NaN or <= 0, uses nominal value (no compensation)
904 float actualShuntR_adc0_mOhm =
905 std::numeric_limits<float>::quiet_NaN();
906 float actualShuntR_adc1_mOhm =
907 std::numeric_limits<float>::quiet_NaN();
908 float actualShuntR_adc2_mOhm =
909 std::numeric_limits<float>::quiet_NaN();
910 float actualShuntR_adc3_mOhm =
911 std::numeric_limits<float>::quiet_NaN();
912
913 // Per-phase ADC mapping (which ADC channel maps to which motor phase)
914 // If not set (std::nullopt), uses defaults: U->I0, V->I1, W->I2, Y2->I3
915 std::optional<tmc9660::tmcl::AdcMapping>
917 std::optional<tmc9660::tmcl::AdcMapping>
919 std::optional<tmc9660::tmcl::AdcMapping>
921 std::optional<tmc9660::tmcl::AdcMapping>
923
924 // Per-ADC inversion settings
925 // If not set (std::nullopt), uses Table 24 defaults based on motor type:
926 // DC: ADC_I0=INVERTED, ADC_I1=NOT_INVERTED
927 // BLDC: ADC_I0=INVERTED, ADC_I1=INVERTED, ADC_I2=INVERTED
928 // Stepper: ADC_I0=INVERTED, ADC_I1=NOT_INVERTED, ADC_I2=INVERTED, ADC_I3=NOT_INVERTED
929 std::optional<tmc9660::tmcl::AdcInversion>
931 std::optional<tmc9660::tmcl::AdcInversion>
933 std::optional<tmc9660::tmcl::AdcInversion>
935 std::optional<tmc9660::tmcl::AdcInversion>
937
938 // Auto-calibration settings
939 bool autoCalibrate =
940 false;
941 uint32_t calibrationTimeoutMs =
942 2000;
943 };
944
1033 bool configureAuto(const AutoConfig& config) noexcept;
1034
1035 private:
1036 friend class TMC9660;
1037 explicit CurrentSensing(TMC9660& parent) noexcept : driver(parent) {}
1039 } currentSensing{*this};
1040
1041 //***************************************************************************
1042 //** SUBSYSTEM: Gate Driver **//
1043 //***************************************************************************
1044
1047 struct GateDriver {
1058 tmc9660::tmcl::PwmOutputPolarity high_side) noexcept;
1059
1084 bool configureBreakBeforeMakeTiming(uint8_t low_side_uvw, uint8_t high_side_uvw, uint8_t low_side_y2,
1085 uint8_t high_side_y2) noexcept;
1086
1102 bool configureBreakBeforeMakeTiming_ns(float lowSideUVW_ns, float highSideUVW_ns,
1103 float lowSideY2_ns, float highSideY2_ns) noexcept;
1104
1113 bool enableAdaptiveDriveTime(bool enable_uvw, bool enable_y2) noexcept;
1114
1142 bool configureDriveTimes(uint8_t sink_time_uvw, uint8_t source_time_uvw, uint8_t sink_time_y2,
1143 uint8_t source_time_y2) noexcept;
1144
1160 bool configureDriveTimes_ns(float sinkTimeUVW_ns, float sourceTimeUVW_ns, float sinkTimeY2_ns,
1161 float sourceTimeY2_ns) noexcept;
1162
1175 tmc9660::tmcl::GateCurrentSource source_current_uvw,
1176 tmc9660::tmcl::GateCurrentSink sink_current_y2,
1177 tmc9660::tmcl::GateCurrentSource source_current_y2) noexcept;
1178
1186
1201 tmc9660::tmcl::UndervoltageEnable enable_bst_uvw,
1202 tmc9660::tmcl::UndervoltageEnable enable_bst_y2) noexcept;
1203
1217 tmc9660::tmcl::OvercurrentEnable enable_uvw_high_side,
1218 tmc9660::tmcl::OvercurrentEnable enable_y2_low_side,
1219 tmc9660::tmcl::OvercurrentEnable enable_y2_high_side) noexcept;
1220
1248 tmc9660::tmcl::OvercurrentThreshold uvw_high_side_threshold,
1249 tmc9660::tmcl::OvercurrentThreshold y2LowSideThreshold,
1250 tmc9660::tmcl::OvercurrentThreshold y2HighSideThreshold) noexcept;
1251
1268 tmc9660::tmcl::OvercurrentTiming uvw_high_side_time,
1270 tmc9660::tmcl::OvercurrentTiming y2HighSideTime) noexcept;
1271
1288 tmc9660::tmcl::OvercurrentTiming uvw_high_side_time,
1290 tmc9660::tmcl::OvercurrentTiming y2HighSideTime) noexcept;
1291
1302 tmc9660::tmcl::VdsUsage y2Enable) noexcept;
1303
1317 tmc9660::tmcl::VgsShortEnable enable_low_side_off,
1318 tmc9660::tmcl::VgsShortEnable enable_high_side_on,
1319 tmc9660::tmcl::VgsShortEnable enable_high_side_off) noexcept;
1320
1334 tmc9660::tmcl::VgsShortEnable enable_low_side_off,
1335 tmc9660::tmcl::VgsShortEnable enable_high_side_on,
1336 tmc9660::tmcl::VgsShortEnable enable_high_side_off) noexcept;
1337
1347 tmc9660::tmcl::VgsBlankingTime y2Time) noexcept;
1348
1358 tmc9660::tmcl::VgsDeglitchTime y2Time) noexcept;
1359
1367
1375
1381 bool setFaultHandlerRetries(uint8_t retries) noexcept;
1382
1383 //-------------------------------------------------------------------------
1384 // Auto-Configuration
1385 //-------------------------------------------------------------------------
1386
1422 // Required parameters
1430
1431 // Optional parameters with defaults
1433 std::numeric_limits<float>::quiet_NaN();
1435
1436 // Safety margin multipliers (optional, with conservative defaults)
1438 1.5f;
1439 float blankingMargin = 1.2f;
1440
1441 // Fault handling behavior (optional, with safe defaults)
1443 tmc9660::tmcl::GdrvRetryBehaviour::OPEN_CIRCUIT;
1446 tmc9660::tmcl::DriveFaultBehaviour::OPEN_CIRCUIT;
1449 5;
1450
1451 // Gate driver timing overrides (optional, for advanced tuning)
1452 std::optional<float>
1455 std::optional<float>
1458
1459 // Gate driver interface configuration (optional, with safe defaults)
1461 tmc9660::tmcl::PwmOutputPolarity::ACTIVE_HIGH;
1465 tmc9660::tmcl::PwmOutputPolarity::ACTIVE_HIGH;
1468
1469 // Undervoltage protection configuration (optional, with safe defaults)
1471 tmc9660::tmcl::UndervoltageLevel::DISABLED;
1474 };
1475
1593
1594 private:
1595 friend class TMC9660;
1596 explicit GateDriver(TMC9660& parent) noexcept : driver(parent) {}
1598 } gateDriver{*this};
1599
1600 //***************************************************************************
1601 //** SUBSYSTEM: Feedback Sensors **//
1602 //***************************************************************************
1603
1607 // –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
1608 // HALL sensors (digital Hall)
1609 // –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
1610
1628 tmc9660::tmcl::HallSectorOffset sectorOffset = tmc9660::tmcl::HallSectorOffset::DEG_0,
1629 tmc9660::tmcl::Direction inverted = tmc9660::tmcl::Direction::NOT_INVERTED,
1630 tmc9660::tmcl::EnableDisable enableExtrapolation = tmc9660::tmcl::EnableDisable::DISABLED,
1631 uint8_t filterLength = 0) noexcept;
1632
1648 bool setHallPositionOffsets(int16_t offset0 = 0, int16_t offset60 = 10922,
1649 int16_t offset120 = 21845, int16_t offset180 = -32768,
1650 int16_t offset240 = -21846, int16_t offset300 = -10923,
1651 int16_t globalOffset = 0) noexcept;
1652
1667 bool setHallPositionOffsetsDegrees(float offset0Deg = 0.0f, float offset60Deg = 60.0f,
1668 float offset120Deg = 120.0f, float offset180Deg = 180.0f,
1669 float offset240Deg = 240.0f, float offset300Deg = 300.0f,
1670 float globalOffsetDeg = 0.0f) noexcept;
1671
1686 bool setHallPositionOffsetsRadians(float offset0Rad = 0.0f, float offset60Rad = 1.04719755f,
1687 float offset120Rad = 2.09439510f,
1688 float offset180Rad = 3.14159265f,
1689 float offset240Rad = 4.18879020f,
1690 float offset300Rad = 5.23598775f,
1691 float globalOffsetRad = 0.0f) noexcept;
1692
1701 static int16_t degreesToHallOffset(float degrees) noexcept;
1702
1711 static int16_t radiansToHallOffset(float radians) noexcept;
1712
1717 bool getHallPhiE(int16_t& phi_e) noexcept;
1718
1719 // –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
1720 // ABN encoders (ABN1, ABN2)
1721 // –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
1722
1736 uint32_t counts_per_rev,
1737 tmc9660::tmcl::Direction inverted = tmc9660::tmcl::Direction::NOT_INVERTED,
1738 tmc9660::tmcl::EnableDisable nChannelInverted =
1739 tmc9660::tmcl::EnableDisable::DISABLED) noexcept;
1740
1758 tmc9660::tmcl::AbnInitMethod initMethod =
1759 tmc9660::tmcl::AbnInitMethod::FORCED_PHI_E_ZERO_WITH_ACTIVE_SWING,
1760 uint16_t initDelay = 1000, int32_t initVelocity = 5, int16_t nChannelOffset = 0) noexcept;
1761
1767 bool getABNInitializationState(tmc9660::tmcl::AbnInitState& state) noexcept;
1768
1773 bool getABNPhiE(int16_t& phi_e) noexcept;
1774
1779 bool getABNRawValue(uint32_t& value) noexcept;
1780
1794 bool configureABNNChannel(tmc9660::tmcl::AbnNChannelFiltering filterMode =
1795 tmc9660::tmcl::AbnNChannelFiltering::FILTERING_OFF,
1796 tmc9660::tmcl::EnableDisable clearOnNextNull =
1797 tmc9660::tmcl::EnableDisable::DISABLED) noexcept;
1798
1799 // –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
1800
1815 uint32_t counts_per_rev,
1816 tmc9660::tmcl::Direction inverted = tmc9660::tmcl::Direction::NOT_INVERTED,
1817 uint8_t gearRatio = 1) noexcept;
1818
1819 // ABN-2 (secondary encoder) getters
1824 bool getSecondaryABNCountsPerRev(uint32_t& counts) noexcept;
1825
1830 bool getSecondaryABNDirection(tmc9660::tmcl::Direction& dir) noexcept;
1831
1836 bool getSecondaryABNGearRatio(uint8_t& ratio) noexcept;
1837
1842 bool setSecondaryABNEncoderEnabled(bool enable) noexcept;
1843
1848 bool getSecondaryABNEncoderValue(uint32_t& value) noexcept;
1849
1850 // –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
1851
1852 // –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
1853 // SPI encoder timing & frame size
1854 // –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
1855
1866 bool configureSPIEncoder(uint8_t cmd_size, uint16_t cs_settle_time_ns,
1867 uint8_t cs_idle_time_us) noexcept;
1868
1880 uint32_t position_mask, uint8_t positionShift = 0,
1881 tmc9660::tmcl::Direction invertDirection = tmc9660::tmcl::Direction::NOT_INVERTED) noexcept;
1882
1891 bool setSPIEncoderRequestData(const uint8_t* requestData, uint8_t size) noexcept;
1892
1903 bool configureSPIEncoderInitialization(tmc9660::tmcl::SpiInitMethod init_method,
1904 int16_t offset = 0) noexcept;
1905
1915 bool setSPIEncoderLUTCorrection(tmc9660::tmcl::EnableDisable enable,
1916 int8_t shiftFactor = 0) noexcept;
1917
1924 bool uploadSPIEncoderLUTEntry(uint8_t index, int8_t value) noexcept;
1925
1926 // SPI encoder timing & frame size
1929 bool getSPIEncoderCSSettleDelay(uint16_t& timeNs) noexcept;
1930
1933 bool getSPIEncoderCSIdleDelay(uint8_t& timeUs) noexcept;
1934
1937 bool getSPIEncoderMainCmdSize(uint8_t& size) noexcept;
1938
1941 bool getSPIEncoderSecondaryCmdSize(uint8_t& size) noexcept;
1942
1943 // –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
1944 // SPI encoder data & status
1947 bool getSPIEncoderPositionMask(uint32_t& mask) noexcept;
1948
1951 bool getSPIEncoderPositionShift(uint8_t& shift) noexcept;
1952
1955 bool getSPIEncoderPositionValue(uint32_t& value) noexcept;
1956
1959 bool getSPIEncoderCommutationAngle(int16_t& angle) noexcept;
1960
1961 // –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
1962 // SPI encoder initialization & offset
1965 bool getSPIEncoderInitialization(tmc9660::tmcl::SpiInitMethod& method,
1966 int16_t& offset) noexcept;
1967
1970 bool getSPIEncoderDirection(tmc9660::tmcl::Direction& dir) noexcept;
1971
1972 // –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
1973 // SPI LUT
1976 bool getSPIEncoderLUTAddress(uint8_t& address) noexcept;
1977
1980 bool getSPIEncoderLUTData(int8_t& data) noexcept;
1981
1984 bool getSPIEncoderLUTShiftFactor(int8_t& shift_factor) noexcept;
1985
1986 //-------------------------------------------------------------------------
1987 // Auto-Configuration
1988 //-------------------------------------------------------------------------
1989
1992 struct HallConfig {
1993 // Required parameters
1995 tmc9660::tmcl::HallSectorOffset::DEG_0;
1997
1998 // Optional parameters with defaults
2000 tmc9660::tmcl::Direction::NOT_INVERTED;
2002 tmc9660::tmcl::EnableDisable::DISABLED;
2004 uint8_t filterLength =
2005 0;
2006
2007 // Position offsets (optional, use NaN to skip)
2008 std::optional<float>
2010 std::optional<float>
2012 std::optional<float>
2014 std::optional<float>
2016 std::optional<float>
2018 std::optional<float>
2020 std::optional<float> globalOffsetDeg;
2021 };
2022
2025 struct AbnConfig {
2026 // Required parameters
2027 uint32_t countsPerRev;
2028
2029 // Optional parameters with defaults
2031 tmc9660::tmcl::Direction::NOT_INVERTED;
2033 tmc9660::tmcl::EnableDisable::DISABLED;
2035
2036 // Initialization parameters (optional)
2037 tmc9660::tmcl::AbnInitMethod initMethod = tmc9660::tmcl::AbnInitMethod::
2038 FORCED_PHI_E_ZERO_WITH_ACTIVE_SWING;
2040 uint16_t initDelay = 1000;
2041 int32_t initVelocity = 5;
2042 int16_t nChannelOffset = 0;
2043
2044 // N-channel filtering (optional)
2046 tmc9660::tmcl::AbnNChannelFiltering::FILTERING_OFF;
2049 tmc9660::tmcl::EnableDisable::DISABLED;
2051 };
2052
2055 struct Abn2Config {
2056 // Required parameters
2057 uint32_t countsPerRev;
2058
2059 // Optional parameters with defaults
2061 tmc9660::tmcl::Direction::NOT_INVERTED;
2062 uint8_t gearRatio =
2063 1;
2064 bool enable = true;
2065 };
2066
2070 // Required parameters
2071 uint8_t cmdSize;
2072 uint32_t positionMask;
2073
2074 // Optional parameters with defaults
2075 uint16_t csSettleTimeNs = 0;
2076 uint8_t csIdleTimeUs = 0;
2077 uint8_t positionShift = 0;
2079 tmc9660::tmcl::Direction::NOT_INVERTED;
2080
2081 // Initialization parameters (optional)
2082 tmc9660::tmcl::SpiInitMethod initMethod = tmc9660::tmcl::SpiInitMethod::
2083 FORCED_PHI_E_ZERO_WITH_ACTIVE_SWING;
2085 int16_t offset = 0;
2086
2087 // Request data for continuous transfer (optional)
2088 std::optional<std::array<uint8_t, 16>>
2091
2092 // LUT correction (optional)
2094 tmc9660::tmcl::EnableDisable::DISABLED;
2096 int8_t lutShiftFactor = 0;
2097 };
2098
2106 bool configureAuto(const HallConfig& config) noexcept;
2107
2115 bool configureAuto(const AbnConfig& config) noexcept;
2116
2125 bool configureAuto(const Abn2Config& config) noexcept;
2126
2135 bool configureAuto(const SpiEncoderConfig& config) noexcept;
2136
2137 // –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
2138
2139 private:
2140 friend class TMC9660;
2141 explicit FeedbackSense(TMC9660& parent) noexcept : driver(parent) {}
2143 } feedbackSense{*this};
2144
2145 //***************************************************************************
2146 //** SUBSYSTEM: Torque/Flux Control (FOC) **//
2147 //***************************************************************************
2148
2159 //-------------------------------------------------------------------------
2160 // Torque / Flux control (104–120)
2161 //-------------------------------------------------------------------------
2165 bool stop() noexcept;
2166
2171 bool setTargetTorque(int16_t milliamps) noexcept;
2176 bool getActualTorque(int16_t& milliamps) noexcept;
2177
2182 bool setTargetFlux(int16_t milliamps) noexcept;
2187 bool getActualFlux(int32_t& milliamps) noexcept;
2188
2193 bool setTorqueOffset(int16_t milliamps) noexcept;
2198 bool getTorqueOffset(int16_t& milliamps) noexcept;
2199
2204 bool setFluxOffset(int16_t milliamps) noexcept;
2209 bool getFluxOffset(int16_t& milliamps) noexcept;
2210
2220 bool setCurrentLoopGains(uint16_t p, uint16_t i, bool separate = false, uint16_t fluxP = 0,
2221 uint16_t fluxI = 0) noexcept;
2226 bool setTorqueFluxPiSeparation(tmc9660::tmcl::TorqueFluxPiSeparation sep) noexcept;
2227
2233 bool setCurrentNormalization(tmc9660::tmcl::CurrentPiNormalization p_norm,
2234 tmc9660::tmcl::CurrentPiNormalization i_norm) noexcept;
2235
2240 bool getTorquePiError(int32_t& error) noexcept;
2245 bool getFluxPiError(int32_t& error) noexcept;
2250 bool getTorquePiIntegrator(int32_t& integrator) noexcept;
2255 bool getFluxPiIntegrator(int32_t& integrator) noexcept;
2256
2257 //-------------------------------------------------------------------------
2258 // Open‐loop support (45–47)
2259 //-------------------------------------------------------------------------
2264 bool getOpenloopAngle(int16_t& angle) noexcept;
2265
2270 bool setOpenloopCurrent(uint16_t milliamps) noexcept;
2275 bool getOpenloopCurrent(uint16_t& milliamps) noexcept;
2276
2281 bool setOpenloopVoltage(uint16_t voltage) noexcept;
2286 bool getOpenloopVoltage(uint16_t& voltage) noexcept;
2287
2288 //-------------------------------------------------------------------------
2289 // Field-weakening (308, 310)
2290 //-------------------------------------------------------------------------
2293 bool setFieldWeakeningI(uint16_t milliamps) noexcept;
2294 bool getFieldWeakeningI(uint16_t& milliamps) noexcept;
2295
2296 bool setFieldWeakeningVoltageThreshold(uint16_t voltage) noexcept;
2297 bool getFieldWeakeningVoltageThreshold(uint16_t& voltage) noexcept;
2299
2302 bool setTargetTorqueBiquadFilterEnable(bool enable) noexcept;
2303 bool getTargetTorqueBiquadFilterEnable(bool& enable) noexcept;
2304
2305 bool setTargetTorqueBiquadFilterACoeff1(int32_t coeff) noexcept;
2306 bool getTargetTorqueBiquadFilterACoeff1(int32_t& coeff) noexcept;
2307
2308 bool setTargetTorqueBiquadFilterACoeff2(int32_t coeff) noexcept;
2309 bool getTargetTorqueBiquadFilterACoeff2(int32_t& coeff) noexcept;
2310
2311 bool setTargetTorqueBiquadFilterBCoeff0(int32_t coeff) noexcept;
2312 bool getTargetTorqueBiquadFilterBCoeff0(int32_t& coeff) noexcept;
2313
2314 bool setTargetTorqueBiquadFilterBCoeff1(int32_t coeff) noexcept;
2315 bool getTargetTorqueBiquadFilterBCoeff1(int32_t& coeff) noexcept;
2316
2317 bool setTargetTorqueBiquadFilterBCoeff2(int32_t coeff) noexcept;
2318 bool getTargetTorqueBiquadFilterBCoeff2(int32_t& coeff) noexcept;
2320
2323 bool getFocVoltageUx(int16_t& voltage) noexcept;
2324 bool getFocVoltageWy(int16_t& voltage) noexcept;
2325 bool getFocVoltageV(int16_t& voltage) noexcept;
2326 bool getFocVoltageUq(int16_t& voltage) noexcept;
2328
2331 bool getFocCurrentUx(int16_t& milliamps) noexcept;
2332 bool getFocCurrentV(int16_t& milliamps) noexcept;
2333 bool getFocCurrentWy(int16_t& milliamps) noexcept;
2334 bool getFocCurrentIq(int16_t& milliamps) noexcept;
2336
2339 bool getTorqueFluxCombinedTargetValues(uint32_t& value) noexcept;
2340 bool getTorqueFluxCombinedActualValues(uint32_t& value) noexcept;
2341 bool getVoltageDqCombinedActualValues(uint32_t& value) noexcept;
2342 bool getIntegratedActualTorqueValue(uint32_t& value) noexcept;
2344
2345 //-------------------------------------------------------------------------
2346 // Auto-Configuration
2347 //-------------------------------------------------------------------------
2348
2356 // ========================================================================
2357 // PI Controller Configuration
2358 // ========================================================================
2359
2370 std::optional<uint16_t>
2372 std::optional<uint16_t>
2374
2383 bool separateTorqueFluxLoops =
2384 false;
2385
2391 std::optional<uint16_t>
2393 std::optional<uint16_t>
2395
2408 std::optional<tmc9660::tmcl::CurrentPiNormalization>
2410 std::optional<tmc9660::tmcl::CurrentPiNormalization>
2412
2413 // ========================================================================
2414 // Field Weakening Configuration
2415 // ========================================================================
2416
2426 bool enableFieldWeakening = false;
2427
2440 float fieldWeakeningVoltageThresholdPercent =
2441 0.85f;
2443
2455 uint16_t fieldWeakeningI = 100;
2457
2458 // ========================================================================
2459 // Advanced Configuration (Optional)
2460 // ========================================================================
2461
2468 int16_t torqueOffset_mA = 0;
2469 int16_t fluxOffset_mA = 0;
2470
2486 bool enableTorqueBiquadFilter =
2487 false;
2488
2518 std::optional<int32_t> biquadACoeff1;
2520 std::optional<int32_t> biquadACoeff2;
2522 std::optional<int32_t>
2525 std::optional<int32_t> biquadBCoeff1;
2527 std::optional<int32_t> biquadBCoeff2;
2529 };
2530
2539 bool configureAuto(const TorqueFluxConfig& config) noexcept;
2540
2541 private:
2542 friend class TMC9660;
2543 explicit TorqueFluxControl(TMC9660& parent) noexcept : driver(parent) {}
2545 } torqueFluxControl{*this};
2546
2547 //***************************************************************************
2548 //** SUBSYSTEM: Velocity Control **//
2549 //***************************************************************************
2550
2560 //-------------------------------------------------------------------------
2561 // Velocity control (123–139)
2562 //-------------------------------------------------------------------------
2566 bool stop() noexcept;
2567
2572 bool setVelocitySensor(tmc9660::tmcl::VelocitySensorSelection sel) noexcept;
2577 bool getVelocitySensor(tmc9660::tmcl::VelocitySensorSelection& sel) noexcept;
2578
2583 bool setTargetVelocity(int32_t velocity) noexcept;
2588 bool getActualVelocity(int32_t& velocity) noexcept;
2589
2594 bool setVelocityOffset(int32_t offset) noexcept;
2599 bool getVelocityOffset(int32_t& offset) noexcept;
2600
2606 bool setVelocityLoopGains(uint16_t p, uint16_t i) noexcept;
2612 bool setVelocityNormalization(tmc9660::tmcl::VelocityPiNorm p_norm,
2613 tmc9660::tmcl::VelocityPiNorm i_norm) noexcept;
2614
2619 bool getVelocityPiIntegrator(int32_t& integrator) noexcept;
2624 bool getVelocityPiError(int32_t& error) noexcept;
2625
2630 bool setVelocityScalingFactor(uint16_t factor) noexcept;
2635 bool getVelocityScalingFactor(uint16_t& factor) noexcept;
2636
2642 bool setStopOnVelocityDeviation(uint32_t max_error, bool softStop = true) noexcept;
2648 bool getStopOnVelocityDeviation(uint32_t& max_error, bool& soft_stop) noexcept;
2649
2654 bool setVelocityLoopDownsampling(uint8_t divider) noexcept;
2659 bool getVelocityLoopDownsampling(uint8_t& divider) noexcept;
2660
2661 // Note: VELOCITY_REACHED_THRESHOLD is not a configurable parameter in TMC9660.
2662 // The VELOCITY_REACHED flag is set when both actual and target velocity are below
2663 // an internal threshold. Parameter 134 is STOP_ON_VELOCITY_DEVIATION, not
2664 // VELOCITY_REACHED_THRESHOLD.
2665
2670 bool setVelocityMeterSwitchThreshold(uint32_t threshold) noexcept;
2675 bool getVelocityMeterSwitchThreshold(uint32_t& threshold) noexcept;
2676
2681 bool setVelocityMeterSwitchHysteresis(uint16_t hysteresis) noexcept;
2686 bool getVelocityMeterSwitchHysteresis(uint16_t& hysteresis) noexcept;
2687
2692 bool getVelocityMeterMode(tmc9660::tmcl::VelocityMeterMode& mode) noexcept;
2693
2696 bool setActualVelocityBiquadFilterEnable(bool enable) noexcept;
2697 bool getActualVelocityBiquadFilterEnable(bool& enable) noexcept;
2698 bool setActualVelocityBiquadFilterACoeff1(int32_t coeff) noexcept;
2699 bool getActualVelocityBiquadFilterACoeff1(int32_t& coeff) noexcept;
2700 bool setActualVelocityBiquadFilterACoeff2(int32_t coeff) noexcept;
2701 bool getActualVelocityBiquadFilterACoeff2(int32_t& coeff) noexcept;
2702 bool setActualVelocityBiquadFilterBCoeff0(int32_t coeff) noexcept;
2703 bool getActualVelocityBiquadFilterBCoeff0(int32_t& coeff) noexcept;
2704 bool setActualVelocityBiquadFilterBCoeff1(int32_t coeff) noexcept;
2705 bool getActualVelocityBiquadFilterBCoeff1(int32_t& coeff) noexcept;
2706 bool setActualVelocityBiquadFilterBCoeff2(int32_t coeff) noexcept;
2707 bool getActualVelocityBiquadFilterBCoeff2(int32_t& coeff) noexcept;
2709
2712 bool getIntegratedActualVelocityValue(uint32_t& value) noexcept;
2714
2715 //-------------------------------------------------------------------------
2716 // Auto-Configuration
2717 //-------------------------------------------------------------------------
2718
2722 // Required parameters
2725
2726 // Optional parameters with defaults
2732 std::optional<uint16_t> velocityP;
2733
2739 std::optional<uint16_t> velocityI;
2740
2742 tmc9660::tmcl::VelocityPiNorm::SHIFT_16_BIT;
2745 tmc9660::tmcl::VelocityPiNorm::SHIFT_16_BIT;
2747
2748 // Velocity scaling (optional, can be auto-calculated from encoder CPR and motor parameters)
2768 std::optional<uint16_t>
2771
2780 std::optional<uint32_t>
2783
2790 std::optional<uint8_t>
2792
2798 std::optional<uint32_t> pwmFrequency_Hz;
2800
2801 // Velocity loop downsampling (optional)
2820 uint8_t loopDownsampling = 5;
2821
2822 // Velocity reached threshold (optional)
2823 uint32_t velocityReachedThreshold = 1000;
2824
2825 // Stop on deviation (optional)
2826 std::optional<uint32_t>
2829 bool stopOnDeviationSoftStop =
2830 true;
2831
2832 // Velocity meter (optional, can be auto-calculated for optimal performance)
2851 std::optional<uint32_t> meterSwitchThreshold;
2853 uint16_t meterHysteresis = 500;
2854
2855 // Velocity offset (optional)
2856 int32_t velocityOffset = 0;
2857
2858 // Biquad filter (optional)
2872 std::optional<bool>
2875
2900 std::optional<int32_t> velocityBiquadACoeff1;
2902 std::optional<int32_t> velocityBiquadACoeff2;
2904 std::optional<int32_t> velocityBiquadBCoeff0;
2906 std::optional<int32_t> velocityBiquadBCoeff1;
2908 std::optional<int32_t> velocityBiquadBCoeff2;
2910 };
2911
2920 bool configureAuto(const VelocityConfig& config) noexcept;
2921
2922 private:
2923 friend class TMC9660;
2924 explicit VelocityControl(TMC9660& parent) noexcept : driver(parent) {}
2926 } velocityControl{*this};
2927
2928 //***************************************************************************
2929 //** SUBSYSTEM: Position Control **//
2930 //***************************************************************************
2931
2941 //-------------------------------------------------------------------------
2942 // Position control (142–157)
2943 //-------------------------------------------------------------------------
2947 bool stop() noexcept;
2948
2953 bool setPositionSensor(tmc9660::tmcl::PositionSensorSelection sel) noexcept;
2958 bool getPositionSensor(tmc9660::tmcl::PositionSensorSelection& sel) noexcept;
2959
2964 bool setTargetPosition(int32_t position) noexcept;
2969 bool getActualPosition(int32_t& position) noexcept;
2970
2975 bool setPositionScalingFactor(uint16_t factor) noexcept;
2980 bool getPositionScalingFactor(uint16_t& factor) noexcept;
2981
2987 bool setPositionLoopGains(uint16_t p, uint16_t i) noexcept;
2993 bool setPositionNormalization(tmc9660::tmcl::VelocityPiNorm p_norm,
2994 tmc9660::tmcl::VelocityPiNorm i_norm) noexcept;
2995
3000 bool getPositionPiIntegrator(int32_t& integrator) noexcept;
3005 bool getPositionPiError(int32_t& error) noexcept;
3006
3012 bool setStopOnPositionDeviation(uint32_t max_error, bool softStop = true) noexcept;
3018 bool getStopOnPositionDeviation(uint32_t& max_error, bool& soft_stop) noexcept;
3019
3024 bool setPositionLoopDownsampling(uint8_t divider) noexcept;
3029 bool getPositionLoopDownsampling(uint8_t& divider) noexcept;
3030
3035 bool setPositionLimitLow(int32_t limit) noexcept;
3040 bool getPositionLimitLow(int32_t& limit) noexcept;
3041
3046 bool setPositionLimitHigh(int32_t limit) noexcept;
3051 bool getPositionLimitHigh(int32_t& limit) noexcept;
3052
3057 bool setPositionReachedThreshold(uint32_t threshold) noexcept;
3062 bool getPositionReachedThreshold(uint32_t& threshold) noexcept;
3063
3064 //-------------------------------------------------------------------------
3065 // Ref switch & stop-event (161–170)
3066 //-------------------------------------------------------------------------
3071 bool setReferenceSwitchEnable(tmc9660::tmcl::ReferenceSwitchEnable enable) noexcept;
3076 bool getReferenceSwitchEnable(tmc9660::tmcl::ReferenceSwitchEnable& enable) noexcept;
3077
3082 bool setReferenceSwitchPolaritySwap(tmc9660::tmcl::ReferenceSwitchPolaritySwap config) noexcept;
3088 tmc9660::tmcl::ReferenceSwitchPolaritySwap& config) noexcept;
3089
3095 tmc9660::tmcl::ReferenceSwitchLatchSettings setting) noexcept;
3101 tmc9660::tmcl::ReferenceSwitchLatchSettings& setting) noexcept;
3102
3107 bool setEventStopSettings(tmc9660::tmcl::EventStopSettings settings) noexcept;
3112 bool getEventStopSettings(tmc9660::tmcl::EventStopSettings& settings) noexcept;
3113
3118 bool setReferenceSwitchSearchMode(tmc9660::tmcl::ReferenceSwitchSearchMode mode) noexcept;
3123 bool getReferenceSwitchSearchMode(tmc9660::tmcl::ReferenceSwitchSearchMode& mode) noexcept;
3124
3129 bool setReferenceSwitchSearchSpeed(int32_t speed) noexcept;
3134 bool getReferenceSwitchSearchSpeed(int32_t& speed) noexcept;
3135
3140 bool setReferenceSwitchSpeed(int32_t speed) noexcept;
3145 bool getReferenceSwitchSpeed(int32_t& speed) noexcept;
3146
3151 bool getRightLimitSwitchPosition(int32_t& position) noexcept;
3152
3157 bool getHomeSwitchPosition(int32_t& position) noexcept;
3158
3163 bool getLastReferencePosition(int32_t& position) noexcept;
3164
3167 // Raw inputs for ABN, hall, reference switches, driver enabled,
3168 // hall filtered and ABN2 or Step/Dir (Parameter 304: MCC_INPUTS_RAW)
3169 bool getMccInputsRaw(uint16_t& inputs) noexcept;
3171
3172 //-------------------------------------------------------------------------
3173 // Auto-Configuration
3174 //-------------------------------------------------------------------------
3175
3179 // Required parameters
3182
3183 // Optional parameters with defaults
3189 std::optional<uint16_t> positionP;
3190
3196 std::optional<uint16_t> positionI;
3197
3199 tmc9660::tmcl::VelocityPiNorm::SHIFT_16_BIT;
3202 tmc9660::tmcl::VelocityPiNorm::SHIFT_16_BIT;
3204
3205 // Position scaling (optional, can be auto-calculated from encoder CPR)
3206 std::optional<uint16_t>
3209 std::optional<uint32_t>
3212
3213 // Position loop downsampling (optional)
3238 uint8_t loopDownsampling = 1;
3239
3240 // Position limits (optional)
3241 std::optional<int32_t>
3243 std::optional<int32_t>
3245
3246 // Position reached threshold (optional)
3247 uint32_t positionReachedThreshold = 100;
3248
3249 // Stop on deviation (optional)
3250 std::optional<uint32_t>
3253 bool stopOnDeviationSoftStop =
3254 true;
3255 };
3256
3265 bool configureAuto(const PositionConfig& config) noexcept;
3266
3267 private:
3268 friend class TMC9660;
3269 explicit PositionControl(TMC9660& parent) noexcept : driver(parent) {}
3271 } positionControl{*this};
3272
3273 //***************************************************************************
3274 //** SUBSYSTEM: Motion Ramp **//
3275 //***************************************************************************
3276
3293 struct Ramp {
3297 bool enable(bool on) noexcept;
3298
3304 bool setAcceleration(uint32_t a1, uint32_t a2, uint32_t a_max) noexcept;
3305
3311 bool setDeceleration(uint32_t d1, uint32_t d2, uint32_t d_max) noexcept;
3312
3320 bool setVelocities(uint32_t v_start, uint32_t v_stop, uint32_t v1, uint32_t v2,
3321 uint32_t v_max) noexcept;
3322
3327 bool setTiming(uint16_t t_vmax_cycles, uint16_t t_zero_wait_cycles) noexcept;
3328
3341 bool enableFeedForward(bool enable_vel_ff, bool enable_accel_ff, uint16_t accel_ff_gain,
3342 tmc9660::tmcl::AccelerationFFShift accel_ff_shift) noexcept;
3343
3347 bool setDirectVelocityMode(bool enable) noexcept;
3348
3354 bool getRampVelocity(int32_t& velocity) noexcept;
3355
3361 bool getRampPosition(int32_t& position) noexcept;
3362
3363 //-------------------------------------------------------------------------
3364 // Auto-Configuration
3365 //-------------------------------------------------------------------------
3366
3369 struct RampConfig {
3370 // Required parameters
3376 uint32_t maxVelocity = 134217727;
3377
3378 // Optional parameters with defaults
3384 std::optional<uint32_t>
3386
3392 std::optional<uint32_t>
3394
3400 std::optional<uint32_t>
3402
3408 std::optional<uint32_t>
3410
3415 std::optional<uint32_t>
3417
3422 std::optional<uint32_t>
3424
3429 std::optional<uint32_t>
3431
3436 std::optional<uint32_t>
3438
3443 std::optional<uint32_t>
3445
3450 std::optional<uint32_t>
3452
3458 std::optional<uint16_t> timeAtVmax;
3459
3465 std::optional<uint16_t> timeZeroWait;
3466
3472 std::optional<bool> enableRamp;
3473
3479 std::optional<bool>
3481
3486 std::optional<bool>
3488
3493 std::optional<bool> enableAccelerationFeedForward;
3495
3501 std::optional<uint16_t>
3503
3508 std::optional<tmc9660::tmcl::AccelerationFFShift>
3510 };
3511
3520 bool configureAuto(const RampConfig& config) noexcept;
3521
3522 private:
3523 friend class TMC9660;
3524 explicit Ramp(TMC9660& parent) noexcept : driver(parent) {}
3526 } ramp{*this};
3527
3528 //***************************************************************************
3529 //** SUBSYSTEM: Step/Dir Input Extrapolation **//
3530 //***************************************************************************
3531
3543 struct StepDir {
3544
3554
3563 bool enableInterface(bool on) noexcept;
3564
3573 bool enableExtrapolation(bool enable) noexcept;
3574
3582 bool setSignalTimeout(uint16_t timeout_ms) noexcept;
3583
3591 bool setMaxExtrapolationVelocity(uint32_t e_rpm) noexcept;
3592
3601 bool enableVelocityFeedForward(bool enable_vel_ff) noexcept;
3602
3603 private:
3604 friend class TMC9660;
3605 explicit StepDir(TMC9660& parent) noexcept : driver(parent) {}
3607 } stepDir{*this};
3608
3609 //***********************************************************************
3610 //** SUBSYSTEM: Reference Search **//
3611 //***********************************************************************
3612
3616 bool start() noexcept;
3618 bool stop() noexcept;
3620 bool getStatus(tmc9660::tmcl::ReferenceSearchStatus& status) noexcept;
3621
3622 private:
3623 friend class TMC9660;
3624 explicit ReferenceSearch(TMC9660& parent) noexcept : driver(parent) {}
3626 } referenceSearch{*this};
3627
3628 //***************************************************************************
3629 //** SUBSYSTEM: Brake Chopper **//
3630 //***************************************************************************
3631
3635 struct Brake {
3640 bool enableChopper(bool enable) noexcept;
3641
3646 bool setVoltageLimit(float voltage) noexcept;
3647
3652 bool setHysteresis(float voltage) noexcept;
3653
3657 bool release() noexcept;
3658
3662 bool engage() noexcept;
3663
3668 bool setReleasingDutyCycle(uint8_t percent) noexcept;
3669
3674 bool setHoldingDutyCycle(uint8_t percent) noexcept;
3675
3680 bool setReleasingDuration(uint16_t milliseconds) noexcept;
3681
3686 bool invertOutput(bool invert) noexcept;
3687
3688 //-------------------------------------------------------------------------
3689 // Auto-Configuration
3690 //-------------------------------------------------------------------------
3691
3695 // Brake chopper configuration (optional)
3701 std::optional<bool> enableChopper;
3702
3712 std::optional<float> chopperVoltageThreshold_V;
3714
3720 std::optional<float>
3722
3723 // Mechanical brake configuration (optional)
3729 std::optional<uint8_t>
3731
3737 std::optional<uint8_t>
3739
3745 std::optional<uint16_t>
3747
3752 std::optional<bool> invertOutput;
3753 };
3754
3763 bool configureAuto(const BrakeConfig& config) noexcept;
3764
3765 private:
3766 friend class TMC9660;
3767 explicit Brake(TMC9660& parent) noexcept : driver(parent) {}
3769 } brake{*this};
3770
3771 //***************************************************************************
3772 //** SUBSYSTEM: I²t Overload Protection **//
3773 //***************************************************************************
3774
3785 struct IIT {
3797 bool configure(uint16_t timeConstant1_ms, float continuousCurrent1_A, uint16_t timeConstant2_ms,
3798 float continuousCurrent2_A) noexcept;
3799
3803 bool resetIntegralState() noexcept;
3804
3808 bool setThermalWindingTimeConstant1(uint16_t ms) noexcept;
3811 bool getThermalWindingTimeConstant1(uint16_t& ms) noexcept;
3812
3816 bool setLimit1(uint32_t limit) noexcept;
3819 bool getLimit1(uint32_t& limit) noexcept;
3820
3824 bool setThermalWindingTimeConstant2(uint16_t ms) noexcept;
3827 bool getThermalWindingTimeConstant2(uint16_t& ms) noexcept;
3828
3832 bool setLimit2(uint32_t limit) noexcept;
3835 bool getLimit2(uint32_t& limit) noexcept;
3836
3840 bool getActualTotalMotorCurrent(uint32_t& current, uint8_t motorIndex = 0) noexcept;
3841
3845 bool getSum1(uint32_t& sum) noexcept;
3846
3850 bool getSum2(uint32_t& sum) noexcept;
3851
3852 private:
3853 friend class TMC9660;
3854 explicit IIT(TMC9660& parent) noexcept : driver(parent) {}
3856 } iit{*this};
3857
3858 //===========================================================================
3859 //== SUBSYSTEM: Telemetry & Status ==//
3860 //===========================================================================
3861
3865 struct Telemetry {
3870 bool getGeneralStatusFlags(uint32_t& flags) noexcept;
3871
3876 float getSupplyVoltage() noexcept;
3877
3883 float getChipTemperature() noexcept;
3884
3888 int16_t getMotorCurrent() noexcept;
3889
3894 int32_t getActualVelocity() noexcept;
3895
3900 int32_t getActualPosition() noexcept;
3901
3906 bool getGeneralErrorFlags(uint32_t& flags) noexcept;
3907
3912 bool getGateDriverErrorFlags(uint32_t& flags) noexcept;
3913
3918 bool clearGeneralErrorFlags(uint32_t mask) noexcept;
3919
3924 bool clearGateDriverErrorFlags(uint32_t mask) noexcept;
3925
3930 bool getADCStatusFlags(uint32_t& flags) noexcept;
3931
3936 bool clearADCStatusFlags(uint32_t mask) noexcept;
3937
3941 uint16_t getExternalTemperature() noexcept;
3942
3943 private:
3944 friend class TMC9660;
3945 explicit Telemetry(TMC9660& parent) noexcept;
3947 } telemetry{*this};
3948
3949 //***************************************************************************
3950 //** SUBSYSTEM: Stop / Event **//
3951 //***************************************************************************
3952
3955 struct StopEvents {
3969 uint32_t max_vel_error, uint32_t max_pos_error,
3970 bool softStop = true) noexcept;
3972
3989 bool configureReferenceSwitches(
3990 uint8_t mask, bool invert_l, bool invert_r, bool invert_h,
3991 bool swap_lr) noexcept;
3993
4001 bool getAndClearLatchedPosition(int32_t& pos) noexcept;
4003
4004 //-------------------------------------------------------------------------
4005 // Auto-Configuration
4006 //-------------------------------------------------------------------------
4007
4011 // Deviation stop (optional)
4019 std::optional<uint32_t> maxVelocityDeviation;
4021
4029 std::optional<uint32_t> maxPositionDeviation;
4031
4036 std::optional<bool>
4038
4039 // Reference switches (optional)
4048 std::optional<uint8_t>
4050
4053 std::optional<bool> invertLeftSwitch;
4054
4057 std::optional<bool> invertRightSwitch;
4058
4061 std::optional<bool> invertHomeSwitch;
4062
4065 std::optional<bool> swapLeftRight;
4066 };
4067
4076 bool configureAuto(const StopEventsConfig& config) noexcept;
4077
4078 private:
4079 friend class TMC9660;
4080 explicit StopEvents(TMC9660& parent) noexcept : driver(parent) {}
4082 } stopEvents{*this};
4083
4084 //===========================================================================
4085 //== SUBSYSTEM: Protection ==//
4086 //===========================================================================
4087
4090 struct Protection {
4097 bool configureVoltage(uint16_t over_volt_threshold, uint16_t under_volt_threshold) noexcept;
4098
4109 bool configureTemperature(float warning_deg_c, float shutdown_deg_c) noexcept;
4110
4119 bool setOvercurrentEnabled(bool enabled) noexcept;
4120
4130 bool configureI2t(uint16_t timeConstant1_ms, float continuousCurrent1_A,
4131 uint16_t timeConstant2_ms, float continuousCurrent2_A) noexcept;
4132
4136 bool resetI2tState() noexcept;
4137
4138 //-------------------------------------------------------------------------
4139 // Auto-Configuration
4140 //-------------------------------------------------------------------------
4141
4145 // Voltage protection (optional, with defaults)
4154 std::optional<float>
4156
4165 std::optional<float>
4167
4168 // Temperature protection (optional, with defaults)
4176 std::optional<float>
4178
4186 std::optional<float> temperatureShutdown_C;
4188
4189 // Overcurrent protection (optional, with default)
4195 std::optional<bool>
4197
4198 // I²t thermal protection (optional, with defaults)
4204 std::optional<uint16_t>
4206
4212 std::optional<float> i2tContinuousCurrent1_A;
4214
4220 std::optional<uint16_t>
4222
4228 std::optional<float> i2tContinuousCurrent2_A;
4230 };
4231
4240 bool configureAuto(const ProtectionConfig& config) noexcept;
4241
4242 private:
4243 friend class TMC9660;
4244 explicit Protection(TMC9660& parent) noexcept : driver(parent) {}
4246 } protection{*this};
4247
4248 //===========================================================================
4249 //== SUBSYSTEM: Script ==//
4250 //===========================================================================
4251
4254 struct Script {
4264 bool upload(const std::vector<uint32_t>& script_data) noexcept;
4265
4271 bool start(uint16_t address = 0) noexcept;
4272
4276 bool stop() noexcept;
4277
4283 bool step() noexcept;
4284
4290 bool reset() noexcept;
4291
4296 bool getStatus(uint32_t& status) noexcept;
4297
4303 bool readMemory(uint16_t address, uint32_t& value) noexcept;
4304
4309 bool addBreakpoint(uint16_t address) noexcept;
4310
4315 bool removeBreakpoint(uint16_t address) noexcept;
4316
4320 bool clearBreakpoints() noexcept;
4321
4326 bool getMaxBreakpointCount(uint32_t& count) noexcept;
4327
4328 private:
4329 friend class TMC9660;
4330 explicit Script(TMC9660& parent) noexcept : driver(parent) {}
4332 } script{*this};
4333
4334 //***************************************************************************
4335 //** SUBSYSTEM: RamDebug **//
4336 //***************************************************************************
4339 struct RamDebug {
4347 bool init(uint32_t sample_count) noexcept;
4348
4352 bool startCapture() noexcept;
4353
4359 bool readData(uint32_t index, uint32_t& data) noexcept;
4360
4366 bool getStatus(bool& is_running) noexcept;
4367
4368 private:
4369 friend class TMC9660;
4370 explicit RamDebug(TMC9660& parent) noexcept : driver(parent) {}
4372 } ramDebug{*this};
4373
4374 //===========================================================================
4375 //** SUBSYSTEM: FLASH STORAGE ==//
4376 //===========================================================================
4377
4389 struct NvmStorage {
4396 bool storeToFlash() noexcept;
4397
4404 bool recallFromFlash() noexcept;
4405
4413 bool eraseFlashBank(uint8_t n) noexcept;
4414
4415 private:
4416 friend class TMC9660;
4417 explicit NvmStorage(TMC9660& parent) noexcept : driver(parent) {}
4419 } nvmStorage{*this};
4420
4421 //===========================================================================
4422 //== SUBSYSTEM: Heartbeat (Watchdog) ==//
4423 //===========================================================================
4424
4434 struct Heartbeat {
4445 bool configure(tmc9660::tmcl::HeartbeatMonitoringConfig mode, uint32_t timeout_ms) noexcept;
4446
4447 //-------------------------------------------------------------------------
4448 // Auto-Configuration
4449 //-------------------------------------------------------------------------
4450
4459 std::optional<bool> enable;
4460
4466 std::optional<uint32_t> timeoutMs;
4467 };
4468
4476 bool configureAuto(const HeartbeatConfig& config) noexcept;
4477
4478 private:
4479 friend class TMC9660;
4480 explicit Heartbeat(TMC9660& parent) noexcept : driver(parent) {}
4482 } heartbeat{*this};
4483
4484 //***************************************************************************
4485 //** SUBSYSTEM: Global Parameter Access **//
4486 //***************************************************************************
4494 struct Globals {
4496 bool writeBank0(tmc9660::tmcl::GlobalParamBank0 param, uint32_t value) noexcept;
4497
4499 bool readBank0(tmc9660::tmcl::GlobalParamBank0 param, uint32_t& value) noexcept;
4500
4502 bool writeBank2(tmc9660::tmcl::GlobalParamBank2 param, int32_t value) noexcept;
4503
4505 bool readBank2(tmc9660::tmcl::GlobalParamBank2 param, int32_t& value) noexcept;
4506
4508 bool writeBank3(tmc9660::tmcl::GlobalParamBank3 param, uint32_t value) noexcept;
4509
4511 bool readBank3(tmc9660::tmcl::GlobalParamBank3 param, uint32_t& value) noexcept;
4512
4513 // High level helpers --------------------------------------------------
4515 bool setSerialAddress(uint8_t address) noexcept;
4516
4518 bool getSerialAddress(uint8_t& address) noexcept;
4519
4521 bool setHostAddress(uint8_t address) noexcept;
4522
4524 bool getHostAddress(uint8_t& address) noexcept;
4525
4528 uint32_t timeout_ms) noexcept;
4529
4532 uint32_t& timeout_ms) noexcept;
4533
4535 bool setIODirectionMask(uint32_t mask) noexcept;
4536
4538 bool getIODirectionMask(uint32_t& mask) noexcept;
4539
4541 bool setPullEnableMask(uint32_t mask) noexcept;
4542
4544 bool getPullEnableMask(uint32_t& mask) noexcept;
4545
4547 bool setPullDirectionMask(uint32_t mask) noexcept;
4548
4550 bool getPullDirectionMask(uint32_t& mask) noexcept;
4551
4553 bool setAutoStart(bool enable) noexcept;
4554
4556 bool getAutoStart(bool& enable) noexcept;
4557
4559 bool setClearUserVariables(bool clear) noexcept;
4560
4562 bool getClearUserVariables(bool& clear) noexcept;
4563
4565 bool setUserVariable(uint8_t index, int32_t value) noexcept;
4566
4568 bool getUserVariable(uint8_t index, int32_t& value) noexcept;
4569
4571 bool setTimerPeriod(uint8_t timer, uint32_t period_ms) noexcept;
4572
4574 bool getTimerPeriod(uint8_t timer, uint32_t& period_ms) noexcept;
4575
4577 bool setInputTrigger(uint8_t index, tmc9660::tmcl::TriggerTransition transition) noexcept;
4578
4580 bool getInputTrigger(uint8_t index, tmc9660::tmcl::TriggerTransition& transition) noexcept;
4581
4582 private:
4583 friend class TMC9660;
4584 explicit Globals(TMC9660& parent) noexcept : driver(parent) {}
4586 } globals{*this};
4587
4588 //***************************************************************************
4589 //** SUBSYSTEM: General-purpose GPIO (Digital/Analog I/O) **//
4590 //***************************************************************************
4591
4601 struct GPIO {
4610 bool setMode(uint8_t pin, bool output, bool pullEnable = false, bool pullUp = true) noexcept;
4611
4617 bool writePin(uint8_t pin, bool value) noexcept;
4618
4624 bool readDigital(uint8_t pin, bool& value) noexcept;
4625
4633 bool readAnalog(uint8_t pin, uint16_t& value) noexcept;
4634
4635 private:
4636 friend class TMC9660;
4637 explicit GPIO(TMC9660& parent) noexcept : driver(parent) {}
4639 } gpio{*this};
4640
4641 //***************************************************************************
4642 //** SUBSYSTEM: Power Management **//
4643 //***************************************************************************
4644
4654 struct Power {
4661 bool enableWakePin(bool enable) noexcept;
4662
4670
4671 //-------------------------------------------------------------------------
4672 // Auto-Configuration
4673 //-------------------------------------------------------------------------
4674
4683 std::optional<bool> enableWakePin;
4684
4690 std::optional<tmc9660::tmcl::PowerDownTimeout>
4692 };
4693
4701 bool configureAuto(const PowerConfig& config) noexcept;
4702
4703 private:
4704 friend class TMC9660;
4705 explicit Power(TMC9660& parent) noexcept : driver(parent) {}
4707 } power{*this};
4708
4709 // ===========================================================================
4710 // Driver Version
4711 // ===========================================================================
4712
4714 static constexpr const char* GetDriverVersion() noexcept {
4715 return HF_TMC9660_VERSION_STRING;
4716 }
4717
4719 static constexpr uint8_t GetDriverVersionMajor() noexcept {
4720 return HF_TMC9660_VERSION_MAJOR;
4721 }
4722
4724 static constexpr uint8_t GetDriverVersionMinor() noexcept {
4725 return HF_TMC9660_VERSION_MINOR;
4726 }
4727
4729 static constexpr uint8_t GetDriverVersionPatch() noexcept {
4730 return HF_TMC9660_VERSION_PATCH;
4731 }
4732
4733 //==================================================
4734 // PRIVATE MEMBERS
4735 //==================================================
4736private:
4737 CommType& comm_;
4739 uint8_t address_;
4741 std::unique_ptr<tmc9660::TMC9660Bootloader<CommType>> bootloader_;
4743
4744#ifdef TMC_API_EXTERNAL_CRC_TABLE
4745 extern const uint8_t tmcCRCTable_Poly7Reflected[256];
4746#else
4747 const uint8_t tmcCRCTable_Poly7Reflected[256] = {
4748 0x00, 0x91, 0xE3, 0x72, 0x07, 0x96, 0xE4, 0x75, 0x0E, 0x9F, 0xED, 0x7C, 0x09, 0x98, 0xEA,
4749 0x7B, 0x1C, 0x8D, 0xFF, 0x6E, 0x1B, 0x8A, 0xF8, 0x69, 0x12, 0x83, 0xF1, 0x60, 0x15, 0x84,
4750 0xF6, 0x67, 0x38, 0xA9, 0xDB, 0x4A, 0x3F, 0xAE, 0xDC, 0x4D, 0x36, 0xA7, 0xD5, 0x44, 0x31,
4751 0xA0, 0xD2, 0x43, 0x24, 0xB5, 0xC7, 0x56, 0x23, 0xB2, 0xC0, 0x51, 0x2A, 0xBB, 0xC9, 0x58,
4752 0x2D, 0xBC, 0xCE, 0x5F, 0x70, 0xE1, 0x93, 0x02, 0x77, 0xE6, 0x94, 0x05, 0x7E, 0xEF, 0x9D,
4753 0x0C, 0x79, 0xE8, 0x9A, 0x0B, 0x6C, 0xFD, 0x8F, 0x1E, 0x6B, 0xFA, 0x88, 0x19, 0x62, 0xF3,
4754 0x81, 0x10, 0x65, 0xF4, 0x86, 0x17, 0x48, 0xD9, 0xAB, 0x3A, 0x4F, 0xDE, 0xAC, 0x3D, 0x46,
4755 0xD7, 0xA5, 0x34, 0x41, 0xD0, 0xA2, 0x33, 0x54, 0xC5, 0xB7, 0x26, 0x53, 0xC2, 0xB0, 0x21,
4756 0x5A, 0xCB, 0xB9, 0x28, 0x5D, 0xCC, 0xBE, 0x2F, 0xE0, 0x71, 0x03, 0x92, 0xE7, 0x76, 0x04,
4757 0x95, 0xEE, 0x7F, 0x0D, 0x9C, 0xE9, 0x78, 0x0A, 0x9B, 0xFC, 0x6D, 0x1F, 0x8E, 0xFB, 0x6A,
4758 0x18, 0x89, 0xF2, 0x63, 0x11, 0x80, 0xF5, 0x64, 0x16, 0x87, 0xD8, 0x49, 0x3B, 0xAA, 0xDF,
4759 0x4E, 0x3C, 0xAD, 0xD6, 0x47, 0x35, 0xA4, 0xD1, 0x40, 0x32, 0xA3, 0xC4, 0x55, 0x27, 0xB6,
4760 0xC3, 0x52, 0x20, 0xB1, 0xCA, 0x5B, 0x29, 0xB8, 0xCD, 0x5C, 0x2E, 0xBF, 0x90, 0x01, 0x73,
4761 0xE2, 0x97, 0x06, 0x74, 0xE5, 0x9E, 0x0F, 0x7D, 0xEC, 0x99, 0x08, 0x7A, 0xEB, 0x8C, 0x1D,
4762 0x6F, 0xFE, 0x8B, 0x1A, 0x68, 0xF9, 0x82, 0x13, 0x61, 0xF0, 0x85, 0x14, 0x66, 0xF7, 0xA8,
4763 0x39, 0x4B, 0xDA, 0xAF, 0x3E, 0x4C, 0xDD, 0xA6, 0x37, 0x45, 0xD4, 0xA1, 0x30, 0x42, 0xD3,
4764 0xB4, 0x25, 0x57, 0xC6, 0xB3, 0x22, 0x50, 0xC1, 0xBA, 0x2B, 0x59, 0xC8, 0xBD, 0x2C, 0x5E,
4765 0xCF,
4766 };
4767#endif
4768};
4769
4770// Include template implementation
4771#define TMC9660_HEADER_INCLUDED
4772// NOLINTNEXTLINE(bugprone-suspicious-include) - Intentional: template implementation file
4773#include "../src/tmc9660.ipp"
4774#undef TMC9660_HEADER_INCLUDED
4775
4777inline const char* GetDriverVersion() noexcept {
4778 return HF_TMC9660_VERSION_STRING;
4779}
4780
4781} // namespace tmc9660
Main TMC9660 bootloader interface class.
Definition tmc9660_bootloader.hpp:53
Main class representing a TMC9660 motor driver in Parameter Mode.
Definition tmc9660.hpp:124
BootloaderInitResult
Bootloader initialization result codes.
Definition tmc9660.hpp:172
@ Success
Successfully initialized the bootloader.
@ NoConfig
No bootloader configuration provided.
@ Failure
Failed to initialize the bootloader.
bool writeParameter(tmc9660::tmcl::Parameters id, uint32_t value, uint8_t motorIndex=0) noexcept
Set (write) an axis (motor-specific) parameter on the TMC9660.
bool enterBootloaderMode() noexcept
Exit parameter mode and return to bootloader mode.
Definition tmc9660.hpp:294
CommType & comm_
sending/receiving data.
Definition tmc9660.hpp:4737
const tmc9660::BootloaderConfig * bootCfg_
Definition tmc9660.hpp:4742
const uint8_t tmcCRCTable_Poly7Reflected[256]
Definition tmc9660.hpp:4747
bool GpioSet(TMC9660CtrlPin pin, GpioSignal signal) noexcept
std::unique_ptr< tmc9660::TMC9660Bootloader< CommType > > bootloader_
Bootloader helper.
Definition tmc9660.hpp:4741
bool GpioRead(TMC9660CtrlPin pin, GpioSignal &signal) noexcept
uint8_t address_
Definition tmc9660.hpp:4739
static constexpr uint8_t GetDriverVersionMajor() noexcept
Get the compiled driver major version number.
Definition tmc9660.hpp:4719
static constexpr uint8_t GetDriverVersionPatch() noexcept
Get the compiled driver patch version number.
Definition tmc9660.hpp:4729
tmc9660::TMC9660Bootloader< CommType > * getBootloader() noexcept
Get direct access to the bootloader instance.
Definition tmc9660.hpp:267
bool readGlobalParameter(GlobalParamBankVariant id, uint8_t bank, uint32_t &value) noexcept
Read a global parameter from the TMC9660.
std::variant< uint8_t, tmc9660::tmcl::GlobalParamBank0, tmc9660::tmcl::GlobalParamBank2, tmc9660::tmcl::GlobalParamBank3 > GlobalParamBankVariant
Definition tmc9660.hpp:329
CommType & comm() noexcept
Get the communication interface used by this TMC9660 instance.
Definition tmc9660.hpp:146
TMC9660(CommType &comm, uint8_t address=0, const tmc9660::BootloaderConfig *bootCfg=nullptr) noexcept
Construct a TMC9660 driver instance.
TMC9660::BootloaderInitResult bootloaderInit(const tmc9660::BootloaderConfig *cfg=nullptr, bool performReset=true, bool retrieveBootloaderInfo=false, bool failOnVerifyError=true) noexcept
Complete bootloader initialization and transition to parameter mode.
static constexpr uint8_t GetDriverVersionMinor() noexcept
Get the compiled driver minor version number.
Definition tmc9660.hpp:4724
bool writeGlobalParameter(GlobalParamBankVariant id, uint8_t bank, uint32_t value) noexcept
Set (write) a global parameter on the TMC9660.
bool GpioSetInactive(TMC9660CtrlPin pin) noexcept
bool sendCommand(tmc9660::tmcl::Op opcode, uint16_t type=0, uint8_t motor=0, uint32_t value=0, uint32_t *reply=nullptr) noexcept
Send a TMCL command. Optionally return the 32-bit reply value.
static constexpr const char * GetDriverVersion() noexcept
Get the compiled driver version string.
Definition tmc9660.hpp:4714
bool readParameter(tmc9660::tmcl::Parameters id, uint32_t &value, uint8_t motorIndex=0) noexcept
Read an axis (motor-specific) parameter from the TMC9660.
bool GpioSetActive(TMC9660CtrlPin pin) noexcept
UndervoltageEnable
Definition tmc9660_param_mode_tmcl.hpp:1313
GateCurrentSource
Definition tmc9660_param_mode_tmcl.hpp:868
GateCurrentSink
Definition tmc9660_param_mode_tmcl.hpp:808
OvercurrentTiming
Definition tmc9660_param_mode_tmcl.hpp:1135
AdcMapping
Definition tmc9660_param_mode_tmcl.hpp:2048
OvercurrentThreshold
Definition tmc9660_param_mode_tmcl.hpp:1091
VgsShortEnable
Definition tmc9660_param_mode_tmcl.hpp:1396
PowerDownTimeout
Definition tmc9660_param_mode_tmcl.hpp:4640
StepDirStepDividerShift
Definition tmc9660_param_mode_tmcl.hpp:4522
VelocityPiNorm
Definition tmc9660_param_mode_tmcl.hpp:2946
MotorDirection
Definition tmc9660_param_mode_tmcl.hpp:1612
VgsBlankingTime
Definition tmc9660_param_mode_tmcl.hpp:1432
DriveFaultBehaviour
Definition tmc9660_param_mode_tmcl.hpp:3774
Direction
Definition tmc9660_param_mode_tmcl.hpp:2558
BootstrapCurrentLimit
Definition tmc9660_param_mode_tmcl.hpp:912
VdsUsage
Definition tmc9660_param_mode_tmcl.hpp:1167
GdrvRetryBehaviour
Definition tmc9660_param_mode_tmcl.hpp:3735
CsaFilter
Definition tmc9660_param_mode_tmcl.hpp:2012
PwmSwitchingScheme
Definition tmc9660_param_mode_tmcl.hpp:1646
EnableDisable
Definition tmc9660_param_mode_tmcl.hpp:2526
AdcShuntType
Definition tmc9660_param_mode_tmcl.hpp:1938
PwmOutputPolarity
Definition tmc9660_param_mode_tmcl.hpp:748
SpiInitMethod
Definition tmc9660_param_mode_tmcl.hpp:2494
AdcInversion
Definition tmc9660_param_mode_tmcl.hpp:2080
GlobalParamBank3
Definition tmc9660_param_mode_tmcl.hpp:568
GlobalParamBank0
Definition tmc9660_param_mode_tmcl.hpp:479
OvercurrentEnable
Definition tmc9660_param_mode_tmcl.hpp:1022
Parameters
Definition tmc9660_param_mode_tmcl.hpp:5228
CsaGain
Definition tmc9660_param_mode_tmcl.hpp:1976
VelocitySensorSelection
Definition tmc9660_param_mode_tmcl.hpp:2907
MotorType
Definition tmc9660_param_mode_tmcl.hpp:1580
VgsDeglitchTime
Definition tmc9660_param_mode_tmcl.hpp:1476
HeartbeatMonitoringConfig
Definition tmc9660_param_mode_tmcl.hpp:4037
AbnNChannelFiltering
Definition tmc9660_param_mode_tmcl.hpp:2386
HallSectorOffset
Definition tmc9660_param_mode_tmcl.hpp:2426
PositionSensorSelection
Definition tmc9660_param_mode_tmcl.hpp:3155
UndervoltageLevel
Definition tmc9660_param_mode_tmcl.hpp:1281
TriggerTransition
Definition tmc9660_param_mode_tmcl.hpp:611
AbnInitMethod
Definition tmc9660_param_mode_tmcl.hpp:2312
GlobalParamBank2
Definition tmc9660_param_mode_tmcl.hpp:519
AccelerationFFShift
Definition tmc9660_param_mode_tmcl.hpp:3028
IdleMotorPwmBehavior
Definition tmc9660_param_mode_tmcl.hpp:1800
Definition bootloader_config.hpp:9
TMC9660CtrlPin
TMC9660 control pin identifiers with board-agnostic naming.
Definition tmc9660_comm_interface.hpp:126
GpioSignal
GPIO signal states with board-agnostic naming.
Definition tmc9660_comm_interface.hpp:140
Complete bootloader configuration structure.
Definition bootloader_config.hpp:998
Configuration structure for brake auto-configuration.
Definition tmc9660.hpp:3694
std::optional< bool > enableChopper
Enable brake chopper (optional, default: false).
Definition tmc9660.hpp:3701
std::optional< uint8_t > holdingDutyCycle
PWM duty cycle for brake holding in percent (optional, default: 30%).
Definition tmc9660.hpp:3738
std::optional< float > chopperHysteresis_V
Brake chopper hysteresis in volts (optional, default: 2.0V).
Definition tmc9660.hpp:3721
std::optional< float > chopperVoltageThreshold_V
Brake chopper voltage threshold in volts (optional, default: 30.0V for 24V systems).
Definition tmc9660.hpp:3712
std::optional< bool > invertOutput
Invert brake output polarity (optional, default: false).
Definition tmc9660.hpp:3752
std::optional< uint8_t > releasingDutyCycle
PWM duty cycle for brake release in percent (optional, default: 50%).
Definition tmc9660.hpp:3730
std::optional< uint16_t > releasingDuration_ms
Brake release duration in milliseconds (optional, default: 100ms).
Definition tmc9660.hpp:3746
Subsystem controlling the brake chopper and mechanical brake features.
Definition tmc9660.hpp:3635
TMC9660 & driver
Definition tmc9660.hpp:3768
bool setHysteresis(float voltage) noexcept
Set the hysteresis for the brake chopper threshold.
bool setReleasingDutyCycle(uint8_t percent) noexcept
Set the PWM duty cycle for releasing the brake.
bool setHoldingDutyCycle(uint8_t percent) noexcept
Set the PWM duty cycle for holding the brake released.
bool invertOutput(bool invert) noexcept
Invert or normalize the brake output signal polarity.
bool configureAuto(const BrakeConfig &config) noexcept
Auto-configure brake parameters.
bool release() noexcept
Trigger a release of the mechanical brake.
Brake(TMC9660 &parent) noexcept
Definition tmc9660.hpp:3767
bool engage() noexcept
Engage (lock) the mechanical brake.
bool setReleasingDuration(uint16_t milliseconds) noexcept
Set the duration of the brake release initial phase.
bool enableChopper(bool enable) noexcept
Enable or disable the brake chopper functionality.
bool setVoltageLimit(float voltage) noexcept
Set the overvoltage threshold for the brake chopper.
Configuration structure for auto-configuring current sensing.
Definition tmc9660.hpp:888
std::optional< tmc9660::tmcl::AdcMapping > phaseY2_adcMapping
ADC mapping for phase Y2. Default: ADC_I3.
Definition tmc9660.hpp:922
std::optional< tmc9660::tmcl::AdcMapping > phaseW_adcMapping
ADC mapping for phase W (WY1). Default: ADC_I2.
Definition tmc9660.hpp:920
std::optional< tmc9660::tmcl::AdcInversion > adc1_inverted
Inversion for ADC_I1. Default: based on motor type.
Definition tmc9660.hpp:932
tmc9660::tmcl::MotorType motorType
Motor type (used for default ADC inversion settings)
Definition tmc9660.hpp:892
std::optional< tmc9660::tmcl::AdcInversion > adc0_inverted
Inversion for ADC_I0. Default: based on motor type.
Definition tmc9660.hpp:930
float expectedPeakCurrent_A
Expected peak phase current in amperes (e.g., 3.0 for 3A)
Definition tmc9660.hpp:891
std::optional< tmc9660::tmcl::AdcInversion > adc2_inverted
Inversion for ADC_I2. Default: based on motor type.
Definition tmc9660.hpp:934
std::optional< tmc9660::tmcl::AdcInversion > adc3_inverted
Inversion for ADC_I3. Default: based on motor type.
Definition tmc9660.hpp:936
std::optional< tmc9660::tmcl::AdcMapping > phaseU_adcMapping
ADC mapping for phase U (UX1). Default: ADC_I0.
Definition tmc9660.hpp:916
float shuntResistance_mOhm
Nominal shunt resistor value in milliohms (e.g. 3.0 for 3 mΩ)
Definition tmc9660.hpp:890
std::optional< tmc9660::tmcl::AdcMapping > phaseV_adcMapping
ADC mapping for phase V (VX2). Default: ADC_I1.
Definition tmc9660.hpp:918
Subsystem for configuring ADC-based current measurement.
Definition tmc9660.hpp:672
bool readRaw(int16_t &adc0, int16_t &adc1, int16_t &adc2, int16_t &adc3) noexcept
Read raw ADC values (Parameters 13-16: ADC_I0_RAW ... ADC_I3_RAW).
bool getCalibrationStatus(bool &is_calibrated) noexcept
Check if ADC offset calibration has been completed.
bool setOffsets(int16_t offset0, int16_t offset1, int16_t offset2, int16_t offset3) noexcept
Set ADC offset (Parameters 34-37: ADC_I0_OFFSET ... ADC_I3_OFFSET).
bool configureAuto(const AutoConfig &config) noexcept
Auto-configure current sensing based on shunt resistance and expected current.
TMC9660 & driver
Definition tmc9660.hpp:1038
bool getInversion(tmc9660::tmcl::AdcInversion &inv0, tmc9660::tmcl::AdcInversion &inv1, tmc9660::tmcl::AdcInversion &inv2, tmc9660::tmcl::AdcInversion &inv3) noexcept
Get ADC inversion (Parameters 30-33: ADC_I0_INVERTED ... ADC_I3_INVERTED).
bool setScalingFactor(uint16_t scaling_factor) noexcept
Set current scaling factor (Parameter 21: CURRENT_SCALING_FACTOR).
bool getCSAFilter(tmc9660::tmcl::CsaFilter &filter012, tmc9660::tmcl::CsaFilter &filter3) noexcept
Get current sense amplifier filter (Parameters 19/20: CSA_FILTER_ADC_I0_TO_ADC_I2,...
bool calibrateOffsets(bool waitForCompletion=false, uint32_t timeoutMs=1000) noexcept
Calibrate the ADC offsets for current measurement.
bool getScalingFactors(uint16_t &scale0, uint16_t &scale1, uint16_t &scale2, uint16_t &scale3) noexcept
Get individual ADC scaling factors (Parameters 26-29: ADC_I0_SCALE ... ADC_I3_SCALE).
bool setPhaseAdcMapping(tmc9660::tmcl::AdcMapping ux1, tmc9660::tmcl::AdcMapping vx2, tmc9660::tmcl::AdcMapping wy1, tmc9660::tmcl::AdcMapping y2) noexcept
Set ADC mapping for each phase (Parameters 22-25: PHASE_UX1_ADC_MAPPING ... PHASE_Y2_ADC_MAPPING).
bool setShuntType(tmc9660::tmcl::AdcShuntType shuntType) noexcept
Set the ADC shunt type (Parameter 12: ADC_SHUNT_TYPE).
bool getCSAGain(tmc9660::tmcl::CsaGain &gain012, tmc9660::tmcl::CsaGain &gain3) noexcept
Get current sense amplifier gain (Parameters 17/18: CSA_GAIN_ADC_I0_TO_ADC_I2, CSA_GAIN_ADC_I3).
bool getScalingFactor(uint16_t &scaling_factor) noexcept
Get current scaling factor (Parameter 21: CURRENT_SCALING_FACTOR).
bool getShuntType(tmc9660::tmcl::AdcShuntType &shuntType) noexcept
Get the ADC shunt type (Parameter 12: ADC_SHUNT_TYPE).
bool getPhaseAdcMapping(tmc9660::tmcl::AdcMapping &ux1, tmc9660::tmcl::AdcMapping &vx2, tmc9660::tmcl::AdcMapping &wy1, tmc9660::tmcl::AdcMapping &y2) noexcept
Get ADC mapping for each phase (Parameters 22-25: PHASE_UX1_ADC_MAPPING ... PHASE_Y2_ADC_MAPPING).
bool setCSAFilter(tmc9660::tmcl::CsaFilter filter012, tmc9660::tmcl::CsaFilter filter3) noexcept
Set current sense amplifier filter (Parameters 19/20: CSA_FILTER_ADC_I0_TO_ADC_I2,...
bool setScalingFactors(uint16_t scale0, uint16_t scale1, uint16_t scale2, uint16_t scale3) noexcept
Set individual ADC scaling factors (Parameters 26-29: ADC_I0_SCALE ... ADC_I3_SCALE).
CurrentSensing(TMC9660 &parent) noexcept
Definition tmc9660.hpp:1037
bool readScaledAndOffset(int16_t &adc0, int16_t &adc1, int16_t &adc2, int16_t &adc3) noexcept
Read scaled and offset-compensated ADC values (Parameters 38-41: ADC_I0 ... ADC_I3).
bool setInversion(tmc9660::tmcl::AdcInversion inv0, tmc9660::tmcl::AdcInversion inv1, tmc9660::tmcl::AdcInversion inv2, tmc9660::tmcl::AdcInversion inv3) noexcept
Set ADC inversion (Parameters 30-33: ADC_I0_INVERTED ... ADC_I3_INVERTED).
bool setCSAGain(tmc9660::tmcl::CsaGain gain012, tmc9660::tmcl::CsaGain gain3) noexcept
Set current sense amplifier gain (Parameters 17/18: CSA_GAIN_ADC_I0_TO_ADC_I2, CSA_GAIN_ADC_I3).
bool getOffsets(int16_t &offset0, int16_t &offset1, int16_t &offset2, int16_t &offset3) noexcept
Get ADC offset (Parameters 34-37: ADC_I0_OFFSET ... ADC_I3_OFFSET).
Configuration structure for ABN2 (secondary) encoder auto-configuration.
Definition tmc9660.hpp:2055
uint32_t countsPerRev
Encoder resolution in counts per revolution (CPR) [0-16777215].
Definition tmc9660.hpp:2057
tmc9660::tmcl::Direction direction
Encoder direction (default: NOT_INVERTED)
Definition tmc9660.hpp:2060
bool enable
Enable the ABN2 encoder (default: true)
Definition tmc9660.hpp:2064
uint8_t gearRatio
Gear ratio between encoder and motor shaft [1-255] (default: 1, directly coupled)
Definition tmc9660.hpp:2062
Configuration structure for ABN encoder auto-configuration.
Definition tmc9660.hpp:2025
uint16_t initDelay
Initialization delay in ms [1000-10000] (default: 1000ms)
Definition tmc9660.hpp:2040
tmc9660::tmcl::AbnInitMethod initMethod
Definition tmc9660.hpp:2037
int32_t initVelocity
Initialization velocity [-200000 to 200000] (default: 5)
Definition tmc9660.hpp:2041
tmc9660::tmcl::EnableDisable clearOnNextNull
Definition tmc9660.hpp:2048
uint32_t countsPerRev
Encoder resolution in counts per revolution (CPR) [0-16777215].
Definition tmc9660.hpp:2027
tmc9660::tmcl::AbnNChannelFiltering nChannelFiltering
Definition tmc9660.hpp:2045
int16_t nChannelOffset
N-channel offset [-32768 to 32767] (default: 0)
Definition tmc9660.hpp:2042
tmc9660::tmcl::EnableDisable nChannelInverted
Definition tmc9660.hpp:2032
tmc9660::tmcl::Direction direction
Encoder direction (default: NOT_INVERTED)
Definition tmc9660.hpp:2030
Configuration structure for Hall sensor auto-configuration.
Definition tmc9660.hpp:1992
std::optional< float > offset300Deg
Offset for 300° Hall position in degrees (optional, default: 300°)
Definition tmc9660.hpp:2019
std::optional< float > offset0Deg
Offset for 0° Hall position in degrees (optional, default: 0°)
Definition tmc9660.hpp:2009
std::optional< float > offset60Deg
Offset for 60° Hall position in degrees (optional, default: 60°)
Definition tmc9660.hpp:2011
std::optional< float > offset240Deg
Offset for 240° Hall position in degrees (optional, default: 240°)
Definition tmc9660.hpp:2017
std::optional< float > offset180Deg
Offset for 180° Hall position in degrees (optional, default: 180°)
Definition tmc9660.hpp:2015
std::optional< float > offset120Deg
Offset for 120° Hall position in degrees (optional, default: 120°)
Definition tmc9660.hpp:2013
std::optional< float > globalOffsetDeg
Global offset in degrees (optional, default: 0°)
Definition tmc9660.hpp:2020
Configuration structure for SPI encoder auto-configuration.
Definition tmc9660.hpp:2069
uint32_t positionMask
Bit mask to extract position from SPI response [0-4294967295].
Definition tmc9660.hpp:2072
uint8_t positionShift
Right shift for position counter [0-127] (default: 0)
Definition tmc9660.hpp:2077
uint8_t csIdleTimeUs
CS idle time between frames [0-102 µs] (default: 0)
Definition tmc9660.hpp:2076
uint8_t cmdSize
Size of SPI transfer frame [1-16 bytes].
Definition tmc9660.hpp:2071
int8_t lutShiftFactor
LUT common shift factor [0-4] (default: 0)
Definition tmc9660.hpp:2096
int16_t offset
Manual offset for USE_OFFSET initialization method (default: 0)
Definition tmc9660.hpp:2085
tmc9660::tmcl::EnableDisable lutCorrection
Definition tmc9660.hpp:2093
uint16_t csSettleTimeNs
CS settle delay time [0-6375 ns] (default: 0)
Definition tmc9660.hpp:2075
tmc9660::tmcl::Direction direction
SPI encoder direction (default: NOT_INVERTED)
Definition tmc9660.hpp:2078
tmc9660::tmcl::SpiInitMethod initMethod
Definition tmc9660.hpp:2082
std::optional< std::array< uint8_t, 16 > > requestData
Definition tmc9660.hpp:2089
Subsystem for feedback sensor configuration.
Definition tmc9660.hpp:1606
bool configureAuto(const Abn2Config &config) noexcept
Auto-configure ABN2 (secondary) encoder feedback.
bool getSecondaryABNEncoderValue(uint32_t &value) noexcept
Read the raw ABN2 encoder internal counter value.
bool getSPIEncoderSecondaryCmdSize(uint8_t &size) noexcept
Read SPI_ENCODER_SECONDARY_TRANSFER_CMD_SIZE (0…15 bytes).
bool getSPIEncoderPositionValue(uint32_t &value) noexcept
Read SPI_ENCODER_POSITION_COUNTER_VALUE.
bool getSPIEncoderLUTShiftFactor(int8_t &shift_factor) noexcept
Read SPI_LUT_COMMON_SHIFT_FACTOR.
bool getSPIEncoderPositionShift(uint8_t &shift) noexcept
Read SPI_ENCODER_POSITION_COUNTER_SHIFT.
bool configureSecondaryABNEncoder(uint32_t counts_per_rev, tmc9660::tmcl::Direction inverted=tmc9660::tmcl::Direction::NOT_INVERTED, uint8_t gearRatio=1) noexcept
Configure the secondary ABN encoder input.
bool getABNPhiE(int16_t &phi_e) noexcept
Read the electrical angle (phi_e) calculated from ABN feedback.
bool getSPIEncoderInitialization(tmc9660::tmcl::SpiInitMethod &method, int16_t &offset) noexcept
Read SPI_ENCODER_INITIALIZATION_METHOD and SPI_ENCODER_OFFSET.
bool setHallPositionOffsetsRadians(float offset0Rad=0.0f, float offset60Rad=1.04719755f, float offset120Rad=2.09439510f, float offset180Rad=3.14159265f, float offset240Rad=4.18879020f, float offset300Rad=5.23598775f, float globalOffsetRad=0.0f) noexcept
Set Hall sensor position offsets using radians.
bool getSecondaryABNCountsPerRev(uint32_t &counts) noexcept
Read ABN_2_STEPS (encoder steps per rotation, 0…16777215).
bool setSPIEncoderLUTCorrection(tmc9660::tmcl::EnableDisable enable, int8_t shiftFactor=0) noexcept
Enable or disable SPI encoder lookup table correction.
bool configureHall(tmc9660::tmcl::HallSectorOffset sectorOffset=tmc9660::tmcl::HallSectorOffset::DEG_0, tmc9660::tmcl::Direction inverted=tmc9660::tmcl::Direction::NOT_INVERTED, tmc9660::tmcl::EnableDisable enableExtrapolation=tmc9660::tmcl::EnableDisable::DISABLED, uint8_t filterLength=0) noexcept
Configure digital Hall sensors for BLDC commutation.
bool configureABNNChannel(tmc9660::tmcl::AbnNChannelFiltering filterMode=tmc9660::tmcl::AbnNChannelFiltering::FILTERING_OFF, tmc9660::tmcl::EnableDisable clearOnNextNull=tmc9660::tmcl::EnableDisable::DISABLED) noexcept
Configure N-channel filtering for ABN encoder.
bool getSPIEncoderMainCmdSize(uint8_t &size) noexcept
Read SPI_ENCODER_MAIN_TRANSFER_CMD_SIZE (1…16 bytes).
bool getHallPhiE(int16_t &phi_e) noexcept
Read the electrical angle (phi_e) calculated from Hall feedback.
TMC9660 & driver
Definition tmc9660.hpp:2142
bool getSPIEncoderLUTAddress(uint8_t &address) noexcept
Read SPI_LUT_ADDRESS_SELECT.
bool uploadSPIEncoderLUTEntry(uint8_t index, int8_t value) noexcept
Upload a single entry to the SPI encoder correction lookup table.
bool setHallPositionOffsetsDegrees(float offset0Deg=0.0f, float offset60Deg=60.0f, float offset120Deg=120.0f, float offset180Deg=180.0f, float offset240Deg=240.0f, float offset300Deg=300.0f, float globalOffsetDeg=0.0f) noexcept
Set Hall sensor position offsets using degrees.
bool getSPIEncoderLUTData(int8_t &data) noexcept
Read SPI_LUT_DATA.
bool getSPIEncoderCSSettleDelay(uint16_t &timeNs) noexcept
Read SPI_ENCODE_CS_SETTLE_DELAY_TIME (0…6375 ns).
static int16_t radiansToHallOffset(float radians) noexcept
Convert electrical angle from radians to 16-bit format.
FeedbackSense(TMC9660 &parent) noexcept
Definition tmc9660.hpp:2141
bool configureSPIEncoderInitialization(tmc9660::tmcl::SpiInitMethod init_method, int16_t offset=0) noexcept
Configure SPI encoder initialization method.
bool getABNRawValue(uint32_t &value) noexcept
Read the raw ABN encoder internal counter value.
bool getSPIEncoderCommutationAngle(int16_t &angle) noexcept
Read SPI_ENCODER_COMMUTATION_ANGLE (-32768…32767).
bool getSPIEncoderCSIdleDelay(uint8_t &timeUs) noexcept
Read SPI_ENCODER_CS_IDLE_DELAY_TIME (0…102 µs).
bool configureAuto(const AbnConfig &config) noexcept
Auto-configure ABN encoder feedback.
static int16_t degreesToHallOffset(float degrees) noexcept
Convert electrical angle from degrees to 16-bit format.
bool configureSPIEncoderDataFormat(uint32_t position_mask, uint8_t positionShift=0, tmc9660::tmcl::Direction invertDirection=tmc9660::tmcl::Direction::NOT_INVERTED) noexcept
Configure SPI encoder data format and processing.
bool getSPIEncoderPositionMask(uint32_t &mask) noexcept
Read SPI_ENCODER_POSITION_COUNTER_MASK.
bool configureAuto(const HallConfig &config) noexcept
Auto-configure Hall sensor feedback.
bool configureSPIEncoder(uint8_t cmd_size, uint16_t cs_settle_time_ns, uint8_t cs_idle_time_us) noexcept
Configure a SPI-based encoder for feedback.
bool getSecondaryABNDirection(tmc9660::tmcl::Direction &dir) noexcept
Read ABN_2_DIRECTION (normal/inverted).
bool getSecondaryABNGearRatio(uint8_t &ratio) noexcept
Read ABN_2_GEAR_RATIO (1…255).
bool configureABNInitialization(tmc9660::tmcl::AbnInitMethod initMethod=tmc9660::tmcl::AbnInitMethod::FORCED_PHI_E_ZERO_WITH_ACTIVE_SWING, uint16_t initDelay=1000, int32_t initVelocity=5, int16_t nChannelOffset=0) noexcept
Configure ABN encoder initialization method.
bool getSPIEncoderDirection(tmc9660::tmcl::Direction &dir) noexcept
Read SPI_ENCODER_DIRECTION.
bool setHallPositionOffsets(int16_t offset0=0, int16_t offset60=10922, int16_t offset120=21845, int16_t offset180=-32768, int16_t offset240=-21846, int16_t offset300=-10923, int16_t globalOffset=0) noexcept
Set Hall sensor position offsets for improved accuracy.
bool getABNInitializationState(tmc9660::tmcl::AbnInitState &state) noexcept
Read the current state of ABN encoder initialization.
bool setSPIEncoderRequestData(const uint8_t *requestData, uint8_t size) noexcept
Set up SPI encoder request data for continuous transfer mode.
bool configureABNEncoder(uint32_t counts_per_rev, tmc9660::tmcl::Direction inverted=tmc9660::tmcl::Direction::NOT_INVERTED, tmc9660::tmcl::EnableDisable nChannelInverted=tmc9660::tmcl::EnableDisable::DISABLED) noexcept
Configure an ABN incremental encoder for feedback.
bool configureAuto(const SpiEncoderConfig &config) noexcept
Auto-configure SPI encoder feedback.
bool setSecondaryABNEncoderEnabled(bool enable) noexcept
Enable or disable the secondary ABN encoder.
Subsystem for configuring general-purpose IOs (GPIOs).
Definition tmc9660.hpp:4601
bool setMode(uint8_t pin, bool output, bool pullEnable=false, bool pullUp=true) noexcept
Configure a GPIO pin as input or output.
TMC9660 & driver
Definition tmc9660.hpp:4638
Configuration structure for auto-configuring power stage protection.
Definition tmc9660.hpp:1421
float blankingMargin
Blanking time safety margin multiplier (default: 1.2x)
Definition tmc9660.hpp:1439
tmc9660::tmcl::UndervoltageLevel supplyLevel
Definition tmc9660.hpp:1470
float expectedPeakCurrent_A
Expected peak phase current in amperes.
Definition tmc9660.hpp:1429
tmc9660::tmcl::PwmOutputPolarity pwmHighPolarity
Definition tmc9660.hpp:1464
tmc9660::tmcl::DriveFaultBehaviour faultBehaviour
Definition tmc9660.hpp:1445
float shuntResistance_mOhm
Definition tmc9660.hpp:1425
float motorInductance_uH
Definition tmc9660.hpp:1432
tmc9660::tmcl::PwmOutputPolarity pwmLowPolarity
Definition tmc9660.hpp:1460
float overcurrentMargin
Overcurrent threshold margin above expected peak (default: 1.5x)
Definition tmc9660.hpp:1437
float mosfet_gateCharge_nC
MOSFET gate charge in nanocoulombs (Qg from datasheet)
Definition tmc9660.hpp:1424
uint8_t faultHandlerRetries
Maximum number of retries per detected fault [0-255] (default: 5)
Definition tmc9660.hpp:1448
float pwmFrequency_Hz
PWM switching frequency in Hz.
Definition tmc9660.hpp:1428
float mosfet_RdsOn_mOhm
MOSFET on-resistance in milliohms (at operating junction temp)
Definition tmc9660.hpp:1423
std::optional< float > targetTurnOffTime_ns
Definition tmc9660.hpp:1456
float busVoltage_V
DC bus voltage in volts.
Definition tmc9660.hpp:1427
std::optional< float > targetTurnOnTime_ns
Definition tmc9660.hpp:1453
tmc9660::tmcl::GdrvRetryBehaviour retryBehaviour
Definition tmc9660.hpp:1442
Subsystem for configuring the MOSFET gate driver.
Definition tmc9660.hpp:1047
bool setFaultHandlerRetries(uint8_t retries) noexcept
Set the maximum number of retries for fault handling.
bool enableVdsMonitoringLow(tmc9660::tmcl::VdsUsage uvw_enable, tmc9660::tmcl::VdsUsage y2Enable) noexcept
Enable or disable VDS monitoring for overcurrent protection on UVW and Y2 low sides.
bool setDriveFaultBehavior(tmc9660::tmcl::DriveFaultBehaviour fault_behavior) noexcept
Configure drive fault behavior.
bool enableAdaptiveDriveTime(bool enable_uvw, bool enable_y2) noexcept
Enable or disable adaptive drive time for UVW and Y2 phases.
bool configureDriveTimes_ns(float sinkTimeUVW_ns, float sourceTimeUVW_ns, float sinkTimeY2_ns, float sourceTimeY2_ns) noexcept
Configure drive times using nanoseconds (recommended API).
bool configureBreakBeforeMakeTiming(uint8_t low_side_uvw, uint8_t high_side_uvw, uint8_t low_side_y2, uint8_t high_side_y2) noexcept
Configure the break-before-make timing for the gate driver (advanced API).
bool configureBreakBeforeMakeTiming_ns(float lowSideUVW_ns, float highSideUVW_ns, float lowSideY2_ns, float highSideY2_ns) noexcept
Configure break-before-make timing using nanoseconds (recommended API).
bool configureCurrentLimits(tmc9660::tmcl::GateCurrentSink sink_current_uvw, tmc9660::tmcl::GateCurrentSource source_current_uvw, tmc9660::tmcl::GateCurrentSink sink_current_y2, tmc9660::tmcl::GateCurrentSource source_current_y2) noexcept
Configure gate driver current limits for UVW and Y2 phases.
bool configureVgsShortProtectionY2(tmc9660::tmcl::VgsShortEnable enable_low_side_on, tmc9660::tmcl::VgsShortEnable enable_low_side_off, tmc9660::tmcl::VgsShortEnable enable_high_side_on, tmc9660::tmcl::VgsShortEnable enable_high_side_off) noexcept
Configure gate-to-source short protection for Y2 phase.
bool setOvercurrentDeglitch(tmc9660::tmcl::OvercurrentTiming uvw_low_side_time, tmc9660::tmcl::OvercurrentTiming uvw_high_side_time, tmc9660::tmcl::OvercurrentTiming y2LowSideTime, tmc9660::tmcl::OvercurrentTiming y2HighSideTime) noexcept
Configure the overcurrent protection deglitch time for UVW and Y2 phases.
bool configureBootstrapCurrentLimit(tmc9660::tmcl::BootstrapCurrentLimit limit) noexcept
Configure bootstrap current limit.
bool configureDriveTimes(uint8_t sink_time_uvw, uint8_t source_time_uvw, uint8_t sink_time_y2, uint8_t source_time_y2) noexcept
Configure drive times for UVW and Y2 phases (advanced API).
bool setOvercurrentBlanking(tmc9660::tmcl::OvercurrentTiming uvw_low_side_time, tmc9660::tmcl::OvercurrentTiming uvw_high_side_time, tmc9660::tmcl::OvercurrentTiming y2LowSideTime, tmc9660::tmcl::OvercurrentTiming y2HighSideTime) noexcept
Configure the overcurrent protection blanking time for UVW and Y2 phases.
bool setVgsShortBlankingTime(tmc9660::tmcl::VgsBlankingTime uvw_time, tmc9660::tmcl::VgsBlankingTime y2Time) noexcept
Set gate-to-source short protection blanking time.
bool setVgsShortDeglitchTime(tmc9660::tmcl::VgsDeglitchTime uvw_time, tmc9660::tmcl::VgsDeglitchTime y2Time) noexcept
Set gate-to-source short protection deglitch time.
bool configureVgsShortProtectionUVW(tmc9660::tmcl::VgsShortEnable enable_low_side_on, tmc9660::tmcl::VgsShortEnable enable_low_side_off, tmc9660::tmcl::VgsShortEnable enable_high_side_on, tmc9660::tmcl::VgsShortEnable enable_high_side_off) noexcept
Configure gate-to-source short protection for UVW phases.
bool enableOvercurrentProtection(tmc9660::tmcl::OvercurrentEnable enable_uvw_low_side, tmc9660::tmcl::OvercurrentEnable enable_uvw_high_side, tmc9660::tmcl::OvercurrentEnable enable_y2_low_side, tmc9660::tmcl::OvercurrentEnable enable_y2_high_side) noexcept
Enable or disable overcurrent protection for UVW and Y2 phases.
bool setOvercurrentThresholds(tmc9660::tmcl::OvercurrentThreshold uvw_low_side_threshold, tmc9660::tmcl::OvercurrentThreshold uvw_high_side_threshold, tmc9660::tmcl::OvercurrentThreshold y2LowSideThreshold, tmc9660::tmcl::OvercurrentThreshold y2HighSideThreshold) noexcept
Configure overcurrent protection thresholds for UVW and Y2 phases.
TMC9660 & driver
Definition tmc9660.hpp:1597
bool configureUndervoltageProtection(tmc9660::tmcl::UndervoltageLevel supplyLevel, tmc9660::tmcl::UndervoltageEnable enable_vdrv, tmc9660::tmcl::UndervoltageEnable enable_bst_uvw, tmc9660::tmcl::UndervoltageEnable enable_bst_y2) noexcept
Configure undervoltage protection settings.
bool configurePowerStageProtection(const PowerStageProfile &profile) noexcept
Auto-configure complete power stage based on physical properties.
bool setOutputPolarity(tmc9660::tmcl::PwmOutputPolarity low_side, tmc9660::tmcl::PwmOutputPolarity high_side) noexcept
Set the gate driver output polarity.
GateDriver(TMC9660 &parent) noexcept
Definition tmc9660.hpp:1596
bool setRetryBehavior(tmc9660::tmcl::GdrvRetryBehaviour retry_behavior) noexcept
Configure fault retry behavior.
Convenience helpers for reading and writing global parameters.
Definition tmc9660.hpp:4494
bool getSerialAddress(uint8_t &address) noexcept
Get module serial address (bank0:SERIAL_ADDRESS).
bool readBank2(tmc9660::tmcl::GlobalParamBank2 param, int32_t &value) noexcept
Read a signed user variable from bank 2.
bool writeBank2(tmc9660::tmcl::GlobalParamBank2 param, int32_t value) noexcept
Write a signed user variable in bank 2.
bool getClearUserVariables(bool &clear) noexcept
Get clear-user-variable flag.
bool setAutoStart(bool enable) noexcept
Enable or disable auto-start of stored program (bank0:AUTO_START_ENABLE).
bool getTimerPeriod(uint8_t timer, uint32_t &period_ms) noexcept
Get interrupt timer period (bank3).
bool getPullDirectionMask(uint32_t &mask) noexcept
Get pull direction mask.
bool setPullDirectionMask(uint32_t mask) noexcept
Set pull direction mask (bank0:IO_INPUT_PULLUP_PULLDOWN_DIRECTION_MASK).
TMC9660 & driver
Definition tmc9660.hpp:4585
bool setInputTrigger(uint8_t index, tmc9660::tmcl::TriggerTransition transition) noexcept
Set trigger transition for digital input n (bank3 INPUT_n_TRIGGER_TRANSITION).
bool setClearUserVariables(bool clear) noexcept
Configure clearing of user variables on startup (bank0:CLEAR_USER_VARIABLES).
bool setUserVariable(uint8_t index, int32_t value) noexcept
Set user variable by index (bank2).
bool writeBank0(tmc9660::tmcl::GlobalParamBank0 param, uint32_t value) noexcept
Write a value to bank 0 (system settings).
bool getIODirectionMask(uint32_t &mask) noexcept
Get GPIO direction mask (bank0:IO_DIRECTION_MASK).
bool setSerialAddress(uint8_t address) noexcept
Set module serial address (bank0:SERIAL_ADDRESS).
bool getHostAddress(uint8_t &address) noexcept
Get host serial address (bank0:SERIAL_HOST_ADDRESS).
bool readBank0(tmc9660::tmcl::GlobalParamBank0 param, uint32_t &value) noexcept
Read a value from bank 0 (system settings).
bool getAutoStart(bool &enable) noexcept
Read auto-start enable flag.
bool getUserVariable(uint8_t index, int32_t &value) noexcept
Read user variable by index (bank2).
bool getHeartbeat(tmc9660::tmcl::HeartbeatMonitoringConfig &iface, uint32_t &timeout_ms) noexcept
Read heartbeat monitoring configuration.
bool getInputTrigger(uint8_t index, tmc9660::tmcl::TriggerTransition &transition) noexcept
Get trigger transition for digital input n.
bool setHostAddress(uint8_t address) noexcept
Set host serial address (bank0:SERIAL_HOST_ADDRESS).
bool setPullEnableMask(uint32_t mask) noexcept
Set pull-up/down enable mask (bank0:IO_INPUT_PULLUP_PULLDOWN_ENABLE_MASK).
bool writeBank3(tmc9660::tmcl::GlobalParamBank3 param, uint32_t value) noexcept
Write a value to bank 3 (interrupt configuration).
Globals(TMC9660 &parent) noexcept
Definition tmc9660.hpp:4584
bool configureHeartbeat(tmc9660::tmcl::HeartbeatMonitoringConfig iface, uint32_t timeout_ms) noexcept
Configure heartbeat monitoring interface and timeout.
bool readBank3(tmc9660::tmcl::GlobalParamBank3 param, uint32_t &value) noexcept
Read a value from bank 3 (interrupt configuration).
bool getPullEnableMask(uint32_t &mask) noexcept
Get pull-up/down enable mask.
bool setTimerPeriod(uint8_t timer, uint32_t period_ms) noexcept
Set interrupt timer period (bank3).
bool setIODirectionMask(uint32_t mask) noexcept
Set GPIO direction mask (bank0:IO_DIRECTION_MASK).
Configuration structure for heartbeat auto-configuration.
Definition tmc9660.hpp:4453
std::optional< bool > enable
Enable heartbeat monitoring (optional, default: false).
Definition tmc9660.hpp:4459
std::optional< uint32_t > timeoutMs
Heartbeat timeout in milliseconds (optional, default: 1000ms).
Definition tmc9660.hpp:4466
Subsystem for configuring the communication watchdog (heartbeat).
Definition tmc9660.hpp:4434
TMC9660 & driver
Definition tmc9660.hpp:4481
bool configure(tmc9660::tmcl::HeartbeatMonitoringConfig mode, uint32_t timeout_ms) noexcept
Enable the heartbeat monitor and set timeout.
bool configureAuto(const HeartbeatConfig &config) noexcept
Auto-configure heartbeat parameters.
Heartbeat(TMC9660 &parent) noexcept
Definition tmc9660.hpp:4480
Subsystem for motor thermal overload protection via I²t integration.
Definition tmc9660.hpp:3785
bool configure(uint16_t timeConstant1_ms, float continuousCurrent1_A, uint16_t timeConstant2_ms, float continuousCurrent2_A) noexcept
Configure the two I²t monitoring windows.
bool setThermalWindingTimeConstant2(uint16_t ms) noexcept
Set the winding time constant for window 2.
bool getLimit1(uint32_t &limit) noexcept
Get the I²t limit for window 1.
bool getThermalWindingTimeConstant2(uint16_t &ms) noexcept
Get the winding time constant for window 2.
bool getLimit2(uint32_t &limit) noexcept
Get the I²t limit for window 2.
TMC9660 & driver
Definition tmc9660.hpp:3855
bool setLimit2(uint32_t limit) noexcept
Set the I²t limit for window 2.
bool getActualTotalMotorCurrent(uint32_t &current, uint8_t motorIndex=0) noexcept
Read the total motor current (torque+flux).
bool setThermalWindingTimeConstant1(uint16_t ms) noexcept
Set the winding time constant for window 1.
bool resetIntegralState() noexcept
Reset both I²t accumulators to zero.
bool getSum1(uint32_t &sum) noexcept
Read the current integrated sum of window 1.
bool setLimit1(uint32_t limit) noexcept
Set the I²t limit for window 1.
bool getThermalWindingTimeConstant1(uint16_t &ms) noexcept
Get the winding time constant for window 1.
bool getSum2(uint32_t &sum) noexcept
Read the current integrated sum of window 2.
Configuration structure for auto-configuring motor parameters.
Definition tmc9660.hpp:607
std::optional< tmc9660::tmcl::CommutationMode > commutationMode
Definition tmc9660.hpp:632
tmc9660::tmcl::MotorType motorType
Motor type (DC, BLDC, STEPPER)
Definition tmc9660.hpp:609
float maxPhaseCurrent_A
Definition tmc9660.hpp:613
uint8_t polePairs
Number of pole pairs (for BLDC/Stepper, typically 1-21)
Definition tmc9660.hpp:610
uint32_t pwmFrequency_Hz
Definition tmc9660.hpp:611
Motor configuration and control subsystem.
Definition tmc9660.hpp:380
TMC9660 & driver
Definition tmc9660.hpp:663
bool configureAuto(const MotorProfile &profile) noexcept
Auto-configure motor parameters based on high-level motor characteristics.
bool setType(tmc9660::tmcl::MotorType type, uint8_t polePairs=1) noexcept
Configure the motor type (DC, BLDC, or stepper) and basic motor settings.
MotorConfig(TMC9660 &parent) noexcept
Definition tmc9660.hpp:662
Subsystem for storing and recalling parameters from nonvolatile flash.
Definition tmc9660.hpp:4389
bool storeToFlash() noexcept
Store all writable parameters to flash or EEPROM.
TMC9660 & driver
Definition tmc9660.hpp:4418
Configuration structure for position control auto-configuration.
Definition tmc9660.hpp:3178
tmc9660::tmcl::PositionSensorSelection sensorSelection
Position feedback sensor selection (required)
Definition tmc9660.hpp:3181
std::optional< int32_t > positionLimitLow
Low position limit (optional, disabled if not provided)
Definition tmc9660.hpp:3242
std::optional< uint32_t > stopOnDeviationMaxError
Definition tmc9660.hpp:3251
std::optional< uint16_t > positionI
Position I gain [0-32767] (optional, default: 100).
Definition tmc9660.hpp:3196
std::optional< int32_t > positionLimitHigh
High position limit (optional, disabled if not provided)
Definition tmc9660.hpp:3244
std::optional< uint16_t > positionScalingFactor
Definition tmc9660.hpp:3207
std::optional< uint32_t > encoderCountsPerRev
Definition tmc9660.hpp:3210
std::optional< uint16_t > positionP
Position P gain [0-32767] (optional, default: 2000).
Definition tmc9660.hpp:3189
Subsystem for position control (FOC outer loop).
Definition tmc9660.hpp:2940
bool getReferenceSwitchPolaritySwap(tmc9660::tmcl::ReferenceSwitchPolaritySwap &config) noexcept
Read switch polarity/swap config.
bool getPositionScalingFactor(uint16_t &factor) noexcept
Read position scaling factor.
bool setReferenceSwitchPolaritySwap(tmc9660::tmcl::ReferenceSwitchPolaritySwap config) noexcept
Configure switch polarity and swap.
bool getPositionLoopDownsampling(uint8_t &divider) noexcept
Read position loop downsampling.
bool getReferenceSwitchSpeed(int32_t &speed) noexcept
Read reference positioning speed.
bool setStopOnPositionDeviation(uint32_t max_error, bool softStop=true) noexcept
Configure stop-on-position-deviation.
bool getReferenceSwitchSearchSpeed(int32_t &speed) noexcept
Read reference search speed.
bool getStopOnPositionDeviation(uint32_t &max_error, bool &soft_stop) noexcept
Read stop-on-position-deviation settings.
PositionControl(TMC9660 &parent) noexcept
Definition tmc9660.hpp:3269
bool getPositionReachedThreshold(uint32_t &threshold) noexcept
Read position reached threshold.
bool setPositionSensor(tmc9660::tmcl::PositionSensorSelection sel) noexcept
Select position feedback sensor.
bool getRightLimitSwitchPosition(int32_t &position) noexcept
Read right-limit-switch position.
bool setReferenceSwitchSpeed(int32_t speed) noexcept
Set reference positioning speed.
bool getActualPosition(int32_t &position) noexcept
Read actual position.
bool setPositionNormalization(tmc9660::tmcl::VelocityPiNorm p_norm, tmc9660::tmcl::VelocityPiNorm i_norm) noexcept
Set position PI normalization.
bool getMccInputsRaw(uint16_t &inputs) noexcept
bool setPositionScalingFactor(uint16_t factor) noexcept
Set position scaling factor.
bool setPositionLoopGains(uint16_t p, uint16_t i) noexcept
Configure position PI gains.
bool setReferenceSwitchLatchSettings(tmc9660::tmcl::ReferenceSwitchLatchSettings setting) noexcept
Configure switch latch settings.
bool setPositionLoopDownsampling(uint8_t divider) noexcept
Set position loop downsampling.
TMC9660 & driver
Definition tmc9660.hpp:3270
bool getPositionLimitHigh(int32_t &limit) noexcept
Read high position limit.
bool stop() noexcept
Stop position control (SYSTEM_OFF).
bool setReferenceSwitchSearchSpeed(int32_t speed) noexcept
Set reference search speed.
bool getReferenceSwitchSearchMode(tmc9660::tmcl::ReferenceSwitchSearchMode &mode) noexcept
Read reference search mode.
bool getHomeSwitchPosition(int32_t &position) noexcept
Read home-switch position.
bool setEventStopSettings(tmc9660::tmcl::EventStopSettings settings) noexcept
Configure event-stop settings.
bool setPositionLimitLow(int32_t limit) noexcept
Set low position limit.
bool getPositionLimitLow(int32_t &limit) noexcept
Read low position limit.
bool getPositionSensor(tmc9660::tmcl::PositionSensorSelection &sel) noexcept
Read position feedback sensor.
bool getPositionPiError(int32_t &error) noexcept
Read position-PI error.
bool getReferenceSwitchEnable(tmc9660::tmcl::ReferenceSwitchEnable &enable) noexcept
Read reference switch enable mask.
bool setReferenceSwitchEnable(tmc9660::tmcl::ReferenceSwitchEnable enable) noexcept
Enable/disable reference switch stops.
bool setPositionLimitHigh(int32_t limit) noexcept
Set high position limit.
bool getReferenceSwitchLatchSettings(tmc9660::tmcl::ReferenceSwitchLatchSettings &setting) noexcept
Read switch latch settings.
bool setReferenceSwitchSearchMode(tmc9660::tmcl::ReferenceSwitchSearchMode mode) noexcept
Set reference search mode.
bool getEventStopSettings(tmc9660::tmcl::EventStopSettings &settings) noexcept
Read event-stop settings.
bool setTargetPosition(int32_t position) noexcept
Set target position.
bool getPositionPiIntegrator(int32_t &integrator) noexcept
Read position-PI integrator.
bool configureAuto(const PositionConfig &config) noexcept
Auto-configure position control parameters.
bool getLastReferencePosition(int32_t &position) noexcept
Read last reference position.
bool setPositionReachedThreshold(uint32_t threshold) noexcept
Set position reached threshold.
Configuration structure for power management auto-configuration.
Definition tmc9660.hpp:4677
std::optional< bool > enableWakePin
Enable external wake-up pin (optional, default: false).
Definition tmc9660.hpp:4683
std::optional< tmc9660::tmcl::PowerDownTimeout > powerDownTimeout
Power-down timeout period (optional, default: disabled).
Definition tmc9660.hpp:4691
Subsystem for entering low-power hibernation mode and configuring wake.
Definition tmc9660.hpp:4654
bool enableWakePin(bool enable) noexcept
Enable or disable the external wake-up pin.
Power(TMC9660 &parent) noexcept
Definition tmc9660.hpp:4705
bool configureAuto(const PowerConfig &config) noexcept
Auto-configure power management parameters.
TMC9660 & driver
Definition tmc9660.hpp:4706
bool enterPowerDown(tmc9660::tmcl::PowerDownTimeout period) noexcept
Put the chip into power-down mode for a set duration.
Configuration structure for protection auto-configuration.
Definition tmc9660.hpp:4144
std::optional< float > undervoltageThreshold_V
Undervoltage threshold in volts (optional, default: 20.0V for 24V systems).
Definition tmc9660.hpp:4166
std::optional< uint16_t > i2tTimeConstant2_ms
I²t window 2 time constant in milliseconds (optional, default: 1000ms).
Definition tmc9660.hpp:4221
std::optional< float > i2tContinuousCurrent1_A
I²t window 1 continuous current limit in Amps (optional, default: 1.5A).
Definition tmc9660.hpp:4212
std::optional< float > temperatureShutdown_C
Temperature shutdown threshold in °C (optional, default: 100.0°C).
Definition tmc9660.hpp:4186
std::optional< float > i2tContinuousCurrent2_A
I²t window 2 continuous current limit in Amps (optional, default: 1.25A).
Definition tmc9660.hpp:4228
std::optional< uint16_t > i2tTimeConstant1_ms
I²t window 1 time constant in milliseconds (optional, default: 100ms).
Definition tmc9660.hpp:4205
std::optional< float > overvoltageThreshold_V
Overvoltage threshold in volts (optional, default: 28.0V for 24V systems).
Definition tmc9660.hpp:4155
std::optional< float > temperatureWarning_C
Temperature warning threshold in °C (optional, default: 80.0°C).
Definition tmc9660.hpp:4177
std::optional< bool > enableOvercurrent
Enable overcurrent protection (optional, default: true).
Definition tmc9660.hpp:4196
Subsystem for motor protection features.
Definition tmc9660.hpp:4090
bool configureVoltage(uint16_t over_volt_threshold, uint16_t under_volt_threshold) noexcept
Configure overvoltage and undervoltage protection thresholds.
Protection(TMC9660 &parent) noexcept
Definition tmc9660.hpp:4244
bool resetI2tState() noexcept
Reset the integrated I²t sum accumulators.
bool configureTemperature(float warning_deg_c, float shutdown_deg_c) noexcept
Configure over-temperature protection thresholds.
TMC9660 & driver
Definition tmc9660.hpp:4245
bool setOvercurrentEnabled(bool enabled) noexcept
Enable or disable overcurrent protection on the driver outputs.
bool configureAuto(const ProtectionConfig &config) noexcept
Auto-configure protection parameters.
bool configureI2t(uint16_t timeConstant1_ms, float continuousCurrent1_A, uint16_t timeConstant2_ms, float continuousCurrent2_A) noexcept
Configure the two I²t monitoring windows for motor current.
Subsystem for debug and data logging features.
Definition tmc9660.hpp:4339
bool init(uint32_t sample_count) noexcept
Initialize and configure the RAMDebug feature (data logging).
bool startCapture() noexcept
Start capturing data using RAMDebug.
TMC9660 & driver
Definition tmc9660.hpp:4371
Configuration structure for ramp auto-configuration.
Definition tmc9660.hpp:3369
std::optional< uint16_t > timeZeroWait
Wait time at end of ramp (optional, default: 0).
Definition tmc9660.hpp:3465
std::optional< uint32_t > maxAcceleration
Maximum acceleration in µ units/s² (optional, default: 1000).
Definition tmc9660.hpp:3385
std::optional< bool > enableRamp
Enable ramp generator (optional, default: false).
Definition tmc9660.hpp:3472
std::optional< uint16_t > timeAtVmax
Minimum time at VMAX before deceleration (optional, default: 0).
Definition tmc9660.hpp:3458
std::optional< uint32_t > velocityThreshold1
Velocity threshold 1 in internal units (optional, default: 0).
Definition tmc9660.hpp:3430
std::optional< bool > enableVelocityFeedForward
Enable velocity feedforward (optional, default: false).
Definition tmc9660.hpp:3487
std::optional< uint32_t > maxDeceleration
Maximum deceleration in µ units/s² (optional, default: 1000).
Definition tmc9660.hpp:3409
std::optional< tmc9660::tmcl::AccelerationFFShift > accelerationFeedForwardShift
Acceleration feedforward shift (optional, default: SHIFT_4).
Definition tmc9660.hpp:3509
std::optional< uint32_t > stopVelocity
Stop velocity in internal units (optional, default: 1).
Definition tmc9660.hpp:3451
std::optional< bool > enableAccelerationFeedForward
Enable acceleration feedforward (optional, default: false).
Definition tmc9660.hpp:3493
std::optional< uint32_t > startVelocity
Start velocity in internal units (optional, default: 0).
Definition tmc9660.hpp:3444
std::optional< uint32_t > deceleration1
First deceleration segment in µ units/s² (optional, default: 8000).
Definition tmc9660.hpp:3416
std::optional< uint32_t > acceleration2
Second acceleration segment in µ units/s² (optional, default: 4000).
Definition tmc9660.hpp:3401
uint32_t maxVelocity
Maximum velocity in internal units (required).
Definition tmc9660.hpp:3376
std::optional< uint32_t > deceleration2
Second deceleration segment in µ units/s² (optional, default: 8000).
Definition tmc9660.hpp:3423
std::optional< bool > enableDirectVelocityMode
Enable direct velocity mode (optional, default: true).
Definition tmc9660.hpp:3480
std::optional< uint32_t > acceleration1
First acceleration segment in µ units/s² (optional, default: 8000).
Definition tmc9660.hpp:3393
std::optional< uint32_t > velocityThreshold2
Velocity threshold 2 in internal units (optional, default: 0).
Definition tmc9660.hpp:3437
std::optional< uint16_t > accelerationFeedForwardGain
Acceleration feedforward gain (optional, default: 8).
Definition tmc9660.hpp:3502
Hardware 8-segment acceleration/dec-acc profile controller.
Definition tmc9660.hpp:3293
bool setTiming(uint16_t t_vmax_cycles, uint16_t t_zero_wait_cycles) noexcept
Timing constraints at Vmax and between moves.
bool setDirectVelocityMode(bool enable) noexcept
Direct-velocity mode instead of classic PI velocity loop.
bool getRampVelocity(int32_t &velocity) noexcept
Get the current target velocity calculated by the ramp controller.
TMC9660 & driver
Definition tmc9660.hpp:3525
bool enableFeedForward(bool enable_vel_ff, bool enable_accel_ff, uint16_t accel_ff_gain, tmc9660::tmcl::AccelerationFFShift accel_ff_shift) noexcept
Enable hardware feed-forward terms and set gain/shift.
bool getRampPosition(int32_t &position) noexcept
Get the current target position calculated by the ramp controller.
bool enable(bool on) noexcept
Enable or disable the ramp generator block.
Ramp(TMC9660 &parent) noexcept
Definition tmc9660.hpp:3524
bool setDeceleration(uint32_t d1, uint32_t d2, uint32_t d_max) noexcept
Set deceleration segments D1, D2, Dmax (µ units/s²).
bool setAcceleration(uint32_t a1, uint32_t a2, uint32_t a_max) noexcept
Set acceleration segments A1, A2, Amax (µ units/s²).
bool setVelocities(uint32_t v_start, uint32_t v_stop, uint32_t v1, uint32_t v2, uint32_t v_max) noexcept
Configure velocity thresholds and limits.
bool configureAuto(const RampConfig &config) noexcept
Auto-configure ramp parameters.
Subsystem for executing a reference search (homing) routine.
Definition tmc9660.hpp:3614
TMC9660 & driver
Definition tmc9660.hpp:3625
bool start() noexcept
Start the reference search procedure.
bool getStatus(tmc9660::tmcl::ReferenceSearchStatus &status) noexcept
Query the current reference search status code.
bool stop() noexcept
Abort an ongoing reference search.
Subsystem for TMCL script execution control.
Definition tmc9660.hpp:4254
bool start(uint16_t address=0) noexcept
Start or restart execution of the stored script.
TMC9660 & driver
Definition tmc9660.hpp:4331
bool upload(const std::vector< uint32_t > &script_data) noexcept
Upload a TMCL script to the TMC9660's internal memory.
Subsystem for controlling the STEP/DIR pulse input interface.
Definition tmc9660.hpp:3543
bool enableExtrapolation(bool enable) noexcept
Enable signal extrapolation between STEP pulses.
bool setMaxExtrapolationVelocity(uint32_t e_rpm) noexcept
Set maximum allowed extrapolation velocity.
bool enableInterface(bool on) noexcept
Enable or disable the STEP/DIR interface.
StepDir(TMC9660 &parent) noexcept
Definition tmc9660.hpp:3605
bool enableVelocityFeedForward(bool enable_vel_ff) noexcept
Enable hardware feed-forward terms and set gain/shift.
bool setMicrostepResolution(tmc9660::tmcl::StepDirStepDividerShift µSteps) noexcept
Configure microstep resolution for each STEP pulse.
bool setSignalTimeout(uint16_t timeout_ms) noexcept
Timeout before extrapolated motion stops after last pulse.
TMC9660 & driver
Definition tmc9660.hpp:3606
Configuration structure for stop events auto-configuration.
Definition tmc9660.hpp:4010
std::optional< uint32_t > maxPositionDeviation
Maximum allowed position deviation for stop condition (optional, disabled if not provided).
Definition tmc9660.hpp:4029
std::optional< bool > invertLeftSwitch
Invert left switch polarity (optional, default: false).
Definition tmc9660.hpp:4053
std::optional< bool > swapLeftRight
Swap left and right switch wiring (optional, default: false).
Definition tmc9660.hpp:4065
std::optional< bool > deviationSoftStop
Use soft stop (ramp down) for deviation stop (optional, default: true).
Definition tmc9660.hpp:4037
std::optional< uint32_t > maxVelocityDeviation
Maximum allowed velocity deviation for stop condition (optional, disabled if not provided).
Definition tmc9660.hpp:4019
std::optional< bool > invertRightSwitch
Invert right switch polarity (optional, default: false).
Definition tmc9660.hpp:4057
std::optional< bool > invertHomeSwitch
Invert home switch polarity (optional, default: false).
Definition tmc9660.hpp:4061
std::optional< uint8_t > referenceSwitchMask
Reference switch enable mask (optional, default: 0 = all disabled).
Definition tmc9660.hpp:4049
Configure automatic stop/latch behaviour for deviation, switches.
Definition tmc9660.hpp:3955
bool configureAuto(const StopEventsConfig &config) noexcept
Auto-configure stop events parameters.
StopEvents(TMC9660 &parent) noexcept
Definition tmc9660.hpp:4080
bool enableDeviationStop(uint32_t max_vel_error, uint32_t max_pos_error, bool softStop=true) noexcept
Stop when ramp target deviates from actual > thresholds.
TMC9660 & driver
Definition tmc9660.hpp:4081
Subsystem for reading various telemetry and status information from the driver.
Definition tmc9660.hpp:3865
bool clearADCStatusFlags(uint32_t mask) noexcept
Clear bits in the ADC_STATUS_FLAGS register (write-1-to-clear).
int16_t getMotorCurrent() noexcept
Read the current motor current (torque current).
float getChipTemperature() noexcept
Read the internal chip temperature.
int32_t getActualVelocity() noexcept
Read the measured actual velocity of the motor.
bool getGeneralStatusFlags(uint32_t &flags) noexcept
Read the GENERAL_STATUS_FLAGS register.
float getSupplyVoltage() noexcept
Read the current supply (bus) voltage.
bool getGeneralErrorFlags(uint32_t &flags) noexcept
Read the GENERAL_ERROR_FLAGS register.
int32_t getActualPosition() noexcept
Read the measured actual position of the motor.
bool clearGateDriverErrorFlags(uint32_t mask) noexcept
Clear bits in the GDRV_ERROR_FLAGS register.
bool getADCStatusFlags(uint32_t &flags) noexcept
Read the ADC_STATUS_FLAGS register (clipped ADC channels).
TMC9660 & driver
Definition tmc9660.hpp:3946
uint16_t getExternalTemperature() noexcept
Read the external temperature sensor raw value.
bool clearGeneralErrorFlags(uint32_t mask) noexcept
Clear bits in the GENERAL_ERROR_FLAGS register.
bool getGateDriverErrorFlags(uint32_t &flags) noexcept
Read the GDRV_ERROR_FLAGS register.
Configuration structure for torque/flux control auto-configuration.
Definition tmc9660.hpp:2355
std::optional< uint16_t > fluxI
Flux I gain [0-32767] (optional, only used if separateTorqueFluxLoops = true)
Definition tmc9660.hpp:2394
std::optional< int32_t > biquadBCoeff2
Definition tmc9660.hpp:2527
std::optional< tmc9660::tmcl::CurrentPiNormalization > iNormalization
I-term normalization format (optional, defaults to SHIFT_16_BIT)
Definition tmc9660.hpp:2411
std::optional< uint16_t > torqueP
Direct PI gain configuration (optional).
Definition tmc9660.hpp:2371
std::optional< int32_t > biquadACoeff2
Definition tmc9660.hpp:2520
std::optional< int32_t > biquadBCoeff1
Definition tmc9660.hpp:2525
std::optional< int32_t > biquadACoeff1
Biquad filter coefficients (optional, only used if enableTorqueBiquadFilter = true).
Definition tmc9660.hpp:2518
std::optional< uint16_t > torqueI
Torque I gain [0-32767] (optional, defaults to 100 if not provided)
Definition tmc9660.hpp:2373
std::optional< tmc9660::tmcl::CurrentPiNormalization > pNormalization
PI normalization format (optional).
Definition tmc9660.hpp:2409
std::optional< uint16_t > fluxP
Flux PI gains (only used if separateTorqueFluxLoops = true).
Definition tmc9660.hpp:2392
std::optional< int32_t > biquadBCoeff0
Definition tmc9660.hpp:2523
Subsystem for torque and flux current control (FOC inner loop).
Definition tmc9660.hpp:2158
bool setFieldWeakeningI(uint16_t milliamps) noexcept
bool getTorquePiError(int32_t &error) noexcept
Read torque PI error.
bool getFieldWeakeningVoltageThreshold(uint16_t &voltage) noexcept
bool setTorqueOffset(int16_t milliamps) noexcept
Set torque offset (feed-forward).
bool getActualFlux(int32_t &milliamps) noexcept
Read actual flux current.
TorqueFluxControl(TMC9660 &parent) noexcept
Definition tmc9660.hpp:2543
bool getTargetTorqueBiquadFilterEnable(bool &enable) noexcept
bool getTorqueFluxCombinedActualValues(uint32_t &value) noexcept
bool getFocCurrentIq(int16_t &milliamps) noexcept
bool setCurrentNormalization(tmc9660::tmcl::CurrentPiNormalization p_norm, tmc9660::tmcl::CurrentPiNormalization i_norm) noexcept
Set normalization for current-PI outputs.
bool getFocVoltageUq(int16_t &voltage) noexcept
bool getFocCurrentUx(int16_t &milliamps) noexcept
bool setOpenloopVoltage(uint16_t voltage) noexcept
Set open-loop voltage.
bool getTargetTorqueBiquadFilterBCoeff1(int32_t &coeff) noexcept
bool getTargetTorqueBiquadFilterACoeff1(int32_t &coeff) noexcept
bool setTargetTorqueBiquadFilterBCoeff1(int32_t coeff) noexcept
bool getVoltageDqCombinedActualValues(uint32_t &value) noexcept
bool configureAuto(const TorqueFluxConfig &config) noexcept
Auto-configure torque/flux control parameters.
bool getOpenloopVoltage(uint16_t &voltage) noexcept
Read open-loop voltage.
bool setFluxOffset(int16_t milliamps) noexcept
Set flux offset (feed-forward).
bool getFocCurrentWy(int16_t &milliamps) noexcept
bool getFieldWeakeningI(uint16_t &milliamps) noexcept
bool getTargetTorqueBiquadFilterBCoeff2(int32_t &coeff) noexcept
TMC9660 & driver
Definition tmc9660.hpp:2544
bool setCurrentLoopGains(uint16_t p, uint16_t i, bool separate=false, uint16_t fluxP=0, uint16_t fluxI=0) noexcept
Configure current-loop PI gains.
bool getActualTorque(int16_t &milliamps) noexcept
Read actual torque.
bool getTargetTorqueBiquadFilterACoeff2(int32_t &coeff) noexcept
bool getIntegratedActualTorqueValue(uint32_t &value) noexcept
bool getTorquePiIntegrator(int32_t &integrator) noexcept
Read torque-PI integrator state.
bool getFluxOffset(int16_t &milliamps) noexcept
Read flux offset.
bool setTargetTorqueBiquadFilterBCoeff0(int32_t coeff) noexcept
bool setTargetTorqueBiquadFilterEnable(bool enable) noexcept
bool setTargetTorqueBiquadFilterACoeff1(int32_t coeff) noexcept
bool stop() noexcept
Stop torque/flux control (SYSTEM_OFF).
bool getFluxPiError(int32_t &error) noexcept
Read flux PI error.
bool getFocCurrentV(int16_t &milliamps) noexcept
bool getOpenloopCurrent(uint16_t &milliamps) noexcept
Read open-loop current.
bool setOpenloopCurrent(uint16_t milliamps) noexcept
Set open-loop current.
bool getFocVoltageUx(int16_t &voltage) noexcept
bool getFocVoltageWy(int16_t &voltage) noexcept
bool setFieldWeakeningVoltageThreshold(uint16_t voltage) noexcept
bool getFluxPiIntegrator(int32_t &integrator) noexcept
Read flux-PI integrator state.
bool getFocVoltageV(int16_t &voltage) noexcept
bool getTargetTorqueBiquadFilterBCoeff0(int32_t &coeff) noexcept
bool getTorqueFluxCombinedTargetValues(uint32_t &value) noexcept
bool setTorqueFluxPiSeparation(tmc9660::tmcl::TorqueFluxPiSeparation sep) noexcept
Select combined or separate torque/flux PI parameters.
bool setTargetTorqueBiquadFilterBCoeff2(int32_t coeff) noexcept
bool setTargetTorqueBiquadFilterACoeff2(int32_t coeff) noexcept
bool setTargetTorque(int16_t milliamps) noexcept
Set desired torque.
bool getOpenloopAngle(int16_t &angle) noexcept
Read open-loop angle.
bool setTargetFlux(int16_t milliamps) noexcept
Set desired flux current.
bool getTorqueOffset(int16_t &milliamps) noexcept
Read torque offset.
Configuration structure for velocity control auto-configuration.
Definition tmc9660.hpp:2721
std::optional< uint16_t > velocityI
Velocity I gain [0-32767] (optional, default: 1).
Definition tmc9660.hpp:2739
std::optional< uint32_t > pwmFrequency_Hz
PWM frequency in Hz (optional, used for velocity meter threshold calculation).
Definition tmc9660.hpp:2798
std::optional< uint16_t > velocityP
Velocity P gain [0-32767] (optional, default: 800).
Definition tmc9660.hpp:2732
std::optional< int32_t > velocityBiquadBCoeff0
Definition tmc9660.hpp:2904
std::optional< int32_t > velocityBiquadACoeff2
Definition tmc9660.hpp:2902
std::optional< uint32_t > stopOnDeviationMaxError
Definition tmc9660.hpp:2827
tmc9660::tmcl::VelocitySensorSelection sensorSelection
Velocity feedback sensor selection (required)
Definition tmc9660.hpp:2724
std::optional< uint16_t > velocityScalingFactor
Velocity scaling factor [1-2047] (optional).
Definition tmc9660.hpp:2769
std::optional< uint32_t > meterSwitchThreshold
Velocity meter switch threshold (optional, auto-calculated if not provided).
Definition tmc9660.hpp:2851
std::optional< int32_t > velocityBiquadACoeff1
Velocity biquad filter coefficients (optional, only used if enableVelocityBiquadFilter is explicitly ...
Definition tmc9660.hpp:2900
std::optional< uint32_t > encoderCountsPerRev
Encoder counts per mechanical revolution (CPR) for auto-calculating velocity scaling.
Definition tmc9660.hpp:2781
std::optional< int32_t > velocityBiquadBCoeff2
Definition tmc9660.hpp:2908
std::optional< int32_t > velocityBiquadBCoeff1
Definition tmc9660.hpp:2906
std::optional< bool > enableVelocityBiquadFilter
Enable/disable biquad filter on actual velocity feedback.
Definition tmc9660.hpp:2873
std::optional< uint8_t > motor_polePairs
Motor pole pairs (optional, used for auto-calculating velocity scaling).
Definition tmc9660.hpp:2791
Subsystem for velocity control (FOC middle loop).
Definition tmc9660.hpp:2559
bool getVelocityLoopDownsampling(uint8_t &divider) noexcept
Read velocity loop downsampling.
bool getIntegratedActualVelocityValue(uint32_t &value) noexcept
bool setVelocityNormalization(tmc9660::tmcl::VelocityPiNorm p_norm, tmc9660::tmcl::VelocityPiNorm i_norm) noexcept
Set velocity PI normalization.
bool stop() noexcept
Stop velocity control (SYSTEM_OFF).
VelocityControl(TMC9660 &parent) noexcept
Definition tmc9660.hpp:2924
bool setActualVelocityBiquadFilterBCoeff0(int32_t coeff) noexcept
bool setVelocityLoopDownsampling(uint8_t divider) noexcept
Set velocity loop downsampling.
bool getVelocityPiError(int32_t &error) noexcept
Read velocity-PI error.
bool getActualVelocityBiquadFilterBCoeff2(int32_t &coeff) noexcept
bool setVelocityMeterSwitchThreshold(uint32_t threshold) noexcept
Set velocity meter switch threshold.
bool setVelocityScalingFactor(uint16_t factor) noexcept
Set velocity scaling factor.
bool setActualVelocityBiquadFilterBCoeff1(int32_t coeff) noexcept
bool setStopOnVelocityDeviation(uint32_t max_error, bool softStop=true) noexcept
Configure stop-on-velocity-deviation.
bool setVelocitySensor(tmc9660::tmcl::VelocitySensorSelection sel) noexcept
Select velocity feedback sensor.
TMC9660 & driver
Definition tmc9660.hpp:2925
bool setActualVelocityBiquadFilterACoeff2(int32_t coeff) noexcept
bool getActualVelocityBiquadFilterEnable(bool &enable) noexcept
bool getVelocityMeterSwitchHysteresis(uint16_t &hysteresis) noexcept
Read velocity meter hysteresis.
bool setActualVelocityBiquadFilterEnable(bool enable) noexcept
bool getActualVelocityBiquadFilterBCoeff1(int32_t &coeff) noexcept
bool setVelocityMeterSwitchHysteresis(uint16_t hysteresis) noexcept
Set velocity meter hysteresis.
bool getVelocityMeterSwitchThreshold(uint32_t &threshold) noexcept
Read velocity meter switch threshold.
bool setTargetVelocity(int32_t velocity) noexcept
Set target velocity.
bool getVelocityPiIntegrator(int32_t &integrator) noexcept
Read velocity-PI integrator.
bool getActualVelocityBiquadFilterACoeff2(int32_t &coeff) noexcept
bool setVelocityLoopGains(uint16_t p, uint16_t i) noexcept
Configure velocity PI gains.
bool getActualVelocityBiquadFilterACoeff1(int32_t &coeff) noexcept
bool setActualVelocityBiquadFilterACoeff1(int32_t coeff) noexcept
bool getVelocityMeterMode(tmc9660::tmcl::VelocityMeterMode &mode) noexcept
Read current velocity meter mode.
bool getVelocitySensor(tmc9660::tmcl::VelocitySensorSelection &sel) noexcept
Read velocity feedback sensor.
bool getStopOnVelocityDeviation(uint32_t &max_error, bool &soft_stop) noexcept
Read stop-on-velocity-deviation settings.
bool getActualVelocity(int32_t &velocity) noexcept
Read actual velocity.
bool getActualVelocityBiquadFilterBCoeff0(int32_t &coeff) noexcept
bool configureAuto(const VelocityConfig &config) noexcept
Auto-configure velocity control parameters.
bool getVelocityScalingFactor(uint16_t &factor) noexcept
Read velocity scaling factor.
bool setActualVelocityBiquadFilterBCoeff2(int32_t coeff) noexcept
bool getVelocityOffset(int32_t &offset) noexcept
Read velocity offset.
bool setVelocityOffset(int32_t offset) noexcept
Set velocity offset.
Main TMC9660 bootloader interface class.
Communication interfaces for TMC9660 Parameter Mode devices using TMCL protocol over SPI.
TMCL operation and reply code enumerations for TMC9660 parameter mode.