Skip to content

drivers/sensors: Add AS5047D magnetic encoder driver#18802

Open
DheerajSingh1107 wants to merge 1 commit intoapache:masterfrom
DheerajSingh1107:feature/as5047d-driver
Open

drivers/sensors: Add AS5047D magnetic encoder driver#18802
DheerajSingh1107 wants to merge 1 commit intoapache:masterfrom
DheerajSingh1107:feature/as5047d-driver

Conversation

@DheerajSingh1107
Copy link
Copy Markdown

Summary

This PR adds a new SPI-based magnetic encoder driver for the AMS AS5047D.

The AS5047D is a 14-bit on-axis magnetic rotary encoder that communicates over SPI and is commonly used in motor control and robotics applications requiring precise angular position feedback.

This driver provides:

  • 14-bit angular position readout (0–16383)
  • SPI communication interface compatible with NuttX SPI framework
  • Basic error detection using status bits from the device

The implementation follows existing NuttX sensor driver patterns and is designed to be reusable across supported boards.

Impact

  • New Feature: Adds support for AS5047D encoder
  • No breaking changes: Existing drivers and subsystems are unaffected
  • Hardware: Requires an SPI interface (tested on STM32F4 SPI3)
  • Build: Adds a new driver option (must be enabled via config)
  • Use case: Motor control, robotics, FOC systems requiring precise angle feedback

No impact on existing APIs or backward compatibility.

Testing

Tested on:

  • Board: STM32F446re (SPI3)
  • Setup: AS5047D connected via SPI with proper CS handling

Test Procedure:

  1. Initialized SPI bus and driver in NuttX

  2. Performed continuous angle reads

  3. Verified:

    • Stable 14-bit output range (0–16383)
    • No constant or stuck values
    • Correct response to shaft rotation
  4. Checked error flags in returned data
    Observations:

  • Angle values update correctly with rotation
  • No communication faults observed under normal operation
  • Timing adjustments were required for stable SPI reads
    Logs (example):
image

This adds support for the AMS AS5047D SPI magnetic encoder.

Features:
- 14-bit angle read
- SPI interface
- basic error handling

Tested on STM32F4 with SPI3.

Signed-off-by: Dheeraj Singh <Dheerajsingh1107@gmail.com>
@github-actions github-actions Bot added Area: Sensors Sensors issues Size: L The size of the change in this PR is large labels Apr 24, 2026
Copy link
Copy Markdown
Contributor

@acassis acassis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DheerajSingh1107 thank you for your contribution, please align the CMakelist:

if(CONFIG_SENSORS_AS5047D)
  list(APPEND SRCS as5047d.c)
endif()

@linguini1
Copy link
Copy Markdown
Contributor

Please add documentation for this driver :)

@acassis
Copy link
Copy Markdown
Contributor

acassis commented Apr 26, 2026

@DheerajSingh1107 please take a look at this PR I submitted to MT6816 (#18807) and add a board config to some board you are using with it and Documentation to your AS5047D, this way a new user will be able to get it working easily

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Sensors Sensors issues Size: L The size of the change in this PR is large

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants