Beginners Guide to the Quadrature Encoder

What is a quadrature encoder?

Quadrature encoders are a type of sensor used to detect the motion of a mechanical system. They are commonly used to detect the speed and angular rotation (total revolutions) of a device such as a motor or motor driven shaft. They may also be used to detect linear motion.

This brief explores quadrature encoder concepts using the large mechanism shown in Figure 1. This was built using industrial control and automation components offered by DigiKey. The size is ideal from an education perspective as the individual components can readily be identified. More importantly, the mechanism allows us to see the relative angles of the rotating interrupter disk and the twin phase sensors. This is further aided by the slow rotation and the visual indicators provided by the Banner Engineering DS18V6LP phase sensors prominently displayed on the front of the mechanism.

Figure 1: Picture of a quadrature encoder featuring a Phase Dock 1007 Wokbench base, 3D printed components, and a selection of industrial components offered by DigiKey.

Are the design files for the quadrature encoder available?

Here are the design files for the encoder and motor brackets. If you do make a copy or modify the design, kindly include pictures in the space below. Also, your questions and comments are welcomed.

Quadrature Encoder Files.zip (1.6 MB)

What is meant by the terms incremental and absolute?

The term incremental is often used to describe the quadrature encoder. Here, incremental means small change as in, “a small increment of time or a small change in position.” While this is true, the term is better understood when used to describe a system featuring a quadrature encoder and the associated logic such as a microcontroller or Programmable Logic Controller (PLC). The system’s logic controller monitors the quadrature encoder and then increments or decrements a variable in response to the quadrature encoder’s outputs. Consequently, the term incremental is more closely associated with the controller than with the sensor. Another way to look at this is to recognize that the quadrature encoder itself has no absolute position information. Instead, it is the logic controller that must process and maintain position. This is a challenging time-sensitive operation. Any deviation and the position information will be lost resulting in a floundering mechanical system. Likewise, a loss of power will corrupt the controllers reckoning of position.

Tech Tip: Loss of position for a quadrature encoder-based system is highly undesirable as a calibration procedure is required upon device startup or at any point where the position information is suspect. In a production setting, this consumes valuable time that could be otherwise been used to manufacture product.

Relationship to the absolute encoder

A related but contrasting sensor is the absolute encoder. With an absolute encoder, the position information is maintained in the encoder itself. The system is immune to power loss as the position information is always available to the encoder’s internal reading mechanism in the same way that a potentiometer always “knows” the resistance.

While this would seem like an advantage, absolute encoders are not common as they are considerably more expensive than their quadrature encoder counterparts for a given performance level. For example, consider a Computer Numerical Control (CNC) machine with a large bed driven by a motor via a ball screw. A simple and inexpensive quadrature encoder attached to the drive motor could be used to track the motion with high resolution. The equivalent absolute encoder would be prohibitively expensive, large, or not available.

To better understand the relationships you are encouraged to study the datasheet for each type of encoder. As a starting point, consider this absolute sensor designed for robotic arm position sensing.

Advantage of a computer-controlled tracking of position

To better the distinction between the two sensors we recognize that a quadrature encoder-based system is largely software based in nature with position maintained in a program using type int or type long int. As a result, the computer-based system with a quadrature encoder could track position with 2^32 or even 2^64 unique steps. By contrast, the operation of an absolute decoder is analog in nature. Here the term analog implies that a series of internal sensors are required to read the position information. For practical applications absolute encoders top out at around 16 bits. This is expected as the encoder size must increase for the size of code and sensors must shrink.

Quadrature encoder with a single absolute position

There is one hybrid exception to the term absolute as applied to the quadrature encoder. As will be shown, some encoders are equipped with an “index” output. This is used to indicate that the quadrature encoder is in a known location. This information may then be used as part of a homing mechanism. We use the term hybrid as the resulting sensor is not an absolute sensor. Instead, we can detect a single position which is often identified as the absolute home position.

What is the meaning of the term quadrature as applied to a quadrature encoder?

Quadrature is a noun describing the angular (mathematical) relationship between two rotating objects. Specifically, it refers to things that have a 90-degree relationship relative to each other. A few examples include:

  • the mathematical relationships described by the sine and cosine functions
  • the quadrature (half-moon) that occurs then the moon is at a right angle to the sun relative to the earth
  • electrical signals used in radio communications systems including the in-phase signal (“I”) and quadrature signal (“Q”) with its 90 degree phase shift
  • electrical signals used in early power distribution systems including Tesla’s famous induction motor.

Tech Tip: Today’s electrical power generation and distribution systems predominately feature a three-phase system where the electrical signals are offset from each other by 120 electrical degrees. This was not always the case, as some early polyphase system featured a quadrature signal. One rudimentary way to develop a quadrature relationship is to physically mount two single phase generators on the same shaft such that the generators are rotated relative to each other to provide the necessary 90-degree phase relationship. The resulting “A” generator produces in the in-phase signal and the “B” generator produces the quadrature signal.

How is the quadrature signal produced in a quadrature encoder?

The term quadrature describes a relationship. To construct a quadrature encoder, we need to place two sensors so that they form a quadrature in relationship to the thing that is being measured. The mechanism shown in Figure 1 and pictured in Video 1 features a rotating disk with slots that will interrupt the beam of the Banner Engineering DS18VP6LP retroreflective sensors. These sensors are physically spaced so that they are in quadrature to the interrupt disk.

Close inspection of Figure 2 shows that the interrupter disk, sensors, and reflectors are a matched trio. The sensors and reflector are spaced so that both sensors may be either blocked or exposed by the interrupter disk. As the disk rotated the sensors develop an on-off pattern of 00, 01, 11, and 10. Technically this is a gray code with a single sensor changing at any given time. If we reverse the direction of rotation, we see a slightly different gray code 00, 10, 11, and 01. These patterns are shown in Video 1 with the forward and reverse operation of the motor.

Figure 2: Close up image showing the relationship between the quadrature sensors, interrupter disk, and reflector. Note that the interrupter disk is sized to either allow or to block both sensors.

Video 1: Operation of the quadrature encoder in the forward and reverse directions.

Tech Tip: The retroreflective sensor is constructed as a compact single body element that integrates both transmitter and receiver. The chosen Banner Engineering sensor featured a transmitter that produces a red visible beam. This beam is returned to the sensor via an optical reflector. The combined purpose of the sensor is to detect an object that breaks the beam. The retroreflective sensors I considerably more capable than suggested by Figure 1. The beam may be detected up to 11.4 ft with proper alignment. Devices with increased range are also available. For example, the same family features devices with a 65.6 ft range.

How is the quadrature encoder integrated with a microcontroller or PLC?

The quadrature encoder is not a freestanding device as it does not directly indicate direction of rotational velocity. Instead, the quadrature encoder must be attached to and monitored by a microcontroller, Programmable Logic Controller (PLC), or other stand-along device.

An oversimplistic view of quadrature encoder integrations suggests a two-steps process. First, we connect the encoder to the associated microcontroller or PLC. Second, we write a few lines of code to capture the associated on-off pattern. In practice things are much more complex as we quickly run headlong into problems with timing. This is not a problem with the encoder, rather it’s a question of programming techniques and speed of the associated microcontroller or PLC collectively referred to as logic.

To better understand, let’s state the fundamental principles of quadrature system integration:

  • The position, direction, and velocity metrics are maintained in the associated logic.

  • The logic must respond to each, and every gray code signal transition developed by the encoder. Loss of even a single transition will result in a mechanical system that is floundering out of control.

For additional information about designing logic for the quadrature encoder please see these previous DigiKey tech forum articles:

Tech Tip: Suppose a quadrature encoder is used for a servo mechanism. Such a system may be expected to hold a mechanical load in a stationary position. An example is a robot arm holding a weight against gravity. In such as situation, we can reasonably expect the arm to physically stop and brake with the encoder at a transition point causing the encoder’s A and B phase outputs to toggle between two code such as 00 and 01. The logic must respond appropriately by bouncing between two positions such as a count of 134,555 and 134,556. A classic mistake is to construct/program logic that incrementally counts in this situation leading to an erroneous position.

What is the index output associated with a quadrature encoder?

Occasionally you will encounter a quadrature encoder with an “index” output. This sensor output provides an absolute indicator that the quadrature encoder is at a known location. This components for the index are seen in Figures 1 and 3. In Figure 1 see locking nut on the face of the interrupter. In Figure 3 we can see the inductive proximity sensor that detects the presence of the screw head.

As for sensor selection, the inductive proximity sensor and associated metal screw were chosen for diversity. Given the nature of the trainer, it is desirable to show a variety of industrial control sensors in action. We should also mention that Pololu makes a variety of metal gearmotors some of which are equipped with integral quadrature encoders physically attached directly to the motor shaft. For an example, please refer to the previously mention Arduino article.

