Chapter 8. rotational encoder

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

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.

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.

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: