How to use rotary encoder to quickly convert mechanical rotation into digital signal

In the digital age, it is necessary to quickly and efficiently measure the rotation of a mechanical shaft on a motor or rotary instrument knob. Analog methods such as potentiometers and rotary switches are being replaced by rotary encoders that directly digitize rotary motion, but designers need to be able to understand the differences between various encoder types and accurately interpret the encoder’s digital output .

   This article will introduce the function and working principle of rotary encoder. Then explain how to interpret its signal, and then introduce several encoder solutions and their practical applications.

  The role of rotary encoder

   Rotary encoder is a sensor that measures the rotation of a mechanical shaft. The shaft can be located on the motor, where the rotary encoder reads the angular position or speed. They can also read the angular position of dials, knobs or other electronic control devices on the front panel of an instrument or device, instead of potentiometers and rotary switches.

   Let's take a look at the timer control device on home appliances. In the previous analog era, a variable resistor or potentiometer could be used to sense the position of the control device. Using today's microprocessor-based design, rotary encoders can generate more efficient digital inputs.

  Encoders can also be used in control systems to provide feedback for mechanical parts, allowing them to move in response to control commands. Whether it is a control system in a car or a robot device, the encoder can provide the necessary sensing for the control microprocessor. Older solutions like single-turn potentiometers cannot sense a complete rotation of a shaft, but rotary encoders can sense a complete rotation without stopping.

The rotary encoder converts these mechanical displacements into electrical signals that can be sent to the processor for analysis. According to the electrical output of the encoder, the rotation direction, angular position and rotation speed can be derived. Compared with a potentiometer, the digital output of a rotary encoder makes this process easier.

  The working principle of rotary encoder

   There are two main types of encoders, incremental encoders and encoders. The incremental encoder reads the change in angular displacement, and the encoder reads the angle of the encoder shaft. They are implemented using three common technologies, namely optical, mechanical or magnetic technology.

  The optical encoder adopts a coding disc structure, and the code disc has light-transmitting and light-shielding sections, allowing light to pass through a specific area. The photodiode uses LEDs and photodiodes on both sides of the code disc (Figure 1). The photodiode detects the light passing through the code disc and outputs pulse waveforms corresponding to the light transmission and shading patterns on the code disc section.

