Article Library > How to Use Rotary Encoders to Quickly Convert Mechanical Rotation into Digital Signals

How to Use Rotary Encoders to Quickly Convert Mechanical Rotation into Digital Signals

By Art Pini

Contributed By Digi-Key's North American Editors

2018-12-11

In a 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 between various encoder types, and accurately interpret their digital outputs.

This article will describe the role of rotary encoders and how they work. It will then show 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, the 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.

Optical encoders are built using a disc with translucent and opaque segments laid out to let light through certain areas. Using an 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, sixteen in this case (Table 1). An alternative to binary code is grey code, which is a binary code where adjacent binary words differ by only a single bit transition.

Segment Number

Sector Range (Degrees)

Binary Code

0

360/0 - 22.5

0000

1

22.5 - 45

0001

2

45 - 67.5

0010

3

67.5 - 90

0011

4

90 - 112.5

0100

5

112.5 - 135

0101

6

135 - 157.5

0110

7

157.5 - 180

0111

8

180 - 202.5

1000

9

202.5 - 225

1001

10

225 - 247.5

1010

11

247.5 - 270

1011

12

270 - 292.5

1100

13

292.5 - 315

1101

14

315 - 337.5

1110

15

337.5 - 360/0

1111

Table 1: The sixteen binary states for an absolute encoder with four bits. (Table 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).

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

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.

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 optical encoder showing the phase relationships between the A and B signal outputs (Image 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 degrees. 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, 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.

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. (Image 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

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.

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

The CTS 291 series 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.’sEMS22Q51-D28-LT4 is a 32 PPR to 256 PPR incremental magnetic encoder that operates from either a 5 or a 3.3 volt supply. The device is a member of the EMS22Q series of non-contacting encoders that supports 32 to 256 PPR angular resolution. 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. (Image 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. (Image source: Bourns Inc.)

Designers of devices for low-cost and hobbyist 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 which 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.

Conclusion

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.

Disclaimer: The opinions, beliefs, and viewpoints expressed by the various authors and/or forum participants on this website do not necessarily reflect the opinions, beliefs, and viewpoints of Digi-Key Electronics or official policies of Digi-Key Electronics.

About this author

Art Pini

Arthur (Art) Pini is a contributing author at Digi-Key Electronics. He has a Bachelor of Electrical Engineering degree from City College of New York and a Master of Electrical Engineering degree from the City University of New York. He has over 50 years experience in electronics and has worked in key engineering and marketing roles at Teledyne LeCroy, Summation, Wavetek, and Nicolet Scientific. He has interests in measurement technology and extensive experience with oscilloscopes, spectrum analyzers, arbitrary waveform generators, digitizers, and power meters.