Example Code

Measuring Angular Position of An Encoder Using Counter Output as Clock

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Hardware

  • Data Acquisition (DAQ)

    Software

  • LabVIEW

    Driver

  • NI DAQmx

Code and Documents

Attachment

Overview:
Demonstrates on measuring angular position of a quadrature encoder at the Counter Input channel using digital pulses generated by the Counter Output as the source clock.

Description:
The encoder position is measured on the counter's default A, B, and Z input terminals (refer to section IV, I/O Connections Overview, below for more information).
Note: For buffered position measurement, an external sample clock is necessary to signal when a sample should be inserted into the buffer.  This is set by the Sample Clock Source control.  
This example is set up to use the other counter available in the device to provide the external clock.

Requirements:

  1. LabVIEW 2012 or compatible.
  2. NI-DAQmx 15.5.1 or compatible.


Instructions:

  1. Select the Physical Channel which corresponds to the counter at which the angular position of the encoder will be measured.
  2. Enter all the control values under Counter Input tab to specify how the counter input channel measures position.  
    Samples to Read control will determine how many samples are read each time the while loop iterates.
  3. Set the Counter Output channel as the clock source.
    Note:  An external sample clock must be used.  Counters do not have an internal sample clock available.  
  4. Run this VI and monitor the Acquired Data indicator to verify the encoders angular position.


Block Diagram Steps:

  1. Create a Counter Input channel to measure the Encoder angular position.
  2. Call the DAQmx Timing VI (Sample Clock) to configure the external sample clock timing parameters.
  3. The Sample Clock Source determines when a sample will be inserted into the buffer.
    The 100kHz, 20MHz, and 80MHz timebases cannot be used as the Sample Clock Source. The Edge parameter can be used to determine when a sample is taken.
  4. Call the Start VI to arm the counter and begin measuring position.  The counter will be preloaded with the Initial Angle.
  5. For continuous measurements, the counter will continually read all available data until the Stop button is pressed on the front panel.
  6. Call the Clear Task VI to clear the Task.
  7. Use the popup dialog box to display an error if any.

 

Front Panel.PNG

 

bd.png

 

**This document has been updated to meet the current required format for the NI Code Exchange.**

Kyle A.
National Instruments
Senior Applications Engineer

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.