TMC5160 Driver 0.1.0
API reference
Loading...
Searching...
No Matches
tmc5160_status.hpp
Go to the documentation of this file.
1
11#ifndef TMC5160_STATUS_HPP
12#define TMC5160_STATUS_HPP
13
14#include <array>
15#include <cstdint>
16
17#include "tmc5160_registers.hpp"
18#include "tmc5160_types.hpp"
19#include "tmc5160_units.hpp"
20
21namespace tmc5160 {
22
25 bool reset{false};
26 bool drv_err{false};
27 bool uv_cp{false};
28};
29
32 uint32_t sg_result{0};
33 uint32_t cs_actual{0};
34 bool s2vs_a{false};
35 bool s2vs_b{false};
36 bool stealth{false};
37 bool full_step{false};
38 bool stall{false};
39 bool over_temp{false};
40 bool over_temp_warning{false};
41 bool s2g_a{false};
42 bool s2g_b{false};
43 bool open_load_a{false};
44 bool open_load_b{false};
45 bool standstill{false};
46 uint32_t raw{0};
47};
48
50struct RampStatus {
51 bool stop_left_active{false};
52 bool stop_right_active{false};
53 bool latch_left{false};
54 bool latch_right{false};
55 bool event_stop_left{false};
56 bool event_stop_right{false};
57 bool event_stop_stall{false};
58 bool event_pos_reached{false};
59 bool velocity_reached{false};
60 bool position_reached{false};
61 bool velocity_zero{false};
62 bool zero_wait_active{false};
63 bool second_move{false};
64 bool stall{false};
65 uint32_t raw{0};
66};
67
70 bool n_event{false};
71 bool deviation_warn{false};
72};
73
75struct InputPins {
76 bool refl_step{false};
77 bool refr_dir{false};
78 bool encb_dcen{false};
79 bool enca_dcin{false};
80 bool drv_enn{false};
81 bool encn_dco{false};
82 bool sd_mode{false};
83 bool swcomp_in{false};
84 uint32_t version{0};
85};
86
88struct Offsets {
89 int32_t phase_a{0};
90 int32_t phase_b{0};
91};
92
94struct OtpImage {
95 uint32_t clock_trim{0};
96 bool s2_level_12{false};
97 bool bbm_clks_2{false};
98 bool tbl_01{false};
99 uint32_t raw{0};
100};
101
104 uint32_t scale_sum{0};
105 int32_t scale_auto{0};
106 uint32_t ofs_auto{0};
107 uint32_t grad_auto{0};
108};
109
112 int32_t cur_a{0};
113 int32_t cur_b{0};
114};
115
123
125struct Snapshot {
129 int32_t position{0};
130 int32_t velocity{0};
131 uint32_t step_time{0};
132 uint32_t mscnt{0};
133};
134
137 uint32_t version{0};
138 bool sd_mode{false};
139 bool uv_cp_seen{false};
140 bool stall_latched{false};
141 uint32_t advisories{0};
142 uint32_t current_run_ma{0};
143 uint32_t current_hold_ma{0};
144};
145
146namespace detail {
147
149[[nodiscard]] constexpr int32_t SignExtend(uint32_t v, uint32_t bits) noexcept {
150 const uint32_t sign = uint32_t{1} << (bits - 1U);
151 const uint32_t low = v & ((sign << 1U) - 1U);
152 return static_cast<int32_t>((low ^ sign)) - static_cast<int32_t>(sign);
153}
154
156[[nodiscard]] constexpr bool Bit(uint32_t v, uint32_t b) noexcept {
157 return ((v >> b) & 1U) != 0U;
158}
159
161[[nodiscard]] constexpr uint32_t Put(bool on, uint32_t pos) noexcept {
162 return static_cast<uint32_t>(on) << pos;
163}
164
165[[nodiscard]] constexpr GlobalStatus DecodeGlobal(uint32_t raw) noexcept {
166 return GlobalStatus{.reset = Bit(raw, 0), .drv_err = Bit(raw, 1), .uv_cp = Bit(raw, 2)};
167}
168
169[[nodiscard]] constexpr DriverStatus DecodeDriver(uint32_t raw) noexcept {
170 DriverStatus d{};
171 d.sg_result = raw & 0x3FFU;
172 d.cs_actual = (raw >> 16U) & 0x1FU;
173 d.s2vs_a = Bit(raw, 12);
174 d.s2vs_b = Bit(raw, 13);
175 d.stealth = Bit(raw, 14);
176 d.full_step = Bit(raw, 15);
177 d.stall = Bit(raw, 24);
178 d.over_temp = Bit(raw, 25);
179 d.over_temp_warning = Bit(raw, 26);
180 d.s2g_a = Bit(raw, 27);
181 d.s2g_b = Bit(raw, 28);
182 d.open_load_a = Bit(raw, 29);
183 d.open_load_b = Bit(raw, 30);
184 d.standstill = Bit(raw, 31);
185 d.raw = raw;
186 return d;
187}
188
189[[nodiscard]] constexpr RampStatus DecodeRamp(uint32_t raw) noexcept {
190 RampStatus r{};
191 r.stop_left_active = Bit(raw, 0);
192 r.stop_right_active = Bit(raw, 1);
193 r.latch_left = Bit(raw, 2);
194 r.latch_right = Bit(raw, 3);
195 r.event_stop_left = Bit(raw, 4);
196 r.event_stop_right = Bit(raw, 5);
197 r.event_stop_stall = Bit(raw, 6);
198 r.event_pos_reached = Bit(raw, 7);
199 r.velocity_reached = Bit(raw, 8);
200 r.position_reached = Bit(raw, 9);
201 r.velocity_zero = Bit(raw, 10);
202 r.zero_wait_active = Bit(raw, 11);
203 r.second_move = Bit(raw, 12);
204 r.stall = Bit(raw, 13);
205 r.raw = raw;
206 return r;
207}
208
209[[nodiscard]] constexpr InputPins DecodeInputs(uint32_t raw) noexcept {
210 InputPins p{};
211 p.refl_step = Bit(raw, 0);
212 p.refr_dir = Bit(raw, 1);
213 p.encb_dcen = Bit(raw, 2);
214 p.enca_dcin = Bit(raw, 3);
215 p.drv_enn = Bit(raw, 4);
216 p.encn_dco = Bit(raw, 5);
217 p.sd_mode = Bit(raw, 6);
218 p.swcomp_in = Bit(raw, 7);
219 p.version = raw >> 24U;
220 return p;
221}
222
223[[nodiscard]] constexpr OtpImage DecodeOtp(uint32_t raw) noexcept {
224 return OtpImage{.clock_trim = raw & 0x1FU,
225 .s2_level_12 = Bit(raw, 5),
226 .bbm_clks_2 = Bit(raw, 6),
227 .tbl_01 = Bit(raw, 7),
228 .raw = raw & 0xFFU};
229}
230
231[[nodiscard]] constexpr StealthChopState DecodeStealthChop(uint32_t scale,
232 uint32_t autos) noexcept {
233 return StealthChopState{.scale_sum = scale & 0xFFU,
234 .scale_auto = SignExtend(scale >> 16U, 9),
235 .ofs_auto = autos & 0xFFU,
236 .grad_auto = (autos >> 16U) & 0xFFU};
237}
238
239[[nodiscard]] constexpr MicrostepCurrents DecodeMscuract(uint32_t raw) noexcept {
240 return MicrostepCurrents{.cur_a = SignExtend(raw >> 16U, 9), .cur_b = SignExtend(raw, 9)};
241}
242
244[[nodiscard]] constexpr uint32_t GconfWord(const Config& c, bool direct) noexcept {
245 const Diag& d = c.diag;
246 uint32_t w = Put(c.flags.recalibrate, 0) | Put(c.standstill.fast_standstill, 1) |
247 Put(c.stealth.enable, 2) | Put(c.flags.multistep_filt, 3) |
248 Put(c.flags.invert_direction, 4);
249 w |= Put(d.diag0_error, 5) | Put(d.diag0_otpw, 6) | Put(d.diag0_stall || d.diag0_step_output, 7);
250 w |= Put(d.diag1_stall || d.diag1_dir_output, 8) | Put(d.diag1_index, 9) |
251 Put(d.diag1_on_state, 10);
252 w |= Put(d.diag1_steps_skipped, 11) | Put(d.diag0_push_pull, 12) | Put(d.diag1_push_pull, 13);
253 w |= Put(c.thresholds.small_hysteresis, 14) | Put(c.flags.stop_input, 15) | Put(direct, 16);
254 return w;
255}
256
258[[nodiscard]] constexpr uint32_t ChopconfWord(const Config& c, uint32_t toff) noexcept {
259 const Chopper& k = c.chopper;
260 const bool const_off = k.mode == ChopperMode::ConstOffTime;
261 const uint32_t low = const_off ? (k.tfd & 7U) : k.hstrt;
262 const uint32_t high = const_off ? k.offset : k.hend;
263 uint32_t w = toff & 15U;
264 w |= low << 4U;
265 w |= high << 7U;
266 w |= Put(const_off && ((k.tfd & 8U) != 0U), 11) | Put(const_off && k.no_comparator, 12);
267 w |= Put(const_off, 14) | (static_cast<uint32_t>(k.tbl & 3U) << 15U);
268 w |= Put(k.high_fullstep, 18) | Put(k.high_const_off, 19) |
269 (static_cast<uint32_t>(k.tpfd & 15U) << 20U);
270 w |= (static_cast<uint32_t>(k.mres) << 24U) | Put(k.interpolate, 28) | Put(k.double_edge, 29);
271 w |= Put(c.protection.disable_s2g, 30) | Put(c.protection.disable_s2vs, 31);
272 return w;
273}
274
276[[nodiscard]] constexpr uint32_t IholdIrunWord(const units::CurrentPlan& p, const Standstill& s,
277 uint32_t ihold) noexcept {
278 return (ihold & 31U) | ((p.irun & 31U) << 8U) |
279 (static_cast<uint32_t>(s.hold_delay & 15U) << 16U);
280}
281
283[[nodiscard]] constexpr uint32_t PwmconfWord(const StealthChop& s) noexcept {
284 return static_cast<uint32_t>(s.ofs) | (static_cast<uint32_t>(s.grad) << 8U) |
285 (static_cast<uint32_t>(s.freq & 3U) << 16U) | Put(s.autoscale, 18) | Put(s.autograd, 19) |
286 (static_cast<uint32_t>(s.freewheel) << 20U) | (static_cast<uint32_t>(s.reg & 15U) << 24U) |
287 (static_cast<uint32_t>(s.lim & 15U) << 28U);
288}
289
291[[nodiscard]] constexpr uint32_t CoolconfWord(const CoolStep& k, const StallGuard& g) noexcept {
292 return static_cast<uint32_t>(k.semin & 15U) | (static_cast<uint32_t>(k.seup & 3U) << 5U) |
293 (static_cast<uint32_t>(k.semax & 15U) << 8U) |
294 (static_cast<uint32_t>(k.sedn & 3U) << 13U) | Put(k.min_quarter, 15) |
295 ((static_cast<uint32_t>(static_cast<int32_t>(g.threshold)) & 0x7FU) << 16U) |
296 Put(g.filter, 24);
297}
298
300[[nodiscard]] constexpr uint32_t DcctrlWord(const DcStep& d) noexcept {
301 return static_cast<uint32_t>(d.dc_time & 0x3FFU) | (static_cast<uint32_t>(d.dc_sg) << 16U);
302}
303
305[[nodiscard]] constexpr uint32_t ShortconfWord(const Protection& p) noexcept {
306 return static_cast<uint32_t>(p.s2vs_level & 15U) |
307 (static_cast<uint32_t>(p.s2g_level & 15U) << 8U) |
308 (static_cast<uint32_t>(p.filter & 3U) << 16U) | Put(p.long_delay, 18);
309}
310
312[[nodiscard]] constexpr uint32_t DrvconfWord(const Bridge& b) noexcept {
313 return static_cast<uint32_t>(b.bbm_time & 31U) | (static_cast<uint32_t>(b.bbm_clks & 15U) << 8U) |
314 (static_cast<uint32_t>(b.ot_level) << 16U) |
315 (static_cast<uint32_t>(b.drive_strength & 3U) << 18U) |
316 (static_cast<uint32_t>(b.sense_filter & 3U) << 20U);
317}
318
320[[nodiscard]] constexpr uint32_t SwmodeWord(const Switches& s) noexcept {
321 return Put(s.stop_left, 0) | Put(s.stop_right, 1) | Put(s.left_active_low, 2) |
322 Put(s.right_active_low, 3) | Put(s.swap, 4) | Put(s.latch_left_active, 5) |
323 Put(s.latch_left_inactive, 6) | Put(s.latch_right_active, 7) |
324 Put(s.latch_right_inactive, 8) | Put(s.latch_encoder, 9) | Put(s.stop_on_stall, 10) |
325 Put(s.soft_stop, 11);
326}
327
329[[nodiscard]] constexpr uint32_t EncmodeWord(const Encoder& e) noexcept {
330 const NEvent& n = e.n_event;
331 return Put(n.pol_a, 0) | Put(n.pol_b, 1) | Put(n.pol_n, 2) | Put(n.ignore_ab, 3) |
332 Put(n.repeat, 4) | Put(n.once, 5) | Put(n.pos_edge, 6) | Put(n.neg_edge, 7) |
333 Put(n.clear_counter, 8) | Put(n.latch_xactual, 9) | Put(e.scale.decimal, 10);
334}
335
337[[nodiscard]] constexpr uint32_t MslutselWord(const MicrostepTable& t) noexcept {
338 return static_cast<uint32_t>(t.w[0] & 3U) | (static_cast<uint32_t>(t.w[1] & 3U) << 2U) |
339 (static_cast<uint32_t>(t.w[2] & 3U) << 4U) | (static_cast<uint32_t>(t.w[3] & 3U) << 6U) |
340 (static_cast<uint32_t>(t.x1) << 8U) | (static_cast<uint32_t>(t.x2) << 16U) |
341 (static_cast<uint32_t>(t.x3) << 24U);
342}
343
345[[nodiscard]] constexpr uint32_t MslutstartWord(const MicrostepTable& t) noexcept {
346 return static_cast<uint32_t>(t.start_sin) | (static_cast<uint32_t>(t.start_sin90) << 16U);
347}
348
350[[nodiscard]] constexpr uint32_t NodeconfWord(uint32_t node, uint32_t send_delay) noexcept {
351 return (node & 0xFFU) | ((send_delay & 15U) << 8U);
352}
353
355struct WordContext {
356 const Config& config;
357 const units::CurrentPlan& plan;
358 bool direct;
359 bool enabled;
360 bool hold_at_run;
361};
362
364using WordFn = uint32_t (*)(const WordContext&) noexcept;
365
367struct WordEntry {
368 uint8_t address;
369 WordFn encode;
370};
371
374inline constexpr std::array<WordEntry, 38> kWordTable{{
375 {.address = reg::kGconf,
376 .encode = [](const WordContext& x) noexcept { return GconfWord(x.config, x.direct); }},
377 {.address = reg::kShortConf,
378 .encode = [](const WordContext& x) noexcept { return ShortconfWord(x.config.protection); }},
379 {.address = reg::kDrvConf,
380 .encode = [](const WordContext& x) noexcept { return DrvconfWord(x.config.bridge); }},
381 {.address = reg::kGlobalScaler,
382 .encode = [](const WordContext& x) noexcept { return x.plan.global_scaler_reg; }},
383 {.address = reg::kIholdIrun,
384 .encode =
385 [](const WordContext& x) noexcept {
386 return IholdIrunWord(x.plan, x.config.standstill,
387 x.hold_at_run ? x.plan.irun : x.plan.ihold);
388 }},
389 {.address = reg::kTpowerdown,
390 .encode =
391 [](const WordContext& x) noexcept {
392 return uint32_t{x.config.standstill.power_down_delay};
393 }},
394 {.address = reg::kTpwmthrs,
395 .encode = [](const WordContext& x) noexcept { return x.config.thresholds.pwm; }},
396 {.address = reg::kTcoolthrs,
397 .encode = [](const WordContext& x) noexcept { return x.config.thresholds.cool; }},
398 {.address = reg::kThigh,
399 .encode = [](const WordContext& x) noexcept { return x.config.thresholds.high; }},
400 {.address = reg::kVstart,
401 .encode = [](const WordContext& x) noexcept { return x.config.ramp.vstart; }},
402 {.address = reg::kA1, .encode = [](const WordContext& x) noexcept { return x.config.ramp.a1; }},
403 {.address = reg::kV1, .encode = [](const WordContext& x) noexcept { return x.config.ramp.v1; }},
404 {.address = reg::kAmax,
405 .encode = [](const WordContext& x) noexcept { return x.config.ramp.amax; }},
406 {.address = reg::kVmax,
407 .encode = [](const WordContext& x) noexcept { return x.config.ramp.vmax; }},
408 {.address = reg::kDmax,
409 .encode = [](const WordContext& x) noexcept { return x.config.ramp.dmax; }},
410 {.address = reg::kD1, .encode = [](const WordContext& x) noexcept { return x.config.ramp.d1; }},
411 {.address = reg::kVstop,
412 .encode = [](const WordContext& x) noexcept { return x.config.ramp.vstop; }},
413 {.address = reg::kTzerowait,
414 .encode = [](const WordContext& x) noexcept { return x.config.ramp.zero_wait; }},
415 {.address = reg::kVdcmin,
416 .encode = [](const WordContext& x) noexcept { return x.config.dcstep.vdcmin; }},
417 {.address = reg::kSwMode,
418 .encode = [](const WordContext& x) noexcept { return SwmodeWord(x.config.switches); }},
419 {.address = reg::kEncmode,
420 .encode = [](const WordContext& x) noexcept { return EncmodeWord(x.config.encoder); }},
421 {.address = reg::kEncConst,
422 .encode =
423 [](const WordContext& x) noexcept { return units::EncConstWord(x.config.encoder.scale); }},
424 {.address = reg::kEncDeviation,
425 .encode = [](const WordContext& x) noexcept { return x.config.encoder.deviation; }},
426 {.address = 0x60U,
427 .encode = [](const WordContext& x) noexcept { return x.config.table.words[0]; }},
428 {.address = 0x61U,
429 .encode = [](const WordContext& x) noexcept { return x.config.table.words[1]; }},
430 {.address = 0x62U,
431 .encode = [](const WordContext& x) noexcept { return x.config.table.words[2]; }},
432 {.address = 0x63U,
433 .encode = [](const WordContext& x) noexcept { return x.config.table.words[3]; }},
434 {.address = 0x64U,
435 .encode = [](const WordContext& x) noexcept { return x.config.table.words[4]; }},
436 {.address = 0x65U,
437 .encode = [](const WordContext& x) noexcept { return x.config.table.words[5]; }},
438 {.address = 0x66U,
439 .encode = [](const WordContext& x) noexcept { return x.config.table.words[6]; }},
440 {.address = 0x67U,
441 .encode = [](const WordContext& x) noexcept { return x.config.table.words[7]; }},
442 {.address = reg::kMslutsel,
443 .encode = [](const WordContext& x) noexcept { return MslutselWord(x.config.table); }},
444 {.address = reg::kMslutstart,
445 .encode = [](const WordContext& x) noexcept { return MslutstartWord(x.config.table); }},
446 {.address = reg::kChopconf,
447 .encode =
448 [](const WordContext& x) noexcept {
449 return ChopconfWord(x.config, x.enabled ? x.config.chopper.toff : 0U);
450 }},
451 {.address = reg::kCoolconf,
452 .encode =
453 [](const WordContext& x) noexcept { return CoolconfWord(x.config.cool, x.config.stall); }},
454 {.address = reg::kDcctrl,
455 .encode = [](const WordContext& x) noexcept { return DcctrlWord(x.config.dcstep); }},
456 {.address = reg::kPwmconf,
457 .encode = [](const WordContext& x) noexcept { return PwmconfWord(x.config.stealth); }},
458 {.address = reg::kNodeconf,
459 .encode =
460 [](const WordContext& x) noexcept {
461 return NodeconfWord(x.config.uart.node, x.config.uart.send_delay);
462 }},
463}};
464
471[[nodiscard]] constexpr uint32_t WordFor(const WordContext& x, uint8_t address) noexcept {
472 for (const WordEntry& e : kWordTable) {
473 if (e.address == address) {
474 return e.encode(x);
475 }
476 }
477 return 0U;
478}
479
480// The encoders reproduce the reset values and the datasheet's examples (pages 32, 48, 116).
481static_assert(PwmconfWord(StealthChop{}) == reg::kPwmconfReset);
482static_assert(ChopconfWord(Config{}, 0U) == reg::kChopconfReset);
483static_assert(MslutselWord(MicrostepTable{}) == reg::kDefaultMslutsel);
484static_assert(MslutstartWord(MicrostepTable{}) == reg::kDefaultMslutstart);
485static_assert((SignExtend(0x1FFU, 9) == -1) && (SignExtend(0x0FFU, 9) == 255));
486static_assert((DecodeMscuract(0x01FF0001U).cur_a == -1) &&
487 (DecodeMscuract(0x01FF0001U).cur_b == 1));
488
489} // namespace detail
490
491} // namespace tmc5160
492
493#endif // TMC5160_STATUS_HPP
constexpr uint8_t kThigh
THIGH (W, 20 bits), page 39.
Definition tmc5160_registers.hpp:51
constexpr uint8_t kPwmconf
PWMCONF (W, 32 bits), page 48.
Definition tmc5160_registers.hpp:84
constexpr uint8_t kCoolconf
COOLCONF (W, 25 bits), page 48.
Definition tmc5160_registers.hpp:81
constexpr uint8_t kDmax
DMAX (W, 16 bits), page 40.
Definition tmc5160_registers.hpp:60
constexpr uint8_t kSwMode
SW_MODE (RW, 12 bits), page 42.
Definition tmc5160_registers.hpp:66
constexpr uint32_t kPwmconfReset
Reset value of PWMCONF (page 48).
Definition tmc5160_registers.hpp:123
constexpr uint32_t kDefaultMslutstart
Reset value of MSLUTSTART: START_SIN 0, START_SIN90 247 (page 47).
Definition tmc5160_registers.hpp:119
constexpr uint8_t kVstart
VSTART (W, 18 bits), page 40.
Definition tmc5160_registers.hpp:55
constexpr uint8_t kGconf
GCONF (RW, 18 bits), page 32.
Definition tmc5160_registers.hpp:32
constexpr uint8_t kV1
V1 (W, 20 bits), page 40.
Definition tmc5160_registers.hpp:57
constexpr uint8_t kTzerowait
TZEROWAIT (W, 16 bits), page 41.
Definition tmc5160_registers.hpp:63
constexpr uint32_t kDefaultMslutsel
Reset value of MSLUTSEL (page 47).
Definition tmc5160_registers.hpp:117
constexpr uint8_t kShortConf
SHORT_CONF (W, 19 bits), page 35.
Definition tmc5160_registers.hpp:42
constexpr uint8_t kNodeconf
NODECONF (W, 12 bits): UART node, page 34.
Definition tmc5160_registers.hpp:35
constexpr uint8_t kGlobalScaler
GLOBALSCALER (W, 8 bits), page 36.
Definition tmc5160_registers.hpp:44
constexpr uint8_t kMslutsel
MSLUTSEL (W, 32 bits), page 47.
Definition tmc5160_registers.hpp:76
constexpr uint8_t kTcoolthrs
TCOOLTHRS (W, 20 bits), page 39.
Definition tmc5160_registers.hpp:50
constexpr uint8_t kVdcmin
VDCMIN (W, 23 bits), page 42.
Definition tmc5160_registers.hpp:65
constexpr uint8_t kA1
A1 (W, 16 bits), page 40.
Definition tmc5160_registers.hpp:56
constexpr uint8_t kMslutstart
MSLUTSTART (W, 24 bits), page 47.
Definition tmc5160_registers.hpp:77
constexpr uint8_t kAmax
AMAX (W, 16 bits), page 40.
Definition tmc5160_registers.hpp:58
constexpr uint8_t kTpowerdown
TPOWERDOWN (W, 8 bits), page 38.
Definition tmc5160_registers.hpp:47
constexpr uint8_t kEncmode
ENCMODE (RW, 11 bits), page 45.
Definition tmc5160_registers.hpp:69
constexpr uint8_t kTpwmthrs
TPWMTHRS (W, 20 bits), page 39.
Definition tmc5160_registers.hpp:49
constexpr uint8_t kD1
D1 (W, 16 bits), page 40.
Definition tmc5160_registers.hpp:61
constexpr uint8_t kIholdIrun
IHOLD_IRUN (W, 20 bits), page 38.
Definition tmc5160_registers.hpp:46
constexpr uint8_t kDrvConf
DRV_CONF (W, 22 bits), page 35.
Definition tmc5160_registers.hpp:43
constexpr uint32_t kChopconfReset
Reset value of CHOPCONF (page 48).
Definition tmc5160_registers.hpp:121
constexpr uint8_t kEncConst
ENC_CONST (W, 32 bits), page 45.
Definition tmc5160_registers.hpp:71
constexpr uint8_t kVmax
VMAX (W, 23 bits), page 40.
Definition tmc5160_registers.hpp:59
constexpr uint8_t kChopconf
CHOPCONF (RW, 32 bits), page 48.
Definition tmc5160_registers.hpp:80
constexpr uint8_t kVstop
VSTOP (W, 18 bits), page 41.
Definition tmc5160_registers.hpp:62
constexpr uint8_t kDcctrl
DCCTRL (W, 24 bits), page 48.
Definition tmc5160_registers.hpp:82
constexpr uint8_t kEncDeviation
ENC_DEVIATION (W, 20 bits), page 45.
Definition tmc5160_registers.hpp:74
@ ConstOffTime
Classic constant off time.
The TMC5160 driver: everything it declares lives here; internals in detail.
Definition tmc5160.hpp:34
What start-up learned about the chip.
Definition tmc5160_status.hpp:136
uint32_t advisories
Advise() of the configuration.
Definition tmc5160_status.hpp:141
uint32_t current_hold_ma
The nominal hold current the registers give.
Definition tmc5160_status.hpp:143
bool sd_mode
IOIN.SD_MODE: the strap level.
Definition tmc5160_status.hpp:138
uint32_t current_run_ma
The nominal run current the registers give.
Definition tmc5160_status.hpp:142
bool stall_latched
RAMP_STAT held a stall stop from the last session (not cleared).
Definition tmc5160_status.hpp:140
uint32_t version
IOIN.VERSION.
Definition tmc5160_status.hpp:137
bool uv_cp_seen
GSTAT showed a charge pump undervoltage at start-up.
Definition tmc5160_status.hpp:139
DRV_STATUS, decoded (page 56).
Definition tmc5160_status.hpp:31
uint32_t cs_actual
Actual current scale, 0 to 31.
Definition tmc5160_status.hpp:33
bool over_temp
Overtemperature shutdown.
Definition tmc5160_status.hpp:39
bool standstill
The motor is at standstill.
Definition tmc5160_status.hpp:45
bool open_load_b
Open load, phase B (informative).
Definition tmc5160_status.hpp:44
bool s2vs_a
Short to supply, phase A.
Definition tmc5160_status.hpp:34
bool s2g_b
Short to ground, phase B.
Definition tmc5160_status.hpp:42
uint32_t sg_result
StallGuard2 result, 0 to 1023.
Definition tmc5160_status.hpp:32
bool s2vs_b
Short to supply, phase B.
Definition tmc5160_status.hpp:35
bool full_step
Full-step mode is active.
Definition tmc5160_status.hpp:37
bool open_load_a
Open load, phase A (informative).
Definition tmc5160_status.hpp:43
bool stealth
StealthChop is active.
Definition tmc5160_status.hpp:36
bool stall
StallGuard2 reports a stall.
Definition tmc5160_status.hpp:38
bool over_temp_warning
Overtemperature pre-warning.
Definition tmc5160_status.hpp:40
bool s2g_a
Short to ground, phase A.
Definition tmc5160_status.hpp:41
uint32_t raw
The register as read.
Definition tmc5160_status.hpp:46
ENC_STATUS, decoded (page 45).
Definition tmc5160_status.hpp:69
bool deviation_warn
The encoder deviates from XACTUAL.
Definition tmc5160_status.hpp:71
bool n_event
An N event was detected.
Definition tmc5160_status.hpp:70
What Service() found and cleared.
Definition tmc5160_status.hpp:117
GlobalStatus global
GSTAT at the time of the call.
Definition tmc5160_status.hpp:118
DriverStatus driver
DRV_STATUS at the time of the call.
Definition tmc5160_status.hpp:121
EncoderStatus encoder
ENC_STATUS at the time of the call (zero in StepDir mode).
Definition tmc5160_status.hpp:120
RampStatus ramp
RAMP_STAT at the time of the call.
Definition tmc5160_status.hpp:119
GSTAT, decoded (page 33).
Definition tmc5160_status.hpp:24
bool reset
The chip was reset since GSTAT was last cleared.
Definition tmc5160_status.hpp:25
bool drv_err
The driver shut down on overtemperature or a short.
Definition tmc5160_status.hpp:26
bool uv_cp
Charge pump undervoltage was seen.
Definition tmc5160_status.hpp:27
IOIN, decoded (page 34).
Definition tmc5160_status.hpp:75
bool encn_dco
Level of ENCN_DCO_CFG6.
Definition tmc5160_status.hpp:81
bool enca_dcin
Level of ENCA_DCIN_CFG5.
Definition tmc5160_status.hpp:79
bool refr_dir
Level of REFR_DIR.
Definition tmc5160_status.hpp:77
bool sd_mode
Level of the SD_MODE strap.
Definition tmc5160_status.hpp:82
bool drv_enn
Level of DRV_ENN.
Definition tmc5160_status.hpp:80
bool swcomp_in
Level of the single-wire comparator input.
Definition tmc5160_status.hpp:83
bool refl_step
Level of REFL_STEP.
Definition tmc5160_status.hpp:76
bool encb_dcen
Level of ENCB_DCEN_CFG4.
Definition tmc5160_status.hpp:78
uint32_t version
VERSION, bits 31 to 24.
Definition tmc5160_status.hpp:84
MSCURACT, decoded (page 47): the unscaled microstep currents, -255 to 255.
Definition tmc5160_status.hpp:111
int32_t cur_a
Phase A (bits 24 to 16).
Definition tmc5160_status.hpp:112
int32_t cur_b
Phase B (bits 8 to 0).
Definition tmc5160_status.hpp:113
OFFSET_READ, decoded (page 36).
Definition tmc5160_status.hpp:88
int32_t phase_b
Offset calibration of phase B, signed.
Definition tmc5160_status.hpp:90
int32_t phase_a
Offset calibration of phase A, signed.
Definition tmc5160_status.hpp:89
OTP_READ, decoded (page 35, 37).
Definition tmc5160_status.hpp:94
bool tbl_01
TBL defaults to %01 instead of %10.
Definition tmc5160_status.hpp:98
bool s2_level_12
Short levels default to 12 instead of 6.
Definition tmc5160_status.hpp:96
uint32_t clock_trim
FCLKTRIM, 5 bits.
Definition tmc5160_status.hpp:95
uint32_t raw
The register as read.
Definition tmc5160_status.hpp:99
bool bbm_clks_2
BBMCLKS defaults to 2 instead of 4.
Definition tmc5160_status.hpp:97
RAMP_STAT, decoded (page 44).
Definition tmc5160_status.hpp:50
bool event_pos_reached
The target position was reached.
Definition tmc5160_status.hpp:58
bool latch_right
A right latch is ready.
Definition tmc5160_status.hpp:54
bool event_stop_stall
A stall stop event.
Definition tmc5160_status.hpp:57
bool stop_left_active
The left switch is active.
Definition tmc5160_status.hpp:51
bool position_reached
XACTUAL equals XTARGET.
Definition tmc5160_status.hpp:60
bool latch_left
A left latch is ready.
Definition tmc5160_status.hpp:53
bool velocity_zero
VACTUAL is zero.
Definition tmc5160_status.hpp:61
bool zero_wait_active
TZEROWAIT is running.
Definition tmc5160_status.hpp:62
bool event_stop_left
A left stop event.
Definition tmc5160_status.hpp:55
bool velocity_reached
VACTUAL equals VMAX.
Definition tmc5160_status.hpp:59
uint32_t raw
The register as read.
Definition tmc5160_status.hpp:65
bool event_stop_right
A right stop event.
Definition tmc5160_status.hpp:56
bool second_move
The ramp reversed direction.
Definition tmc5160_status.hpp:63
bool stop_right_active
The right switch is active.
Definition tmc5160_status.hpp:52
bool stall
The stall input is active.
Definition tmc5160_status.hpp:64
One pipelined batch of the values a monitor wants together.
Definition tmc5160_status.hpp:125
int32_t velocity
VACTUAL, signed.
Definition tmc5160_status.hpp:130
GlobalStatus global
GSTAT.
Definition tmc5160_status.hpp:126
RampStatus ramp
RAMP_STAT.
Definition tmc5160_status.hpp:128
uint32_t step_time
TSTEP.
Definition tmc5160_status.hpp:131
DriverStatus driver
DRV_STATUS.
Definition tmc5160_status.hpp:127
int32_t position
XACTUAL.
Definition tmc5160_status.hpp:129
uint32_t mscnt
MSCNT.
Definition tmc5160_status.hpp:132
PWM_SCALE and PWM_AUTO, decoded (page 48).
Definition tmc5160_status.hpp:103
uint32_t ofs_auto
PWM_OFS_AUTO.
Definition tmc5160_status.hpp:106
int32_t scale_auto
PWM_SCALE_AUTO, signed 9 bits; near 0 after a successful tuning.
Definition tmc5160_status.hpp:105
uint32_t scale_sum
PWM_SCALE_SUM, the actual duty, 0 to 255.
Definition tmc5160_status.hpp:104
uint32_t grad_auto
PWM_GRAD_AUTO.
Definition tmc5160_status.hpp:107
TMC5160 register map: addresses, access rules, reserved bits and reset values.
Public types of the TMC5160 driver: errors, Result<T>, configuration, validation and advice.
Pure integer conversions between datasheet register units and physical units, and the current plan th...