thumbnail image

  • Home
  • About 
    • Core Values
    • Updates
    • Global Community
  • Learn 
    • ACE-Lab
    • ACE-CORE
  • Build 
    • Build You Own ACE-Lab
    • Automate with Agentic
  • …  
    • Home
    • About 
      • Core Values
      • Updates
      • Global Community
    • Learn 
      • ACE-Lab
      • ACE-CORE
    • Build 
      • Build You Own ACE-Lab
      • Automate with Agentic
Contact

  • Home
  • About 
    • Core Values
    • Updates
    • Global Community
  • Learn 
    • ACE-Lab
    • ACE-CORE
  • Build 
    • Build You Own ACE-Lab
    • Automate with Agentic
  • …  
    • Home
    • About 
      • Core Values
      • Updates
      • Global Community
    • Learn 
      • ACE-Lab
      • ACE-CORE
    • Build 
      • Build You Own ACE-Lab
      • Automate with Agentic
Contact
  • DC Motor Encoder Measurement and Filtering | ACE-Lab

    Operate · O05 · Control Engineering

    DC Motor Encoder Measurement and Filtering

    Convert encoder counts into motor speed in RPM, capture the result in Simulink, and filter the measurement so it is suitable for analysis and closed-loop feedback.

    Contents

    Key Learning Outcomes From Motor Rotation to Encoder Counts Hardware Set-Up Calculating Speed from Encoder Counts Simulink Measurement Chain Filtering the Speed Measurement Data Logging and Interpretation Additional Modelling Exercise Reflective Questions Useful Resources Concluding Remarks

    Key Learning Outcomes

    By the end of this section, you should be able to:

    01

    Configure a DC motor, motor driver and encoder so that rotational position can be measured by the Arduino Uno.

    02

    Calculate motor speed in RPM from the change in encoder count over a known sampling interval.

    03

    Implement the encoder-to-RPM processing chain in Simulink and capture input/output data for analysis.

    04

    Filter and evaluate the measured speed signal, then use the data as the basis for motor modelling and closed-loop feedback control.

    From Motor Rotation to Encoder Counts

    The encoder provides a discrete measurement of motor position. As the motor rotates, the encoder count changes. The change in count over a known sampling interval can therefore be used to estimate rotational speed.

    For the motor used in this exercise, the encoder provides 12 impulses per motor revolution and the gearbox ratio is 298:1. These two quantities are used to convert encoder movement into output-shaft revolutions.

    Why the measurement matters: a feedback controller can only respond to the information supplied by its measurement signal. Converting raw encoder counts into a stable, physically meaningful RPM signal is therefore an important part of the control-system implementation, rather than simply a data-processing task.

    Hardware Set-Up

    The Arduino controls the Maker Drive motor driver, while the encoder provides the measurement needed to determine rotational speed. In the source Simulink configuration, encoder channels A and B are connected to Arduino pins 2 and 3.

    Hardware setup for DC motor speed measurement using encoder
    Figure 1: Hardware Set Up for DC Motor Speed Measurement using Encoder
    Connect the DC motor to the Maker Drive motor output terminals.
    Connect the 9 V battery to the motor-power input and connect battery negative to the Maker Drive ground.
    Connect Arduino GND to Maker Drive GND so the control signals share a common reference.
    Connect the Arduino control pins to the Maker Drive inputs used for motor direction and PWM speed command.
    Connect the encoder A and B signals to suitable Arduino inputs; the source model uses pins 2 and 3.
    Connect the Arduino to the computer by USB and verify the wiring before running the motor.

    Calculating Speed from Encoder Counts

    The source exercise uses a backward difference, described as the Backward Euler approximation, to estimate how quickly the encoder position is changing:

    count rate[k] = (N[k] − N[k−1]) / Ts
    (1)

    That count rate is then converted into output-shaft RPM using the encoder resolution and gearbox ratio:

    RPM[k] = ((N[k] − N[k−1]) / Ts) · 60 / (12 · 298)
    (2)

    For a sampling interval of 0.01 s, the conversion can be implemented as a single lumped gain:

    60 / (0.01 · 12 · 298) ≈ 1.678
    (3)
    Interpretation: the Unit Delay provides N[k−1]. Subtracting the previous count from the current count gives the encoder movement during one sample. The gain then converts that movement into RPM.

    Simulink Measurement Chain

    The exercise applies a full PWM input of 255 to the motor and simultaneously captures encoder data. A Unit Delay and summation block form the discrete difference, and gain blocks convert the result into RPM. Goto/From blocks and Scope logging are used to collect the input and output signals.

    Simulink input voltage applied to DC motor with encoder measurement
    Figure 2: Input Voltage Applied to the DC Motor with an Encoder
    Encoder data capture and RPM conversion configuration in Simulink
    Figure 3: Encoder Data Capture and Configuration using Simulink
    Combined Simulink encoder and motor input model
    (a) Combined Simulink model
    Encoder count scope output
    (b) Encoder count output
    Measured RPM scope output
    (c) RPM output
    Figure 4: Encoder Data Capture and Configuration using Simulink (With One Gain Block used for the Main Components)
    Source check: the written equation in the speed-measurement document describes division by Ts. One embedded figure shows an intermediate gain labelled 0.01, while the combined implementation uses 60/0.01. The page therefore follows the written equation and the combined gain.

    Filtering the Speed Measurement

    Taking the discrete difference of encoder counts makes changes in position visible, but it also makes quantisation and rapid count-to-count variation visible. A low-pass filter can be used to produce a smoother speed signal before it is used for feedback.

    A first-order discrete low-pass filter is used to smooth the measured RPM signal:

    H(z) = 0.0198 / (1 − 0.9802 z−1)
    (4)

    Equivalently, the filter can be viewed as the recurrence:

    yf[k] = 0.9802 yf[k−1] + 0.0198 y[k]
    (5)
    Filtering trade-off: stronger smoothing reduces measurement noise, but it also adds delay. This matters whenever the filtered RPM signal is used as feedback in a closed-loop controller.
    Scope showing unfiltered, rejected and filtered motor speed data from the PI control exercise
    Figure 5: Example unfiltered, data-rejection and filtered motor-speed signals

    Data Logging and Interpretation

    Within each Scope block, the source exercise enables Log data to workspace and selects Structure with time. Goto/From blocks are used to route the applied input and measured RPM to scopes so that the motor response can be analysed after the experiment.

    • The PWM input provides the known excitation applied to the motor.
    • The encoder-derived RPM provides the measured system output.
    • Unfiltered and filtered signals can be retained together so the effect of filtering remains visible.
    • The observed speed response is described in the source exercise as having the form of a first-order system.

    Additional Exercise: Develop a Motor Model

    Using the measured RPM response, develop a mathematical model that captures the main motor dynamics. Plot the measured RPM and model output together, then quantify the fit using the mean squared error (MSE).

    MSE = (1/n) Σ (y[k] − ŷ[k])²
    (6)

    This provides a bridge from direct measurement to model-based control design: the same experimental data can be used both to understand the physical motor and to create a model for controller development.

    Reflective Questions

    Click on a question block to reveal the suggested answer.

    Suggested answer: Speed is estimated from the change in position. The Unit Delay stores the previous encoder count N[k−1] so that it can be subtracted from the current count N[k].
    Suggested answer: The encoder count is measured on the motor side. The 12 impulses per revolution and 298:1 gearbox determine how many encoder counts correspond to one output-shaft revolution.
    Suggested answer: The measurement becomes smoother and less sensitive to rapid count-to-count variation, but the filter adds lag. That lag matters when the signal is later used inside a feedback loop.
    Suggested answer: Together they form an input-output data set. That data can be used to inspect the motor response, compare filtering choices and develop a mathematical model of the plant.

    Useful Resources

    MathWorks

    Arduino Encoder Block

    Official Simulink Support Package reference for measuring quadrature-encoder tick count and direction with Arduino hardware.

    Open resource
    MathWorks

    Discrete Filter Block

    Reference for implementing fixed-coefficient discrete IIR filters in Simulink.

    Open resource
    MathWorks

    Arduino Hardware Getting Started

    A useful reference for building, configuring and running Simulink models on Arduino hardware.

    Open resource

    Concluding Remarks

    This section has converted encoder position counts into a physically meaningful speed measurement in RPM. The processing chain combines a discrete difference, encoder/gearbox scaling and a low-pass filter to create a signal that can be used for analysis and feedback.

    The resulting filtered RPM signal provides a practical measurement that can be used for analysis, modelling and closed-loop motor-speed control.

Terms and Conditions Returns & Refunds Privacy Policy

Cookie Use
We use cookies to ensure a smooth browsing experience. By continuing we assume you accept the use of cookies.
Learn More