A rotational encoder has a knob that a user can turn to display a series of prompts on an LCD screen, or to adjust the input or output on a product such as a stereo receiver. The component is almost always connected to inputs on a microcontroller and is usually fitted with detents that provide tactile feedback suggesting many closely spaced positions. The encoder often allows the user to make a selection by pushing the knob in, which closes an internal momentary switch. Thus, this type of encoder functions as a pushbutton as well as a switch.
A rotational encoder is an incremental or relative device, meaning that it merely creates and breaks internal switch connections when rotation occurs, without providing a unique code to identify each absolute rotational position. An absolute encoder is discussed in the rotary switch entry of this encyclopedia.
No schematic symbol exists to represent a rotational encoder.
An encoder contains two pairs of contacts, which open and close out of phase with each other when the shaft rotates. In a clockwise direction, the A pair of contacts may be activated momentarily before the B pair; in a counter-clockwise direction, the B pair may be activated before the A pair. (Some encoders reverse this phase difference.) Thus if one contact from each pair is connected with two inputs of an appropriately programmed microcontroller, and if the other contact of each pair is connected with negative ground, the microcontroller can deduce which way the knob is turning by sensing which pair of contacts closes first. The microcontroller can then count the number of pulses from the contacts and interpret this to adjust an output or update a display.
A simplified schematic is shown in Figure 8-1. The two buttons inside the dashed line represent the two pairs of contacts inside the encoder, while the chip is a microcontroller. The knob and shaft that activate the internal switches are not shown. The schematic assumes that when a contact closes, it pulls the chip input to a low state. A pullup resistor is added to each input of the chip to prevent the pins from "floating" when either pair of contacts is open.
Figure 8-1. Simplified schematic showing the typical setup for a rotational encoder. The pushbuttons inside the dashed line represent the contacts inside the encoder. The chip is a microcontroller.
Figure 8-2 gives a conceptual view of the outputs of an encoder that is turned clockwise (top) and then counter-clockwise (bottom). Some encoders may reverse this phase sequence. Red and black colors have been assigned to the pin states on the assumption that the terminals that are common to both pairs of contacts are connected with negative ground. Thus a "high" pulse in the graphical representation actually indicates that the encoder is grounding its output.
Figure 8-2. Hypothetical outputs from a rotational encoder, assuming that the common terminals of the contact pairs are connected to negative ground. A high pulse in the graphical representation therefore indicates that the contact pair is grounded. The number of detents relative to the number of pulses per rotation varies from one type of encoder to another.
Microcontrollers have become so ubiquitous, and rotational encoders are so cheap, they have displaced rotary switches in many applications where a low current is being switched. The combination of a rotational encoder and a microcontroller is very versatile, allowing display and control of an almost unlimited number of menus and options.
There are two types of rotational encoders containing mechanical contacts: absolute and relative. An absolute encoder generates a code corresponding with each specific rotational position. The code is usually a binary output among four or more pins. It is discussed under mechanical encoder in the rotary switch section of this encyclopedia. The variants listed here are all relative encoders.
Rotational encoders from different manufacturers may have as few as 4 or as many as 24 pulses per rotation (PPR), with 12 to 36 detents (or no detents at all, in a few models.) The relationship between pulses and detents shown in Figure 8-2 is typical but is far from being universal. The number of detents may be equal to, greater than, or less than the number of pulses per rotation.
Rotational encoders are generally panel-mounted or through-hole devices. In the latter category, most are horizontally mounted, with a minority being at 90 degrees to the board.
In an encoder containing two switches, four switch-state combinations are possible: OFF-OFF, ON-OFF, OFF-ON, and ON-ON. This is known as a quadrature output. All of the rotational encoders discussed here conform with that system.
Rotational encoders vary widely in the resistance that they offer when the user turns the knob. This is largely a function of the detents, if they are included. Still, all rotational encoders generally offer less rotational resistance than a rotary switch, and do not have the kind of heavy-duty knobs that are typically used with rotary switches. Since an encoder creates only a stream of pulses without any absolute positional information, a knob with any kind of pointer on it is inappropriate.
Virtually all rotational encoders are designed to work with a low-voltage supply, 12VDC or less. All of them are intended for low currents, reflecting their purpose to drive microcontroller inputs. Some sample rotational encoders are pictured in Figure 8-3. At rear: nine pulses per rotation (PPR), 36 detents, 10mA at 10VDC. Far left: 20PPR, 20 detents, with switch. Far right: 24PPR, no detents, 1mA at 5VDC. Center (blue): 16PPR, no detents, 1mA at 5VDC. Front: 12PPR, 24 detents, 1mA at 10VDC, requires Allen wrench or similar hexagonal shaft to engage with the rotor.
Any mechanical switch will suffer some degree of contact bounce when its contacts close. Datasheets for rotational encoders may include a specification for bounce duration ranging from around 2ms to 5ms, which is sometimes known as the settling time. Naturally, a lower value is preferred. The microcontroller that interprets the positional information from the encoder can include a debouncing routine that simply disregards any signals during the bounce period following switch closure.
Sliding noise is the opposite of contact bounce. When two contacts have made a connection and then rub across each other (as occurs inside a rotational encoder while the knob is being turned), the connection may suffer momentary lapses. Datasheets for rotational encoders generally do not supply ratings for this.
As noted above, a rotational encoder can only be used in conjunction with a microcontroller or similar device that is capable of interpreting the phase difference between the pairs of contacts, and is capable of counting the number of opening/closing events while the knob is being turned. (Some dedicated chips are designed for this specific purpose.)
It can be adapted to be driven by a stepper motor, to provide feedback regarding the rotation of the motor shaft, and its output can also be interpreted to calculate angular acceleration.
Programming the microcontroller is the most significant obstacle. Generally the program should follow a sequence suggested by this pseudocode:
Check:
Compare their status with previously saved states for A and B. If the status has not changed, repeat from Check.
Debounce:
If the changed states are in a small minority, probably the signal was erroneous, caused by bounce or sliding noise. Go back to Check and start over.
Interpret:
Deduce the rotational direction from these four possibilities: