|
HF-AS5047U Driver
0.1.0-dev
HF-AS5047U C++ Driver
|
Portable C++20 driver for the AS5047U magnetic encoder from ams with SPI interface, CRC protection, DAEC, and DFSβ’
π ππ Live Complete Documentation - Interactive guides, examples, and step-by-step tutorials
HF-AS5047U is a portable C++20 driver for the AS5047U magnetic encoder from ams. It delivers fast 14βbit absolute angle readings over SPI, optional CRC protection and advanced features like Dynamic Angle Error Compensation (DAEC) and an adaptive Dynamic Filter System (DFSβ’). The sensor can also output incremental (A/B/I) and 3βphase commutation (UVW) signals or a PWM encoded angle, making it a dropβin replacement for optical encoders in high-performance motor control and robotics.
The driver uses a CRTP-based SpiInterface for hardware abstraction, allowing it to run on any platform (ESP32, STM32, Arduino, etc.) with zero runtime overhead. It implements all major features from the AS5047U datasheet including absolute angle readout with/without DAEC, velocity measurement, AGC and magnetic field diagnostics, ABI/UVW/PWM interface configuration, error/status flag handling, and full OTP programming sequence.
For detailed setup, see Installation and Quick Start Guide.
For detailed installation instructions, see docs/installation.md.
| Method | Description |
|---|---|
GetAngle(AngleUnit) | Read absolute angle in selected unit (LSB/deg/rad) |
GetVelocity(VelocityUnit) | Read velocity in selected unit (LSB/deg/s/rad/s/RPM) |
GetAngle() | Read 14-bit compensated absolute angle |
GetRawAngle() | Read 14-bit raw absolute angle |
GetVelocity() | Read signed 14-bit velocity (LSB units) |
GetVelocityDegPerSec() | Velocity in degrees/sec |
GetVelocityRPM() | Velocity in revolutions per minute |
GetAGC() | Read AGC (0β255) value |
GetMagnitude() | Read magnetic field magnitude |
GetErrorFlags() | Read and clear error/status flags |
SetZeroPosition() | Set new zero offset |
SetDirection() | Set rotation direction (CW or CCW) |
SetABIResolution() | Set ABI output resolution (10β14 bits) |
SetUVWPolePairs() | Set UVW pole pairs (1β7) |
ConfigureInterface() | Enable/disable ABI, UVW, PWM |
SetDynamicAngleCompensation() | Enable/disable DAEC |
SetAdaptiveFilter() | Enable/disable adaptive filter (DFS) |
SetFilterPreset() | Set filter from preset (LowNoise, Balanced, HighBandwidth) |
GetAdaptiveFilterEnabled() | Read whether adaptive filter is enabled |
GetFilterParameters() | Read current K_min and K_max register codes |
ProgramOTP() | Program current settings into OTP |
For complete API documentation, see docs/api_reference.md.
Compatibility note: the unit-specific helpers (GetAngleDegrees(), GetVelocityRPM(), etc.) remain available for existing code, but new code should prefer the unit-enum overloads.
For ESP32 examples and integration tests, see the examples/esp32 directory.
Detailed example walkthroughs are available in docs/examples.md.
For complete documentation, see the docs directory.
Pull requests and suggestions are welcome! Please follow the existing code style and include tests for new features.
This project is licensed under the GNU General Public License v3.0. See the [LICENSE](LICENSE) file for details.