Using Quadrature Encoders With E Series DAQ Boards: Application Note 084
Using Quadrature Encoders With E Series DAQ Boards: Application Note 084
Encoders
An encoder is a device that converts linear or rotary displacement into digital or pulse signals. The most popular
type of encoder is the optical encoder, which consists of a rotating disk, a light source, and a photodetector (light
sensor). The disk, which is mounted on the rotating shaft, has patterns of opaque and transparent sectors coded into
the disk (see Figure 1). As the disk rotates, these patterns interrupt the light emitted onto the photodetector,
generating a digital or pulse signal output.
____________________________
Product and company names are trademarks or trade names of their respective companies.
341124A-01
May 1996
There are two general types of encoders absolute and incremental encoders.
Absolute Encoders An absolute encoder generates a unique word pattern for every position of the shaft. The
tracks of the absolute encoder disk, generally four to six, commonly are coded to generate binary code, binary-coded
decimal (BCD), or gray code outputs. Absolute encoders are most commonly used in applications where the device
will be inactive for long periods of time, there is risk of power down, or the starting position is unknown.
Incremental Encoders An incremental encoder generates a pulse, as opposed to an entire digital word, for each
incremental step. Although the incremental encoder does not output absolute position, it does provide more
resolution at a lower price. For example, an incremental encoder with a single code track, referred to as a
tachometer encoder, generates a pulse signal whose frequency indicates the velocity of displacement. However, the
output of the single-channel encoder does not indicate direction. To determine direction, a two-channel, or
quadrature, encoder uses two detectors and two code tracks.
Quadrature Encoders
The most common type of incremental encoder uses two output channels (A and B) to sense position. Using two
code tracks with sectors positioned 90 out of phase (Figure 2), the two output channels of the quadrature encoder
indicate both position and direction of rotation. If A leads B, for example, the disk is rotating in a clockwise
direction. If B leads A, then the disk is rotating in a counter-clockwise direction. Therefore, by monitoring both the
number of pulses and the relative phase of signals A and B, you can track both the position and direction of rotation.
In addition, some quadrature detectors include a third output channel, called a zero or reference signal, which
supplies a single pulse per revolution. This single pulse can be used for precise determination of a reference
position.
Limitations of Method 1
While the configuration described above is very simple to implement, this method has a couple of potentially serious
drawbacks. If the encoder disk is not rotating, but is vibrating enough back and forth to cause active transitions on
Channel A, then each movement will be incorrectly counted. The effect of this dither motion is illustrated in Figure
5. As the encoder disk moves back and forth across A2, Channel B remains low but the DAQ-STC counter
continues to increment the count, resulting in an incorrect position reading. The quadrature clock converter device
described in the next section solves this problem.
Another problem results when encoder outputs include noise or jitter that is large enough to be erroneously counted
as a valid state transition. You can solve this problem with lowpass filters on the A and B signal outputs.
Software
You control and use National Instruments DAQ products with NI-DAQ, a software driver that you can use with
LabVIEW, LabWindows/CVI, ComponentWorks, or a third-party programming language. NI-DAQ includes
function calls to use the DAQ-STC device for counting and timing.
LabVIEW The How to Count.vi example that is included with the LabVIEW package includes several
programming examples for counting applications with the DAQ-STC. Counting method number 3, count up and
down, can be used with the quadrature encoder setups described in this application note. In short, this method
enables the up/down counting by setting the count direction parameter in the CTR MODE CONFIG function to a
value of 3.
LabWindows/CVI and NI-DAQ When using LabWindows/CVI, or NI-DAQ with other programming languages,
you program the DAQ-STC with GPCTR function calls. In particular, to configure a DAQ-STC counter for
up/down counting, use the GPCTR_Change_Parameter function with parameter type set to ND_UP_DOWN and
parameter value set to ND_HARDWARE.
Once the DAQ-STC is properly configured and your software program correctly retrieves the count from the
counter, you can convert the count into rotation by using one of the following simple formulas:
10
11