|
HF-AS5047U Driver
0.1.0-dev
HF-AS5047U C++ Driver
|
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 and clear error flags. | |
| 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 () |
| Permanently program current settings into OTP memory. | |
| 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 | WriteReg (const RegT ®, uint8_t retries=AS5047U_CFG::CRC_RETRIES) |
| Writes data to a specified register in the AS5047U sensor. | |
| AS5047U_Error | GetStickyErrorFlags () const |
| Retrieve and clear the accumulated 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. | |
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.
| SpiType | The SPI bus type (must inherit from as5047u::SpiInterface<SpiType>) |
|
explicitnoexcept |
Construct a new AS5047U encoder driver.
| bus | Reference to an SPI interface implementation. |
| format | SPI frame format to use (16-bit, 24-bit, or 32-bit). Default is 16-bit frames. |
|
default |
|
inlinestaticconstexpr |
Compute the CRC8 value used by AS5047U SPI frames.
| 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:
abi is true and uvw false, ABI outputs are enabled and PWM (if enabled) is on W pin.uvw is true and abi false, UVW outputs are enabled and PWM (if enabled) is on I pin.abi and uvw are true, both interfaces are active (PWM not available in this mode).| abi | Enable ABI (A, B, I) outputs. |
| uvw | Enable UVW commutation outputs. |
| pwm | Enable PWM output on the appropriate pin (W if UVW disabled, I if ABI disabled). |
| void as5047u::AS5047U< SpiType >::DumpStatus | ( | ) | const |
Dump formatted status and diagnostics using printf.
| bool as5047u::AS5047U< SpiType >::GetAdaptiveFilterEnabled | ( | uint8_t | retries = AS5047U_CFG::CRC_RETRIES | ) | const |
Read whether the adaptive filter is enabled.
| uint8_t as5047u::AS5047U< SpiType >::GetAGC | ( | uint8_t | retries = AS5047U_CFG::CRC_RETRIES | ) | const |
Read the current Automatic Gain Control (AGC) value (0-255).
| retries | Number of retries on CRC/framing error (default 0 = no retry). |
| float as5047u::AS5047U< SpiType >::GetAngle | ( | AngleUnit | unit, |
| uint8_t | retries = AS5047U_CFG::CRC_RETRIES ) const |
Read absolute angle in caller-selected unit.
| unit | Output unit (LSB / degrees / radians). |
| retries | Number of retries on CRC/framing error (default 0 = no retry). |
| 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).
| retries | Number of retries on CRC/framing error (default 0 = no retry). |
| float as5047u::AS5047U< SpiType >::GetAngleDegrees | ( | uint8_t | retries = AS5047U_CFG::CRC_RETRIES | ) | const |
Read absolute angle in degrees.
| retries | Number of retries on CRC/framing error (default 0 = no retry). |
| AS5047U_REG::SETTINGS2::AngleOutputSource as5047u::AS5047U< SpiType >::GetAngleOutputSource | ( | ) | const |
Get currently selected angle output source for 0x3FFF reads.
| float as5047u::AS5047U< SpiType >::GetAngleRadians | ( | uint8_t | retries = AS5047U_CFG::CRC_RETRIES | ) | const |
Read absolute angle in radians.
| retries | Number of retries on CRC/framing error (default 0 = no retry). |
| AS5047U_REG::DIA as5047u::AS5047U< SpiType >::GetDiagnostics | ( | ) | const |
Read the full diagnostic register (DIA).
|
inlinestaticconstexprnoexcept |
Get the compiled driver version string.
|
inlinestaticconstexprnoexcept |
Get the compiled driver major version number.
|
inlinestaticconstexprnoexcept |
Get the compiled driver minor version number.
|
inlinestaticconstexprnoexcept |
Get the compiled driver patch version number.
| uint16_t as5047u::AS5047U< SpiType >::GetErrorFlags | ( | uint8_t | retries = AS5047U_CFG::CRC_RETRIES | ) | const |
Read and clear error flags.
| retries | Number of retries on CRC/framing error (default 0 = no retry). |
| 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).
| AS5047U_REG::SETTINGS3::Hysteresis as5047u::AS5047U< SpiType >::GetHysteresis | ( | ) | const |
Get current incremental output hysteresis setting.
| uint16_t as5047u::AS5047U< SpiType >::GetMagnitude | ( | uint8_t | retries = AS5047U_CFG::CRC_RETRIES | ) | const |
Read the current magnetic field magnitude (14-bit value).
| retries | Number of retries on CRC/framing error (default 0 = no retry). |
| 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).
| retries | Number of retries on CRC/framing error (default 0 = no retry). |
| AS5047U_Error as5047u::AS5047U< SpiType >::GetStickyErrorFlags | ( | ) | const |
Retrieve and clear the accumulated sticky error flags.
| int16_t as5047u::AS5047U< SpiType >::GetVelocity | ( | uint8_t | retries = AS5047U_CFG::CRC_RETRIES | ) | const |
Read the current rotational velocity (signed 14-bit).
| retries | Number of retries on CRC/framing error (default 0 = no retry). |
| float as5047u::AS5047U< SpiType >::GetVelocity | ( | VelocityUnit | unit, |
| uint8_t | retries = AS5047U_CFG::CRC_RETRIES ) const |
Read rotational velocity in caller-selected unit.
| unit | Output unit (LSB / deg/s / rad/s / RPM). |
| retries | Number of retries on CRC/framing error (default 0 = no retry). |
| float as5047u::AS5047U< SpiType >::GetVelocityDegPerSec | ( | uint8_t | retries = AS5047U_CFG::CRC_RETRIES | ) | const |
Get rotational velocity in degrees per second.
| retries | Number of retries on CRC/framing error (default 0 = no retry). |
| float as5047u::AS5047U< SpiType >::GetVelocityRadPerSec | ( | uint8_t | retries = AS5047U_CFG::CRC_RETRIES | ) | const |
Get rotational velocity in radians per second.
| retries | Number of retries on CRC/framing error (default 0 = no retry). |
| float as5047u::AS5047U< SpiType >::GetVelocityRPM | ( | uint8_t | retries = AS5047U_CFG::CRC_RETRIES | ) | const |
Get rotational velocity in revolutions per minute.
| retries | Number of retries on CRC/framing error (default 0 = no retry). |
| uint16_t as5047u::AS5047U< SpiType >::GetZeroPosition | ( | uint8_t | retries = AS5047U_CFG::CRC_RETRIES | ) | const |
Get the currently configured soft zero position offset (14-bit).
| retries | Number of retries on CRC/framing error (default 0 = no retry). |
| bool as5047u::AS5047U< SpiType >::ProgramOTP | ( | ) |
Permanently program current settings into OTP memory.
Performs the full OTP programming sequence:
|
inline |
Reads data from a specified register in the AS5047U sensor.
| RegT | The register type which must have an ADDRESS static member and be decodable |
This method reads the raw value from the specified register address and decodes it into a strongly-typed register object.
| 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.
| enable | True for 150°C mode (NOISESET=1), false for low-noise (NOISESET=0). |
| bool as5047u::AS5047U< SpiType >::SetABIResolution | ( | uint8_t | resolution_bits, |
| uint8_t | retries = AS5047U_CFG::CRC_RETRIES ) |
Set the ABI (incremental encoder) resolution.
| resolution_bits | Resolution in bits (10 to 14 bits). |
| bool as5047u::AS5047U< SpiType >::SetAdaptiveFilter | ( | bool | enable, |
| uint8_t | retries = AS5047U_CFG::CRC_RETRIES ) |
Enable/disable the adaptive filter (Dynamic Filter System).
| 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.
| source | Angle output source:
|
|
inline |
Define the rotation direction for increasing angle.
Writes SETTINGS2 (0x0019) bit 2 (DIR) per datasheet Fig.47: 0 = CW default, 1 = invert direction.
| clockwise | If true, clockwise yields increasing angle (DIR=0). If false, invert direction (DIR=1). |
| retries | Number of retries on CRC/framing error (default 0 = no retry). |
| bool as5047u::AS5047U< SpiType >::SetDynamicAngleCompensation | ( | bool | enable, |
| uint8_t | retries = AS5047U_CFG::CRC_RETRIES ) |
Enable/disable Dynamic Angle Error Compensation (DAEC).
| 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.
| 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).
|
noexcept |
Set the SPI frame format (16, 24, or 32-bit).
| format | The desired SPI frame format. |
| 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.
| hysteresis | Hysteresis level:
|
| bool as5047u::AS5047U< SpiType >::SetIndexPulseLength | ( | uint8_t | lsb_len, |
| uint8_t | retries = AS5047U_CFG::CRC_RETRIES ) |
Set the index pulse width for ABI output.
| lsb_len | Index pulse length in LSB periods (3 or 1). |
|
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.
| pad | Pad byte value (0x00–0xFF) to send as the MSB of each 32-bit transfer. |
| 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.
| pairs | Number of pole pairs (1-7). |
| bool as5047u::AS5047U< SpiType >::SetZeroPosition | ( | uint16_t | angle_lsb, |
| uint8_t | retries = AS5047U_CFG::CRC_RETRIES ) |
Set a new zero reference position (soft offset).
| angle_lsb | 14-bit angle value that should be treated as 0°. |
|
inline |
Writes data to a specified register in the AS5047U sensor.
| RegT | The register type which must have an ADDRESS static member and be encodable |
| reg | The register object containing the data to be written |
| retries | Number of retries on CRC/framing error (default 0 = no retry) |