Rotary encoder

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search
A Gray code absolute rotary encoder with 13 tracks. At the top, the housing, interrupter disk, and light source can be seen; at the bottom the sensing element and support components.

A rotary encoder, also called a shaft encoder, is an electro-mechanical device that converts the angular position or motion of a shaft or axle to analog or digital output signals.

There are two main types of rotary encoder: absolute and incremental. The output of an absolute encoder indicates the current shaft position, making it an angle transducer. The output of an incremental encoder provides information about the motion of the shaft, which typically is processed elsewhere into information such as position, speed and distance.

Rotary encoders are used in a wide range of applications that require monitoring or control, or both, of mechanical systems, including industrial controls, robotics, photographic lenses,[1] computer input devices such as optomechanical mice and trackballs, controlled stress rheometers, and rotating radar platforms.

Encoder technologies[edit]

Hall effect quadrature encoder, sensing gear teeth on the driveshaft of a robot vehicle.
  • Conductive: A series of circumferential copper tracks etched onto a PCB is used to encode the information. Contact brushes sense the conductive areas. This form of encoder is now rarely seen except as a user input in digital multimeters.
  • Optical: This uses a light shining onto a photodiode through slits in a metal or glass disc. Reflective versions also exist. This is one of the most common technologies. Optical encoders are very sensitive to dust.
  • On-Axis Magnetic: This technology typically uses a specially magnetized 2 pole neodymium magnet attached to the motor shaft. Because it can be fixed to the end of the shaft, it can work with motors that only have 1 shaft extending out of the motor body. The accuracy can vary from a few degrees to under 1 degree. Resolutions can be as low as 1 degree or as high as 0.09 degree (4000 CPR, Count per Revolution).[2] Poorly designed internal interpolation can cause output jitter, but this can be overcome with internal sample averaging.
  • Off-Axis Magnetic: This technology typically employs the use of rubber bonded ferrite magnets attached to a metal hub. This offers flexibility in design and low cost for custom applications. Due to the flexibility in many off axis encoder chips they can be programmed to accept any number of pole widths so the chip can be placed in any position required for the application. Magnetic encoders operate in harsh environments where optical encoders would fail to work.

Basic types[edit]


Incremental encoder

An absolute encoder maintains position information when power is removed from the encoder.[3] The position of the encoder is available immediately on applying power. The relationship between the encoder value and the physical position of the controlled machinery is set at assembly; the system does not need to return to a calibration point to maintain position accuracy.

An absolute encoder has multiple code rings with various binary weightings which provide a data word representing the absolute position of the encoder within one revolution. This type of encoder is often referred to as a parallel absolute encoder.[4]

A multi-turn absolute rotary encoder includes additional code wheels and gears. A high-resolution wheel measures the fractional rotation, and lower-resolution geared code wheels record the number of whole revolutions of the shaft.[5]


An incremental encoder will immediately report changes in position, which is an essential capability in some applications. However, it does not report or keep track of absolute position. As a result, the mechanical system monitored by an incremental encoder may have to be moved to a fixed reference point to initialize the position measurement.

Absolute encoder[edit]

Absolute rotary encoder[edit]


Digital absolute encoders produce a unique digital code for each distinct angle of the shaft. They come in two basic types: optical and mechanical.

Mechanical absolute encoders[edit]

A metal disc containing a set of concentric rings of openings is fixed to an insulating disc, which is rigidly fixed to the shaft. A row of sliding contacts is fixed to a stationary object so that each contact wipes against the metal disc at a different distance from the shaft. As the disc rotates with the shaft, some of the contacts touch metal, while others fall in the gaps where the metal has been cut out. The metal sheet is connected to a source of electric current, and each contact is connected to a separate electrical sensor. The metal pattern is designed so that each possible position of the axle creates a unique binary code in which some of the contacts are connected to the current source (i.e. switched on) and others are not (i.e. switched off).

Because brush-type contacts are susceptible to wear, encoders using contacts are not common; they can be found in low-speed applications such as manual volume or tuning controls in a radio receiver.

