AS5047U Driver 0.1.0
API reference
Loading...
Searching...
No Matches
as5047u.hpp
Go to the documentation of this file.
1
12#ifndef AS5047U_HPP
13#define AS5047U_HPP
14
15#include <cstddef>
16#include <cstdint>
17
18#include "as5047u_detail.hpp"
19#include "as5047u_registers.hpp"
21#include "as5047u_types.hpp"
22#include "as5047u_version.h"
23
24namespace as5047u {
25
26namespace detail {
27
28// Port hooks: a `Declares*` concept only tests the name, the `Has*` concept the exact signature,
29// `noexcept` and the result type; the driver rejects a hook that is declared but does not match
30// (KB-CPP20-007).
31
33template <typename Port>
34concept DeclaresDelayUs = requires(Port& port) { port.DelayUs(1U); };
35
38template <typename Port>
39concept HasDelayUs = requires { ExactHook<Port, void(uint32_t) noexcept>::Take(&Port::DelayUs); };
40
42template <typename Port>
43concept DeclaresLog = requires(Port& port) { port.Log(LogLevel::Info, ""); };
44
46template <typename Port>
47concept HasLog =
48 requires { ExactHook<Port, void(LogLevel, const char*) noexcept>::Take(&Port::Log); };
49
53template <typename Port>
54void DelayUs(Port& port, uint32_t us) noexcept {
55 if constexpr (HasDelayUs<Port>) {
56 port.DelayUs(us);
57 } else {
58 static_assert(kAlwaysFalse<Port>,
59 "as5047u: the port must implement `void DelayUs(uint32_t us) noexcept`");
60 }
61}
62
64template <typename Port>
65void Log(Port& port, [[maybe_unused]] LogLevel level,
66 [[maybe_unused]] const char* message) noexcept {
67 if constexpr (HasLog<Port>) {
68 port.Log(level, message);
69 } else {
70 (void)port;
71 }
72}
73
75constexpr int16_t SignExtend14(uint16_t raw) noexcept {
76 const auto v = static_cast<int32_t>(static_cast<uint32_t>(raw) & reg::kDataMask);
77 return static_cast<int16_t>(((static_cast<uint32_t>(v) & 0x2000U) != 0U) ? (v - 0x4000) : v);
78}
79static_assert((SignExtend14(0x1FFF_u16) == 8191) && (SignExtend14(0x2000_u16) == -8192) &&
80 (SignExtend14(0x3FFF_u16) == -1));
81
83constexpr ErrorFlags DecodeErrorFlags(uint16_t raw) noexcept {
84 const auto v = static_cast<uint32_t>(raw);
85 ErrorFlags f{};
86 f.agc_warning = (v & reg::kErrflAgcWarning) != 0U;
87 f.mag_half = (v & reg::kErrflMagHalf) != 0U;
88 f.p2ram_warning = (v & reg::kErrflP2ramWarning) != 0U;
89 f.p2ram_error = (v & reg::kErrflP2ramError) != 0U;
90 f.framing = (v & reg::kErrflFraming) != 0U;
91 f.command = (v & reg::kErrflCommand) != 0U;
92 f.crc = (v & reg::kErrflCrc) != 0U;
93 f.watchdog = (v & reg::kErrflWatchdog) != 0U;
94 f.offset_comp = (v & reg::kErrflOffComp) != 0U;
95 f.cordic_overflow = (v & reg::kErrflCordic) != 0U;
96 f.raw = raw;
97 return f;
98}
99
101constexpr Diagnostics DecodeDiagnostics(uint16_t raw) noexcept {
102 const auto v = static_cast<uint32_t>(raw);
103 Diagnostics d{};
104 d.vdd_5v = (v & reg::kDiaVdd5V) != 0U;
105 d.loops_finished = (v & reg::kDiaLoopsFinished) != 0U;
106 d.cordic_overflow = (v & reg::kDiaCordicOverflow) != 0U;
107 d.agc_low = (v & reg::kDiaCompLow) != 0U;
108 d.agc_high = (v & reg::kDiaCompHigh) != 0U;
109 d.mag_half = (v & reg::kDiaMagHalf) != 0U;
110 d.offset_comp_done = (v & reg::kDiaOffsetCompDone) != 0U;
111 d.agc_done = (v & reg::kDiaAgcDone) != 0U;
112 d.spi_frame_count = static_cast<uint8_t>((v & reg::kDiaSpiCountMask) >> reg::kDiaSpiCountShift);
113 d.raw = raw;
114 return d;
115}
116
118[[nodiscard]] constexpr Error ClassifyErrorFlags(uint16_t errfl) noexcept {
119 const auto v = static_cast<uint32_t>(errfl);
120 if ((v & reg::kErrflCrc) != 0U) {
121 return Error::Crc;
122 }
123 if ((v & reg::kErrflFraming) != 0U) {
124 return Error::Framing;
125 }
126 if ((v & reg::kErrflCommand) != 0U) {
127 return Error::Command;
128 }
129 if ((v & reg::kErrflDeviceFault) != 0U) {
130 return Error::DeviceFault;
131 }
132 return Error::Ok;
133}
134
136constexpr bool IsVerify(Verify v) noexcept {
137 return IsEnumerator(v);
138}
139
140// Settings encoder and decoder: free constexpr functions, emitted once whatever the port type, and
141// proved below with static_assert (KB-CPP20-009, -012). Each register is built in uint32_t and
142// narrowed once (KB-CPP20-021, -022).
143
146constexpr uint32_t BitIf(bool on, uint16_t bit) noexcept {
147 return on ? static_cast<uint32_t>(bit) : 0U;
148}
149
152constexpr NonVolatileRegisters EncodeSettings(const Config& c,
153 const NonVolatileRegisters& now) noexcept {
154 using reg::At;
155 using reg::NvIndex;
156 NonVolatileRegisters r = now;
157 const auto zero = static_cast<uint32_t>(c.zero_position);
158 r[At(NvIndex::Disable)] = static_cast<uint16_t>(
161 r[At(NvIndex::Zposm)] = static_cast<uint16_t>((zero >> reg::kZeroHighShift) & reg::kZposmMask);
162 r[At(NvIndex::Zposl)] =
163 static_cast<uint16_t>((static_cast<uint32_t>(now[At(NvIndex::Zposl)]) & reg::kZposlDiaBits) |
164 (zero & reg::kZposlMask));
165 r[At(NvIndex::Settings1)] = static_cast<uint16_t>(
166 (static_cast<uint32_t>(now[At(NvIndex::Settings1)]) & reg::kS1DiaBits) |
167 ((static_cast<uint32_t>(c.filter_k_min_code) << reg::kS1KminShift) & reg::kS1KminMask) |
168 (static_cast<uint32_t>(c.filter_k_max_code) & reg::kS1KmaxMask));
169 r[At(NvIndex::Settings2)] = static_cast<uint16_t>(
175 BitIf(c.pwm_enable, reg::kS2PwmOn) |
177 r[At(NvIndex::Settings3)] = static_cast<uint16_t>(
178 ((static_cast<uint32_t>(c.uvw_pole_pairs) - 1U) & reg::kS3UvwppMask) |
179 ((static_cast<uint32_t>(c.hysteresis_code) << reg::kS3HysShift) & reg::kS3HysMask) |
180 ((static_cast<uint32_t>(c.abi_resolution_code) << reg::kS3AbiresShift) & reg::kS3AbiresMask));
181 return r;
182}
183
186constexpr Config DecodeSettings(const NonVolatileRegisters& r, const Config& base) noexcept {
187 using reg::At;
188 using reg::NvIndex;
189 Config c = base;
190 const auto disable = static_cast<uint32_t>(r[At(NvIndex::Disable)]);
191 c.uvw_enable = (disable & reg::kDisableUvwOff) == 0U;
192 c.abi_enable = (disable & reg::kDisableAbiOff) == 0U;
193 c.adaptive_filter = (disable & reg::kDisableFilterOff) == 0U;
194 c.zero_position = static_cast<uint16_t>(
195 ((static_cast<uint32_t>(r[At(NvIndex::Zposm)]) & reg::kZposmMask) << reg::kZeroHighShift) |
196 (static_cast<uint32_t>(r[At(NvIndex::Zposl)]) & reg::kZposlMask));
197 const auto s1 = static_cast<uint32_t>(r[At(NvIndex::Settings1)]);
198 c.filter_k_min_code = static_cast<uint8_t>((s1 & reg::kS1KminMask) >> reg::kS1KminShift);
199 c.filter_k_max_code = static_cast<uint8_t>(s1 & reg::kS1KmaxMask);
200 const auto s2 = static_cast<uint32_t>(r[At(NvIndex::Settings2)]);
205 c.dynamic_compensation = (s2 & reg::kS2DaecDis) == 0U;
206 c.abi_decimal = (s2 & reg::kS2AbiDecimal) != 0U;
208 c.pwm_enable = (s2 & reg::kS2PwmOn) != 0U;
209 const auto s3 = static_cast<uint32_t>(r[At(NvIndex::Settings3)]);
210 const uint32_t pole_pairs = (s3 & reg::kS3UvwppMask) + 1U;
211 // UVWPP code 7 also means 7 pole pairs (Figure 48).
213 static_cast<uint8_t>((pole_pairs > kMaxUvwPolePairs) ? kMaxUvwPolePairs : pole_pairs);
214 c.hysteresis_code = static_cast<uint8_t>((s3 & reg::kS3HysMask) >> reg::kS3HysShift);
215 c.abi_resolution_code = static_cast<uint8_t>((s3 & reg::kS3AbiresMask) >> reg::kS3AbiresShift);
216 return c;
217}
218
220constexpr Config RoundTripSample() noexcept {
221 Config c{};
223 c.zero_position = 0x1234U;
224 c.dynamic_compensation = false;
225 c.adaptive_filter = false;
226 c.filter_k_min_code = 5U;
227 c.filter_k_max_code = 2U;
229 c.abi_enable = false;
230 c.uvw_enable = false;
231 c.pwm_enable = true;
232 c.abi_resolution_code = 4U;
233 c.abi_decimal = true;
235 c.uvw_pole_pairs = 7U;
236 c.hysteresis_code = 3U;
237 c.high_temperature_noise = true;
239 return c;
240}
241
242// The reset configuration encodes to the reset values of an unprogrammed part (all 0), and every
243// field decodes back to what was encoded, also with the DIA enable bits set.
244static_assert(EncodeSettings(Config{}, NonVolatileRegisters{}) == NonVolatileRegisters{});
245static_assert(DecodeSettings(EncodeSettings(Config{}, {}), Config{}) == Config{});
246static_assert(DecodeSettings(EncodeSettings(RoundTripSample(), {}), Config{}) == RoundTripSample());
247static_assert(DecodeSettings(EncodeSettings(RoundTripSample(),
248 NonVolatileRegisters{0, 0, 0xC0U, 0xC0U, 0, 0, 0}),
249 Config{}) == RoundTripSample());
250
251} // namespace detail
252
259// clang-format off: the hook table below must keep one row per line.
299// clang-format on
300template <SpiPort Port>
301class AS5047U {
302 static_assert(!detail::DeclaresDelayUs<Port> || detail::HasDelayUs<Port>,
303 "as5047u: the DelayUs hook must be `void DelayUs(uint32_t us) noexcept`, so that "
304 "no wait is truncated");
305 static_assert(!detail::DeclaresLog<Port> || detail::HasLog<Port>,
306 "as5047u: the optional Log hook must be `void Log(LogLevel, const char* message) "
307 "noexcept`");
308
309public:
315 explicit AS5047U(Port& port, const Config& config = {}) noexcept : bus_(port), config_(config) {}
316
318 AS5047U(const AS5047U&) = delete;
320 AS5047U& operator=(const AS5047U&) = delete;
321
324
349
351 [[nodiscard]] bool IsInitialized() const noexcept {
352 return initialized_;
353 }
354
361
365
385 Result<void> ApplyConfig(const Config& config, Verify verify = Verify::None) noexcept;
386
391 [[nodiscard]] const Config& GetConfig() const& noexcept {
392 return config_;
393 }
395 void GetConfig() const&& = delete;
396
403 Result<void> SetZeroPosition(uint16_t counts, Verify verify = Verify::None) noexcept;
404
416 Result<uint16_t> SetZeroHere(Verify verify = Verify::None) noexcept;
417
424 Result<void> SetDirection(Direction direction, Verify verify = Verify::None) noexcept;
425
429
442 Result<uint16_t> ReadAngleCounts() noexcept;
447 Result<float> ReadAngleDegrees() noexcept;
449 Result<float> ReadAngleRadians() noexcept;
452 Result<int16_t> ReadVelocityCounts() noexcept;
454 Result<float> ReadVelocityDegPerSec() noexcept;
456 Result<float> ReadVelocityRpm() noexcept;
458 Result<uint8_t> ReadAgc() noexcept;
460 Result<uint16_t> ReadMagnitude() noexcept;
461
465
468
487 Result<void> CheckForReset() noexcept;
488
498
500 [[nodiscard]] ErrorFlags GetLastErrorFlags() const noexcept {
501 return detail::DecodeErrorFlags(last_errfl_);
502 }
503
524 [[nodiscard]] ErrorFlags GetLatchedErrorFlags() const noexcept {
525 ErrorFlags f = detail::DecodeErrorFlags(latched_errfl_);
526 f.flags_lost = flags_lost_;
527 return f;
528 }
529
531 void ClearLatchedErrorFlags() noexcept {
532 latched_errfl_ = 0U;
533 flags_lost_ = false;
534 }
535
540 [[nodiscard]] uint16_t GetLastReply() const noexcept {
541 return bus_.LastReply();
542 }
543
558 Result<uint16_t> ReadRegister(uint16_t address) noexcept;
559
572 Result<void> WriteRegister(uint16_t address, uint16_t value,
573 Verify verify = Verify::None) noexcept;
574
577
581
597 Result<void> ProgramOtp(OtpBurnConfirm confirm, OtpReport& report) noexcept;
598
600
601private:
602 Result<void> initialize() noexcept;
603 Result<void> applyConfig(const Config& config, bool verify) noexcept;
604 Result<void> waitReady() noexcept;
605 Error classifyDia() noexcept;
606 Result<void> writeSettings(const Config& config, bool verify) noexcept;
607 Result<uint16_t> readRaw(uint16_t address) noexcept;
608 Result<uint16_t> readChecked(uint16_t address) noexcept;
609 Result<uint16_t> readMeasurement(uint16_t address) noexcept;
610 Result<uint16_t> measure(uint16_t address) noexcept;
611 Result<uint16_t> readErrfl() noexcept;
612 Result<void> writeRaw(uint16_t address, uint16_t value, bool verify) noexcept;
613 Result<void> resolveFlags(bool measurement) noexcept;
614 Result<void> checkReset() noexcept;
615 void flagsLost() noexcept;
616 void rereadAfterFailedWrite(const Config& base, bool settings) noexcept;
617 Result<NonVolatileRegisters> readNonVolatile() noexcept;
618 Result<void> programOtp(OtpReport& report) noexcept;
619 Result<void> otpPrepare(OtpReport& report) noexcept;
620 Result<void> otpBurn(OtpReport& report) noexcept;
621 Result<void> otpVerify(OtpReport& report) noexcept;
622 Result<void> fail(Error error, const char* message) noexcept;
623
626 template <typename T>
627 Result<T> afterAccess(const Result<T>& r) noexcept {
628 if (!reset_hint_ && !lost_hint_) {
629 return r;
630 }
631 if (!initialized_) {
632 reset_hint_ = false; // already uninitialised: EnsureInitialized() writes everything
633 lost_hint_ = false;
634 return r;
635 }
636 // A reset replaces the call's own result. A compare that could not be read leaves a failed
637 // call's own error, but fails a call that succeeded with the compare's error: no value is
638 // returned while a reset may have gone unseen (the compare stays pending).
639 const auto c = checkReset();
640 if (c.error == Error::DeviceReset) {
642 }
643 if (!c && r.ok()) {
644 return Result<T>::Failure(c.error);
645 }
646 return r;
647 }
648
649 [[nodiscard]] FrameFormat writeFormat() const noexcept {
650 return (config_.frame == FrameFormat::Bits16) ? FrameFormat::Bits24 : config_.frame;
651 }
652
653 detail::FrameBus<Port> bus_;
654 Config config_{};
655 uint16_t last_errfl_{0};
656 uint16_t latched_errfl_{0};
658 NonVolatileRegisters expected_nv_{};
659 bool flags_lost_{false};
661 bool reset_hint_{false};
664 bool lost_hint_{false};
665 bool initialized_{false};
666};
667
670} // namespace as5047u
671
672// codeql::misra_deviation_next_line(MD-CPP-009)
673#include "../src/as5047u.ipp" // IWYU pragma: export
674
675#endif // AS5047U_HPP
Compile-time helpers of the AS5047U driver: exact hook matching, the dependent-false helper,...
AS5047U register map: addresses, field masks and shifts.
The SPI port of the AS5047U driver: the CRTP base, the SpiPort concept and the frame layer.
Public types of the AS5047U driver: errors, Result<T>, configuration, decoded registers.
Driver for one AS5047U on a platform port.
Definition as5047u.hpp:301
Result< void > Deinitialize() noexcept
Mark the driver uninitialised; the next EnsureInitialized() starts the chip again (the recovery after...
Result< void > SetDirection(Direction direction, Verify verify=Verify::None) noexcept
Set the direction in which the angle increases.
Result< void > ApplyConfig(const Config &config, Verify verify=Verify::None) noexcept
Change the configuration.
Result< float > ReadAngleRadians() noexcept
Result< void > SetZeroPosition(uint16_t counts, Verify verify=Verify::None) noexcept
Set the zero position (ZPOSM, ZPOSL).
ErrorFlags GetLastErrorFlags() const noexcept
Definition as5047u.hpp:500
ErrorFlags GetLatchedErrorFlags() const noexcept
Every ERRFL flag the driver has read since the last ClearLatchedErrorFlags(). No I/O.
Definition as5047u.hpp:524
const Config & GetConfig() const &noexcept
Definition as5047u.hpp:391
Result< Diagnostics > ReadDiagnostics() noexcept
AS5047U & operator=(const AS5047U &)=delete
One driver object per chip.
Result< NonVolatileRegisters > ReadNonVolatile() noexcept
Result< float > ReadVelocityRpm() noexcept
Result< int16_t > ReadVelocityCounts() noexcept
Result< void > CheckForReset() noexcept
Check that the chip still holds the settings the driver wrote: the cheap test for a reset of the chip...
Result< void > ProgramOtp(OtpBurnConfirm confirm, OtpReport &report) noexcept
Burn the current settings into the OTP. This cannot be undone.
Result< float > ReadAngleDegrees() noexcept
uint16_t GetLastReply() const noexcept
Definition as5047u.hpp:540
void ClearLatchedErrorFlags() noexcept
Empty the latch of GetLatchedErrorFlags(), flags_lost included. No I/O.
Definition as5047u.hpp:531
AS5047U(Port &port, const Config &config={}) noexcept
Bind the driver to a port and store the configuration. No I/O, cannot fail.
Definition as5047u.hpp:315
Result< void > WriteRegister(uint16_t address, uint16_t value, Verify verify=Verify::None) noexcept
Write a register: the command and data frames, nothing more unless verify asks for a read-back....
Result< uint16_t > ReadAngleCounts() noexcept
The angle at address 0x3FFF (with DAEC unless it is off): the hot path.
Result< float > ReadVelocityDegPerSec() noexcept
Result< uint16_t > ReadUncompensatedAngleCounts() noexcept
Result< uint8_t > ReadAgc() noexcept
Result< ErrorFlags > ReadErrorFlags() noexcept
Read ERRFL, which clears it on the chip. The value is also kept in GetLastErrorFlags() and ORed into ...
bool IsInitialized() const noexcept
Definition as5047u.hpp:351
AS5047U(const AS5047U &)=delete
One driver object per chip.
void GetConfig() const &&=delete
Not on a temporary driver: the reference would dangle (KB-CPP20-044).
Result< uint16_t > ReadRegister(uint16_t address) noexcept
Read one register once: the command frame and the NOP frame that carries the answer,...
Result< uint16_t > SetZeroHere(Verify verify=Verify::None) noexcept
Make the current position read as 0.
Result< void > EnsureInitialized() noexcept
Start the chip, once: the only way to initialise the driver.
Result< uint16_t > ReadMagnitude() noexcept
LogLevel
Severity passed to the optional Log() hook.
Definition as5047u_types.hpp:189
Error
Why a call failed. Every call of the driver returns one of these in its Result.
Definition as5047u_types.hpp:37
constexpr uint8_t kMaxUvwPolePairs
Highest UVW pole-pair count.
Definition as5047u_types.hpp:361
std::array< uint16_t, reg::kNonVolatileCount > NonVolatileRegisters
The non-volatile registers DISABLE to ECC, in address order; index with reg::At(reg::NvIndex).
Definition as5047u_types.hpp:399
Direction
Direction in which the angle increases (SETTINGS2.DIR).
Definition as5047u_types.hpp:218
Verify
Whether a run-time write reads the register back, chosen per call.
Definition as5047u_types.hpp:261
FrameFormat
SPI frame length. The chip recognises the length of each frame, so the driver may mix them.
Definition as5047u_types.hpp:203
@ Info
Lifecycle events: initialised, OTP burned.
@ Framing
The chip saw an SPI framing error (ERRFL.Framing_error).
@ Crc
A reply's CRC was wrong, or the chip saw a wrong CRC (ERRFL.CRC_error).
@ Ok
The call succeeded.
@ Command
The chip saw an invalid command (ERRFL.Command_error).
@ ThreeLsb
3 LSB. Reset value.
@ CounterClockwise
Inverted (DIR = 1).
@ Clockwise
The datasheet's default direction, seen from above the magnet.
@ Abi
A, B and index pulses; PWM, when on, goes on pin W. Reset value.
@ Uvw
U, V and W commutation signals; PWM, when on, goes on pin I.
@ None
Command and data frames only. The default: nothing extra on a timed path.
@ Bits16
16-bit frames, no CRC: the fastest reads, but a corrupted reply goes unnoticed.
@ Bits24
24-bit frames with CRC-8 in both directions. Default.
constexpr uint16_t kErrflCordic
Definition as5047u_registers.hpp:123
constexpr uint16_t kZeroHighShift
Zero position bits 13..6 go in ZPOSM.
Definition as5047u_registers.hpp:182
constexpr uint16_t kDisableFilterOff
FILTER_disable: adaptive filter off.
Definition as5047u_registers.hpp:175
constexpr uint16_t kDiaOffsetCompDone
Offset compensation finished.
Definition as5047u_registers.hpp:160
constexpr uint16_t kDiaVdd5V
VDD_mode: 1 = 5 V operation.
Definition as5047u_registers.hpp:152
constexpr uint16_t kS2PwmOn
PWMon: PWM output on.
Definition as5047u_registers.hpp:200
constexpr uint16_t kDiaMagHalf
Field at half the regulated value.
Definition as5047u_registers.hpp:157
constexpr uint16_t kErrflCommand
Invalid SPI command.
Definition as5047u_registers.hpp:119
constexpr uint16_t kDiaSpiCountMask
Definition as5047u_registers.hpp:163
constexpr uint16_t kErrflP2ramError
ECC found an uncorrectable P2RAM error.
Definition as5047u_registers.hpp:117
constexpr uint16_t kZposlMask
ZPOSL bits 5..0 hold zero-position bits 5..0.
Definition as5047u_registers.hpp:180
constexpr uint16_t kDiaAgcDone
AGC loop finished.
Definition as5047u_registers.hpp:161
constexpr uint16_t kDiaSpiCountShift
SPI_cnt: frame counter, bits 12..11.
Definition as5047u_registers.hpp:162
constexpr uint16_t kErrflMagHalf
Field at half the regulated value.
Definition as5047u_registers.hpp:115
constexpr uint16_t kErrflDeviceFault
The flags that mean the measurement path is faulty.
Definition as5047u_registers.hpp:128
constexpr uint16_t kErrflWatchdog
Internal oscillator or watchdog fault.
Definition as5047u_registers.hpp:121
constexpr uint16_t kErrflAgcWarning
AGC at its minimum or maximum.
Definition as5047u_registers.hpp:114
constexpr uint16_t kS3AbiresShift
ABIRES, bits 7..5.
Definition as5047u_registers.hpp:207
constexpr uint16_t kDiaCompLow
AGC at its low limit.
Definition as5047u_registers.hpp:155
constexpr uint16_t kDisableUvwOff
UVW_off: UVW pins tristate.
Definition as5047u_registers.hpp:173
constexpr uint16_t kS1KminMask
K_min mask.
Definition as5047u_registers.hpp:188
constexpr uint16_t kS3UvwppMask
UVWPP: pole pairs minus one, bits 2..0.
Definition as5047u_registers.hpp:204
constexpr uint16_t kS1KmaxMask
K_max code, bits 2..0.
Definition as5047u_registers.hpp:186
constexpr std::size_t At(NvIndex index) noexcept
The array index of a non-volatile register.
Definition as5047u_registers.hpp:78
constexpr uint16_t kS2DataSelect
Data_select: 0x3FFF reads ANGLEUNC.
Definition as5047u_registers.hpp:199
constexpr uint16_t kDataMask
The 14 address or data bits of a frame word.
Definition as5047u_registers.hpp:102
constexpr uint16_t kS3AbiresMask
ABIRES mask.
Definition as5047u_registers.hpp:208
constexpr uint16_t kS2AbiDecimal
ABI_DEC: decimal ABI resolution.
Definition as5047u_registers.hpp:198
constexpr uint16_t kErrflOffComp
Offset compensation not finished.
Definition as5047u_registers.hpp:122
constexpr uint16_t kDiaCordicOverflow
CORDIC overflow.
Definition as5047u_registers.hpp:154
constexpr uint16_t kS1KminShift
K_min code, bits 5..3.
Definition as5047u_registers.hpp:187
constexpr uint16_t kDisableAbiOff
ABI_off: A, B and I pins tristate.
Definition as5047u_registers.hpp:174
constexpr uint16_t kErrflP2ramWarning
ECC corrected one bit in P2RAM.
Definition as5047u_registers.hpp:116
constexpr uint16_t kZposlDiaBits
ZPOSL bits 7..6: Dia1_en, Dia2_en (kept).
Definition as5047u_registers.hpp:181
NvIndex
Index of a non-volatile register in NonVolatileRegisters (address order from DISABLE).
Definition as5047u_registers.hpp:63
constexpr uint16_t kS2NoiseSet
NOISESET: reduced noise at 150 °C, 3.3 V.
Definition as5047u_registers.hpp:194
constexpr uint16_t kS2Dir
DIR: invert the rotation direction.
Definition as5047u_registers.hpp:195
constexpr uint16_t kErrflCrc
CRC error on a MOSI frame.
Definition as5047u_registers.hpp:120
constexpr uint16_t kS2UvwAbi
UVW_ABI: 0 = ABI with PWM on W, 1 = UVW.
Definition as5047u_registers.hpp:196
constexpr uint16_t kS3HysMask
HYS mask.
Definition as5047u_registers.hpp:206
constexpr uint16_t kErrflFraming
SPI framing error.
Definition as5047u_registers.hpp:118
constexpr uint16_t kS2IndexWidth1
IWIDTH: 1 = 1 LSB index pulse, 0 = 3 LSB.
Definition as5047u_registers.hpp:193
constexpr uint16_t kS1DiaBits
Dia3_en, Dia4_en (kept).
Definition as5047u_registers.hpp:189
constexpr uint16_t kS3HysShift
HYS, bits 4..3.
Definition as5047u_registers.hpp:205
constexpr uint16_t kDiaLoopsFinished
All magnetic loops have settled.
Definition as5047u_registers.hpp:153
constexpr uint16_t kS2DaecDis
DAECDIS: dynamic compensation off.
Definition as5047u_registers.hpp:197
constexpr uint16_t kZposmMask
ZPOSM holds zero-position bits 13..6.
Definition as5047u_registers.hpp:179
constexpr uint16_t kDiaCompHigh
AGC at its high limit.
Definition as5047u_registers.hpp:156
The AS5047U driver: everything it declares lives here; internals in detail.
Definition as5047u.hpp:24
Everything EnsureInitialized() and ApplyConfig() write to the chip.
Definition as5047u_types.hpp:287
Direction direction
SETTINGS2.DIR.
Definition as5047u_types.hpp:305
bool high_temperature_noise
Definition as5047u_types.hpp:320
uint16_t zero_position
ZPOSM/ZPOSL, counts 0 to 16383.
Definition as5047u_types.hpp:306
bool uvw_enable
U/V/W pins driven (DISABLE.UVW_off = 0).
Definition as5047u_types.hpp:313
bool pwm_enable
SETTINGS2.PWMon.
Definition as5047u_types.hpp:314
uint8_t filter_k_max_code
SETTINGS1.K_max code, 0 to 7.
Definition as5047u_types.hpp:310
bool uncompensated_at_angle_register
SETTINGS2.Data_select: address 0x3FFF (and the PWM output) carry the angle without DAEC.
Definition as5047u_types.hpp:322
bool abi_decimal
SETTINGS2.ABI_DEC.
Definition as5047u_types.hpp:316
uint8_t uvw_pole_pairs
SETTINGS3.UVWPP + 1, 1 to 7.
Definition as5047u_types.hpp:318
uint8_t filter_k_min_code
SETTINGS1.K_min code, 0 to 7.
Definition as5047u_types.hpp:309
uint8_t hysteresis_code
SETTINGS3.HYS, 0 to 3.
Definition as5047u_types.hpp:319
IndexWidth index_width
SETTINGS2.IWIDTH.
Definition as5047u_types.hpp:317
bool abi_enable
A/B/I pins driven (DISABLE.ABI_off = 0).
Definition as5047u_types.hpp:312
bool adaptive_filter
Velocity filter on (DISABLE bit 6 = 0).
Definition as5047u_types.hpp:308
IncrementalOutput incremental
SETTINGS2.UVW_ABI.
Definition as5047u_types.hpp:311
bool dynamic_compensation
DAEC on (SETTINGS2.DAECDIS = 0).
Definition as5047u_types.hpp:307
FrameFormat frame
Definition as5047u_types.hpp:292
uint8_t abi_resolution_code
SETTINGS3.ABIRES, 0 to 7.
Definition as5047u_types.hpp:315
DIA, decoded: the state of the chip's internal loops.
Definition as5047u_types.hpp:385
bool vdd_5v
VDD_mode: the chip runs from 5 V (else 3.3 V).
Definition as5047u_types.hpp:386
ERRFL, decoded. Reading ERRFL clears it on the chip.
Definition as5047u_types.hpp:364
bool flags_lost
Not an ERRFL bit: in GetLatchedErrorFlags() only, true when a read of ERRFL failed after its command ...
Definition as5047u_types.hpp:380
bool agc_warning
AGC at its minimum or maximum: magnet too far or too close.
Definition as5047u_types.hpp:365
The typed confirmation ProgramOtp() requires: burning the OTP cannot be undone, so the call names its...
Definition as5047u_types.hpp:351
Outcome of AS5047U::ProgramOtp().
Definition as5047u_types.hpp:402
The value of a call, or why there is none.
Definition as5047u_types.hpp:129
static constexpr Result Failure(Error e) noexcept
A failed result.
Definition as5047u_types.hpp:155