Connect Quadrature Encoders to a DAQ Device
Included in the Section
This document provides step-by-step instructions for wiring and configuring your NI data acquisition device for quadrature encoder measurements. Before you begin using your NI data acquisition hardware, you must install your application development environment (ADE) and NI-DAQmx driver software. Refer to the NI LabVIEW and NI-DAQmx document for more information.
You can use an NI Multifunction DAQ device, an NI CompactDAQ chassis with a digital I/O C Series module, or an NI Counter/Timer device to perform position measurements with quadrature encoders (also called an angular encoder). The counters on each of these devices can measure angular position with X1, X2, or X4 angular encoders. Quadrature encoders cause two signals to pulse while a shaft in the encoder rotates. These signals are signal A (also called channel A) and signal B (also called channel B), each of which is typically a TTL digital signal.
NI X Series devices and NI CompactDAQ chassis have four general-purpose 32-bit counter/timers. NI M Series devices and some other DAQ devices have two counter/timers. These general-purpose counter/timers use 5 V TTL digital signals and can be used for many measurement and pulse generation applications. Figure 1 shows Counter 0 on an X Series device.
Figure 1. Counter 0 on an NI X Series Device
All four counters are identical. Counters have eight input signals, although in most applications only a few inputs are used. Each counter has a FIFO that can be used for buffered acquisition and generation.
Channel A and B are offset by 90°, which determines the direction the encoder moves. When channel A leads channel B in a quadrature cycle, the counter increments. When channel B leads channel A in a quadrature cycle, the counter decrements. The amount of increments and decrements per cycle depends on the type of encoding—X1, X2, or X4.
Figure 2 shows a quadrature cycle and the resulting increments and decrements for X1 encoding. When channel A leads channel B, the increment occurs on the rising edge of channel A. When channel B leads channel A, the decrement occurs on the falling edge of channel A.
Figure 2. X1 Encoding
The same behavior holds for X2 encoding except the counter increments or decrements on each edge of channel A, depending on which channel leads the other. Each cycle results in two increments or decrements, as shown in Figure 3.
Figure 3. X2 Encoding
Similarly, the counter increments or decrements on each edge of channels A and B for X4 encoding. Whether the counter increments or decrements depends on which channel leads the other. Each cycle results in four increments or decrements, as shown in Figure 4.
Figure 4. X4 Encoding
Some quadrature encoders have a third channel, channel Z, which is also referred to as the index channel. A high level on channel Z causes the counter to be reloaded with a specified value in a specified phase of the quadrature cycle. You can program this reload to occur in any one of the four phases in a quadrature cycle.
Channel Z behavior—when it goes high and how long it stays high—differs with quadrature encoder designs. You must refer to the documentation for your quadrature encoder to obtain timing of channel Z with respect to channels A and B. You must then ensure that channel Z is high during at least a portion of the phase you specify for reload. For instance, in Figure 5, channel Z is never high when channel A is high and channel B is low. Thus, the reload must occur in some other phase.
In Figure 5, the reload phase is when both channel A and channel B are low. The reload occurs when this phase is true and channel Z is high. Incrementing and decrementing takes priority over reloading. Thus, when the channel B goes low to enter the reload phase, the increment occurs first. The reload occurs within one maximum timebase period after the reload phase becomes true. After the reload occurs, the counter continues to count as before. The figure illustrates channel Z reload with X4 decoding.
Figure 5. Channel Z Reloaded with X4 Decoding
Before connecting any signals, locate your device pinout.
Figure 6. Device Terminals Help
The following terminal types correspond with quadrature encoder measurements:
You can use NI Measurement & Automation Explorer (MAX) to quickly verify the accuracy of your measurement system setup. Using an NI-DAQmx Global Virtual Channel you can configure a quadrature encoder measurement without any programming. A virtual channel is a concept of the NI-DAQmx driver architecture used to represent a collection of device property settings that can include a name, a physical channel, input terminal connections, the type of measurement or generation, and scaling information.
Follow these steps to begin:
Figure 7. Creating an NI-DAQmx Virtual Channel
Figure 8. Device Physical Channels
Figure 9. Setting up an Angular Position Channel in MAX
The next step is to physically connect the quadrature encoder to your DAQ device.
Figure 10. Quadrature Encoder Input Signal Connections
NI-DAQmx global virtual channels allow you to preview your measurements.
Figure 11. Previewing an Angular Position Measurement in MAX
You also have the option of saving your NI-DAQmx Global Virtual Channel should you wish to refer to this configuration screen again in the future.