Optical absolute encoders[edit]

The optical encoder's disc is made of glass or plastic with transparent and opaque areas. A light source and photo detector array reads the optical pattern that results from the disc's position at any one time.[6] The Gray code is often used. This code can be read by a controlling device, such as a microprocessor or microcontroller to determine the angle of the shaft.

The absolute analog type produces a unique dual analog code that can be translated into an absolute angle of the shaft.

Magnetic absolute encoders[edit]

The magnetic encoder uses a series of magnetic poles (2 or more) to represent the encoder position to a magnetic sensor (typically magneto-resistive or Hall Effect). The magnetic sensor reads the magnetic pole positions.

This code can be read by a controlling device, such as a microprocessor or microcontroller to determine the angle of the shaft, similar to an optical encoder.

The absolute analog type produces a unique dual analog code that can be translated into an absolute angle of the shaft (by using a special algorithm[citation needed]).

Due to the nature of recording magnetic effects, these encoders may be optimal to use in conditions where other types of encoders may fail due to dust or debris accumulation. Magnetic encoders are also relatively insensitive to vibrations, minor misalignment, or shocks.

Brushless motor commutation

Built-in rotary encoders are used to indicate the angle of the motor shaft in permanent magnet brushless motors, which are commonly used on CNC machines, robots, and other industrial equipment. In such cases, the encoder serves as a feedback device that plays a vital role in proper equipment operation. Brushless motors require electronic commutation, which often is implemented in part by using rotor magnets as a low-resolution absolute encoder (typically six or twelve pulses per revolution). The resulting shaft angle information is conveyed to the servo drive to enable it to energize the proper stator winding at any moment in time.

Capacitive absolute encoders[edit]

An asymmetrical shaped disc is rotated within the encoder. This disc will change the capacitance between two electrodes which can be measured and calculated back to an angular value.[7]

Absolute multi-turn encoder[edit]

A multi-turn encoder can detect and store more than one revolution. The term absolute multi-turn encoder is generally used if the encoder will detect movements of its shaft even if the encoder is not provided with external power.

Battery-powered multi-turn encoder[edit]

This type of encoder uses a battery for retaining the counts across power cycles. It uses energy conserving electrical design to detect the movements.

Geared multi-turn encoder[edit]

These encoders use a train of gears to mechanically store the number of revolutions. The position of the single gears is detected with one of the above-mentioned technologies.[8]

Self-powered multi-turn encoder[edit]

These encoders use the principle of energy harvesting to generate energy from the moving shaft. This principle, introduced in 2007,[9] uses a Wiegand Sensor to produce electricity sufficient to power the encoder and write the turns count to non-volatile memory.[10]

Ways of encoding shaft position[edit]

Standard binary encoding[edit]

Rotary encoder for angle-measuring devices marked in 3-bit binary. The inner ring corresponds to Contact 1 in the table. Black sectors are "on". Zero degrees is on the right-hand side, with angle increasing counterclockwise.

An example of a binary code, in an extremely simplified encoder with only three contacts, is shown below.

Standard Binary Encoding
Sector Contact 1 Contact 2 Contact 3 Angle
0 off off off 0° to 45°
1 off off ON 45° to 90°
2 off ON off 90° to 135°
3 off ON ON 135° to 180°
4 ON off off 180° to 225°
5 ON off ON 225° to 270°
6 ON ON off 270° to 315°
7 ON ON ON 315° to 360°

In general, where there are n contacts, the number of distinct positions of the shaft is 2n. In this example, n is 3, so there are 2³ or 8 positions.

In the above example, the contacts produce a standard binary count as the disc rotates. However, this has the drawback that if the disc stops between two adjacent sectors, or the contacts are not perfectly aligned, it can be impossible to determine the angle of the shaft. To illustrate this problem, consider what happens when the shaft angle changes from 179.9° to 180.1° (from sector 3 to sector 4). At some instant, according to the above table, the contact pattern changes from off-on-on to on-off-off. However, this is not what happens in reality. In a practical device, the contacts are never perfectly aligned, so each switches at a different moment. If contact 1 switches first, followed by contact 3 and then contact 2, for example, the actual sequence of codes is:

