In the digital age, the measurement of rotation of a mechanical shaft on a motor or a rotating instrument knob needs to be done quickly and efficiently. Analog methods such as potentiometers and rotating switches are being replaced by rotary encoders that directly digitize rotary movement, but designers need to be able to appreciate the differences among various encoder types and accurately interpret their digital outputs.

This article describes the role of rotary encoders and how they work. It then shows how to interpret their signals before introducing encoder solutions and their real-world application.

The Role of Rotary Encoders

Rotary encoders are a type of sensor that measures the rotation of a mechanical shaft. The shaft could be on a motor, where it would read the angular position or rotational speed. They could also read the angular position of a dial, knob, or other electronic control on an instrument or appliance front panel, replacing potentiometers and rotary switches.

Consider a timer control on an appliance. In the old analog days, a variable resistor or potentiometer would be used to sense the position of that control. With today's microprocessor-based designs, digital inputs generated by a rotary encoder are more efficient.

Encoders can also be used in control systems to provide feedback that a mechanical part is moving correctly in response to a control command. Whether the control system is in an automobile or a robotic device, encoders provide the necessary sensing to the controlling microprocessor. Older solutions like single-turn potentiometers sense less than a full rotation of the shaft but rotary encoders can sense the full rotation without stops.

Rotary encoders convert these mechanical displacements into electrical signals that can be sent to a processor for interpretation. Based on the electrical outputs of the encoder, the direction of rotation, angular position, and rotational speed can be derived. The digital outputs of rotary encoders make this much simpler compared to potentiometers.

How Rotary Encoders Work

There are two main types of encoders: incremental and absolute. The incremental encoder reads changes in angular displacement while the absolute encoder reads the absolute angle of the encoded shaft. They are implemented using three common technologies: optical, mechanical, or magnetic.

Figure 1. Examples of both incremental and absolute optical discs. The incremental disc generates two square wave signals with a 90° phase difference between them. The absolute disc outputs binary encoded data. (Source: Digi-Key Electronics)

Optical encoders are built using a disc with translucent and opaque segments laid out to let light through certain areas. Using a LED and photodiodes on opposite sides of the disc (Figure 1), the photodiodes detect the light passing through the disc and output pulse waveforms corresponding to the translucent and opaque patterns on the segments of the disc. The absolute disc in Figure 1 has four outputs, providing a unique binary code for each segment on the disc — 16 in this case (see table below). An alternative to binary code is grey code — a binary code where adjacent binary words differ by only a single-bit transition.

The 16 binary states for an absolute encoder with four bits. (Source: Digi-Key Electronics)

The pattern generated by the incremental disc consists of two square waves with a 90° phase difference and is referred to as a quadrature output. This can also be accomplished using a single row pattern and two photoelectric sensors displaced by a distance equivalent to the 90° phase shift. The outputs of quadrature incremental encoders are generally referred to as A and B. The encoder may also include a third once-per-revolution pulse, called an index pulse, to provide a known physical reference.

By combining the index pulse with the quadrature outputs, absolute shaft orientation can be calculated. By having two outputs with a 90° phase shift, it is possible to sense not only the angular rotation but also the direction of the rotation (Figure 2). With the encoder shaft rotating clockwise, the A waveform will lead the B waveform. If the direction of rotation is changed to counter-clockwise, signal B will lead signal A.

Figure 2. The phase relationship between the quadrature signals determines the direction of travel of the encoder disc. (Source: Digi-Key Electronics)

With the two quadrature signals, it is possible to resolve four states per cycle. The states within a single cycle are A = 1 and B = 0, A = 1 and B = 1, A = 0 and B = 1, and finally A = 0 and B = 0. This means that the angular resolution of a quadrature output encoder is four times that of the rated pulses per revolution (PPR).

Viewing and measuring the quadrature outputs of an optical encoder on an oscilloscope shows the phase relationship between the outputs (Figure 3). The A signal is shown in the top trace while the B signal is in the lower trace. The oscilloscope phase parameter P1 is set to measure the phase difference between the A and B signals. The mean phase difference is 90.4° between the two signals.

Figure 3. The quadrature outputs of a 512 pulse-per-revolution (PPR) optical encoder showing the phase relationships between the A and B signal outputs (Source: Digi-Key Electronics)

Only the single A output was used in this example, as the encoder was applied as a tachometer, measuring the rotational speed of a motor. The frequency of the A signal is measured as 28.87 kilohertz (kHz) using the oscilloscope parameter P2. This is converted into the shaft speed by dividing by the 512 pulses per revolution (PPR) and multiplying by 60 to read the shaft angular speed in revolutions per minute (RPM), as read out in parameter P3 as 3383 RPM. Based on these numbers, the 512 PPR of this encoder provides a base resolution of 0.7°. By interpreting the A/B states, 0.175° can be resolved.

Optical encoders offer the benefit of having the highest resolution of all the encoder types. Their costs scale well to inexpensive, low-end applications. On the negative side, they can be bulky. Mechanical encoders use a rotating disc containing concentric rings identical to the patterns used in optical encoders. The rings have a pattern of conductive and insulated areas. Stationary wiper contacts slide over the rotating disc, making contact with each ring and acting as switches. As the contacts wipe across the surface of the disc, contact is made when wiping over a conductive region or broken when wiping over an insulated area. In this manner, a digital pattern is developed for each ring.

One problem that can occur with mechanical encoders is noise caused by contact bounce. This noise can be eliminated by using low-pass filtering or by using software to look at the output state after the bounce noise has subsided. Mechanical encoders are generally the least expensive encoder type. They find application as user interface devices on electronic front panels replacing potentiometers.

Magnetic-based rotary encoders use a multi-pole circular magnet. Alternate north and south magnetic poles are sensed by Hall effect or magneto-resistive sensors, generating quadrature electrical outputs as the magnet turns. Magnetic encoders, like optical encoders, are non-contacting and can be operated at higher speeds and for longer durations than mechanical contact encoders.