You can also configure the driver by editing inc/as5047u_config.hpp:
1
2
3
4
5
6
7
namespaceAS5047U_CFG{// Default SPI frame formatinlineconstexprFrameFormatDEFAULT_FRAME_FORMAT=FrameFormat::SPI_24;// Number of CRC retries (0 = no retry)inlineconstexpruint8_tCRC_RETRIES=3;}
Runtime Configuration
SPI Frame Format
The driver supports three SPI frame formats:
1
2
3
4
5
6
7
8
// 16-bit frames (no CRC, highest throughput)as5047u::AS5047Uencoder(spi,FrameFormat::SPI_16);// 24-bit frames (includes 8-bit CRC, recommended)as5047u::AS5047Uencoder(spi,FrameFormat::SPI_24);// 32-bit frames (includes 8-bit CRC + 8-bit pad for daisy-chain)as5047u::AS5047Uencoder(spi,FrameFormat::SPI_32);
Recommendation: Use SPI_24 for most applications - it provides CRC protection with good throughput.
Change Frame Format at Runtime
1
encoder.SetFrameFormat(FrameFormat::SPI_24);
Sensor Configuration
Zero Position
Set the zero reference position (soft offset):
1
2
3
4
5
6
// Set zero position to current angleuint16_tcurrent_angle=encoder.GetAngle();encoder.SetZeroPosition(current_angle);// Or set a specific value (0-16383)encoder.SetZeroPosition(8192);// 180 degrees
DAEC provides low-latency angle correction for high-speed applications:
1
2
3
4
5
// Enable DAEC (recommended for high-speed applications)encoder.SetDynamicAngleCompensation(true);// Disable DAEC (use raw angle)encoder.SetDynamicAngleCompensation(false);
Adaptive Filter (DFS™)
The Dynamic Filter System adaptively filters noise:
1
2
3
4
5
6
7
// Enable adaptive filterencoder.SetAdaptiveFilter(true);// Set filter parameters (K_min, K_max)// K_min: minimum filter strength (0-15)// K_max: maximum filter strength (0-15)encoder.SetFilterParameters(2,3);
Angle Output Source
Select which angle is used for outputs (ABI, UVW, PWM):
1
2
3
4
5
// Use compensated angle (with DAEC)encoder.SetAngleOutputSource(AS5047U_REG::SETTINGS2::AngleOutputSource::Compensated);// Use raw angle (without DAEC)encoder.SetAngleOutputSource(AS5047U_REG::SETTINGS2::AngleOutputSource::Raw);
Output Configuration
ABI (Incremental Encoder) Output
Configure incremental encoder outputs (A, B, I):
1
2
3
4
5
6
7
8
// Set resolution (10-14 bits)encoder.SetABIResolution(12);// 12-bit = 4096 PPR// Set index pulse length (1 or 3 LSB periods)encoder.SetIndexPulseLength(1);// Enable ABI outputencoder.ConfigureInterface(true,false,false);// ABI only
UVW (Commutation) Output
Configure 3-phase commutation outputs:
1
2
3
4
5
// Set number of pole pairs (1-7)encoder.SetUVWPolePairs(5);// 5 pole pairs// Enable UVW outputencoder.ConfigureInterface(false,true,false);// UVW only
PWM Output
Configure PWM-encoded angle output:
1
2
3
// Enable PWM output// PWM appears on W pin if ABI enabled, or I pin if UVW enabledencoder.ConfigureInterface(true,false,true);// ABI + PWM
Combined Outputs
1
2
3
4
5
// Enable both ABI and UVW (PWM not available in this mode)encoder.ConfigureInterface(true,true,false);// Enable ABI with PWM on W pinencoder.ConfigureInterface(true,false,true);
Advanced Configuration
Hysteresis
Set incremental output hysteresis to reduce jitter:
1
2
// Set hysteresis levelencoder.SetHysteresis(AS5047U_REG::SETTINGS3::Hysteresis::LSB_1);
High-Temperature Mode
Enable 150°C operation mode:
1
encoder.Set150CTemperatureMode(true);
OTP Programming
Program current settings into OTP (One-Time Programmable) memory for permanent configuration:
1
2
3
4
5
6
7
8
9
10
11
// Configure all settings firstencoder.SetZeroPosition(0);encoder.SetDirection(true);encoder.SetABIResolution(12);// ... other settings// Program to OTP (one-time operation, cannot be undone)boolsuccess=encoder.ProgramOTP();if(success){// Settings are now permanent}
Warning: OTP programming is irreversible. Make sure all settings are correct before programming.
CRC Retry Configuration
Configure automatic retry on CRC errors:
1
2
3
4
5
// Read with automatic retry (3 attempts)uint16_tangle=encoder.GetAngle(3);// Or set default retries in config// AS5047U_CFG::CRC_RETRIES = 3;