AS5047U Driver
API reference
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | List of all members
as5047u::AS5047U< SpiType > Class Template Reference

AS5047U magnetic rotary sensor driver class. More...

#include <as5047u.hpp>

Classes

struct  Angle
 Angle conversion helpers. More...
 
struct  Velocity
 Helper constants and methods for velocity unit conversions. More...
 

Public Member Functions

 AS5047U (SpiType &bus, FrameFormat format=AS5047U_CFG::DEFAULT_FRAME_FORMAT) noexcept
 Construct a new AS5047U encoder driver.
 
 ~AS5047U ()=default
 
void SetFrameFormat (FrameFormat format) noexcept
 Set the SPI frame format (16, 24, or 32-bit).
 
uint16_t GetAngle (uint8_t retries=AS5047U_CFG::CRC_RETRIES) const
 Read the 14-bit absolute angle with dynamic compensation (DAEC active).
 
float GetAngle (AngleUnit unit, uint8_t retries=AS5047U_CFG::CRC_RETRIES) const
 Read absolute angle in caller-selected unit.
 
float GetAngleDegrees (uint8_t retries=AS5047U_CFG::CRC_RETRIES) const
 Read absolute angle in degrees.
 
float GetAngleRadians (uint8_t retries=AS5047U_CFG::CRC_RETRIES) const
 Read absolute angle in radians.
 
uint16_t GetRawAngle (uint8_t retries=AS5047U_CFG::CRC_RETRIES) const
 Read the 14-bit absolute angle without dynamic compensation (raw angle).
 
int16_t GetVelocity (uint8_t retries=AS5047U_CFG::CRC_RETRIES) const
 Read the current rotational velocity (signed 14-bit).
 
float GetVelocity (VelocityUnit unit, uint8_t retries=AS5047U_CFG::CRC_RETRIES) const
 Read rotational velocity in caller-selected unit.
 
float GetVelocityDegPerSec (uint8_t retries=AS5047U_CFG::CRC_RETRIES) const
 Get rotational velocity in degrees per second.
 
float GetVelocityRadPerSec (uint8_t retries=AS5047U_CFG::CRC_RETRIES) const
 Get rotational velocity in radians per second.
 
float GetVelocityRPM (uint8_t retries=AS5047U_CFG::CRC_RETRIES) const
 Get rotational velocity in revolutions per minute.
 
uint8_t GetAGC (uint8_t retries=AS5047U_CFG::CRC_RETRIES) const
 Read the current Automatic Gain Control (AGC) value (0-255).
 
uint16_t GetMagnitude (uint8_t retries=AS5047U_CFG::CRC_RETRIES) const
 Read the current magnetic field magnitude (14-bit value).
 
uint16_t GetErrorFlags (uint8_t retries=AS5047U_CFG::CRC_RETRIES) const
 Read the ERRFL register (0x0001) from the chip.
 
void DumpStatus () const
 Dump formatted status and diagnostics using printf.
 
uint16_t GetZeroPosition (uint8_t retries=AS5047U_CFG::CRC_RETRIES) const
 Get the currently configured soft zero position offset (14-bit).
 
bool SetZeroPosition (uint16_t angle_lsb, uint8_t retries=AS5047U_CFG::CRC_RETRIES)
 Set a new zero reference position (soft offset).
 
bool SetDirection (bool clockwise, uint8_t retries=AS5047U_CFG::CRC_RETRIES)
 Define the rotation direction for increasing angle.
 
bool SetABIResolution (uint8_t resolution_bits, uint8_t retries=AS5047U_CFG::CRC_RETRIES)
 Set the ABI (incremental encoder) resolution.
 
bool SetUVWPolePairs (uint8_t pairs, uint8_t retries=AS5047U_CFG::CRC_RETRIES)
 Set the number of pole pairs for UVW commutation outputs.
 
bool SetIndexPulseLength (uint8_t lsb_len, uint8_t retries=AS5047U_CFG::CRC_RETRIES)
 Set the index pulse width for ABI output.
 
bool ConfigureInterface (bool abi, bool uvw, bool pwm, uint8_t retries=AS5047U_CFG::CRC_RETRIES)
 Configure interface outputs (ABI, UVW) and PWM output.
 
bool SetDynamicAngleCompensation (bool enable, uint8_t retries=AS5047U_CFG::CRC_RETRIES)
 Enable/disable Dynamic Angle Error Compensation (DAEC).
 
bool SetAdaptiveFilter (bool enable, uint8_t retries=AS5047U_CFG::CRC_RETRIES)
 Enable/disable the adaptive filter (Dynamic Filter System).
 
bool SetFilterPreset (FilterPreset preset, uint8_t retries=AS5047U_CFG::CRC_RETRIES)
 Set adaptive filter from a preset (easiest way to configure filter).
 
bool SetFilterParameters (uint8_t k_min, uint8_t k_max, uint8_t retries=AS5047U_CFG::CRC_RETRIES)
 Set adaptive filter parameters (K_min and K_max as 3-bit register codes).
 
bool GetAdaptiveFilterEnabled (uint8_t retries=AS5047U_CFG::CRC_RETRIES) const
 Read whether the adaptive filter is enabled.
 
std::pair< uint8_t, uint8_t > GetFilterParameters (uint8_t retries=AS5047U_CFG::CRC_RETRIES) const
 Read current K_min and K_max register codes (0–7 each).
 
bool Set150CTemperatureMode (bool enable, uint8_t retries=AS5047U_CFG::CRC_RETRIES)
 Set temperature mode for 150°C operation (NOISESET bit).
 
bool ProgramOTP (OtpResult *result=nullptr)
 Permanently program the current settings into OTP memory.
 
bool VerifyOTP (const std::array< uint16_t, kOtpRegisterCount > &burned, uint8_t retries=AS5047U_CFG::CRC_RETRIES) const
 Steps 21 and 22 of the OTP procedure: after the power-on cycle (step 20), read DISABLE..ECC (0x0015..0x001B) and compare them with the image ProgramOTP() burned.
 
void SetPad (uint8_t pad) noexcept
 Set the daisy-chain pad byte for 32-bit SPI frames.
 
bool SetHysteresis (AS5047U_REG::SETTINGS3::Hysteresis hysteresis, uint8_t retries=AS5047U_CFG::CRC_RETRIES)
 Set incremental output hysteresis level.
 
AS5047U_REG::SETTINGS3::Hysteresis GetHysteresis () const
 Get current incremental output hysteresis setting.
 
bool SetAngleOutputSource (AS5047U_REG::SETTINGS2::AngleOutputSource source, uint8_t retries=AS5047U_CFG::CRC_RETRIES)
 Select which angle register (0x3FFF) is returned on reads.
 
AS5047U_REG::SETTINGS2::AngleOutputSource GetAngleOutputSource () const
 Get currently selected angle output source for 0x3FFF reads.
 
AS5047U_REG::DIA GetDiagnostics () const
 Read the full diagnostic register (DIA).
 
template<typename RegT >
RegT ReadReg () const
 Reads data from a specified register in the AS5047U sensor.
 
template<typename RegT >
bool ReadReg (RegT &reg, uint8_t retries=AS5047U_CFG::CRC_RETRIES) const
 Read a register and report whether the read succeeded.
 
template<typename RegT >
bool WriteReg (const RegT &reg, uint8_t retries=AS5047U_CFG::CRC_RETRIES)
 Writes data to a specified register in the AS5047U sensor.
 
AS5047U_Error GetStickyErrorFlags () const noexcept
 Error flags accumulated since the last ClearStickyErrorFlags().
 
AS5047U_Error ClearStickyErrorFlags () noexcept
 Clear the sticky error flags.
 

Static Public Member Functions

