Student Projects

cancel
Showing results for 
Search instead for 
Did you mean: 

Angular Position Measurement with a Quadrature Encoder

Angular Position Measurement with a Quadrature Encoder

Purpose

 

The purpose of this document is to provide an explanation of how quadrature encoders work and how they can be used with the NI myDAQ.

Figure 1.png

Figure 1- Angular Encoder

 

Background

 

Quadrature encoders use two sets of light sources and detectors mounted along a track of opaque and clear segments to detect changes in position.  The track is placed between the light source and detector so that when the object to which the track is mounted moves, the light detector outputs a square waveform.

Figure 2.png

Figure 2- Positioning for light source and detector

 

To detect which direction the track is moving, a second series of opaque and clear segments is added to the track along with another light source and detector. Now, when the object is moving, the two light detectors, called channel A and channel B, output signals that are 90 degrees out of phase.

Figure 3.png

Figure 3- Quadrature Encoder track and signal

 

The direction of movement is determined by which signal is leading.  If the track in Figure 3 was moving to the left, channel A would be 90 degrees ahead of channel B (as shown in Figure 3).  If the track was moving to the right, channel B would be 90 degrees ahead of channel A.

Some encoders also have a third output for position reference.  This output is called the index, or the Z-terminal (zero terminal).  For angular encoders, this signal would be detected once per revolution, and is used to maintain precision and to give reference to an absolute position rather than a position relative to the starting one.

Equipment

 

  • NI myDAQ
  • Angular Encoder

Hardware Setup

 

The first three digital lines of the NI myDAQ will be used for reading the signals from the encoder. Refer to the datasheet of the encoder being used to identify the pin-outs of the encoder and how to wire it. Connect the three outputs (or two if there is no index) to the digital channels according to Table 1 below.

Table 1- NI myDAQ counter pin-outs

NI myDAQ Channel

Quadrature Encoder Signal

DIO 0

Channel A

DIO 1

Z-terminal

DIO 2

Channel B

 

Software Instructions

 

A LabVIEW VI has already been written to read the channels of the encoder. Download the attached VI or drag the code below into a block diagram.

VI Snippet- Encoder.png

Figure 4- VI Snippet

 

The VI can also be found in the LabVIEW Example Finder.  To find the VI this way, open a VI and go to Help>>Find Examples… located in the taskbar at the top of the window.  Once the example finder loads, search for “measure angular position” and select the VI named “Measure Angular Positon.vi”.

Figure 5.png

Figure 5- Example Finder

 

Once the VI is open, select the proper device and channel for the myDAQ device being used (ctr0).  Next, select the decoding type. 

Figure 6.png

Figure 6- VI Front Panel

 

The difference between the decoding schemes is which of the signal’s edges are being counted.  In “X1” decoding, only the rising edges of channel A’s signal are counted, which gives a number of discrete points equal to the number of pulses per revolution for the encoder being used. 

Figure 7.png

Figure 7- X1 Decoding

 

The number of points per revolution can be doubled (halving the resolution) if “X2” decoding is used.  This achieved by counting both the rising and falling edges of channel A’s signal.

Figure 8.png

Figure 8- X2 Decoding

 

Lastly, “X4” decoding counts the rising and falling edges of both channels A and B, giving the best resolution (4 times as good as “X1”). 

Figure 9.png

Figure 9- X3 Decoding

 

If a Z-index is being used, press the “Z Index Enable” button and set the “Z Index Value” and “Z Index Phase” to the appropriate values.

Other Resources

 

Using the myDAQ Counter

 

Quadrature Encoder Guide

 

Jeff S.
National Instruments
Comments
NamHKim
Member
Member
on

Thanks for the info.

I've used a type of optical quadrature encoder to measure absolute elbow angle for stroke patients, but it turns out it's not the best candidate because it loses one or two b&w notches here and there, which accumulates over time, and gave me few degrees of error which was way more than tolerable error. It was prominent when the patient 'changes direction' in their flexion/extention elbow movement. If more than one encoder with differently sized notch-wheel is used, some type of error correction can be implemented. So, I'd say single optical encoders are good for speed measurement, but less perfect for absolute angular position sensors.

danm1
Member
Member
on

Hello,

I have a NI-Elvis I and I want to use a encoder with this applications. The virtual instrument does not work? We selected the number of pulses per rotation but movement remains 0. What pins should connect signals A and B?

handsomebo
Member
Member
on

my vi does not work too