Example Code

DAQmx - Measure Angular Position - Buffered - Counter 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
This example demonstrates how to measure angular position using a  quadrature encoder on a Counter Input Channel.  The Decoding Type,  Pulses Per Revolution, Z Index Enable, Z Index Phase, Z Index Value, and  Sample Clock Source are all configurable.

 

Description
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 Clock Source control.  This example is set up  to use the other counter on a two+ counter device to provide the  external clock, eliminating the need to provide an alternate clock.  This does however, use an another counter in addition to the counter which measurese the angular position.

 

Steps to Complete

Front Panel Steps:

  1. Select the Physical Channel which corresponds to the counter you want to measure position on the DAQ device.
  2. Enter the Decoding Type, Pulses Per Revolution, Z Index Enable, Z Index Phase, Z Index Value to specify how you want the counter to measure position.  Set the Clock Source as another counter on the device.
    Note:  An external sample clock must be used.  Counters do not have an internal sample clock available.  You can use the Gen Dig Pulse Train-Continuous example to generate a pulse train on another counter and connect it to the Sample Clock Source you are using in this example.
  3. Set the Samples to Read control.  This will determine how many samples are read each time the while loop iterates.

 

Block Diagram Steps:

  1. Create a Counter Input channel to Angular Encoder.  The Decoding Type, Pulses Per Revolution, Z Index Enable, Z Index Phase, Z Index Value parameters are used to determine how the counter should measure position.
  2. Call the DAQmx Timing VI (Sample Clock) to configure the external sample clock timing parameters such as Sample Mode and Sample Clock Source.  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.
  3. Call the Start VI to arm the counter and begin measuring position.  The counter will be preloaded with the Initial Angle.
  4. For continuous measurements, the counter will continually read all available data until the Stop button is pressed on the front panel.
  5. Call the Clear Task VI to clear the Task.
  6. Use the popup dialog box to display an error if any.

I/O Connections Overview:

The counter will measure position on the A, B, and Z Input Terminals of the counter specified in the Physical Channel I/O control.

Position measurement only works with TIO counters. For more information on the default counter input and output terminals for your device, open the NI-DAQmx Help, and refer to Counter Signal Connections found under the Device Considerations book in the table of contents.

 

Requirement:

LabVIEW 8.5 or compatible

NI-DAQmx 9.0 or compatible

Real of Simulated NI-DAQ device with two or more counters

 

scfp-11642.jpgsnippet.png

 

Ben

National Instruments
Certified LabVIEW Associate Developer
Certified TestStand Developer

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