Quadrature Encoder/Decoder Basics

[Technical Support Page]



"Quadrature" refers to two periodic functions separated by a quarter cycle or 90 degrees.
Examples of these functions are the reactive current or voltage found in capacitive or
inductive circuits. In this chapter, the signals produced by an Incremental Optical
Quadrature Encoder are discussed. The encoder is termed "incremental" because the
output is relative to a starting position and only the "distance moved" is measured.


Encoding

Incremental encoders are available in linear as well as the more common rotary
types. The operation of the rotary type is explained here.

Incremental Encoders

The main components of the rotary incremental encoder are; an encoder disk, light
source and photodetectors, plus amplification circuitry to "square-up" the
photodetector outputs. The encoder disk is imprinted with marks or slots evenly spaced
around its perimeter. As the disk rotates, light strikes the photodetector at the passing
of each slot or mark. Amplifiers then convert the photodetector output to square
wave form. Quadrature signals are produced by using two photodetectors, one
positioned precisely one half a slot or marker width from the other. With this
arrangement, the direction of rotation can be easily detected by monitoring the relative
phase of both signals. For example, if channel A leads channel B, then Counter
Clockwise (CCW) movement could be indicated. Conversely, channel B leading
channel A would indicate Clockwise (CW) rotation.

Typically, rotary encoders also provide an additional single marker or slot on the
disk used to produce a reference pulse. By properly decoding and counting these
signals, the direction of motion, speed, and relative position of the encoder can be
determined.

The number of output pulses produced per revolution per channel is equivalent to
the number of marks around the disk. When decoded through the PCI-20007M-1A,
the number of decoded pulses is actually four times dus figure. Resolution is
multiplied because the circuit generates a pulse at any rising or falling edge of either
of the two phase signals.

In summary, rotary quadrature encoders provide up to three output signals. Two 90
degree out of phase "square wave" type signals for direction indication, and frequently,
a third signal that provides a reference pulse once per revolution.


Decoding

Decoding signals generated by a quadrature encoder is a little more difficult to
understand than the encoding technique. However, understanding how the signals are
processed will help considerably when applying the PCI-20007M-1A's quadrature
decoder feature in an actual situation.

The basic task of the decoder is to provide two counter input lines - one that only
produces clock pulses when CCW motion is detected, and another which only pro-
duces clock pulses when CW motion is detected. These clock pulses are then supplied
to counters on the PCI-20007M-1A (one channel for CW and one for CCW counts).
The counter contents can be compared against each other by software, and the
relative position of the rotary device can be determined from the difference.

One big advantage of this approach is that the actual counting is done by hardware
devices, freeing the computer for other operations. The computer has only to peri-
odically read the counter values and a make a quick subtraction.

Decoder Theory of Operation

First, a closer look at the quadrature signals will be helpful (see Figure 1). In this
example, the direction of rotation is CCW if phase A leads phase B, and CW if
phase A lags B.

The decoder circuit detects a transition and generates a pulse on the appropriate
counter input channel depending on whether the transition is in the CW or CCW
direction. Figure 1 summarizes these signals. Please note that although time is
plotted on the horizontal axis it is not necessarily linear; the mechanical device may
be changing speed as well as direction.