off-on-on (starting position)
on-on-on (first, contact 1 switches on)
on-on-off (next, contact 3 switches off)
on-off-off (finally, contact 2 switches off)

Now look at the sectors corresponding to these codes in the table. In order, they are 3, 7, 6 and then 4. So, from the sequence of codes produced, the shaft appears to have jumped from sector 3 to sector 7, then gone backwards to sector 6, then backwards again to sector 4, which is where we expected to find it. In many situations, this behaviour is undesirable and could cause the system to fail. For example, if the encoder were used in a robot arm, the controller would think that the arm was in the wrong position, and try to correct the error by turning it through 180°, perhaps causing damage to the arm.

Gray encoding[edit]

Rotary encoder for angle-measuring devices marked in 3-bit binary-reflected Gray code (BRGC). The inner ring corresponds to Contact 1 in the table. Black sectors are "on". Zero degrees is on the right-hand side, with angle increasing counter-clockwise.

To avoid the above problem, Gray coding is used. This is a system of binary counting in which any two adjacent codes differ by only one bit position. For the three-contact example given above, the Gray-coded version would be as follows.

Gray Coding
Sector Contact 1 Contact 2 Contact 3 Angle
0 off off off 0° to 45°
1 off off ON 45° to 90°
2 off ON ON 90° to 135°
3 off ON off 135° to 180°
4 ON ON off 180° to 225°
5 ON ON ON 225° to 270°
6 ON off ON 270° to 315°
7 ON off off 315° to 360°

In this example, the transition from sector 3 to sector 4, like all other transitions, involves only one of the contacts changing its state from on to off or vice versa. This means that the sequence of incorrect codes shown in the previous illustration cannot happen.

Single-track Gray encoding[edit]

If the designer moves a contact to a different angular position (but at the same distance from the center shaft), then the corresponding "ring pattern" needs to be rotated the same angle to give the same output. If the most significant bit (the inner ring in Figure 1) is rotated enough, it exactly matches the next ring out. Since both rings are then identical, the inner ring can be omitted, and the sensor for that ring moved to the remaining, identical ring (but offset at that angle from the other sensor on that ring). Those two sensors on a single ring make a quadrature encoder with a single ring.

It is possible to arrange several sensors around a single track (ring) so that consecutive positions differ at only a single sensor; the result is the single-track Gray code encoder.

Data output methods[edit]

Depending on the device and manufacturer, an absolute encoder may use any of several signal types and communication protocols to transmit data, including parallel binary, analog signals (current or voltage), and serial bus systems such as SSI, BiSS, DeviceNet, Modbus, Profibus, CANopen and EtherCAT, which typically employ Ethernet or RS-422/RS-485 physical layers.

Incremental encoder[edit]


An incremental encoder is a linear or rotary electromechanical device that has two output signals, A and B, which issue pulses when the encoder is moved. Some encoders have an additional output signal, typically designated "index" or Z, which indicates the encoder is located at a particular reference position. Also, some encoders provide a status output that indicates internal fault conditions such as a bearing failure or sensor malfunction.

Two square waves in quadrature. The direction of motion is indicated by the sign of the A-B phase angle which, in this case, is negative because A trails B.
Conceptual drawing of a rotary incremental encoder's position sensing mechanism, with the corresponding logic states of the A/B signals shown on the right
A direct-encoding sensor mechanism in a linear incremental encoder. The R signal indicates the encoder is located at its reference position.

The A and B output pulses are quadrature-encoded, meaning that when pulses are being issued, the duty cycle of each pulse is 50% (i.e., the waveform is a square wave) and there is a 90 degree phase difference between A and B. At any particular time, this 90° phase angle will positive or negative depending on the encoder's direction of movement. In the case of a rotary encoder, the phase angle is +90° for clockwise rotation and -90° for counter-clockwise rotation, or vice versa, depending on the device design.

The frequency of the pulses on the A or B output is directly proportional to the encoder's velocity (rate of position change); higher frequencies indicate rapid movement, whereas lower frequencies indicate slower speeds. Static, unchanging signals are output on A and B when the encoder is motionless. In the case of a rotary encoder, the frequency indicates the speed of the encoder's shaft rotation, and in linear encoders the frequency indicates the speed of linear travel.

Position tracking[edit]

Incremental encoders report position changes without being prompted to do so, and they convey this information at data rates which are orders of magnitude faster than those of most types of absolute encoders. The resulting, very low data latency of an incremental encoder allows it to be used to monitor the position of a high speed mechanism in real time -- a capability lacking in most types of absolute encoders. Because of this, incremental encoders are commonly used in applications that require precise measurement of position and velocity.

Unlike absolute encoders, an incremental encoder does not keep track of, nor do its outputs indicate the current encoder position; it only reports incremental changes in position.[4] Consequently, to determine the encoder's position at any particular moment, it is necessary to provide external electronics which will "track" the position. This external circuitry, which is known as an incremental encoder interface, tracks an encoder's position by counting the pulse edges emitted from the encoder's A and B outputs. As it receives each edge, the encoder interface takes into account the phase relationship between A and B and, depending on the sign of the phase angle, will either count up or down. The current "counts" value stored in the counter indicates the distance traveled since tracking began.

To be useful, the encoder counts (maintained by the encoder interface) must be correlated to a reference position in the mechanical system to which the encoder is attached. This is commonly done by "homing" the system, which consists of moving the mechanical system (and encoder) until it aligns with a reference position, and then jamming the associated, correlated counts into the encoder interface's counter. Another common method is jam a reference value into the counter upon receiving a pulse from the encoder's "index" output, if available.

Signal characteristics[edit]

Incremental encoders employ various types of electronic circuits to drive their output signals, and manufacturers often have the ability to build a particular encoder with any of several driver types. Commonly available driver types include push-pull, open collector, and differential RS-422.


A rotary panel encoder

Push-pull outputs (e.g., TTL) typically are used for direct interface to logic circuitry. These are well-suited to applications in which the encoder and interface are located near each other and powered from a common power supply, thus avoiding exposure to electric fields, ground loops and transmission line effects that might corrupt the signals and thereby disrupt position tracking, or worse, damage the encoder interface. Examples of this include rotary panel encoders and other applications where the encoder is connected to the interface via printed circuit conductors or short, shielded cable runs.

Open collector[edit]

Open collector drivers operate over a wide range of signal voltages and often can sink significant output current, making them useful for directly driving current loops, optoisolators and fiber optic transmitters.

An open-collector output must be connected to a positive DC voltage through an external pull-up resistor, which typically is located near the encoder interface to improve noise immunity. The external voltage determines the encoder's high-level signal voltage, whereas the low-level output current is determined by both the signal voltage and load resistance (including pull-up resistor). The load resistance and circuit capacitance act together to form a low-pass filter, which stretches (increases) the signal's rise-time and limits its maximum frequency. For this reason, open collector drivers typically are not used when the encoder will output high frequencies.

Differential RS-422[edit]

Differential output waveforms from an incremental encoder

Differential RS-422 signaling is typically preferred when the encoder will output high frequencies or be located away from the encoder interface, or when the encoder signals may be subjected to electric fields or common-mode voltages, or when the interface must be able to detect connectivity problems between encoder and interface. Examples of this include CMM and CNC machinery, industrial robotics, factory automation, and motion platforms used in aircraft and spacecraft simulators.

When RS-422 outputs are employed, the encoder provides a differential conductor pair for every logic output; for example, "A" and "/A" are commonly-used designations for the active-high and active-low differential pair comprising the encoder's "A" logic output. Consequently, the encoder interface must provide RS-422 line receivers to convert the incoming RS-422 pairs to single-ended logic.

In mission-critical systems, an encoder interface may be required to detect loss of input signals due to encoder power loss or signal driver failure, cable fault or cable disconnect. This is usually accomplished with the aid of enhanced RS-422 line receivers, which sense the absence of driven input signals and report this condition via an "open-circuit" status output. In normal operation, glitches (brief pulses) may appear on the status outputs during input state transitions. Typically, the encoder interface will filter the status signals to prevent these glitches from being erroneously interpreted as faults. Depending on the interface, subsequent processing may include generating an interrupt request upon loss of receiver signal, and forwarding fault signals to the application for error logging or failure analysis.

Incremental encoder interface[edit]

An incremental encoder interface is an electronic circuit that receives signals from an incremental encoder, processes the signals to produce absolute position and other information, and makes the resulting information available to external circuitry.

Incremental encoder interfaces are implemented in a variety of ways, including as ASICs, as IP blocks within FPGAs, as dedicated peripheral interfaces in microcontrollers and, when high count rates are not required, as software managed bit-bang interfaces.

Regardless of the implementation, the interface must sample the encoder's A and B output signals fast enough to detect every AB state change before the next state change occurs. Upon detecting a state change, it will increment or decrement the position counts based on whether A leads or trails B. This is typically done by storing a copy of the previous AB state and, upon state change, using the current and previous AB states to determine movement direction.

Input filter[edit]

In some cases an encoder interface must condition the incoming encoder signals before further processing them. For example, in the case of mechanical-type encoders, the interface must debounce A and B to avoid count errors due to mechanical contact bounce.

Hardware-based interfaces often provide programmable filters for the encoder signals, which may be used to debounce contacts or suppress transients resulting from noise or slowly slewing signals. In bit-bang interfaces, A and B typically are connected to GPIOs that are sampled (via polling or edge interrupts) and debounced by software.

Quadrature decoder[edit]

A quadrature decoder converts the A and B signals from an incremental encoder into direction and count enable signals, which are used to control a synchronous up/down counter

Incremental encoder interfaces commonly use a quadrature decoder to convert the A and B signals into the direction and count enable (clock enable) signals needed for controlling a synchronous, bidirectional (up- and down-counting) binary counter.

Typically, a quadrature decoder is implemented as a finite state machine (FSM) which simultaneously samples the A and B signals and thus produces amalgamate "AB" samples. As each new AB sample is acquired, the FSM will store the previous AB sample for later analysis. The FSM evaluates the differences between the new and previous AB states and generates direction and count enable signals as appropriate for the detected AB state sequence.

Quadrature decoder state table
Description AB state Outputs
Previous Current CE DIR ERR
x1 x2 x4
Moved one increment in "forward" direction
(A leads B)
00 10 1 1 1 1 0
10 11 0 0
11 01 1
01 00 0
Moved one increment in "reverse" direction
(B leads A)
00 01 0 0
01 11 1
11 10 0
10 00 1 1
No detected movement 00 00 0 X
01 01
10 10
11 11
Moved an indeterminate number of increments 00 11 1
01 10
10 01
11 00

In any two consecutive AB samples, the logic state of A or B may change or both states may remain unchanged, but in normal operation the A and B states will never both change. When neither A nor B changes, the quadrature decoder assumes the encoder has not moved and so it negates its count enable output, thereby causing the counts to remain unchanged. When just A or B changes state, the quadrature decoder assumes the encoder has moved one increment of its measurement resolution and, accordingly, it may assert its count enable output to allow the counts to change, and assert or negate its direction output to cause the counts to increment or decrement (or vice versa).

