AS5304 magnetic encoder and AS5000-MR20-44 ring magnet for Micromouse Robot - Main Features of AS5304A and AS5000-MR20-44, Design Considerations, Combining AS5304 with STM32 Encoder Mode


AS5304 magnetic encoder and AS5000-MR20-44 ring magnet for Micromouse Robot - Main Features of AS5304A and AS5000-MR20-44, Design Considerations, Combining AS5304 with STM32 Encoder Mode

The AS5304 is a compact magnetic rotary encoder IC widely used in precision motor control applications. In a Micromouse robot, accurate wheel position and speed measurement are essential for stable movement, wall following, and precise maze navigation. The AS5304 provides a reliable solution for detecting rotational motion without physical contact, making it highly suitable for high-speed autonomous robots.

What is the AS5304 and AS5000-MR20-44?

The AS5304 is a magnetic incremental encoder sensor developed by ams OSRAM. It detects the rotation of a magnetic pole wheel and generates quadrature output signals similar to optical encoders.

Unlike traditional optical encoders, magnetic encoders are:

  • More resistant to dust and vibration
  • Smaller in size
  • MicromouseAS5304A
    Easier to integrate into compact robots
  • More durable in harsh environments


The AS5000-MR20-44 is a ferrite multipole ring magnet with 44 poles and a pole length of 2.0 mm. It is designed for use with linear position magnetic encoders in off-axis rotary applications. Part Number naming convention breaks down as follows:

  • M = Magnet
  • R = Ring
  • 20 = Nominal pole length in 1/10 mm (i.e., 2.0 mm), corresponding to the AS5304 encoder
  • 44 = Number of poles

Why Micromouse Needs an Encoder

A Micromouse robot relies heavily on encoder feedback for:

  • Speed control
  • Distance measurement
  • Accurate turning
  • Position tracking
  • PID motor control
  • Maze mapping algorithms

Without an encoder, the robot cannot determine:

  • How far it moved
  • Whether both wheels rotate equally
  • If the robot drifted during motion
  • Exact turning angles

The AS5304A allows the robot controller to continuously monitor wheel rotation with high precision.


Operating Principle

The AS5304 works together with a magnetic ring or magnetic pole wheel attached to the motor shaft.

As the shaft rotates:

  1. Magnetic poles pass over the sensor
  2. Internal Hall sensors detect magnetic changes
  3. The IC generates:

    • Channel A pulse
    • Channel B pulse

      4. Quadrature signals indicate:

    • Rotation speed
    • Rotation direction

This method is similar to optical quadrature encoders but uses magnetic sensing instead of light interruption.


Main Features of AS5304

  1. Incremental Quadrature Output

  The encoder outputs two square wave signals:

  • A phase
  • B phase

  These signals are 90 degrees out of phase.

  The MCU can determine:

  • Rotation count
  • Direction
  • Speed

  This is ideal for STM32 timer encoder mode.

  2. Compact Size

  Micromouse robots require extremely compact electronics.

  The AS5304:

  • Occupies very little PCB area
  • Fits near micro metal gear motors
  • Supports lightweight robot designs

  3. Non-Contact Sensing

  Since there is no physical contact:

  • Mechanical wear is reduced
  • Reliability increases
  • Long-term accuracy improves

  This is important for repeated maze competitions.

  4. High Speed Capability

  Micromouse robots can move at very high speeds.

  The AS5304 supports fast rotational detection suitable for:

  • Speed runs
  • Acceleration control
  • High RPM gear motors


Main Features of AS5000-MR20-44

MicromouseRingMagnet
  Physical Specifications

  • Outer Diameter (OD): 32 mm
  • Inner Diameter (ID): 24 mm
  • Thickness (T): 1.5 mm
  • Pole Length: 2.0 mm
  • Number of Poles: 44
  • Shape: Ring
  • Material: Plastic bonded Ferrite
  • Magnet Type: Permanent magnet


  Design & Sensor Placement

  The correct measurement radius for the MR20-44 magnet ring is calculated using the formula:

  r_m = (pole_length × number_of_poles) / (2π) = (2.0 × 44) / (2π) ≈ 14.01 mm

  The measurement radius should coincide with the Hall sensor array on the chip.

  For the TSSOP-20 package, the Hall sensor array is located 1.02 mm above the horizontal centerline, or 4.22 mm above the edge of the pins.

  Compatible Encoder IC

  This magnet is specifically designed to pair with the AMS AS5304 (and related AS5306) linear incremental position sensor ICs, which use Hall-effect sensing for off-axis rotary position detection.


Typical Micromouse Encoder System

A typical encoder assembly contains:

  Components

  • DC gear motor
  • Magnet ring or pole wheel
  • AS5304A sensor PCB
  • STM32 microcontroller

  Working Flow

  Motor Shaft Rotation
        ↓
  Magnetic Pole Movement
        ↓
  AS5304A Detection
        ↓
  Quadrature Pulse Output
        ↓
  STM32 Timer Encoder Interface
        ↓
  Speed and Position Calculation

Connection with STM32

The AS5304 is commonly connected to STM32 timers configured in encoder mode.

Example Pins

AS5304STM32
A OutputTIMx_CH1
B OutputTIMx_CH2
VCC3.3V
GNDGND

The STM32 hardware timer automatically counts encoder pulses.


Encoder Resolution

Encoder resolution determines how accurately wheel movement can be measured.

Higher resolution provides:

  • Encoder pulse : 3420
  • Better distance calculation
  • Smoother speed control
  • More accurate turning

However:

  • CPU interrupt load may increase
  • Signal quality becomes more important

Micromouse designers must balance:

  • Speed
  • Resolution
  • Processing capability


Using Encoder Feedback in Micromouse

  1. Speed PID Control

  Encoder pulses allow real-time speed measurement.

  The PID controller compares:

  Target Speed - Actual Speed

  Then motor PWM is adjusted automatically.

  Benefits:

  • Stable movement
  • Straight driving
  • Better acceleration control

  2. Accurate Turning

  During a 90° turn:

  • Encoder counts measure wheel rotation
  • Robot stops exactly at target angle

  This improves:

  • Corner precision
  • Maze alignment
  • Path consistency

  3. Distance Measurement

  The robot calculates travel distance using:

  Distance = Wheel Circumference × Rotation Count

  Accurate distance measurement is critical for:

  • Cell-to-cell movement
  • Flood-fill algorithms
  • Position estimation


Advantages over Optical Encoders

Magnetic EncoderOptical Encoder
Dust resistantSensitive to dust
CompactLarger structure
DurableMore fragile
Lower maintenanceRequires cleaner environment
Easier assemblyMore alignment sensitive

For compact robots like Micromouse, magnetic encoders are often preferred.


Design Considerations

  Magnet Alignment

  The magnet must align correctly with the sensor.

  Poor alignment can cause:

  • Missed pulses
  • Signal instability
  • Position errors

  PCB Placement

  Keep:

  • Stable spacing
  • Minimal vibration
  • Proper shielding from motor noise

  Good PCB layout improves signal reliability.

  Signal Filtering

  Motor noise can introduce encoder errors.

  Common solutions:

  • Pull-up resistors
  • Capacitors
  • Software debouncing
  • Hardware filtering

  Summary Table

ParameterValue
Part NumberAS5000-MR20-44
ShapeRing
OD × ID × Thickness32 mm × 24 mm × 1.5 mm
Number of Poles44
Pole Length2.0 mm
MaterialPlastic Bonded Ferrite
Magnet TypePermanent
Compatible ICAS5304 / AS5306
ApplicationEncoder / Position Sensor


Combining AS5304 with STM32 Encoder Mode

The STM32 timer encoder interface works exceptionally well with the AS5304.

MicromouseAS5304Applied
Advantages include:

  • Hardware pulse counting
  • Reduced CPU usage
  • Accurate direction detection
  • High-speed operation

Popular STM32 MCUs used in Micromouse:

  • STM32F411CEU6 ->
  • STM32F405RG
  • STM32G431CBU6
Micromouse encoder coding :

// units are all in counts and counts per second

void CDriveEncoders::update_encoders() {


int32_t left_delta;

int32_t right_delta;


float left_change ;

float right_change ;


// write code here what you need


left_total = LEnc();

right_total = REnc();


left_delta = LEnc()- prevLEnc;

right_delta = REnc()- prevREnc;


prevLEnc = left_total ;

prevREnc = right_total;


left_change = left_delta * MM_PER_COUNT_LEFT;

right_change = right_delta * MM_PER_COUNT_RIGHT;


s_robot_fwd_increment = 0.5f * (right_change + left_change);

s_robot_rot_increment = (right_change - left_change) * DEG_PER_MM_DIFFERENCE;


s_robot_position += s_robot_fwd_increment;

s_robot_angle += s_robot_rot_increment;


}


PID Controll coding :


float CBody::position_controller() {


objMindForward.update();


// write code here what you need

fwd_error += objMindForward.increment() - objArms.robot_fwd_increment();

float diff = fwd_error - old_fwd_error;

old_fwd_error = fwd_error;

float output = FWD_KP * fwd_error + FWD_KD * diff;


return output;

}


float CBody::angle_controller() {


objMindRotation.update();


// write code here what you need

rot_error += objMindRotation.increment() - objArms.robot_rot_increment();

if (objEyes.steering_enabled) {

rot_error += steering_adjustment;

}

float diff = rot_error - old_rot_error;

old_rot_error = rot_error;

float output =ROT_KP * rot_error + ROT_KD * diff;


return output;

}



Conclusion

The AS5304A magnetic encoder is an excellent choice for Micromouse robots requiring precise motor feedback in a compact form factor. Its magnetic sensing method provides strong resistance to dust and vibration while delivering reliable quadrature signals for accurate motion control.

When combined with an STM32 microcontroller and proper PID algorithms, the AS5304 enables:

  • Stable high-speed driving
  • Precise turning
  • Accurate odometry
  • Improved maze-solving performance

For modern Micromouse designs focused on speed, precision, and reliability, magnetic encoders like the AS5304 are becoming increasingly popular.


Comments

Popular posts from this blog

How to Build a Micromouse Robot - Mechanical, Hardware, Software

Micromouse Competitions - Types, Overview, Comparison, Advantages, Worldwide

Complete Guide to Micromouse Maze - Dimensions, Structure and Components, Building