From 07:00 PM Friday, February 26 - 05:30 PM CST Saturday, February 27, will be undergoing system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Archived: Using Quadrature Encoders with E Series DAQ Boards

NI does not actively maintain this document.

This content provides support for older products and technology, so you may notice outdated links or obsolete information about operating systems or other relevant products.


The DAQ-STC, the System Timing Controller device, is used on NI E Series multifunction DAQ devices as the timing engine for data acquisition and control operations. The DAQ-STC includes two general-purpose counter/timers that are useful for a wide variety of applications. This document describes how you can use the DAQ-STC counter/timers to interface to quadrature encoders.


Note: NI released the next series of multifunction DAQ devices, NI M Series. The M Series devices, based on the NI-STC 2 system timing controller, provide NI-TIO counter features such as quadrature encoder support; anti-dithering circuitry; and 32-bit, 80 MHz flexible counter/timers. This allows quadrature encoder use without the aid of an external quadrature clock converter.



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 (refer to Figure 1). As the disk rotates, these patterns interrupt the light emitted onto the photodetector, generating a digital or pulse signal output.

Figure 1. Optical Encoder

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, usually 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 2-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.

Figure 2. Quadrature Encoder Output Channels A and B

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.

The DAQ-STC Counter/Timer – An Overview

To meet the demands of today's high-performance data acquisition and control applications, NI developed the Data Acquisition System Timing Controller (DAQ-STC), which integrates all data acquisition counter/timer functionality into a single ASIC. Designed primarily for use on multifunction input and output DAQ boards, the DAQ-STC includes 10 counter/timer devices, eight of which are designed to control the timing of analog input and analog output operations. The remaining two counter/timers are 24-bit up/down counter/timers available for a wide variety of timing and counting applications. The DAQ-STC is included on all NI E Series devices, including plug-in boards for PCI bus, PCMCIA cards, and PXI modules.

Each of the two 24-bit counter/timers of the DAQ-STC includes three input signals (SOURCE, GATE, and UP_DOWN) and two output signals (OUT and INTERRUPT), as shown in Figure 3.

Figure 3. Simplified Counter/Timer Model of DAQ-STC

Using Quadrature Encoders with the DAQ-STC

Note: NI released the next series of multifunction DAQ devices, NI M Series. The M Series devices, based on the NI-STC 2 system timing controller, provide NI-TIO counter features such as quadrature encoder support; anti-dithering circuitry; and 32-bit, 80 MHz flexible counter/timers. This allows quadrature encoder use without the aid of an external quadrature clock converter.

While the DAQ-STC includes a number of features useful for a large variety of timing and counting applications, its up/down counting feature is particularly convenient for encoders.

When using the DAQ-STC in event-counting mode, connect the pulse signal to be counted to the SOURCE input. When armed, the DAQ-STC count register increments (or decrements) on each transition at the SOURCE input (configurable for rising or falling edges). In addition, you can configure the DAQ-STC to count up, count down, or count up or down as determined by the state of the UP_DOWN input.

When using quadrature encoders with the DAQ-STC, you have two choices. First, for simple applications, you can connect the encoder directly to the DAQ-STC, without any extra logic or signal conditioning. Although simple to implement, this configuration has the disadvantage of not being able to discern between stationary vibration of the encoder and real rotation. Second, you can interface the encoder to the DAQ-STC using a using a quadrature clock converter IC. This method prevents errors due to jitter and debouncing, and provides higher measurement resolution. These two methods are described in the following sections.

Note on Signal Levels
The DAQ-STC, as well as the quadrature clock converter described here, provides TTL and CMOS compatible inputs and outputs. If your encoder provides outputs that are a different signal level—24 V for example—then you may damage your equipment by connecting it directly to the DAQ-STC or clock converter. Therefore, you must either use an encoder that outputs TTL/CMOS signals, or use appropriate signal conditioning to convert the signal level and isolate the TTL/CMOS circuitry from high voltages. In either case, you may want to optically isolate your A and B signal lines to protect your DAQ board, PC, and operator from accidental application of high voltages.

Method 1 – Direct Connection to DAQ-STC (No Signal Conditioning)
For simple applications, you can connect quadrature encoders to the DAQ-STC counter/timer available on NI E Series DAQ boards. By taking advantage of the UP_DOWN control input, you can use the DAQ-STC to count up or down depending on the direction of shaft rotation.

To connect the encoder to the DAQ-STC, wire Channel A output of the encoder to the SOURCE input of the DAQ-STC and wire Channel B output of the encoder to the UP_DOWN input. Figure 4 illustrates these connections for an AT-MIO-16E-2 board. Notice that the UP_DOWN input is accessed on the P0.6 pin for counter 0 or P0.7 for counter 1.

Figure 4. Direct (Unconditioned) Encoder Connection to E Series DAQ Board

In this configuration, the counter will increment on state transitions (default low-to-high) on Channel A. When a Channel A low-to-high transition occurs, the state of Channel B will be high or low, depending directly on the direction of rotation. Therefore, the DAQ-STC counter will increment when the encoder rotates in one direction and decrement when the encoder rotates in the opposite direction.

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.

Figure 5. Dithering Effect of Vibration

Method 2 – Using Clock Converter with DAQ-STC for Reliable Measurements
You can greatly improve the reliability and quality of encoder measurements by using a clock converter device that conditions the encoder signals to prevent errors due to vibration, noise, and jitter. For example, the Encoder Signal Conditioner from Wineman Technology Inc. converts the A and B signals from an encoder into a clock and an up/down signal that you can connect directly to the DAQ-STC. The WTI Encoder Signal Conditioner also provides optical isolation and anti-dithering circuitry to protect measurement systems and prevent false counts due to mechanical vibration. For additional information, the WTI Encoder Signal Conditioner’s data sheet can be viewed at the end of this document.


You control and use NI DAQ products with NI-DAQ, a software driver that you can use with LabVIEW, LabWindows/CVI, Measurement Studio, 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 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 document. 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 CTR function calls. In particular, to configure a DAQ-STC counter for up/down counting, use the CTR_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:

WTI Encoder Signal Conditioner Data Sheet

Wineman Technology Inc.

(click the images to see full size)