static constexpr uint8_t ComputeCRC8 (uint16_t data16)
 
static constexpr const char * GetDriverVersion () noexcept
 Get the compiled driver version string.
 
static constexpr uint8_t GetDriverVersionMajor () noexcept
 Get the compiled driver major version number.
 
static constexpr uint8_t GetDriverVersionMinor () noexcept
 Get the compiled driver minor version number.
 
static constexpr uint8_t GetDriverVersionPatch () noexcept
 Get the compiled driver patch version number.
 

Detailed Description

template<typename SpiType>
class as5047u::AS5047U< SpiType >

AS5047U magnetic rotary sensor driver class.

Provides high-level access to sensor features: reading angle (with or without DAEC compensation), reading rotation velocity, retrieving AGC and magnitude diagnostics, configuring outputs (ABI, UVW, PWM), handling error flags, and performing OTP programming for permanent configuration storage.

Template Parameters
SpiTypeThe SPI bus type (must inherit from as5047u::SpiInterface<SpiType>)
Note
The driver uses CRTP-based SPI interface for zero virtual call overhead. SPI implementations should inherit from as5047u::SpiInterface<DerivedType>
C++17 CTAD allows automatic type deduction: AS5047U encoder(bus, format); // Type deduced automatically

Constructor & Destructor Documentation

◆ AS5047U()

template<typename SpiType >
as5047u::AS5047U< SpiType >::AS5047U ( SpiType &  bus,
FrameFormat  format = AS5047U_CFG::DEFAULT_FRAME_FORMAT 
)
explicitnoexcept

Construct a new AS5047U encoder driver.

Parameters
busReference to an SPI interface implementation.
formatSPI frame format to use (16-bit, 24-bit, or 32-bit). Default is 16-bit frames.

◆ ~AS5047U()

template<typename SpiType >
as5047u::AS5047U< SpiType >::~AS5047U ( )
default

Member Function Documentation

◆ ClearStickyErrorFlags()

template<typename SpiType >
AS5047U_Error as5047u::AS5047U< SpiType >::ClearStickyErrorFlags ( )
noexcept

Clear the sticky error flags.

Returns
The flags that were set, read and cleared in one atomic step.

◆ ComputeCRC8()

template<typename SpiType >
static constexpr uint8_t as5047u::AS5047U< SpiType >::ComputeCRC8 ( uint16_t  data16)
inlinestaticconstexpr

Compute the CRC8 value used by AS5047U SPI frames.

◆ ConfigureInterface()

template<typename SpiType >
bool as5047u::AS5047U< SpiType >::ConfigureInterface ( bool  abi,
bool  uvw,
bool  pwm,
uint8_t  retries = AS5047U_CFG::CRC_RETRIES 
)

Configure interface outputs (ABI, UVW) and PWM output.

Enables/disables ABI and UVW outputs and configures PWM on the available pin:

  • If abi is true and uvw false, ABI outputs are enabled and PWM (if enabled) is on W pin.
  • If uvw is true and abi false, UVW outputs are enabled and PWM (if enabled) is on I pin.
  • If both abi and uvw are true, both interfaces are active (PWM not available in this mode).
  • If both are false, all interfaces are disabled (PWM can still be enabled on W by default).
Parameters
abiEnable ABI (A, B, I) outputs.
uvwEnable UVW commutation outputs.
pwmEnable PWM output on the appropriate pin (W if UVW disabled, I if ABI disabled).

◆ DumpStatus()

template<typename SpiType >
void as5047u::AS5047U< SpiType >::DumpStatus ( ) const

Dump formatted status and diagnostics using printf.

◆ GetAdaptiveFilterEnabled()

template<typename SpiType >
bool as5047u::AS5047U< SpiType >::GetAdaptiveFilterEnabled ( uint8_t  retries = AS5047U_CFG::CRC_RETRIES) const

Read whether the adaptive filter is enabled.

◆ GetAGC()

template<typename SpiType >
uint8_t as5047u::AS5047U< SpiType >::GetAGC ( uint8_t  retries = AS5047U_CFG::CRC_RETRIES) const

Read the current Automatic Gain Control (AGC) value (0-255).

Parameters
retriesNumber of retries on CRC/framing error (default 0 = no retry).
Returns
The current AGC value.

◆ GetAngle() [1/2]

template<typename SpiType >
float as5047u::AS5047U< SpiType >::GetAngle ( AngleUnit  unit,
uint8_t  retries = AS5047U_CFG::CRC_RETRIES 
) const

Read absolute angle in caller-selected unit.

Parameters
unitOutput unit (LSB / degrees / radians).
retriesNumber of retries on CRC/framing error (default 0 = no retry).
Returns
Angle value in the requested unit.

◆ GetAngle() [2/2]

template<typename SpiType >
uint16_t as5047u::AS5047U< SpiType >::GetAngle ( uint8_t  retries = AS5047U_CFG::CRC_RETRIES) const

Read the 14-bit absolute angle with dynamic compensation (DAEC active).

Parameters
retriesNumber of retries on CRC/framing error (default 0 = no retry).
Returns
The current angle in LSB (0-16383).

◆ GetAngleDegrees()

template<typename SpiType >
float as5047u::AS5047U< SpiType >::GetAngleDegrees ( uint8_t  retries = AS5047U_CFG::CRC_RETRIES) const

Read absolute angle in degrees.

Parameters
retriesNumber of retries on CRC/framing error (default 0 = no retry).
Returns
Angle in degrees in the range [0, 360).

◆ GetAngleOutputSource()

template<typename SpiType >
AS5047U_REG::SETTINGS2::AngleOutputSource as5047u::AS5047U< SpiType >::GetAngleOutputSource ( ) const

Get currently selected angle output source for 0x3FFF reads.

Returns
AngleOutputSource enum indicating ANGLECOM or ANGLEUNC.

◆ GetAngleRadians()

template<typename SpiType >
float as5047u::AS5047U< SpiType >::GetAngleRadians ( uint8_t  retries = AS5047U_CFG::CRC_RETRIES) const

Read absolute angle in radians.

Parameters
retriesNumber of retries on CRC/framing error (default 0 = no retry).
Returns
Angle in radians in the range [0, 2π).

◆ GetDiagnostics()

template<typename SpiType >
AS5047U_REG::DIA as5047u::AS5047U< SpiType >::GetDiagnostics ( ) const

Read the full diagnostic register (DIA).

Returns
DIA register struct containing per-bit calibration and status flags.

◆ GetDriverVersion()

template<typename SpiType >
static constexpr const char * as5047u::AS5047U< SpiType >::GetDriverVersion ( )
inlinestaticconstexprnoexcept

Get the compiled driver version string.

Returns
Null-terminated version string, e.g. "1.0.0".

◆ GetDriverVersionMajor()

template<typename SpiType >
static constexpr uint8_t as5047u::AS5047U< SpiType >::GetDriverVersionMajor ( )
inlinestaticconstexprnoexcept

Get the compiled driver major version number.

◆ GetDriverVersionMinor()

template<typename SpiType >
static constexpr uint8_t as5047u::AS5047U< SpiType >::GetDriverVersionMinor ( )
inlinestaticconstexprnoexcept

Get the compiled driver minor version number.

◆ GetDriverVersionPatch()

template<typename SpiType >
static constexpr uint8_t as5047u::AS5047U< SpiType >::GetDriverVersionPatch ( )
inlinestaticconstexprnoexcept

Get the compiled driver patch version number.

◆ GetErrorFlags()

template<typename SpiType >
uint16_t as5047u::AS5047U< SpiType >::GetErrorFlags ( uint8_t  retries = AS5047U_CFG::CRC_RETRIES) const

Read the ERRFL register (0x0001) from the chip.

