Where EEs Navigate A Changing World.
Globe

Quadrature Encoding Explained

by: Michael Stanley & EE HomePage.com
Last revision: Figure 6 was revised on 4 July 2009

One of the most popular schemes for encoding direction and speed data is "quadrature encoding". You will find quadrature encoded signals inside your computer mouse, your desktop scanner, and motion control applications of all kinds. The types of sensors used to generate quadrature encoded signals vary greatly, but the interface itself is extremely simple and easy to understand.

We will illustrate the encoding process using a wheel encoder, shown in Figures 1 and 2, which spins about a center axis.

Figure 1: Wheel encoder view 1
Figure 2: Wheel encoder view 2

The encoder (which can be seen in more detail by clicking on either of the two figures above) has these basic components:

Let us consider the case where the wheel is rotating clockwise, in the direction shown by the arrow in Figure 1. Phototransistors (C) and (D) turn on when exposed to light from the LED through the gaps in the wheel, and off when that light is blocked by the wheel. Thus they will alternate between "on" and "off" based upon the position of wheel (A). If we consider "on" to be logic 1 and "off" to be logic 2, we might record the following sequence of values as the wheel spins:

Sample # Encoder State (D,C) Transition Increment Direction 8 X Estimated Revolution Count
00,0 x,x to 0,0 ASSUMED ZERO unknownASSUMED ZERO
11,0 0,0 to 1,0 +1 clockwise1
21,1 1,0 to 1,1 +1 clockwise2
30,1 1,1 to 0,1 +1 clockwise3
40,0 0,1 to 0,0 +1 clockwise4
51,0 0,0 to 1,0 +1 clockwise6
61,1 1,0 to 1,1 +1 clockwise7
70,1 1,1 to 0,1 +1 clockwise8
80,0 0,1 to 0,0 +1 clockwise9
91,0 0,0 to 1,0 +1 clockwise10

Assuming that encoder states are sampled at regular intervals, we can use the data above to calculate rotation speed.

Now consider the case where we reverse the direction and the wheel and start spinning it counter counter-clockwise.

Sample # Encoder State (D,C) Transition Increment Direction 8 X Estimated Revolution Count
100,0 1,0 to 0,0 -1 counter-clockwise9
110,1 0,0 to 0,1 -1 counter-clockwise8
121,1 0,1 to 1,1 -1 counter-clockwise7
131,0 1,1 to 1,0 -1 counter-clockwise6
140,0 1,0 to 0,0 -1 counter-clockwise5
150,1 0,0 to 0,1 -1 counter-clockwise4
161,1 0,1 to 1,1 -1 counter-clockwise3
171,0 1,1 to 1,0 -1 counter-clockwise2
180,0 1,0 to 0,0 -1 counter-clockwise1
190,1 0,0 to 0,1 -1 counter-clockwise0

Inspecting the states above, we can see that the two bit encoder field (D,C) is Gray Code Encoded. Only one of the two bits changes for any given state transition. Furthermore, we can tell whether the wheel is turning clockwise or counter-clockwise based upon the state transistions, which are mutually exclusive for the two directions, as shown in the table below.

State Clockwise Transition To Here Counter-Clockwise Transition to Here
0,0 0,1 to 0,0 1,0 to 0,0
1,0 0,0 to 1,0 1,1 to 1,0
1,1 1,0 to 1,1 0,1 to 1,1
0,1 1,1 to 0,1 0,0 to 0,1

Most engineers will be more comfortable with the table above represented as a state transition diagram, as shown in Figure 3.

Figure 3: Quadrature Encoder State Transition Diagram

The sensor state (D,C) over time is often depicted as set of waveforms 90 degrees out of phase with one another, as shown in Figure 4. The phase difference of 90 degrees is not critical (altough some LSB accuracy may be gained for cases where it is true). What is important is that state transitions obey the rules outlined in Figure 3. Quadrature encoded signals are used on many different types of sensors, and many microcontrollers have dedicated circuitry to decode these signals, and thus track position over time.

Figure 4: Quadrature Encoded Signals

The resolution of the encoding wheel shown above is roughly 1/4 revolution of the wheel. To increase resolution, most rotary encoders will have many more divisions per rotation than is shown in the figures. Figure 5 shows a real life example of such an encoder used to track one dimension of travel by a mechanical mouse.

Figure 5: Encoder in-situ within a mechanical mouse

Quadrature encoding provides only "relative" position encoding. There is no indication of absolute position, only position relative to some starting point. To address this, some sensors will include an additional signal to flag when the sensor is in its "HOME" position. A linear encoder incorporating an additional "HOME" is shown in Figure 6. In this case, the encoder strip moves left or right under the sensor. Although the physical design is completely different, the encoder outputs for phases A and B are exactly of the form already discussed.

Figure 6: Linear Encoder

To Learn More