14#ifndef TMC5160_TYPES_HPP
15#define TMC5160_TYPES_HPP
22#include "tmc5160_version.h"
39enum class [[nodiscard]]
Error : uint8_t {
70 return "NotInitialized";
72 return "InvalidArgument";
78 return "DeviceIdMismatch";
88 return "UnexpectedReset";
90 return "VerifyFailed";
94 return "ModeMismatch";
96 return "LimitExceeded";
116 [[nodiscard]]
constexpr bool ok() const noexcept {
117 return error == Error::Ok;
120 constexpr explicit operator bool() const noexcept {
130 return {v, Error::Ok};
148 [[nodiscard]]
constexpr bool ok() const noexcept {
149 return error == Error::Ok;
152 constexpr explicit operator bool() const noexcept {
296 [[nodiscard]]
constexpr bool Has(
Ack a)
const noexcept {
297 return (
bits &
static_cast<uint32_t
>(a)) != 0U;
305 return AckSet{
bits |
static_cast<uint32_t
>(a)};
328 uint32_t
hz{12'000'000};
513 std::array<uint8_t, 4>
w{2, 1, 1, 1};
589struct EnumLast<
Mode> {
622[[nodiscard]]
constexpr int32_t TableStep(uint32_t width_code, uint32_t bit)
noexcept {
623 return static_cast<int32_t
>(width_code & 3U) - 1 +
static_cast<int32_t
>(bit & 1U);
627[[nodiscard]]
constexpr uint32_t SegmentWidth(
const MicrostepTable& t, uint32_t n)
noexcept {
634 return (n < t.
x3) ? t.
w[2] : t.
w[3];
638[[nodiscard]]
constexpr int32_t TableEntry(
const MicrostepTable& t, uint32_t n)
noexcept {
639 auto value =
static_cast<int32_t
>(t.
start_sin);
640 for (uint32_t i = 1U; i <= (n & 255U); ++i) {
641 const uint32_t bit = (t.
words[(i >> 5U) & 7U] >> (i & 31U)) & 1U;
642 value += TableStep(SegmentWidth(t, i), bit);
655 if ((table.x1 == 0U) || (table.x1 >= table.x2) || (table.x2 > table.x3)) {
658 auto value =
static_cast<int32_t
>(table.start_sin);
659 for (uint32_t i = 1U; i <= 255U; ++i) {
660 const uint32_t bit = (table.words[(i >> 5U) & 7U] >> (i & 31U)) & 1U;
661 value += detail::TableStep(detail::SegmentWidth(table, i), bit);
662 if ((value < -248) || (value > 248)) {
666 const auto last =
static_cast<int32_t
>(table.start_sin90);
685[[nodiscard]]
constexpr Error Need(
bool ok)
noexcept {
693[[nodiscard]]
constexpr Error Range(uint32_t v, uint32_t lo, uint32_t hi)
noexcept {
694 return Need((v >= lo) && (v <= hi));
697[[nodiscard]]
constexpr Error Order(uint32_t a, uint32_t b)
noexcept {
701[[nodiscard]]
constexpr Error Unless(
bool when,
Error e)
noexcept {
705[[nodiscard]]
constexpr Error ValidateClock(
const Config& c)
noexcept {
706 Error e = Need(IsEnumerator(c.mode) && IsEnumerator(c.verify));
709 e = Both(e, Range(c.uart.node, 0U,
710 c.uart.multi_node ? 254U : 253U));
711 e = Both(e, Range(c.uart.send_delay, c.uart.multi_node ? 2U : 0U, 15U));
712 e = Both(e, Range(c.uart.baud,
kUartMinBaud, c.clock.hz / 16U));
713 e = Both(e, Range(c.spi.chain_length, 1U,
kMaxChain));
714 return Both(e, Order(
static_cast<uint32_t
>(c.spi.chain_index) + 1U, c.spi.chain_length));
717[[nodiscard]]
constexpr Error ValidateDeclared(
const Config& c)
noexcept {
718 const uint32_t supply_max =
719 (c.board.supply_max_mv == 0U) ? c.board.supply_mv : c.board.supply_max_mv;
720 Error e = Range(c.motor.rated_rms_ma, 1U, 100'000U);
721 e = Both(e, Range(c.motor.max_rms_ma, 0U, 100'000U));
722 e = Both(e, Range(c.motor.fullsteps_per_rev, 1U, 1'000'000U));
723 e = Both(e, Range(c.board.rsense_mohm, 1U, 10'000U));
725 e = Both(e, Range(supply_max, c.board.supply_mv,
kVsMaxMv));
726 e = Both(e, Range(c.current.run_ma, 1U, 100'000U));
727 return Both(e, Range(c.standstill.hold_delay, 0U, 15U));
730[[nodiscard]]
constexpr Error ValidateChopper(
const Config& c)
noexcept {
731 const Chopper& k = c.chopper;
732 Error e = Need(IsEnumerator(k.mode) && IsEnumerator(k.mres));
733 e = Both(e, Range(k.toff, 1U, 15U));
734 e = Both(e, Range(k.tbl, (k.toff == 1U) ? 2U : 0U, 3U));
735 e = Both(e, Range(k.tpfd, 0U, 15U));
736 e = Both(e, Range(k.hstrt, 0U, 7U));
737 e = Both(e, Range(k.hend, 0U, 15U));
738 e = Both(e, Range(k.tfd, 0U, 15U));
739 e = Both(e, Range(k.offset, 0U, 15U));
740 const uint32_t effective =
static_cast<uint32_t
>(k.hstrt) +
static_cast<uint32_t
>(k.hend);
744[[nodiscard]]
constexpr Error ValidateStealth(
const Config& c)
noexcept {
745 const StealthChop& s = c.stealth;
746 Error e = Need(IsEnumerator(s.freewheel));
747 e = Both(e, Range(s.freq, 0U, 3U));
748 e = Both(e, Range(s.reg, s.autoscale ? 1U : 0U, 15U));
749 e = Both(e, Range(s.lim, 0U, 15U));
750 return Both(e, Range(c.standstill.power_down_delay, (s.enable && s.autoscale) ? 2U : 0U, 255U));
753[[nodiscard]]
constexpr Error ValidateThresholds(
const Config& c)
noexcept {
754 const Thresholds& t = c.thresholds;
755 Error e = Range(t.pwm, 0U, 0xFFFFFU);
756 e = Both(e, Range(t.cool, 0U, 0xFFFFFU));
757 e = Both(e, Range(t.high, 0U, 0xFFFFFU));
758 e = Both(e, Unless((t.cool != 0U) && (t.pwm != 0U), Order(t.cool, t.pwm)));
759 e = Both(e, Unless((t.high != 0U) && (t.cool != 0U), Order(t.high, t.cool)));
760 const bool needs_cool = (c.cool.semin != 0U) || c.switches.stop_on_stall;
761 e = Both(e, Unless(needs_cool, Range(t.cool, 1U, 0xFFFFFU)));
762 e = Both(e, Range(c.cool.semin, 0U, 15U));
763 e = Both(e, Range(c.cool.semax, 0U, 15U));
764 e = Both(e, Range(c.cool.seup, 0U, 3U));
765 e = Both(e, Range(c.cool.sedn, 0U, 3U));
766 e = Both(e, Need((c.stall.threshold >= -64) && (c.stall.threshold <= 63)));
767 e = Both(e, Unless(c.dcstep.vdcmin != 0U, Range(c.dcstep.vdcmin, 256U, 0x7FFFFFU)));
768 return Both(e, Range(c.dcstep.dc_time, 0U, 1023U));
771[[nodiscard]]
constexpr Error ValidateDcStep(
const Config& c)
noexcept {
772 Error e = Need(!c.custom_table);
773 e = Both(e, Need(c.chopper.high_fullstep && c.chopper.high_const_off));
774 e = Both(e, Range(c.chopper.toff, 3U, 15U));
777 constexpr std::array<uint32_t, 4> kBlankClocks{16U, 24U, 36U, 54U};
778 const uint32_t lowest = kBlankClocks[
static_cast<std::size_t
>(c.chopper.tbl & 3U)] + 1U;
779 return Unless(c.dcstep.vdcmin != 0U, Both(e, Range(c.dcstep.dc_time, lowest, 1023U)));
782[[nodiscard]]
constexpr uint32_t BbmNs(
const Bridge& b)
noexcept {
783 const uint32_t from_time = (
static_cast<uint32_t
>(b.bbm_time) * 83U) / 10U;
784 const uint32_t from_clks =
static_cast<uint32_t
>(b.bbm_clks) * 83U;
785 return (from_time > from_clks) ? from_time : from_clks;
788[[nodiscard]]
constexpr Error ValidateBridge(
const Config& c)
noexcept {
789 const Bridge& b = c.bridge;
790 Error e = Need(IsEnumerator(b.ot_level));
791 e = Both(e, Range(b.bbm_time, 0U, 24U));
792 e = Both(e, Range(b.bbm_clks, 0U, 15U));
793 e = Both(e, Range(b.drive_strength, 0U, 3U));
794 e = Both(e, Range(b.sense_filter, 0U, 3U));
795 e = Both(e, Unless(b.mosfet_switching_ns != 0U,
796 Order(
static_cast<uint32_t
>(b.mosfet_switching_ns) * 130U, BbmNs(b) * 100U)));
797 const Protection& p = c.protection;
798 const uint32_t supply_max =
799 (c.board.supply_max_mv == 0U) ? c.board.supply_mv : c.board.supply_max_mv;
800 e = Both(e, Range(p.s2vs_level, 4U, 15U));
801 e = Both(e, Range(p.s2g_level, (supply_max > 52'000U) ? 12U : 2U, 15U));
802 return Both(e, Range(p.filter, 0U, 3U));
805[[nodiscard]]
constexpr Error ValidateRamp(
const Config& c)
noexcept {
806 const RampProfile& r = c.ramp;
807 Error e = Range(r.vstart, 0U, 0x3FFFFU);
808 e = Both(e, Range(r.a1, 0U, 0xFFFFU));
809 e = Both(e, Range(r.v1, 0U, 0xFFFFFU));
810 e = Both(e, Range(r.amax, 0U, 0xFFFFU));
811 e = Both(e, Range(r.dmax, 0U, 0xFFFFU));
812 e = Both(e, Range(r.d1, 1U, 0xFFFFU));
813 e = Both(e, Range(r.vstop, 1U, 0x3FFFFU));
814 e = Both(e, Range(r.zero_wait, 0U, 0xFFFFU));
816 Range(r.vmax, r.vstart, (c.max_velocity_reg == 0U) ?
kVmaxLimit : c.max_velocity_reg));
821[[nodiscard]]
constexpr Error ValidateDiag(
const Config& c)
noexcept {
822 const Diag& d = c.diag;
824 const bool sd_only = d.diag0_error || d.diag0_otpw || d.diag0_stall || d.diag1_stall ||
825 d.diag1_index || d.diag1_on_state;
826 Error e = Unless(!sd, Need(!sd_only));
827 e = Both(e, Unless(sd, Need(!(d.diag0_step_output || d.diag1_dir_output))));
828 const bool other1 = d.diag1_stall || d.diag1_index || d.diag1_on_state || d.diag1_dir_output;
829 e = Both(e, Unless(d.diag1_steps_skipped, Need(!other1)));
830 e = Both(e, Need(!(c.switches.soft_stop && c.switches.stop_on_stall)));
831 e = Both(e, Range(c.encoder.deviation, 0U, 0xFFFFFU));
832 return Both(e, Order(c.encoder.scale.fraction, c.encoder.scale.decimal ? 9999U : 65'535U));
838[[nodiscard]]
constexpr Error NeedAck(
bool needs,
const Config& c,
Ack ack)
noexcept {
851 using detail::NeedAck;
852 const bool short_off = c.protection.disable_s2g || c.protection.disable_s2vs;
854 ((c.bridge.ot_level ==
OtLevel::C136) && (c.board.supply_mv > 24'000U));
855 const bool hard_stop =
856 (c.switches.stop_left || c.switches.stop_right || c.switches.stop_on_stall) &&
857 !c.switches.soft_stop;
876 Error e = detail::ValidateClock(config);
877 e = detail::Both(e, detail::ValidateDeclared(config));
878 e = detail::Both(e, detail::ValidateChopper(config));
879 e = detail::Both(e, detail::ValidateStealth(config));
880 e = detail::Both(e, detail::ValidateThresholds(config));
881 e = detail::Both(e, detail::ValidateDcStep(config));
882 e = detail::Both(e, detail::ValidateBridge(config));
883 e = detail::Both(e, detail::ValidateRamp(config));
884 e = detail::Both(e, detail::ValidateDiag(config));
893[[nodiscard]]
constexpr uint32_t
Advise(
const Config& config)
noexcept {
895 const auto flag = [&bits](
bool on,
Advice a)
noexcept {
896 bits |=
static_cast<uint32_t
>(on) *
static_cast<uint32_t
>(a);
904 config.clock.external && ((config.clock.hz < 10'000'000U) || (config.clock.hz > 16'000'000U)),
934 [[nodiscard]]
constexpr const Config&
Get() const& noexcept {
938 void Get() const&& = delete;
956 const uint32_t ceiling = (motor.max_rms_ma == 0U) ? motor.
rated_rms_ma : motor.max_rms_ma;
957 c.current.run_ma = (ceiling * 85U) / 100U;
958 c.current.hold_ma = (c.current.run_ma * 3U) / 10U;
965 Board{.rsense_mohm = 100, .supply_mv = 24'000})) ==
Error::Ok);
970 return TMC5160_VERSION_STRING;
974 return TMC5160_VERSION_MAJOR;
978 return TMC5160_VERSION_MINOR;
982 return TMC5160_VERSION_PATCH;
A configuration proven valid at build time.
Definition tmc5160_types.hpp:922
constexpr const Config & Get() const &noexcept
Definition tmc5160_types.hpp:934
consteval CheckedConfig(const Config &config) noexcept
Check config at build time.
Definition tmc5160_types.hpp:928
void Get() const &&=delete
Not on a temporary: the reference would dangle (KB-CPP20-044).
constexpr std::array< uint32_t, 8 > kDefaultMslut
Default sine table words, MSLUT[0] to MSLUT[7] (page 106).
Definition tmc5160_registers.hpp:113
constexpr uint32_t kCurrentTolerancePercent
Full-scale current tolerance.
Definition tmc5160_types.hpp:574
constexpr Error CheckTable(const MicrostepTable &table) noexcept
Whether a table is acceptable: segment starts ordered, every entry within -248 to 247 (the peak may r...
Definition tmc5160_types.hpp:654
constexpr uint32_t kVsMinMv
Lowest VS (page 120).
Definition tmc5160_types.hpp:575
BusStatus
Result of one UART exchange as the port reports it.
Definition tmc5160_types.hpp:199
constexpr uint32_t kMaxChain
Longest SPI daisy chain the driver frames.
Definition tmc5160_types.hpp:580
Microsteps
Microstep resolution (CHOPCONF.MRES): the value is the shift from 256 microsteps.
Definition tmc5160_types.hpp:226
constexpr uint32_t kVfsMv
Sense threshold, typical (page 123).
Definition tmc5160_types.hpp:573
Mode
Where the chip's step pulses come from (SD_MODE strap, section 2.2 page 13).
Definition tmc5160_types.hpp:206
constexpr uint32_t kMaxSckInternalHz
SPI clock with the internal clock (page 25).
Definition tmc5160_types.hpp:582
constexpr const char * GetDriverVersion() noexcept
Definition tmc5160_types.hpp:969
constexpr const char * ToString(Error error) noexcept
The name of an error, for logs.
Definition tmc5160_types.hpp:65
Advice
Soft guidance bits from Advise(); never an error.
Definition tmc5160_types.hpp:671
constexpr uint32_t kUartMinBaud
Lowest UART baud rate (page 26).
Definition tmc5160_types.hpp:577
LogLevel
Severity passed to the optional Log() hook.
Definition tmc5160_types.hpp:171
InputPin
Input pins the port may read through the optional GpioGet() hook.
Definition tmc5160_types.hpp:186
Verify
Extra traffic a setter spends to prove a write (handbook KB-ARCH-041).
Definition tmc5160_types.hpp:212
Freewheel
Standstill mode with IHOLD = 0 (PWMCONF.freewheel, page 38).
Definition tmc5160_types.hpp:247
constexpr Error CheckAcks(const Config &c) noexcept
The guards that an acknowledgement can lift (section 2.5 of the design): each returns Refused when th...
Definition tmc5160_types.hpp:849
StopKind
How Stop() brings the motor to rest (section 6.3.2, page 43).
Definition tmc5160_types.hpp:263
OtLevel
Overtemperature shutdown level (DRV_CONF.OTSELECT, page 36).
Definition tmc5160_types.hpp:239
constexpr Config MakeConfig(const Motor &motor, const Board &board) noexcept
A valid configuration for a declared motor and power stage: run current 90 percent of the rated curre...
Definition tmc5160_types.hpp:952
constexpr Error Validate(const Config &config) noexcept
Check a configuration without touching the chip.
Definition tmc5160_types.hpp:875
Ack
Acknowledgements: each lets one call do what the datasheet warns against.
Definition tmc5160_types.hpp:277
constexpr uint32_t kVmaxLimit
Highest VMAX (page 41).
Definition tmc5160_types.hpp:581
constexpr uint32_t kExternalClockMinHz
Lowest external clock (page 122).
Definition tmc5160_types.hpp:571
constexpr uint32_t kInternalClockHz
Internal oscillator (page 119).
Definition tmc5160_types.hpp:570
void ConfigIsInvalid() noexcept
Reached only when a CheckedConfig is built from an invalid configuration: it is never defined,...
CtrlPin
Output pins the port may drive through the optional GpioSet() hook.
Definition tmc5160_types.hpp:179
constexpr uint32_t kUartRecoveryBits
Idle bit times after a UART error.
Definition tmc5160_types.hpp:578
constexpr uint32_t kExternalClockMaxHz
Highest external clock (page 122).
Definition tmc5160_types.hpp:572
constexpr uint32_t GetDriverVersionMajor() noexcept
Definition tmc5160_types.hpp:973
constexpr uint32_t GetDriverVersionPatch() noexcept
Definition tmc5160_types.hpp:981
RampMode
Ramp generator mode (RAMPMODE, page 40).
Definition tmc5160_types.hpp:255
ChopperMode
Chopper mode (CHOPCONF.chm).
Definition tmc5160_types.hpp:220
constexpr uint32_t GetDriverVersionMinor() noexcept
Definition tmc5160_types.hpp:977
constexpr uint32_t kVsMaxMv
Highest VS (page 120).
Definition tmc5160_types.hpp:576
GpioSignal
Logical level of a control pin; the port maps it to the physical polarity.
Definition tmc5160_types.hpp:193
Error
Why a call failed. Every call of the driver returns one of these in its Result.
Definition tmc5160_types.hpp:39
constexpr uint32_t kUartReadRetries
Extra attempts of a failed UART read.
Definition tmc5160_types.hpp:579
constexpr uint32_t Advise(const Config &config) noexcept
Soft guidance for a configuration: bits of Advice, never an error.
Definition tmc5160_types.hpp:893
@ Fault
The line or the peripheral failed.
@ M256
256 microsteps per full step.
@ MotionController
SD_MODE low: the internal ramp generator moves the motor. Default.
@ StepDir
SD_MODE high: STEP and DIR pins; serial configuration, no ramp.
@ ExternalClock
External clock outside 10 to 16 MHz (page 122).
@ HoldAbove70
Hold current above 70 percent of run (page 38).
@ PwmFrequency
PWM frequency outside 20 to 50 kHz (page 59).
@ IrunBelow16
IRUN below 16: coarse microsteps (page 38).
@ GlobalScalerBelow129
GLOBALSCALER below 129 (page 36).
@ ToffBelow2
TOFF below 2 (page 51).
@ TblOutside
TBL outside 1 to 2 (page 51).
@ PwmLimBelow5
PWM_LIM below 5 (page 54).
@ VstopBelow10
VSTOP below 10 (page 41).
@ Warning
Something unexpected that the driver recovered from.
@ Info
Lifecycle events: initialised, reset.
@ Debug
Detail for bring-up.
@ DcOut
ENCN_DCO_CFG6: DcStep ready output.
@ Diag1
DIAG1_SWP: position compare or stall output.
@ Diag0
DIAG0_SWN: interrupt or error output.
@ Counter
UART: one IFCNT read; it must have counted this write (page 33).
@ Echo
SPI: one more transfer; its reply must mirror the data just written (page 24).
@ ReadBack
Read the register back where the chip allows it (one or two transfers).
@ ShortHighSide
Coils shorted through the high-side MOSFETs.
@ ShortLowSide
Coils shorted through the low-side MOSFETs.
@ Normal
Normal operation.
@ Immediate
VSTART 0 and VMAX 0 in velocity mode: still the AMAX ramp (no VSTART floor).
@ Ramp
Velocity mode with VMAX 0: decelerate with AMAX (page 83).
@ Emergency
Driver off (DRV_ENN, TOFF 0): the motor is not held.
@ C143
143 degrees Celsius.
@ C120
120 degrees Celsius.
@ C150
150 degrees Celsius.
@ C136
136 degrees Celsius.
@ DirectMode
Direct mode: coil currents from XTARGET (page 110).
@ VoltageModeNoCurrentLimit
Direct mode with a voltage-mode chopper (page 110).
@ ShortProtectionOff
diss2g or diss2vs set (page 22).
@ HoldAboveRun
IHOLD above IRUN (page 38).
@ LowOtLevel
120 degrees shutdown, or 136 degrees above 24 V (page 36).
@ HardStopWithStealthChop
Hard stop in StealthChop: overcurrent risk (page 43).
@ VstartAboveVstop
VSTOP below VSTART (page 41).
@ DcIn
ENCA_DCIN_CFG5: DcStep input or emergency stop input.
@ DcEnable
ENCB_DCEN_CFG4: DcStep enable input (STEP/DIR mode).
@ DrvEnn
DRV_ENN, active low on the package pin: ACTIVE means the driver is enabled.
@ VelocityNegative
Run at VMAX in the negative direction.
@ Position
Move to XTARGET with the six-point ramp.
@ VelocityPositive
Run at VMAX in the positive direction.
@ Hold
Velocity stays constant; used as the safe state.
@ SpreadCycle
Hysteresis decay, page 51.
@ ConstOffTime
Classic constant off time.
@ ACTIVE
The pin function is asserted.
@ INACTIVE
The pin function is deasserted.
@ UnexpectedReset
The chip reset (GSTAT.reset, SPI status bit 0): every write-only register is lost.
@ LimitExceeded
The request exceeds a declared motor, board or ramp limit.
@ InvalidArgument
An argument or a Config field is out of range; nothing was sent.
@ DeviceIdMismatch
IOIN.VERSION is not 0x30: another chip, no chip or a wiring fault.
@ Crc
The CRC-8 of a UART reply did not match (never produced on SPI).
@ Bus
A port hook returned false.
@ VerifyFailed
A write-back, echo or interface-counter check did not match.
@ DeviceFault
The driver reports an error (GSTAT.drv_err): short or overtemperature.
@ NotInitialized
EnsureInitialized() has not succeeded, or Deinitialize() ran since.
@ ModeMismatch
The SD_MODE strap or the bus does not match Config::mode.
@ Unsupported
The hook, bus or mode this call needs is absent.
@ Timeout
The chip did not answer in the allowed time or a bounded wait ran out.
@ Busy
The motor is moving or a ramp is running: the call needs standstill.
@ Refused
A guard refused the call: a missing acknowledgement or an unsafe order.
The TMC5160 driver: everything it declares lives here; internals in detail.
Definition tmc5160.hpp:34
A set of acknowledgements.
Definition tmc5160_types.hpp:288
constexpr bool Has(Ack a) const noexcept
Whether a is in the set.
Definition tmc5160_types.hpp:296
uint32_t bits
The Ack values or-ed together.
Definition tmc5160_types.hpp:289
constexpr AckSet With(Ack a) const noexcept
A copy with a added.
Definition tmc5160_types.hpp:304
The power stage as built: the sense resistor and the supply.
Definition tmc5160_types.hpp:319
uint32_t rsense_mohm
Sense resistor per coil in mOhm. Required, 1 or more.
Definition tmc5160_types.hpp:320
uint32_t supply_mv
Motor supply VS in mV, 10000 to 55000 (section 28.1, page 120).
Definition tmc5160_types.hpp:321
uint32_t supply_max_mv
Highest supply that can occur in mV; 0 means supply_mv.
Definition tmc5160_types.hpp:322
Gate driver settings (DRV_CONF, section 6.1 page 35); written only when declared.
Definition tmc5160_types.hpp:406
uint8_t sense_filter
FILT_ISENSE 0 to 3: 100, 200, 300, 400 ns.
Definition tmc5160_types.hpp:411
bool declared
true: the application declares these values; false: not written.
Definition tmc5160_types.hpp:407
uint8_t bbm_time
BBMTIME 0 to 24 (about 8.3 ns each).
Definition tmc5160_types.hpp:408
uint16_t mosfet_switching_ns
Slowest MOSFET switching time in ns, 0 = not declared.
Definition tmc5160_types.hpp:413
uint8_t drive_strength
DRVSTRENGTH 0 to 3.
Definition tmc5160_types.hpp:410
uint8_t bbm_clks
BBMCLKS 0 to 15 clocks.
Definition tmc5160_types.hpp:409
OtLevel ot_level
Overtemperature shutdown level.
Definition tmc5160_types.hpp:412
Chopper configuration (CHOPCONF, section 6.5.2 page 51).
Definition tmc5160_types.hpp:345
uint8_t tfd
Constant off time: fast decay time 0 to 15.
Definition tmc5160_types.hpp:352
uint8_t hstrt
SpreadCycle hysteresis start 0 to 7 (reset 5).
Definition tmc5160_types.hpp:350
uint8_t offset
Constant off time: sine wave offset 0 to 15.
Definition tmc5160_types.hpp:353
uint8_t tbl
Blank time 0 to 3: 16, 24, 36, 54 clocks; reset value 2.
Definition tmc5160_types.hpp:348
bool high_fullstep
Full steps above THIGH.
Definition tmc5160_types.hpp:358
bool high_const_off
Constant off time above THIGH.
Definition tmc5160_types.hpp:359
uint8_t tpfd
Passive fast decay 0 to 15, 128 clocks per step; reset value 4.
Definition tmc5160_types.hpp:349
uint8_t hend
SpreadCycle hysteresis end 0 to 15 (reset 2).
Definition tmc5160_types.hpp:351
uint8_t toff
Off time 1 to 15 (0 is Disable()); reset value 0 means off.
Definition tmc5160_types.hpp:347
ChopperMode mode
SpreadCycle or constant off time.
Definition tmc5160_types.hpp:346
bool no_comparator
Constant off time: no current comparator on fast decay.
Definition tmc5160_types.hpp:354
bool interpolate
Interpolate to 256 microsteps (reset 1).
Definition tmc5160_types.hpp:356
bool double_edge
Step on both STEP edges.
Definition tmc5160_types.hpp:357
Microsteps mres
Microstep resolution.
Definition tmc5160_types.hpp:355
The clock: internal 12 MHz or an external clock on CLK (page 119).
Definition tmc5160_types.hpp:326
bool external
true when an external clock drives CLK.
Definition tmc5160_types.hpp:327
uint32_t hz
The clock frequency: 12 MHz internal, 4 to 18 MHz external.
Definition tmc5160_types.hpp:328
Everything EnsureInitialized() writes to the chip. See docs/configuration.md.
Definition tmc5160_types.hpp:536
Protection protection
Short protection.
Definition tmc5160_types.hpp:553
bool begin_enabled
true: EnsureInitialized() leaves the driver enabled.
Definition tmc5160_types.hpp:565
uint32_t max_velocity_reg
Declared VMAX ceiling; 0 = only the register limit.
Definition tmc5160_types.hpp:541
Encoder encoder
Encoder.
Definition tmc5160_types.hpp:558
Diag diag
DIAG outputs.
Definition tmc5160_types.hpp:555
UartOptions uart
UART options.
Definition tmc5160_types.hpp:561
RampProfile ramp
Ramp registers.
Definition tmc5160_types.hpp:556
Board board
Declared power stage; required.
Definition tmc5160_types.hpp:540
Motor motor
Declared motor; required.
Definition tmc5160_types.hpp:539
MicrostepTable table
The microstep table.
Definition tmc5160_types.hpp:560
StealthChop stealth
StealthChop.
Definition tmc5160_types.hpp:547
AckSet ack
Acknowledgements.
Definition tmc5160_types.hpp:564
Clock clock
The clock source.
Definition tmc5160_types.hpp:538
Thresholds thresholds
Velocity thresholds.
Definition tmc5160_types.hpp:548
Flags flags
General flags.
Definition tmc5160_types.hpp:554
bool include_tolerance
Reduce the current ceiling by the 5 percent full-scale tolerance.
Definition tmc5160_types.hpp:542
Chopper chopper
Chopper.
Definition tmc5160_types.hpp:546
DcStep dcstep
DcStep.
Definition tmc5160_types.hpp:551
SpiOptions spi
SPI options.
Definition tmc5160_types.hpp:562
Switches switches
Reference switches.
Definition tmc5160_types.hpp:557
Mode mode
SD_MODE strap the board uses.
Definition tmc5160_types.hpp:537
Bridge bridge
Gate drivers.
Definition tmc5160_types.hpp:552
StallGuard stall
StallGuard2.
Definition tmc5160_types.hpp:550
Current current
Run and hold current.
Definition tmc5160_types.hpp:544
CoolStep cool
CoolStep.
Definition tmc5160_types.hpp:549
Standstill standstill
Standstill behaviour.
Definition tmc5160_types.hpp:545
Verify verify
Verification the start-up uses on its writes.
Definition tmc5160_types.hpp:563
bool custom_table
true: write table (needs MSCNT = 0).
Definition tmc5160_types.hpp:559
CoolStep (COOLCONF, section 13, page 87).
Definition tmc5160_types.hpp:384
uint8_t semax
Upper threshold offset 0 to 15.
Definition tmc5160_types.hpp:386
uint8_t sedn
Decrement rate 0 to 3: 32, 8, 2, 1 readings.
Definition tmc5160_types.hpp:388
uint8_t seup
Increment 0 to 3: 1, 2, 4, 8.
Definition tmc5160_types.hpp:387
bool min_quarter
Minimum current a quarter instead of a half of IRUN.
Definition tmc5160_types.hpp:389
uint8_t semin
Lower threshold 0 to 15; 0 turns CoolStep off.
Definition tmc5160_types.hpp:385
Run and hold current requests, RMS in mA; PlanCurrent() turns them into registers.
Definition tmc5160_types.hpp:332
uint32_t hold_ma
Standstill current in mA; at most run_ma unless Ack::HoldAboveRun.
Definition tmc5160_types.hpp:334
uint32_t run_ma
Run current in mA, 1 or more.
Definition tmc5160_types.hpp:333
DcStep (VDCMIN, DCCTRL, section 17, page 100).
Definition tmc5160_types.hpp:399
uint32_t vdcmin
VDCMIN, 0 (off) or 256 to 2^23 - 1; bits 7..0 are ignored.
Definition tmc5160_types.hpp:400
uint8_t dc_sg
DC_SG 0 to 255, 16 clocks per count; 0 is off.
Definition tmc5160_types.hpp:402
uint16_t dc_time
DC_TIME 0 to 1023 clocks.
Definition tmc5160_types.hpp:401
DIAG0 and DIAG1 outputs (GCONF bits 5 to 13, section 6.1 page 32).
Definition tmc5160_types.hpp:436
bool diag1_index
DIAG1 on microstep index 0 (StepDir mode).
Definition tmc5160_types.hpp:443
bool diag0_stall
DIAG0 on stall (StepDir mode).
Definition tmc5160_types.hpp:439
bool diag0_otpw
DIAG0 on pre-warning (StepDir mode).
Definition tmc5160_types.hpp:438
bool diag1_push_pull
DIAG1 push-pull instead of open drain.
Definition tmc5160_types.hpp:447
bool diag0_push_pull
DIAG0 push-pull instead of open drain.
Definition tmc5160_types.hpp:446
bool diag1_stall
DIAG1 on stall (StepDir mode).
Definition tmc5160_types.hpp:441
bool diag1_dir_output
DIAG1 outputs the internal DIR (MotionController mode).
Definition tmc5160_types.hpp:442
bool diag0_error
DIAG0 on driver error (StepDir mode).
Definition tmc5160_types.hpp:437
bool diag1_steps_skipped
DIAG1 toggles on skipped DcStep steps; exclusive.
Definition tmc5160_types.hpp:445
bool diag0_step_output
DIAG0 outputs the internal STEP (MotionController mode).
Definition tmc5160_types.hpp:440
bool diag1_on_state
DIAG1 on chopper on-state (StepDir mode).
Definition tmc5160_types.hpp:444
The ENC_CONST accumulation factor (page 45, 107).
Definition tmc5160_types.hpp:495
bool negative
Decimal only: the constant is negative (page 107 rule).
Definition tmc5160_types.hpp:499
bool decimal
ENCMODE.enc_sel_decimal: fraction in 1/10000 instead of 1/65536.
Definition tmc5160_types.hpp:496
uint16_t fraction
Fractional part: 1/65536 (binary) or 1/10000 (decimal, below 10000).
Definition tmc5160_types.hpp:498
int16_t integer
Integer part, signed.
Definition tmc5160_types.hpp:497
Incremental encoder (ABN), written only when declared.
Definition tmc5160_types.hpp:503
EncoderScale scale
Accumulation factor.
Definition tmc5160_types.hpp:506
uint32_t deviation
ENC_DEVIATION in steps, 0 = off, up to 2^20 - 1.
Definition tmc5160_types.hpp:507
bool declared
true: ENCMODE, ENC_CONST and ENC_DEVIATION are written.
Definition tmc5160_types.hpp:504
NEvent n_event
N-channel conditions.
Definition tmc5160_types.hpp:505
General flags (GCONF).
Definition tmc5160_types.hpp:428
bool multistep_filt
GCONF.multistep_filt (page 33; reset text says 1, A12).
Definition tmc5160_types.hpp:431
bool stop_input
GCONF.stop_enable: ENCA_DCIN stops the sequencer.
Definition tmc5160_types.hpp:432
bool recalibrate
GCONF.recalibrate.
Definition tmc5160_types.hpp:430
bool invert_direction
GCONF.shaft.
Definition tmc5160_types.hpp:429
A microstep table (MSLUT, MSLUTSEL, MSLUTSTART, section 6.5 page 47).
Definition tmc5160_types.hpp:511
uint8_t x2
Segment 2 start.
Definition tmc5160_types.hpp:515
std::array< uint32_t, 8 > words
MSLUT[0] to MSLUT[7].
Definition tmc5160_types.hpp:512
uint8_t x1
Segment 1 start.
Definition tmc5160_types.hpp:514
uint8_t start_sin90
Table value at entry 256.
Definition tmc5160_types.hpp:518
uint8_t start_sin
Table value at entry 0.
Definition tmc5160_types.hpp:517
std::array< uint8_t, 4 > w
Segment width codes W0 to W3, 0 to 3.
Definition tmc5160_types.hpp:513
uint8_t x3
Segment 3 start.
Definition tmc5160_types.hpp:516
The motor as its data sheet declares it; the current ceiling comes from here.
Definition tmc5160_types.hpp:310
uint32_t rated_rms_ma
Rated coil current, RMS, in mA. Required, 1 or more.
Definition tmc5160_types.hpp:311
uint32_t fullsteps_per_rev
Full steps per revolution, 1 or more.
Definition tmc5160_types.hpp:315
uint32_t coil_resistance_mohm
Coil resistance in mOhm; 0 = unknown (StealthChop lower limit).
Definition tmc5160_types.hpp:313
uint32_t max_rms_ma
Hard ceiling in mA; 0 means rated_rms_ma.
Definition tmc5160_types.hpp:312
Encoder N-channel event conditions (ENCMODE, page 46).
Definition tmc5160_types.hpp:481
bool pos_edge
Sensitive to the active-going edge.
Definition tmc5160_types.hpp:488
bool once
Latch or clear on the next N event only (clr_once).
Definition tmc5160_types.hpp:487
bool repeat
Latch or clear on every N event (clr_cont).
Definition tmc5160_types.hpp:486
bool pol_n
Active polarity of N.
Definition tmc5160_types.hpp:484
bool latch_xactual
Latch XACTUAL at the event.
Definition tmc5160_types.hpp:491
bool neg_edge
Sensitive to the inactive-going edge.
Definition tmc5160_types.hpp:489
bool pol_a
Required A polarity.
Definition tmc5160_types.hpp:482
bool clear_counter
Clear X_ENC at the event.
Definition tmc5160_types.hpp:490
bool ignore_ab
Ignore A and B.
Definition tmc5160_types.hpp:485
bool pol_b
Required B polarity.
Definition tmc5160_types.hpp:483
Short protection (SHORT_CONF, section 11.2 page 78); written only when declared.
Definition tmc5160_types.hpp:417
bool declared
true: the application declares these values; false: not written.
Definition tmc5160_types.hpp:418
bool disable_s2g
diss2g; needs Ack::ShortProtectionOff.
Definition tmc5160_types.hpp:423
uint8_t s2vs_level
S2VS_LEVEL 4 to 15.
Definition tmc5160_types.hpp:419
bool disable_s2vs
diss2vs; needs Ack::ShortProtectionOff.
Definition tmc5160_types.hpp:424
bool long_delay
shortdelay: 1500 ns instead of 750 ns.
Definition tmc5160_types.hpp:422
uint8_t filter
SHORTFILTER 0 to 3.
Definition tmc5160_types.hpp:421
uint8_t s2g_level
S2G_LEVEL 2 to 15 (12 to 15 above 52 V).
Definition tmc5160_types.hpp:420
The six-point ramp (page 40). Defaults are the datasheet's quick-start values (page 116).
Definition tmc5160_types.hpp:452
uint32_t amax
AMAX 0 to 65535.
Definition tmc5160_types.hpp:456
uint32_t v1
V1 0 to 2^20 - 1; 0 disables A1 and D1.
Definition tmc5160_types.hpp:455
uint32_t d1
D1 1 to 65535.
Definition tmc5160_types.hpp:459
uint32_t zero_wait
TZEROWAIT 0 to 65535, 512 clocks per count.
Definition tmc5160_types.hpp:461
uint32_t vstart
VSTART 0 to 2^18 - 1.
Definition tmc5160_types.hpp:453
uint32_t dmax
DMAX 0 to 65535.
Definition tmc5160_types.hpp:458
uint32_t vstop
VSTOP 1 to 2^18 - 1.
Definition tmc5160_types.hpp:460
uint32_t a1
A1 0 to 65535.
Definition tmc5160_types.hpp:454
uint32_t vmax
VMAX 0 to 2^23 - 512.
Definition tmc5160_types.hpp:457
static constexpr Result Failure(Error e) noexcept
A failed result.
Definition tmc5160_types.hpp:165
constexpr bool ok() const noexcept
Definition tmc5160_types.hpp:148
static constexpr Result Success() noexcept
Definition tmc5160_types.hpp:157
The value of a call, or why there is none.
Definition tmc5160_types.hpp:111
constexpr bool ok() const noexcept
Definition tmc5160_types.hpp:116
static constexpr Result Failure(Error e) noexcept
A failed result.
Definition tmc5160_types.hpp:137
static constexpr Result Success(T v) noexcept
A successful result.
Definition tmc5160_types.hpp:129
The SPI options (used by an SPI port only).
Definition tmc5160_types.hpp:530
uint8_t chain_index
This chip: 0 is the one whose SDI is on MOSI.
Definition tmc5160_types.hpp:532
uint8_t chain_length
Chips in the daisy chain, 1 to kMaxChain.
Definition tmc5160_types.hpp:531
StallGuard2 (COOLCONF, section 13, page 87).
Definition tmc5160_types.hpp:393
bool filter
SFILT.
Definition tmc5160_types.hpp:395
int8_t threshold
SGT, -64 to 63.
Definition tmc5160_types.hpp:394
Standstill behaviour (IHOLD_IRUN.IHOLDDELAY, TPOWERDOWN, GCONF.faststandstill).
Definition tmc5160_types.hpp:338
uint8_t hold_delay
IHOLDDELAY 0 to 15, in 2^18 clocks per step of the current ramp.
Definition tmc5160_types.hpp:339
uint8_t power_down_delay
TPOWERDOWN 0 to 255, in 2^18 clocks; reset value 10.
Definition tmc5160_types.hpp:340
bool fast_standstill
true: standstill after 2^18 clocks instead of 2^20.
Definition tmc5160_types.hpp:341
StealthChop settings (PWMCONF, GCONF.en_pwm_mode, section 6.5.2 page 54).
Definition tmc5160_types.hpp:363
uint8_t reg
PWM_REG 1 to 15 (reset 4).
Definition tmc5160_types.hpp:368
bool autograd
Automatic gradient adaptation (reset 1).
Definition tmc5160_types.hpp:366
uint8_t grad
PWM_GRAD 0 to 255.
Definition tmc5160_types.hpp:371
Freewheel freewheel
Standstill mode with IHOLD = 0.
Definition tmc5160_types.hpp:372
bool autoscale
Automatic current control (reset 1).
Definition tmc5160_types.hpp:365
bool enable
GCONF.en_pwm_mode.
Definition tmc5160_types.hpp:364
uint8_t lim
PWM_LIM 0 to 15 (reset 12).
Definition tmc5160_types.hpp:369
uint8_t freq
PWM frequency 0 to 3: 2/1024, 2/683, 2/512, 2/410 of fCLK.
Definition tmc5160_types.hpp:367
uint8_t ofs
PWM_OFS 0 to 255 (reset 30).
Definition tmc5160_types.hpp:370
Reference switches and stop behaviour (SW_MODE, page 43).
Definition tmc5160_types.hpp:465
bool soft_stop
Stop with the deceleration ramp.
Definition tmc5160_types.hpp:477
bool stop_right
Stop at an active right switch.
Definition tmc5160_types.hpp:467
bool latch_left_inactive
Latch XACTUAL on the inactive edge of left.
Definition tmc5160_types.hpp:472
bool stop_left
Stop at an active left switch.
Definition tmc5160_types.hpp:466
bool stop_on_stall
Stop on stall (sg_stop).
Definition tmc5160_types.hpp:476
bool right_active_low
The right switch is active low.
Definition tmc5160_types.hpp:469
bool swap
Swap left and right.
Definition tmc5160_types.hpp:470
bool latch_left_active
Latch XACTUAL on the active edge of left.
Definition tmc5160_types.hpp:471
bool latch_right_inactive
Latch XACTUAL on the inactive edge of right.
Definition tmc5160_types.hpp:474
bool left_active_low
The left switch is active low.
Definition tmc5160_types.hpp:468
bool latch_encoder
Latch X_ENC as well.
Definition tmc5160_types.hpp:475
bool latch_right_active
Latch XACTUAL on the active edge of right.
Definition tmc5160_types.hpp:473
Velocity thresholds as TSTEP values (page 39); 0 disables.
Definition tmc5160_types.hpp:376
uint32_t pwm
TPWMTHRS: StealthChop below this velocity, 0 to 2^20 - 1.
Definition tmc5160_types.hpp:377
uint32_t cool
TCOOLTHRS: CoolStep and stall output above this velocity.
Definition tmc5160_types.hpp:378
bool small_hysteresis
GCONF.small_hysteresis: 1/32 instead of 1/16.
Definition tmc5160_types.hpp:380
uint32_t high
THIGH: the high-velocity chopper mode above this velocity.
Definition tmc5160_types.hpp:379
The UART options (used by a UART port only).
Definition tmc5160_types.hpp:522
bool multi_node
Several nodes share the line.
Definition tmc5160_types.hpp:525
uint8_t node
NODEADDR 0 to 253 (254 only inside the addressing procedure).
Definition tmc5160_types.hpp:523
uint32_t baud
Baud rate the port runs; 9000 to fCLK / 16.
Definition tmc5160_types.hpp:526
uint8_t send_delay
SENDDELAY 0 to 15, in 8-bit times; at least 2 with multi_node.
Definition tmc5160_types.hpp:524
Compile-time helpers of the TMC5160 driver: typed integer literals, exact hook matching,...
TMC5160 register map: addresses, access rules, reserved bits and reset values.