The chip clears ERRFL when it is read (datasheet Figure 33), so the value covers only what happened since the driver's previous read of ERRFL. Every ERRFL value the driver reads, including this one, is also ORed into the sticky flags (GetStickyErrorFlags()), so nothing read here is lost.

Parameters
retriesNumber of retries on a failed read (default 0 = no retry).
Returns
16-bit error flag register (ERRFL).

◆ GetFilterParameters()

template<typename SpiType >
std::pair< uint8_t, uint8_t > as5047u::AS5047U< SpiType >::GetFilterParameters ( uint8_t  retries = AS5047U_CFG::CRC_RETRIES) const

Read current K_min and K_max register codes (0–7 each).

◆ GetHysteresis()

template<typename SpiType >
AS5047U_REG::SETTINGS3::Hysteresis as5047u::AS5047U< SpiType >::GetHysteresis ( ) const

Get current incremental output hysteresis setting.

Returns
Current Hysteresis enum value (0b00–0b11).

◆ GetMagnitude()

template<typename SpiType >
uint16_t as5047u::AS5047U< SpiType >::GetMagnitude ( uint8_t  retries = AS5047U_CFG::CRC_RETRIES) const

Read the current magnetic field magnitude (14-bit value).

Parameters
retriesNumber of retries on CRC/framing error (default 0 = no retry).
Returns
The current magnetic field magnitude in LSB (0-16383).

◆ GetRawAngle()

template<typename SpiType >
uint16_t as5047u::AS5047U< SpiType >::GetRawAngle ( uint8_t  retries = AS5047U_CFG::CRC_RETRIES) const

Read the 14-bit absolute angle without dynamic compensation (raw angle).

Parameters
retriesNumber of retries on CRC/framing error (default 0 = no retry).
Returns
The current raw angle in LSB (0-16383).

◆ GetStickyErrorFlags()

template<typename SpiType >
AS5047U_Error as5047u::AS5047U< SpiType >::GetStickyErrorFlags ( ) const
noexcept

Error flags accumulated since the last ClearStickyErrorFlags().

ERRFL (0x0001) clears on the chip when it is read (datasheet Figure 33), and the driver reads it after every register access. Every ERRFL value the driver reads is ORed into this cache, which only ClearStickyErrorFlags() clears: reading it, and the driver's own retry decisions, leave it intact.

Returns
Bitwise OR of AS5047U_Error flags.

◆ GetVelocity() [1/2]

template<typename SpiType >
int16_t as5047u::AS5047U< SpiType >::GetVelocity ( uint8_t  retries = AS5047U_CFG::CRC_RETRIES) const

Read the current rotational velocity (signed 14-bit).

Parameters
retriesNumber of retries on CRC/framing error (default 0 = no retry).
Returns
The current velocity in LSB (signed 14-bit).

◆ GetVelocity() [2/2]

template<typename SpiType >
float as5047u::AS5047U< SpiType >::GetVelocity ( VelocityUnit  unit,
uint8_t  retries = AS5047U_CFG::CRC_RETRIES 
) const

Read rotational velocity in caller-selected unit.

Parameters
unitOutput unit (LSB / deg/s / rad/s / RPM).
retriesNumber of retries on CRC/framing error (default 0 = no retry).
Returns
Velocity in the requested unit.

◆ GetVelocityDegPerSec()

template<typename SpiType >
float as5047u::AS5047U< SpiType >::GetVelocityDegPerSec ( uint8_t  retries = AS5047U_CFG::CRC_RETRIES) const

Get rotational velocity in degrees per second.

Parameters
retriesNumber of retries on CRC/framing error (default 0 = no retry).

◆ GetVelocityRadPerSec()

template<typename SpiType >
float as5047u::AS5047U< SpiType >::GetVelocityRadPerSec ( uint8_t  retries = AS5047U_CFG::CRC_RETRIES) const

Get rotational velocity in radians per second.

Parameters
retriesNumber of retries on CRC/framing error (default 0 = no retry).

◆ GetVelocityRPM()

template<typename SpiType >
float as5047u::AS5047U< SpiType >::GetVelocityRPM ( uint8_t  retries = AS5047U_CFG::CRC_RETRIES) const

Get rotational velocity in revolutions per minute.

Parameters
retriesNumber of retries on CRC/framing error (default 0 = no retry).

◆ GetZeroPosition()

template<typename SpiType >
uint16_t as5047u::AS5047U< SpiType >::GetZeroPosition ( uint8_t  retries = AS5047U_CFG::CRC_RETRIES) const

Get the currently configured soft zero position offset (14-bit).

Parameters
retriesNumber of retries on CRC/framing error (default 0 = no retry).
Returns
The current zero position in LSB (0-16383).

◆ ProgramOTP()

template<typename SpiType >
bool as5047u::AS5047U< SpiType >::ProgramOTP ( OtpResult *  result = nullptr)

Permanently program the current settings into OTP memory.

Runs steps 4 to 19 of the datasheet's "Step-by-Step Procedure to Permanently Program the Non-Volatile Memory (OTP)" (DS000637 v1-01, page 41-42, flowchart Figure 60), checking the result of every step and stopping at the first that fails:

  1. read ANGLECOM; 5. write it into ZPOSL[5:0] and ZPOSM[7:0];
  2. read DISABLE..ECC (0x0015..0x001B); 7. ECC = 0x80 (ECC_en);
  3. read ECC_s (0x3FD0); 9. ECC = 0x80 | ECC_s;

read 0x0015..0x001B; 11. compare with what was written;

  1. PROG = 0x01 (PROGEN); 13. PROG = 0x08 (PROGOTP, starts the burn);
  2. poll PROG until it reads 0x0001;
  3. write 0x0000 into 0x0015..0x001B (clear the volatile copy);
  4. PROG = 0x40 (PROGVER, guard band); 17. PROG = 0x04 (OTPREF, reload from OTP); 18. read 0x0015..0x001B; 19. compare with step 10.

Steps 1 to 3 (power-on cycle, write the settings, magnet at the zero position) come before the call; steps 20 to 22 (power-on cycle, read back, compare) after it, with VerifyOTP() and the image in result. 16-bit frames are replaced by 24-bit frames for the duration.

Parameters
resultOptional: the step that failed, whether the burn was started, and the register image that was burned.
Returns
true if every step succeeded and the guard-band comparison (step 19) matched.
Warning
OTP can be programmed only once, and a part that fails step 19 must not be used (datasheet: "Reprogramming is not allowed!"). VDD 4.5 to 5.5 V (5 V mode) or 3.3 to 3.5 V (3.3 V mode), 5 to 45 degC (Figure 59).

◆ ReadReg() [1/2]

template<typename SpiType >
template<typename RegT >
RegT as5047u::AS5047U< SpiType >::ReadReg ( ) const
inline

Reads data from a specified register in the AS5047U sensor.

Template Parameters
RegTThe register type which must have an ADDRESS static member and be decodable
Returns
RegT The register object populated with the data read from the sensor

This method reads the raw value from the specified register address and decodes it into a strongly-typed register object.

◆ ReadReg() [2/2]

template<typename SpiType >
template<typename RegT >
bool as5047u::AS5047U< SpiType >::ReadReg ( RegT &  reg,
uint8_t  retries = AS5047U_CFG::CRC_RETRIES 
) const
inline

Read a register and report whether the read succeeded.

Template Parameters
RegTThe register type (has a static ADDRESS)
Parameters
regReceives the register content (value 0 when the read failed)
retriesNumber of retries on a failed read (default 0 = no retry)
Returns
true if the read went through and the chip reported no CRC or framing error for it; false on a bus error or such a chip error. The reason is in the sticky flags (GetStickyErrorFlags()).