The code disc in has four outputs, which are the binary codes provided for each section on the code disc. In this example, the code is 16 (Table 1). The alternative to the binary code is Gray code, which is a binary code with only one bit change between adjacent binary words.

   0360/0-22.50000

  122.5-450001

  245-67.50010

  367.5-900011

  490-112.50100

  5112.5-1350101

  6135-157.50110

  7157.5-1800111

   8180-202.51000

  9202.5-2251001

  10225-247.51010

  11247.5-2701011

  12270-292.51100

   13292.5-3151101

  14315-337.51110

  15337.5-360/01111

   sector number sector range (degrees) binary code

 Sixteen binary states of a four-bit encoder. (Form: Digi-Key Electronics)

  The pattern generated by the incremental code disc is composed of two square waves with a phase difference of 90°, which is called quadrature output. It is also possible to use a single line pattern and two photoelectric sensors with a shift equivalent to a 90° phase shift to achieve this output.

   The output of quadrature incremental encoder is usually called "A" and "B". The encoder may also include a third pulse, which generates one pulse per revolution, called an index pulse, which provides a known physical reference. By combining the index pulse with the quadrature output, the axis direction can be calculated.

   By acquiring two outputs with a 90° phase shift, not only the angle rotation but also the rotation direction can be sensed (Figure 2).

   The phase relationship between the quadrature signals can determine the direction of motion of the encoder code disc. (Photo: Digi-Key Electronics)

   When the encoder shaft rotates clockwise, the A waveform will lead the B waveform. If the direction of rotation changes to counterclockwise, signal B will lead signal A.

  Using two orthogonal signals, four states of each cycle can be analyzed. The states in a single cycle are A = 1 and B = 0, A = 1 and B = 1, A = 0 and B = 1, and A = 0 and B = 0. This means that the angular resolution of the quadrature output encoder is four times the rated pulses per revolution (PPR).

   By viewing and measuring the quadrature output of the optical encoder on an oscilloscope, the phase relationship between the outputs can be obtained (Figure 3). The A signal is displayed in the upper trace, and the B signal is displayed in the lower trace. Set the oscilloscope phase parameter P1 to measure the phase difference between the A and B signals. The average phase difference between the two signals is 90.4?.

   The quadrature output of the optical encoder with 512 pulses per revolution shows the phase relationship between the A and B signal outputs (photograph: Digi-Key Electronics)

  In this example, only a single A output is used because the encoder is used as a tachometer to measure the speed of the motor. Using the oscilloscope parameter P2, the frequency of signal A is 28.87 kilohertz (kHz). This value is divided by 512 pulses per revolution (PPR) to convert to axis speed, and then multiplied by 60 to get the axis angular velocity (in revolutions per minute (RPM)), which is the reading of 3383 RPM in parameter P3.

   Based on these numbers, the encoder's 512 PPR can provide a basic resolution of 0.7 degrees. By analyzing the A/B status, the resolution can reach 0.175?.

  The resolution of optical encoders in all encoder types is a natural advantage. Because of its low cost, it is very suitable for low-end applications with low prices. The disadvantage is that they can be bulky.

  Mechanical encoders use a rotating code disc that contains concentric rings with the same pattern as the optical encoder. In these concentric rings, the pattern consists of conductive areas and insulating areas. The fixed brush contact slides on the rotating code wheel and contacts each ring to act as a switch. As the contacts brush back and forth on the surface of the code wheel, they make contact when brushing through the conductive area, or disconnect when brushing through the insulating area. In this way, a digital pattern is developed for each ring.

   One problem that may occur with mechanical encoders is that contact jitter causes noise. This type of noise can be eliminated by using low-pass filtering, or use software to check the output status after the jitter noise disappears.

   Mechanical encoder is usually the type of encoder. They are usually used as user interface devices on the electronic front panel to replace potentiometers.

   The magnetic rotary encoder uses a multi-pole circular magnet. Detect alternating north and south magnetic poles by Hall effect or magnetoresistive sensors, and generate orthogonal electrical output as the magnet rotates. Like the optical encoder, the magnetic encoder is a non-contact type. Compared with the contact type mechanical encoder, the operation speed is higher and the duration is longer.

  Use rotary encoder

  The electromechanical characteristics of the rotary encoder require it to be connected to a mechanical device or require user operation. When used as a control interface on electronic equipment, the encoder uses a solid shaft, and is usually installed on the control panel using a panel mounting bushing, and at the same time, it is fixed with hardware.

   Designers can choose options such as pawls to cause a mechanical "click" sound when the encoder rotates, thereby providing the user with tactile feedback that the encoder shaft is moving. The designer can also select a momentary contact switch to activate by pressing the encoder shaft.

   The encoder designed to be installed on a rotating machine (such as a motor or a servo motor) has two choices of hollow shaft or blind shaft (Figure 4).

   Figure 4: Encoders with hollow shaft or blind shaft configuration are intended to be installed on motors or other electromechanical equipment. (Photo: Digi-Key Electronics)

   Hollow shaft encoder is installed on the shaft of a motor or similar mechanical device. This can ensure that it is installed concentrically with the monitored device, avoiding asymmetry or angle errors. The blind shaft is a hollow shaft with limited depth, used to install the encoder on the end of the motor shaft.

  Encoder selection and application

  The choice of rotary encoder depends on application requirements and environment and cost constraints.

   291V1022F832AB of CTS Electronic Components is an optical incremental encoder with 8 PPR angular resolution and 5 volt power supply (Figure 5). The 291 series supports PPR resolutions from 4 to 64 PPR, provides different shaft types and lengths, and pawl options, and can also be equipped with an integrated switch. The rated rotation life of the encoder is up to 3 million revolutions.

   Figure 5: CTS 291V1022F832AB with a typical threaded bushing, lock washer and lock nut designed to be used as a panel mount control device. (Photo: CTS)

   CTS 291 series optical encoders are very suitable for instrument control applications, including medical and laboratory equipment, communications, 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, powered by a 5 volt or 3.3 volt power supply. This device is a member of the EMS22Q series of non-contact encoders and supports angular resolutions from 32 to 256 PPR. Like the previous encoder, it has a variety of shaft and bushing configurations available, but has a rated rotation life of 50 million revolutions. These encoders are very suitable for harsh industrial environments with extreme temperatures, humidity and particle contamination.

   In addition, like many encoders, the device is simple to connect and use.

The EMS22Q series has six pins. There is one power and one ground pin, one low-effective chip select connected to the microcontroller or microprocessor, one index pin, and two data pins (A and B). The resulting quadrature output is shown below.

    mechanical encoder is very useful for designers of low-cost and hobbyist application equipment, such as the EN11-HSM1AF15 20 PPR encoder from TT Electronics. This encoder belongs to the EN11 series and offers 15 or 20 PPR angular resolution, various shaft and bushing lengths, optional switches and a variety of pawl configuration options. The encoder uses a 5 volt power supply, the price is about one-tenth of the optical encoder, and the rotation life is 30,000 revolutions.

to sum up

   Rotary encoder can quickly and effectively sense the angle rotation of the front panel control device, the robot arm or the rotating motor shaft and perform digital conversion, which fills the relevant requirements. Incremental encoders or encoders provide the necessary interfaces for microprocessors or microcontrollers to sense and control electromechanical system components.