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.

Using Rotary Encoders

The electromechanical nature of the rotary encoder requires that it interface with mechanical devices or the user. When encoders are used as control interfaces on electronic devices, they use a solid shaft and are usually mounted on a control panel using a panel-mount bushing with associated hardware.

Designers can choose options such as detents to cause a mechanical “click” as the encoder is rotated, giving users tactile feedback that the encoder shaft is moving. They can also choose a momentary contact switch that is activated by pressing the encoder shaft. Encoders intended to be mounted on rotating machines like motors or servos have hollow or blind shafts (Figure 4).

Figure 4. Hollow or blind shaft configured encoders are intended to be mounted on motors or other electromechanical machines. (Source: Digi-Key Electronics)

A hollow shaft encoder mounts over the shaft of a motor or similar mechanical device. This ensures it is mounted concentrically with the device being monitored and eliminates the chance of asymmetric or angular misalignment. Blind shafts are hollow shafts with limited depth used to mount the encoder on the end of a motor shaft.

Encoder Selection and Application

Figure 5. The CTS 291V1022F832AB with the typical threaded bushing, lock washer, and lock nut intended to be used as a panel-mounted control. (Source: CTS)

The selection of a rotary encoder depends on the application requirements and the environment, as well as cost constraints. The 291V1022F832AB from CTS Electronic Components is an optical incremental encoder with 8 PPR angular resolution that runs off a 5-Volt supply (Figure 5). The 291 Series supports PPR resolutions ranging from 4 to 64 PPR, with optional selection of shaft types and lengths, detents, and an integral switch. The encoder has a rated rotational life of up to 3 million cycles. The optical encoders are ideal for instrument control applications including medical and laboratory equipment, communication, industrial, HVAC, transportation, security, audio, and home entertainment equipment.

Bourns Inc.'s EMS22Q51-D28-LT4 is a 32-PPR to 256-PPR incremental magnetic encoder that operates from either a 5-or a 3.3-Volt supply. Like the previous encoders, it has a variety of available shaft and bushing configurations but has a rated rotation life of 50 million cycles. These encoders are ideal for use in harsh industrial environments in the presence of extreme temperature, moisture, and particle contamination. Also, like many encoders, connecting and using the device is straightforward (Figure 6).

Figure 6. Pin details of the EMS22Q51-D28-LT4 (inset, on left) and block diagram show the simplicity of connecting a 256-PPR incremental magnetic non-contacting encoder to a microcontroller. (Source: Digi-Key Electronics)

The EMS22Q series has six pins — one each for supply and ground, one active low chip select that goes to the microcontroller or microprocessor, one index pin, and two data pins (A and B). The resulting quadrature output is shown in Figure 7.

Figure 7. The EMS22Q produces a quadrature output with a PPR range of 32 to 256. (Source: Bourns Inc.)

Designers of devices for low-cost applications can make good use of a mechanical encoder such as TT Electronics’ EN11-HSM1AF15 20-PPR encoder. This encoder is part of the EN11 series that offers angular resolution of 15 or 20 PPR, a variety of shaft and bushing lengths, a choice of optional switches, and a selection of detent configurations. This encoder operates with a 5-Volt supply, is roughly one-tenth the price of optical encoders, and has a rotational life of 30,000 cycles.


Rotary encoders fill a need for quickly and efficiently sensing and digitizing angular rotation of a front panel control, robotic arm, or a rotating motor shaft. Incremental or absolute encoders provide a necessary interface to microprocessors or microcontrollers to allow sensing and control of electromechanical systems components.

This article was contributed by Digi-Key Electronics , Thief River Falls, MN.