Sunday, October 19, 2014

rotational encoder What It Does,How It Works ,Variants,Values,How to Use it and What Can Go Wrong

 

The term rotationalencoder used to be reserved for high-quality components, often using optical methods to measure rotation with precision (more than 100 intervals in 360 de­ grees). Cheaper, simpler, electromechanical devices were properly referred to as control shaft encoders. However, the term rotational encoder is now applied to almost any device capable of converting rotational position to a digital output via opening and closing internal mechanical contacts; this is the sense in which the term is used here. It is some­ times distinguished from other types of encoder with the term mechanical rotary en­ coder. Magnetic and optical rotary encoders do not contain mechanical switches, are classified as sensors by this encyclopedia, and will appear in Volume 3. They are found in a device such as an optical mouse.

What It Does

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 compo­ nent is almost always connected to inputs on a microcontroller and is usually fitted with de­ tents 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 rela­tive device, meaning that it merely creates and breaks internal switch connections when rota­tion 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 rota­tional encoder.

How It Works

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 momen­tarily before the B pair; in a counter-clockwise di­rection, the B pair may be activated before the A pair. (Some encoders reverse this phase differ­ence.) Thus if one contact from each pair is con­nected with two inputs of an appropriately pro­grammed microcontroller, and if the other con­ tact 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 con­tacts 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.

clip_image006

Figure 8-1. Simplified schematic showing the typical set- up 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 encod­ers 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 com­

clip_image008

Figure 8-2. Hypothetical outputs from a rotational en- coder, assuming that the common terminals of the con- tact 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.

bination of a rotational encoder and a microcon­troller is very versatile, allowing display and con­trol of an almost unlimited number of menus and options.

Variants

There are two types of rotational encoders containing mechanical contacts: absolute and rela­tive. An absolute encoder generates a code cor­responding with each specific rotational posi­ tion. The code is usually a binary output among

four or more pins. It is discussed under mechan­ical encoder in the rotary switch section of this encyclopedia. The variants listed here are all rel­ative encoders.

Pulses and Detents

Rotational encoders from different manufactur­ers 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.

Format

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.

Output

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 en­ coders discussed here conform with that system.

Rotational Resistance

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 in­cluded. Still, all rotational encoders generally of­fer 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 inappro­priate.

Values

Virtually all rotational encoders are designed to work with a low-voltage supply, 12VDC or less. All of them are intended for low currents, reflect­ing 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 hexag­onal shaft to engage with the rotor.

clip_image012

Figure 8-3. Rotational encoders with a variety of specifications. See text for details.

Contact Bounce

Any mechanical switch will suffer some degree of contact bounce when its contacts close. Data­ sheets 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 in­clude a debouncing routine that simply disre­gards any signals during the bounce period fol­lowing switch closure.

Sliding Noise

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 ro­tational encoder while the knob is being turned), the connection may suffer momentary lapses. Datasheets for rotational encoders generally do not supply ratings for this.

How to Use it

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 open­ing/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 mo­tor, to provide feedback regarding the rotation of the motor shaft, and its output can also be in­ terpreted to calculate angular acceleration.

Programming the microcontroller is the most significant obstacle. Generally the program should follow a sequence suggested by this pseudocode:

Check:

• If the encoder contains a pushbutton switch, check it. If the pushbutton is being pressed, go to an appropriate subroutine.

• The status of contacts A.

• The status of contacts B.

Compare their status with previously saved states for A and B. If the status has not changed, repeat from Check.

Debounce:

• Recheck the contacts status rapidly and re­peatedly for 50ms, and count the states for

contacts A and B. (The 50ms duration may be adjusted for different encoders, as an en­ coder with a higher number of pulses per rotation will tend to create shorter pulses.)

• Compare the total number of changed states with unchanged states.

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:

—Contacts A were open and have closed.

—Contacts A were closed and have opened.

—Contacts B were open and have closed.

—Contacts B were closed and have opened. (The specific type of encoder will deter­ mine how these transitions are interpret­ ed.)

• Revise the variable storing the direction of rotation if necessary.

• Depending on the direction of rotation, in­crement or decrement a variable that counts pulses.

• Take action that is appropriate to the direc­tion of rotation and the cumulative number of pulses.

• Go back to Check again.

What Can Go Wrong
Switch Bounce

In addition to a debouncing algorithm in the mi­ crocontroller, a 0.1μF bypass capacitor can be used with each of the output terminals from the encoder, to help reduce the problem of switch bounce.

Contact Burnout

Rotational encoders are TTL-compatible. They are not generally designed to drive even a small output device, such as an LED. The contacts are extremely delicate and will be easily damaged by any attempt to switch a significant current.