If the A and B states both change simultaneously, the clock decoder has no way of determining how many increments, or in what direction the encoder has moved. This can happen if the encoder speed is too fast for the quadrature decoder to process (i.e., the rate of AB state changes exceeds the quadrature decoder's sampling rate; see Nyquist rate) or if the A or B signal is noisy. In most encoder applications this is a catastrophic event because the counter no longer provides an accurate indication of encoder position. Consequently, many quadrature decoders output an additional error signal which is asserted when the A and B states change simultaneously. Due to the severity and time-sensitive nature of this condition, the error signal is often connected to an interrupt request.

Clock multiplier[edit]

A quadrature decoder does not necessarily allow the counts to change for every incremental position change. When a decoder detects an incremental position change (due to a transition of A or B, but not both), it may allow the counts to change or it may inhibit counting, depending on the AB state transition and the decoder's clock multiplier.

The clock multiplier of a quadrature decoder is so named because it results in a count rate which is a multiple of the A or B pulse frequency. Depending on the decoder's design, the clock multiplier may be hardwired into the design or it may be run-time configurable via input signals.

The clock multiplier value may be one, two or four (typically designated "x1", "x2" and "x4"). In the case of a x4 multiplier, the counts will change for every AB state change, thereby resulting in a count rate equal to four times the A or B frequency. The x2 and x1 multipliers allow the counts to change on some, but not all AB state changes, as shown in the quadrature decoder state table above (note: this table shows one of several possible implementations for x2 and x1 multipliers; other implementations may enable counting at different AB transitions).

Incremental rotary encoder[edit]

An incremental encoder

The incremental rotary encoder is the most widely used of all rotary encoders due to its low cost and ability to provide real-time position information. The measurement resolution of an incremental encoder is not limited in any way by its two internal, incremental movement sensors; one can find in the market incremental encoders with up to 10,000 counts per revolution, or more.

A rotary incremental encoder may use mechanical, optical or magnetic sensors to detect rotational position changes. The mechanical type is commonly employed as a manually operated "digital potentiometer" control on electronic equipment. For example, modern home and car stereos typically use mechanical rotary encoders as volume controls. Encoders with mechanical sensors require switch debouncing and consequently are limited in the rotational speeds they can handle. The optical type is used when higher speeds are encountered or a higher degree of precision is required.

Some rotary incremental encoders have an additional "index" output (typically labeled Z), which emits a pulse when the shaft passes through a particular angle. Once every rotation, the Z signal is asserted, typically always at the same angle, until the next AB state change. This is commonly used in radar systems and other applications that require a registration signal when the encoder shaft is located at a particular reference angle.

Inexpensive incremental encoders are used in ball mice. Typically, two encoders are used: one to sense left-right motion and another to sense forward-backward motion.

Other pulse-output rotary encoders[edit]

Rotary encoders with a single output (i.e. tachometers) cannot be used to sense direction of motion but are suitable for measuring speed and for measuring position when the direction of travel is constant. In certain applications they may be used to measure distance of motion (e.g. feet of movement).

See also[edit]

Analogue devices that perform a similar function include the synchro, the resolver, the rotary variable differential transformer (RVDT), and the rotary potentiometer.

A linear encoder is similar to a rotary encoder, but measures position in a straight line, rather than rotation. Linear encoders often use incremental encoding and are used in many machine tools.


  1. ^ "New - Rotary Encoder". Archived from the original on 2013-10-05.  Canon video camera lens, used for zoom and aperture control
  2. ^
  3. ^ Eitel, Elisabeth. Basics of rotary encoders: Overview and new technologies | Machine Design Magazine, 7 May 2014. Accessed: 30 June 2014
  4. ^ a b TI-5000EX Serial/Incremental Encoder Test System User Manual, Mitchell Electronics, Inc.
  5. ^ G. K. McMillan, D.M. Considine (ed.) Process Instruments and Controls Handbook Fifth Edition, McGraw Hill 1999, ISBN 978-0-07-012582-7, page 5.26
  6. ^ "encoders" (PDF). p. 12. Retrieved 20 February 2013. 
  7. ^ "Capacitive Absolute Encoder" (PDF). Camille Bauer. Retrieved 20 February 2013. 
  8. ^ Robert, Repas. "Multi-turn absolute encoders". Retrieved 20 February 2013. [permanent dead link]
  9. ^ "New technology yields encoder that never forgets". journal. 2007. Retrieved 20 February 2013. 
  10. ^ "White Paper Magnetic Encoder" (pdf). FRABA Inc. p. 3. Retrieved 13 February 2013. 

Further readings[edit]

External links[edit]