FIGURE 2. The quadrature encoder simulator.
FIGURE 3. A quadrature encoder helper module.
FIGURE 4. Infrared receiver and transmitter circuit.
60 SERVO 02.2009
left one will still be covered by the spoke. So the data pair
becomes , then [ 11] as the wheel continues to turn,
and both sensors are now under an opening. As the wheel
turns further, the next spoke will move to cover the right
sensor while the left one is still uncovered [ 10]. Finally, the
two sensors will both be covered again repeating the cycle
of four states. These four patterns (states) repeat as long
as the wheel is turning CCW. If the wheel turns clockwise
(CW), we will get the following four states: 00, 10, 11,
and 01 (see Table 1).
To help in visualizing and understanding quadrature
encoding, we wrote a simulation using RobotBASIC that
makes it easy to see exactly how the patterns are generated
in real time (see Figure 2). You can download a free copy
of RobotBASIC and the Quadrature_Simulator.BAS program
(and many other programs) from www.RobotBASIC.com.
It is relatively easy to program a µC to monitor the
pulses from the two infrared sensors to maintain a count of
how many state transitions have occurred (positive is CW
and negative is CCW). This count can be used to calculate
(see later) the wheel's position relative to its initial starting
point. However, if the µC is busy doing other tasks like
sending serial commands to a motor-control HM, it might
miss some state transitions, especially if the wheel is turning
fast. If we had an HM that counted the transitions all by
itself, the µC would communicate with it whenever it needed
to know the count and thus no transition will be missed.
The encoder only returns a count of the movement and
direction (negative or positive values). It is up to the system
that utilizes the encoder to convert the count into an
absolute value of movement meaningful for the situation at
hand. For example, in Figure 1, since we know the size of
the spokes, we can calculate how far the wheel moves.
Since the movement from one spoke to another (a spoke
and opening) produces four states (i.e, a count of 4) then:
Amount_Of_Movement = Count_Of_State_Changes ×
(2 × Spoke_Size) ÷ 4
In Figure 1, the spoke size is 20°, so for every state
transition we know the wheel has moved 10° (1×2× 20÷ 4).
If the wheel rotates to create 33 state transitions, we can
infer that the wheel has moved 330°. If the movement is
CCW, the value would be -330° (- 33× 10). To maintain the
value within 0° to 360°, (as in a compass heading), we
need to add 360° resulting in a heading of 30°. This is all
performed by the µC, not the HM. The HM only returns the
count of state transitions. With a 20° spoke and correctly
placed sensors, the resolution of the system is 10°
(2 × 20÷ 4), giving us ± 5° of precision. You can see how
this works in real time using the simulator. You can observe
the precision limit by comparing the calculated angle value
(per above logic) and the actual angle of the wheel as you
move it. You will notice that the actual angle may be within
± 5° of the calculated angle.
For a finer resolution, a smaller spoke size should
be used. The simulator mentioned above allows you to