AS5047U Driver 0.1.0
API reference
Loading...
Searching...
No Matches
Namespaces | Classes | Concepts | Typedefs | Enumerations | Functions | Variables
as5047u Namespace Reference

The AS5047U driver: everything it declares lives here; internals in detail. More...

Namespaces

namespace  reg
 Register addresses and fields of the AS5047U (datasheet section "Register Description").
 

Classes

class  AS5047U
 Driver for one AS5047U on a platform port. More...
 
struct  Config
 Everything EnsureInitialized() and ApplyConfig() write to the chip. More...
 
struct  Diagnostics
 DIA, decoded: the state of the chip's internal loops. More...
 
struct  ErrorFlags
 ERRFL, decoded. Reading ERRFL clears it on the chip. More...
 
struct  OtpBurnConfirm
 The typed confirmation ProgramOtp() requires: burning the OTP cannot be undone, so the call names its intent and a stray integer cannot stand in for it (KB-CPP-045, KB-CPP20-030). More...
 
struct  OtpReport
 Outcome of AS5047U::ProgramOtp(). More...
 
struct  Result
 The value of a call, or why there is none. More...
 
struct  Result< void >
 The result of a call that returns no value. More...
 
class  SpiInterface
 CRTP base of the platform SPI port. More...
 

Concepts

concept  SpiPort
 Satisfied by a class that derives from SpiInterface<Port> and implements the required hooks with exactly the types above, noexcept and returning bool.
 

Typedefs

using NonVolatileRegisters = std::array< uint16_t, reg::kNonVolatileCount >
 The non-volatile registers DISABLE to ECC, in address order; index with reg::At(reg::NvIndex).
 

Enumerations

enum class  Error : uint8_t {
  Error::Ok = 0 , Error::NotInitialized , Error::InvalidArgument = 2 , Error::Bus = 3 ,
  Error::Timeout = 4 , Error::DeviceIdMismatch = 5 , Error::Crc = 6 , Error::Busy = 7 ,
  Error::DeviceFault = 8 , Error::Unsupported = 9 , Error::Framing = 16 , Error::Command = 17 ,
  Error::WriteMismatch = 18 , Error::OtpVerify = 19 , Error::NoDevice = 20 , Error::NotReady = 21 ,
  Error::MagnetWarning = 22 , Error::DeviceReset = 23
}
 Why a call failed. Every call of the driver returns one of these in its Result. More...
 
enum class  LogLevel : uint8_t { LogLevel::Error = 0 , LogLevel::Warning , LogLevel::Info , LogLevel::Debug }
 Severity passed to the optional Log() hook. More...
 
enum class  FrameFormat : uint8_t { FrameFormat::Bits16 = 0 , FrameFormat::Bits24 = 1 , FrameFormat::Bits32 = 2 }
 SPI frame length. The chip recognises the length of each frame, so the driver may mix them. More...
 
enum class  Direction : uint8_t { Direction::Clockwise = 0 , Direction::CounterClockwise = 1 }
 Direction in which the angle increases (SETTINGS2.DIR). More...
 
enum class  IncrementalOutput : uint8_t { IncrementalOutput::Abi = 0 , IncrementalOutput::Uvw = 1 }
 Which incremental interface the A/B/I-U/V/W pins carry (SETTINGS2.UVW_ABI). More...
 
enum class  IndexWidth : uint8_t { IndexWidth::ThreeLsb = 0 , IndexWidth::OneLsb = 1 }
 Length of the ABI index pulse (SETTINGS2.IWIDTH). More...
 
enum class  Verify : uint8_t { Verify::None = 0 , Verify::ReadBack = 1 }
 Whether a run-time write reads the register back, chosen per call. More...
 

Functions

constexpr Config KconfigDefaults () noexcept
 The configuration menuconfig selected, on top of the defaults.
 
constexpr uint8_t Crc8 (uint16_t word) noexcept
 CRC-8 of a 16-bit frame word: polynomial 0x1D, initial value 0xC4, final XOR 0xFF, not reflected (datasheet "CRC Checksum", Figure 31). Table-driven; equal to the bitwise definition for every word (tests/test_as5047u.cpp).
 
constexpr const char * ToString (Error error) noexcept
 The name of an error, for logs.
 
constexpr Error Validate (const Config &config) noexcept
 Check a configuration without touching the chip.
 
constexpr float CountsToDegrees (uint16_t counts) noexcept
 Convert angle counts to degrees.
 
constexpr float CountsToRadians (uint16_t counts) noexcept
 Convert angle counts to radians.
 
constexpr const char * GetDriverVersion () noexcept
 
constexpr uint32_t GetDriverVersionMajor () noexcept
 
constexpr uint32_t GetDriverVersionMinor () noexcept
 
constexpr uint32_t GetDriverVersionPatch () noexcept
 

Variables

constexpr uint32_t kPowerOnTimeMs = 10
 
constexpr uint32_t kStartupTimeoutMaxMs = 1000
 Largest Config::startup_timeout_ms that Validate() accepts.
 
constexpr uint16_t kCountsPerRevolution = 16384
 Angle counts per revolution (14 bits).
 
constexpr uint16_t kMaxAngleCount = kCountsPerRevolution - 1U
 Highest angle count.
 
constexpr float kVelocityDegPerSecPerLsb = 24.141F
 Velocity resolution in degrees per second per LSB (datasheet, VEL register).
 
constexpr float kPi = 3.14159265358979323846F
 Pi, as a float (C++20's std::numbers is not on every embedded toolchain).
 
constexpr uint32_t kOtpBurnTimeoutMs = 100
 
constexpr OtpBurnConfirm kOtpConfirm {0x0B7B'0B7BU}
 The confirmation to pass to ProgramOtp().
 
constexpr uint8_t kMax3BitCode = 7
 The highest field code for 3-bit fields (filter_k_*_code, abi_resolution_code).
 
constexpr uint8_t kMaxHysteresisCode = 3
 The highest hysteresis code (2-bit field).
 
constexpr uint8_t kMaxUvwPolePairs = 7
 Highest UVW pole-pair count.
 
Bus requirements

What the AS5047U needs from the SPI bus (datasheet "SPI Interface (Slave)", "SPI Timing", Figures 18 and 19, and "SPI Transaction", Figures 20 to 28). A port and a board configuration check their settings against these with static_assert (handbook KB-CPP-123).

constexpr uint8_t kSpiMode = 1
 SPI mode 1: CPOL 0, CPHA 1. The chip samples MOSI on the falling edge of CLK.
 
constexpr bool kMsbFirst = true
 Each frame is clocked most significant bit first.
 
constexpr uint32_t kMaxClockHz = 10'000'000
 Highest CLK frequency: t_clk min 100 ns, so 10 MHz.
 
constexpr uint32_t kMinCsHighNs = 350
 
constexpr uint32_t kCsSetupNs = 350
 CS falling edge to the first CLK rising edge, t_L.
 
constexpr uint32_t kCsHoldNs = 50
 Last CLK falling edge to CS rising edge, t_H: t_clk / 2, so 50 ns at kMaxClockHz.
 
constexpr bool kContinuousWord = false
 
constexpr std::array< uint8_t, 3 > kFrameBits = {16, 24, 32}
 Frame lengths in bits the chip accepts: 16 (reads only, no CRC), 24 and 32 (Figures 20, 23, 26).
 

Detailed Description

The AS5047U driver: everything it declares lives here; internals in detail.

Function Documentation

◆ Crc8()

constexpr uint8_t as5047u::Crc8 ( uint16_t  word)
constexprnoexcept

CRC-8 of a 16-bit frame word: polynomial 0x1D, initial value 0xC4, final XOR 0xFF, not reflected (datasheet "CRC Checksum", Figure 31). Table-driven; equal to the bitwise definition for every word (tests/test_as5047u.cpp).

Parameters
wordThe word the CRC protects (command or data, MOSI or MISO).
Returns
The CRC byte.

◆ KconfigDefaults()

constexpr Config as5047u::KconfigDefaults ( )
constexprnoexcept

The configuration menuconfig selected, on top of the defaults.

Returns
Config{} with the frame format, direction and DAEC taken from Kconfig.

Variable Documentation

◆ kContinuousWord

constexpr bool as5047u::kContinuousWord = false
inlineconstexpr

false: the chip counts clocks while CS is low and executes the frame at the rising CS edge, so idle CLK time between the bytes of one frame is allowed. CS must not rise inside a frame.

◆ kMinCsHighNs

constexpr uint32_t as5047u::kMinCsHighNs = 350
inlineconstexpr

Shortest time CS stays high between two frames, t_CSn (2 t_CLK_SYS + 10 ns with the internal clock at its 9 MHz typical; give margin on a slow internal clock).