What is the homing algorithm?

Note that the index detection presents a narrow target. Careful programming of the control system is required to first find and then position the mechanism to rest in the home position provided by the index.

You may have seen this homing operation in a 3D printer. As part of the initial calibration procedure the printer will drive each axis to the home position. This typically has four steps:

  • Slowly move the mechanism in the direction of the home position.
  • Stop when home is detected.
  • Reverse until no longer at home.
  • At the slow-slow, advance until the home position is found.
  • Stop and the system has been homed.

Perhaps in a future article we can demonstrate the homing algorithm. This will require a variable speed motor controller to operate the motor at slow and then slow-slow speed. Know that excessive speed would drive the system beyond the index making it very difficult to reach the home position. The typical hardware solution for a servomotor speed is a controller that develops a Pulse Width Modulation (PWM) signal. This is then sent to a dedicated motor drive. An example may be found in this article.

Figure 3 The Omron Z4122 inductive proximity index sensor is located above and 45 degrees to the right of the Pololu #4685 gearmotor. The reflector for the retroreflective sensors is seen below the motor in quadrature to the sensor.

Conclusion

This article serves as a brief introduction to a quadrature encoder suitable for use in an education setting. The large physical size is an important consideration as it allows the phase relationships between the various elements. This leads to a better understanding of the device and to the underlying principles common to all quadrature encoders.

The material could be expanded if there is interest. Also, at some point in the future we will explore the homing feature.

Best Wishes,

APDahlen

Return to the Industrial Control and Automation Index.

About the author

Aaron Dahlen, LCDR USCG (Ret.), serves as an application engineer at DigiKey. He has a unique electronics and automation foundation built over a 27-year military career as a technician and engineer which was further enhanced by 12 years of teaching (interwoven). With an MSEE degree from Minnesota State University, Mankato, Dahlen has taught in an ABET accredited EE program, served as the program coordinator for an EET program, and taught component-level repair to military electronics technicians. Dahlen has returned to his Northern Minnesota home and thoroughly enjoys researching and writing articles such as this. LinkedIn | Aaron Dahlen - Application Engineer - DigiKey

Questions

  1. Explain the term “incremental” as is applies to a system featuring a quadrature encoder.

  2. Sketch a diagram showing the quadrature moon in relationship to the earth and the sun’s rays.

  3. Describe the operation of a retroreflective sensor.

  4. Contrast and compare the operation of an inductive proximity sensor with a capacitive proximity sensor. Be sure to focus on what materials may be sensed by each device.

  5. Most industrial sensors have a visual indicator as shown in Video 1. Explain the relevance of this feature from a system troubleshooting perspective.

  6. Referring to Figure 1, observe that the interrupter wheel is divided into alternating high and low points. First, sketch the wheel and the relative position of the quadrature and index sensors. Then using angles emanating from the center of the wheel, identify the quadrature (90-degree) phase shift. Hint: The wheel is divided into 4 sections where each section provided an electrical 360-degree output. This is like an 8-pole synchronous motor that makes 4 electrical rotations for every mechanical rotation.

  7. Each sensor transition of a quadrature encoder is called a count. How many counts per revolution are produced by the encoder featured in this article?

  8. The Pololu motor featured in this brief is rated for 100 RPM at 24 VDC (unloaded). How many Counts Per Second (CPS) are produced by the industrial quadrature encoder featured in this article?

  9. What is a gray code? How can it be leveraged to program robust encoder logic?

  10. A quadrature encoder is used to measure the position of a mechanism. What determines the upper limit for the maximum movement that may be measured? Hint: Consider the fundamental aspect of computer programming.

Critical thinking questions

  1. The interrupter wheel could be redesigned to increase the resolution. What are the limiting factors to improving resolution?

  2. Identify and describe at least three unique Commercially Available Off the Shelf (COTS) quadrature encoder - one should be linear. Be sure to identify the type of sensor, resolution, and typical application.

  3. As a rule, sensors with high resolution are preferred. Explore the relationship within the constraints of mechanical systems. As a starting point, explore the concept of anti-backlash gears and ball screw actuators. Be sure to identify the point of diminishing returns when we consider the performance to cost relationships.

  4. The article states that position is lost in the event of a power failure. Identify and describe a solution to maintain encoder position in the event of a power failure. As a design constraint, your power budget is limited to a small supercapacitor. Hint: What motor accessories are typically associated with a robotic arm to hold position?