Connecting Quadrature Encoders to a DAQ Device

Included in the Section

Before You Begin

This document provides step-by-step instructions for wiring and configuring your NI DAQ device for quadrature encoder measurements. Before you begin using your NI DAQ hardware, you must install your application development environment and NI-DAQmx driver software. Refer to the LabVIEW and NI-DAQmx document for more information.

Quadrature Encoder Measurement Fundamentals

You can use an NI multifunction DAQ device, a 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 angular encoders). 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.

Counters

X Series devices and CompactDAQ chassis have four general-purpose 32-bit counter/timers. M Series devices and some other DAQ devices have two counter/timers. These general-purpose counter/timers use 5 V TTL digital signals for many measurement and pulse generation applications. Figure 1 shows Counter 0 on an X Series device.

Figure 1. Counter 0 on an 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.

Encoding

Channel A and B are offset by 90 deg, 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.

X1 Encoding

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

X2 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

X4 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

Channel Z Behavior

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 the 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 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 reloaded with X4 decoding.

Figure 5. Channel Z Reloaded With X4 Decoding

Locating Your DAQ Device Pinout

Before connecting any signals, locate your device pinout.

  1. Open Measurement & Automation Explorer (MAX) and expand Devices and Interfaces.
  2. Right-click on your device name, and select “Device Pinouts.” Note that the table beneath the connector pinout contains information related to counter inputs.

Figure 6. Device Terminals Help

The following terminal types correspond with quadrature encoder measurements:

  • CTR x A: Quadrature Encoder Channel A — Channel A and channel B determine which direction the encoder moves.
  • CTR x B: Quadrature Encoder Channel B — Channel A and channel B determine which direction the encoder moves.
  • CTR x Z: Quadrature Encoder Index — A high level on channel Z causes the counter to be reloaded with a specified value in a specified phase of the quadrature cycle.
  • PFI x: Programmable Function Interface — PFI lines are TTL digital I/O lines that may be routed to counter inputs or outputs or other digital signals from your DAQ device. Refer to the table beneath your pinout diagram for a list of which PFI lines correspond with which counter inputs.
  • D GND: Digital Ground — The ground reference for digital I/O, counter, and PFI lines.

Configuring a Quadrature Encoder Measurement

You can use MAX to quickly verify the accuracy of your measurement system Set Up. 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:

  1. With MAX open, select Data Neighborhood and click Create New.
  2. Select NI-DAQmx Global Virtual Channel and click Next.
  3. Select Acquire Signals » Counter Input » Position » Angular

Figure 7. Creating an NI-DAQmx Virtual Channel

  1. 6. Select the physical channel that you will connect your encoder to. A physical channel is a terminal or pin at which you can measure or generate an analog or digital signal.

Figure 8. Device Physical Channels

  1. Click Next and enter a name for the global virtual channel or leave the default.
  2. Click Finish to see the following screen in MAX:

Figure 9. Setting Up an Angular Position Channel in MAX

  1. On the Settings tab, type in the Pulses per Revolution (Pulses / Rev). This value is the number of pulses of either the A signal or the B signal — not the total number of pulses on both the A and B signals.
  2. Type in the Initial Angle, the starting angle of the encoder. This value is in the units you specify with the Units pull-down.
  3. Check the Z Index Enable to specify whether your encoder supports z indexing for the measurement.
  4. If you enable the Z index, the Z Index Value specifies in Units the value to reset the measurement to when signal Z is high, and signals A and B are at the states you specify with the Z index Phase pull-down.
  5. Select the Decoding Type to specify how to count and interpret the pulses the encoder generates on signals A and B. Two Pulse Counting is not valid for quadrature encoders. X2 and X4 decoding are more sensitive to smaller changes in position than X1 encoding, with X4 being the most sensitive.

Wiring A Quadrature Encoder to Your Device

The next step is to physically connect the quadrature encoder to your DAQ device.

  1. On the Settings tab of your angular position global channel in MAX, refer to the Signal Connections. Based on your physical channel and whether you enable Z indexing, MAX displays the PFI terminals to which you should connect your quadrature encoder signals. Counter (and PFI) input connections are referenced to D GND.
  2. Refer to your device pinouts, MAX, and the diagram below to connect your A, B, (optional) Z, and COM signals. Your encoder may also offer documentation.

Figure 10. Quadrature Encoder Input Signal Connections

Testing the Signal

Use NI-DAQmx global virtual channels to preview your measurements.

  1. With MAX still open, click back on the NI-DAQmx Global Channel tab and click on the Run button. The angular position value of your measurement is displayed at the top of the screen.

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.

Prev Connect and Set Up Hardware
Introduction to LabVIEW Next