◆ Set150CTemperatureMode()

template<typename SpiType >
bool as5047u::AS5047U< SpiType >::Set150CTemperatureMode ( bool  enable,
uint8_t  retries = AS5047U_CFG::CRC_RETRIES 
)

Set temperature mode for 150°C operation (NOISESET bit).

When enabled, the sensor supports full 150°C range (NOISESET=1), but with increased noise. When disabled, lower noise but max 125°C.

Parameters
enableTrue for 150°C mode (NOISESET=1), false for low-noise (NOISESET=0).

◆ SetABIResolution()

template<typename SpiType >
bool as5047u::AS5047U< SpiType >::SetABIResolution ( uint8_t  resolution_bits,
uint8_t  retries = AS5047U_CFG::CRC_RETRIES 
)

Set the ABI (incremental encoder) resolution.

Parameters
resolution_bitsResolution in bits (10 to 14 bits).

◆ SetAdaptiveFilter()

template<typename SpiType >
bool as5047u::AS5047U< SpiType >::SetAdaptiveFilter ( bool  enable,
uint8_t  retries = AS5047U_CFG::CRC_RETRIES 
)

Enable/disable the adaptive filter (Dynamic Filter System).

◆ SetAngleOutputSource()

template<typename SpiType >
bool as5047u::AS5047U< SpiType >::SetAngleOutputSource ( AS5047U_REG::SETTINGS2::AngleOutputSource  source,
uint8_t  retries = AS5047U_CFG::CRC_RETRIES 
)

Select which angle register (0x3FFF) is returned on reads.

Controls the Data_select bit in SETTINGS2.

Parameters
sourceAngle output source:
  • SETTINGS2::AngleOutputSource::UseANGLECOM: read compensated angle (ANGLECOM)
  • SETTINGS2::AngleOutputSource::UseANGLEUNC: read raw angle (ANGLEUNC)

◆ SetDirection()

template<typename SpiType >
bool as5047u::AS5047U< SpiType >::SetDirection ( bool  clockwise,
uint8_t  retries = AS5047U_CFG::CRC_RETRIES 
)
inline

Define the rotation direction for increasing angle.

Writes SETTINGS2 (0x0019) bit 2 (DIR) per datasheet Fig.47: 0 = CW default, 1 = invert direction.

Parameters
clockwiseIf true, clockwise yields increasing angle (DIR=0). If false, invert direction (DIR=1).
retriesNumber of retries on CRC/framing error (default 0 = no retry).
Returns
true if register write succeeded.

◆ SetDynamicAngleCompensation()

template<typename SpiType >
bool as5047u::AS5047U< SpiType >::SetDynamicAngleCompensation ( bool  enable,
uint8_t  retries = AS5047U_CFG::CRC_RETRIES 
)

Enable/disable Dynamic Angle Error Compensation (DAEC).

◆ SetFilterParameters()

template<typename SpiType >
bool as5047u::AS5047U< SpiType >::SetFilterParameters ( uint8_t  k_min,
uint8_t  k_max,
uint8_t  retries = AS5047U_CFG::CRC_RETRIES 
)

Set adaptive filter parameters (K_min and K_max as 3-bit register codes).

Both arguments are 0–7 (register codes). See SETTINGS1::AdaptiveFilterKmin and AdaptiveFilterKmax for mapping to effective K (datasheet Figure 17). For a single effective K, use SetFilterPreset() instead.

◆ SetFilterPreset()

template<typename SpiType >
bool as5047u::AS5047U< SpiType >::SetFilterPreset ( FilterPreset  preset,
uint8_t  retries = AS5047U_CFG::CRC_RETRIES 
)

Set adaptive filter from a preset (easiest way to configure filter).

Enables the filter and sets K_min/K_max to match the preset. See FilterPreset and datasheet Figure 17 (velocity RMS noise vs K).

◆ SetFrameFormat()

