Example Code

DAQmx Encoder Measurement with Producer Consumer Architecture

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

Download All

Overview
This example was derived from the example DAQmx - Measure Angular Position - Buffered - Counter Clock. Along with acquiring the angular position over time

Description:
This example shows how to process in the data in a producer consumer architecture. The processing done in this example is calculating the average velocity during the acquisition. If this processing is not desired, change this code to match what you would like to do.

Steps to implement or execute code
To implement this example:

  1. Set the physical channel of the counter
  2. Determine all the physical channel for the encoder and timing.
  3. Run the VI
  4. (Optional) Turn on the Highlight Execution to see the flow of the VI

To execute this example:

  1. Install the required software.
  2. Connect the DAQ hardware that supports the Counter features
  3. Confirm the connection with the MAX with TestPanel
  4. Open the VI and refer the Implement Steps

Queues breakdown:

  1. Creates the queue to store the data that needs to be sent between the loops.
  2. Places an element into the queue in order to pass it to the other loop.
  3. Takes an element out of the queue.
  4. Closes the queue

Clock Breakdown:

  1. Creates the Counter Output task. Takes the frequency the buffered acquisition will acquire at and which counter to use.
  2. Sets up the timing for the task.
  3. Starts the Task
  4. Monitors the task to see if there is any errors.
  5. Clears the Task.

Encoder Breakdown:

  1. Creates the Encoder task. Setups what terminals A, B, and Z will be as well as other configuration sets for this task.
  2. Sets up the timing for the task. Uses the clock generated by the Counter output task for the acquisition.
  3. Starts the Task
  4. Reads X values from the buffer. The number samples read is controlled by the Samples to Read input
  5. Clears the Task.

Requirements
Software
LabVIEW 2012 or compatible
NI-DAQmx 16.0 or compatible

Hardware
cDAQ with C series Counter Input Module

 

2017-10-30_9-30-29.jpg2017-10-30_9-27-01.jpg

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


Jim St
National Instruments
RF Product Support Engineer

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