A rotary encoder, also called a shaft encoder, is an electro-mechanical device used to convert the angular position of a shaft or axle to an analog or digital code, making it an angle transducer. These devices are used in industrial controls, robotics, in top-of-the-line photographic lenses, in computer input devices (such as optomechanical mice and trackballs), and in rotating radar platforms.
There are two main types: absolute and incremental (relative).
This code can be read by a controlling device, such as a microprocessor, 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 (by using a special algorithm).
An example of a binary code, in an extremely simplified encoder with only three contacts, is shown below.
| Sector | Contact 1 | Contact 2 | Contact 3 | Angle |
|---|---|---|---|---|
| 1 | off | off | off | 0° to 45° |
| 2 | off | off | on | 45° to 90° |
| 3 | off | on | off | 90° to 135° |
| 4 | off | on | on | 135° to 180° |
| 5 | on | off | off | 180° to 225° |
| 6 | on | off | on | 225° to 270° |
| 7 | on | on | off | 270° to 315° |
| 8 | 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 4 to sector 5). At some instant, according to the above table, the contact pattern will change 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, and so each one will switch at a different moment. If contact 1 switches first, followed by contact 3 and then contact 2, for example, the actual sequence of codes will be
Now look at the sectors corresponding to these codes in the table. In order, they are 4, 8, 7 and then 5. So, from the sequence of codes produced, the shaft appears to have jumped from sector 4 to sector 8, then gone backwards to sector 7, then backwards again to sector 5, 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.
To avoid the above problem, Gray encoding is used. This is a system of binary counting in which two adjacent codes differ in only one position. For the three-contact example given above, the Gray-coded version would be as follows.
| Sector | Contact 1 | Contact 2 | Contact 3 | Angle |
|---|---|---|---|---|
| 1 | off | off | off | 0° to 45° |
| 2 | off | off | on | 45° to 90° |
| 3 | off | on | on | 90° to 135° |
| 4 | off | on | off | 135° to 180° |
| 5 | on | on | off | 180° to 225° |
| 6 | on | on | on | 225° to 270° |
| 7 | on | off | on | 270° to 315° |
| 8 | on | off | off | 315° to 360° |
In this example, the transition from sector 4 to sector 5, 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 here.
For many years, Torsten Sillke and other mathematicians believed that it was impossible to encode position on a single track so that consecutive positions differed at only a single sensor, except for the two-sensor, one-track quadrature encoder. However, in 1996 Hiltgen, Paterson and Brandestini published a paper showing it was possible, with several examples. See Gray code for details.
The fact that incremental encoders use only two sensors does not compromise their accuracy. One can find in the market incremental encoders with up to 10,000 counts per revolution, or more.
There can be an optional third output: reference, which happens once every turn. This is used when there is the need of an absolute reference, such as positioning systems.
The optical type is used when higher RPMs are encountered or a higher degree of precision is required.
Incremental encoders are used to track motion and can be used to determine position and velocity. This can be either linear or rotary motion. Because the direction can be determined, very accurate measurements can be made.
They employ two outputs called A & B which are called quadrature outputs as they are 90 degrees out of phase.
The state diagram:
|
|
The two output wave forms are 90 degrees out of phase, which is all that the quadrature term means. These signals are decoded to produce a count up pulse or a count down pulse. For decoding in software, the A & B outputs are read by software, either via an interrupt on any edge or polling, and the above table is used to decode the direction. For example if the last value was 00 and the current value is 01, the device has moved one half step in the clockwise direction. The mechanical types would be debounced first by requiring that the same (valid) value be read a certain number of times before recognizing a state change.
If the encoder is turning too fast, an invalid transition may occur, such as 00->11. There is no way to know which way the encoder turned; if it was 00->01->11, or 00->10->11.
If the encoder is turning even faster, a backward count may occur. Example: consider the 00->01->11->10 transition (3 steps forward). If the encoder is turning too fast, the system might read only the 00 and then the 10, which yields a 00->10 transition (1 step backward).
This same principle is used in old ball mice to track whether the mouse is moving to the right/left or forward/backward.
Rotary sensors with a single output are not encoders and cannot sense direction, but can sense RPM. They are thus called tachometer sensors.
Encoders may be implemented using a variety of technologies:
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.