template<typename SpiType >
void as5047u::AS5047U< SpiType >::SetFrameFormat ( FrameFormat  format)
noexcept

Set the SPI frame format (16, 24, or 32-bit).

Parameters
formatThe desired SPI frame format.

◆ SetHysteresis()

template<typename SpiType >
bool as5047u::AS5047U< SpiType >::SetHysteresis ( AS5047U_REG::SETTINGS3::Hysteresis  hysteresis,
uint8_t  retries = AS5047U_CFG::CRC_RETRIES 
)

Set incremental output hysteresis level.

Controls the HYS field in SETTINGS3 to add output deadband and reduce chatter.

Parameters
hysteresisHysteresis level:
  • SETTINGS3::Hysteresis::LSB_1 (0b00): 1 LSB deadband (~0.17°, default)
  • SETTINGS3::Hysteresis::LSB_2 (0b01): 2 LSB deadband (~0.35°)
  • SETTINGS3::Hysteresis::LSB_3 (0b10): 3 LSB deadband (~0.52°)
  • SETTINGS3::Hysteresis::NONE (0b11): No hysteresis

◆ SetIndexPulseLength()

template<typename SpiType >
bool as5047u::AS5047U< SpiType >::SetIndexPulseLength ( uint8_t  lsb_len,
uint8_t  retries = AS5047U_CFG::CRC_RETRIES 
)

Set the index pulse width for ABI output.

Parameters
lsb_lenIndex pulse length in LSB periods (3 or 1).

◆ SetPad()

template<typename SpiType >
void as5047u::AS5047U< SpiType >::SetPad ( uint8_t  pad)
noexcept

Set the daisy-chain pad byte for 32-bit SPI frames.

In 32-bit frame mode, the first byte is used as a pad to allow multiple devices on the same bus.

Parameters
padPad byte value (0x00–0xFF) to send as the MSB of each 32-bit transfer.

◆ SetUVWPolePairs()

template<typename SpiType >
bool as5047u::AS5047U< SpiType >::SetUVWPolePairs ( uint8_t  pairs,
uint8_t  retries = AS5047U_CFG::CRC_RETRIES 
)

Set the number of pole pairs for UVW commutation outputs.

Parameters
pairsNumber of pole pairs (1-7).

◆ SetZeroPosition()

template<typename SpiType >
bool as5047u::AS5047U< SpiType >::SetZeroPosition ( uint16_t  angle_lsb,
uint8_t  retries = AS5047U_CFG::CRC_RETRIES 
)

Set a new zero reference position (soft offset).

Parameters
angle_lsb14-bit angle value that should be treated as 0°.

◆ VerifyOTP()

template<typename SpiType >
bool as5047u::AS5047U< SpiType >::VerifyOTP ( const std::array< uint16_t, kOtpRegisterCount > &  burned,
uint8_t  retries = AS5047U_CFG::CRC_RETRIES 
) const

Steps 21 and 22 of the OTP procedure: after the power-on cycle (step 20), read DISABLE..ECC (0x0015..0x001B) and compare them with the image ProgramOTP() burned.

Parameters
burnedOtpResult::written from ProgramOTP().
retriesNumber of retries of each read (default 0 = no retry).
Returns
true if every register reads as burned; false on a difference (the part must not be used) or a failed read.

◆ WriteReg()

template<typename SpiType >
template<typename RegT >
bool as5047u::AS5047U< SpiType >::WriteReg ( const RegT &  reg,
uint8_t  retries = AS5047U_CFG::CRC_RETRIES 
)
inline

Writes data to a specified register in the AS5047U sensor.

Template Parameters
RegTThe register type which must have an ADDRESS static member and be encodable
Parameters
regThe register object containing the data to be written
retriesNumber of retries on CRC/framing error (default 0 = no retry)
Returns
true if the value read back as written; false if it did not, or if the port's transfer() reported a bus error

The documentation for this class was generated from the following files: