AS5047U Driver 0.1.0
API reference
Loading...
Searching...
No Matches
Classes | Typedefs | Enumerations | Functions | Variables
Driver types

Errors, results, configuration and decoded registers. More...

Classes

struct  as5047u::Result< T >
 The value of a call, or why there is none. More...
 
struct  as5047u::Result< void >
 The result of a call that returns no value. More...
 
struct  as5047u::Config
 Everything EnsureInitialized() and ApplyConfig() write to the chip. More...
 
struct  as5047u::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  as5047u::ErrorFlags
 ERRFL, decoded. Reading ERRFL clears it on the chip. More...
 
struct  as5047u::Diagnostics
 DIA, decoded: the state of the chip's internal loops. More...
 
struct  as5047u::OtpReport
 Outcome of AS5047U::ProgramOtp(). More...
 

Typedefs

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

Functions

constexpr const char * as5047u::ToString (Error error) noexcept
 The name of an error, for logs.
 
constexpr Error as5047u::Validate (const Config &config) noexcept
 Check a configuration without touching the chip.
 
constexpr float as5047u::CountsToDegrees (uint16_t counts) noexcept
 Convert angle counts to degrees.
 
constexpr float as5047u::CountsToRadians (uint16_t counts) noexcept
 Convert angle counts to radians.
 
constexpr const char * as5047u::GetDriverVersion () noexcept
 
constexpr uint32_t as5047u::GetDriverVersionMajor () noexcept
 
constexpr uint32_t as5047u::GetDriverVersionMinor () noexcept
 
constexpr uint32_t as5047u::GetDriverVersionPatch () noexcept
 

Variables

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

Detailed Description

Errors, results, configuration and decoded registers.

Enumeration Type Documentation

◆ Direction

enum class as5047u::Direction : uint8_t
strong

Direction in which the angle increases (SETTINGS2.DIR).

Enumerator
Clockwise 

The datasheet's default direction, seen from above the magnet.

CounterClockwise 

Inverted (DIR = 1).

◆ Error

enum class as5047u::Error : uint8_t
strong

Why a call failed. Every call of the driver returns one of these in its Result.

Values 0 to 9 are the shared base set; chip-specific values start at 16. The type is [[nodiscard]]: a call whose Error is dropped does not compile quietly (KB-CPP20-037).

Enumerator
Ok 

The call succeeded.

NotInitialized 

EnsureInitialized() has not succeeded yet, or Deinitialize() ran since.

InvalidArgument 

An argument or a Config field is out of range; nothing was sent.

Bus 

A port hook returned false.

Timeout 

The OTP burn did not finish in kOtpBurnTimeoutMs.

DeviceIdMismatch 

Something answers at start-up, but DIA has bit 10 set, which reads 0 on an AS5047U: not this chip.

Crc 

A reply's CRC was wrong, or the chip saw a wrong CRC (ERRFL.CRC_error).

Busy 

Not returned by this driver (the chip has no busy state).

DeviceFault 

ERRFL reports a fault of the measurement path (P2RAM, watchdog, CORDIC, offset compensation): the value is not a measurement.

Unsupported 

Not returned by this driver.

Framing 

The chip saw an SPI framing error (ERRFL.Framing_error).

Command 

The chip saw an invalid command (ERRFL.Command_error).

WriteMismatch 

A register read back different from what was written.

OtpVerify 

The OTP burn finished, but the guard-band read-back differs: do not use the part (datasheet OTP procedure, step 19).

NoDevice 

A reply that a stuck, floating or looped-back line produces: all zeros or all ones with a wrong CRC, an ERRFL with its reserved bit set, an error bit with no error in ERRFL, or a DIA that stayed 0 (KB-CPP-116).

NotReady 

The chip answers, but DIA did not report every loop finished within Config::startup_timeout_ms (KB-CPP-124).

MagnetWarning 

The reply carried the warning bit and ERRFL holds an AGC or magnetic-half warning: the field is out of range and the angle is not a measurement (KB-CPP-127).

DeviceReset 

The chip was reset, or a reset could not be ruled out: after OffCompNotFinished or WDTST in ERRFL, or in CheckForReset(), the settings registers did not hold what the driver wrote. The driver is uninitialised: call EnsureInitialized() again.

◆ FrameFormat

enum class as5047u::FrameFormat : uint8_t
strong

SPI frame length. The chip recognises the length of each frame, so the driver may mix them.

Writes always use a CRC-protected frame: with Bits16 the driver sends writes as 24-bit frames (the datasheet allows 16-bit frames for reads only).

Enumerator
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.

Bits32 

32-bit frames: a pad byte, then a 24-bit frame (daisy chains).

◆ IncrementalOutput

enum class as5047u::IncrementalOutput : uint8_t
strong

Which incremental interface the A/B/I-U/V/W pins carry (SETTINGS2.UVW_ABI).

Enumerator
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.

◆ IndexWidth

enum class as5047u::IndexWidth : uint8_t
strong

Length of the ABI index pulse (SETTINGS2.IWIDTH).

Enumerator
ThreeLsb 

3 LSB. Reset value.

OneLsb 

1 LSB.

◆ LogLevel

enum class as5047u::LogLevel : uint8_t
strong

Severity passed to the optional Log() hook.

Enumerator
Error 

A call failed.

Warning 

Something unexpected that the driver recovered from.

Info 

Lifecycle events: initialised, OTP burned.

Debug 

Detail for bring-up.

◆ Verify

enum class as5047u::Verify : uint8_t
strong

Whether a run-time write reads the register back, chosen per call.

A write is the two frames the datasheet needs (command and data, CRC-protected, the reply's error bit checked). ReadBack adds one frame pair per register and fails with WriteMismatch when the chip holds something else: it catches a write the chip lost, or a read-only bit. EnsureInitialized() and ProgramOtp() read their writes back whatever is passed elsewhere.

Enumerator
None 

Command and data frames only. The default: nothing extra on a timed path.

ReadBack 

Read each written register back and compare.

Function Documentation

◆ CountsToDegrees()

constexpr float as5047u::CountsToDegrees ( uint16_t  counts)
constexprnoexcept

Convert angle counts to degrees.

Parameters
counts0 to 16383.
Returns
Degrees in [0, 360).

◆ CountsToRadians()

constexpr float as5047u::CountsToRadians ( uint16_t  counts)
constexprnoexcept

Convert angle counts to radians.

Parameters
counts0 to 16383.
Returns
Radians in [0, 2π).

◆ GetDriverVersion()

constexpr const char * as5047u::GetDriverVersion ( )
constexprnoexcept
Returns
The driver version, e.g. "0.1.0", from the generated as5047u_version.h. No I/O.

◆ GetDriverVersionMajor()

constexpr uint32_t as5047u::GetDriverVersionMajor ( )
constexprnoexcept
Returns
The major version. No I/O.

◆ GetDriverVersionMinor()

constexpr uint32_t as5047u::GetDriverVersionMinor ( )
constexprnoexcept
Returns
The minor version. No I/O.

◆ GetDriverVersionPatch()

constexpr uint32_t as5047u::GetDriverVersionPatch ( )
constexprnoexcept
Returns
The patch version. No I/O.

◆ ToString()

constexpr const char * as5047u::ToString ( Error  error)
constexprnoexcept

The name of an error, for logs.

Parameters
errorThe error.
Returns
A static string such as "Crc"; "Unknown" for a value that is not an enumerator.

◆ Validate()

constexpr Error as5047u::Validate ( const Config &  config)
constexprnoexcept

Check a configuration without touching the chip.

Fails when an enum holds a value that is not an enumerator or a code or count is out of its field's range.

Parameters
configThe configuration.
Returns
Error::Ok or Error::InvalidArgument.

Variable Documentation

◆ kOtpBurnTimeoutMs

constexpr uint32_t as5047u::kOtpBurnTimeoutMs = 100
inlineconstexpr

Longest wait for an OTP burn to finish, in milliseconds (polled once per millisecond). The datasheet gives no burn time; this bound is the driver's choice, not verified on hardware.

◆ kPowerOnTimeMs

constexpr uint32_t as5047u::kPowerOnTimeMs = 10
inlineconstexpr

Longest wait from power-on to the first valid angle, t_pon (datasheet "Timing Characteristics", Figure 9): the default start-up deadline.