Example Code

Use a Counter to Determine Loop Iteration Time using LabVIEW with a DAQmx

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 VI shows you how to use a hardware timer to verify the loop time of any loop structure in LabVIEW.


Description

You will need a multifunction DAQ device that includes a counter. I would recommend a PCI or PXI based card as there is less latency on the single point reads. You need to create a Count Edges task using DAQmx. We then need to set some properties for the task created. These are the "Count Edges Input Terminal" and the "Data Transfer Mechanism". We need to choose a built-in timing source for the count edges input terminal, and "Programmed I/O" for the data transfer. We then start the DAQmx task and take an initial count. Once inside the loop we take another reading of the counter value and compare the previous count to the current count. In the code provided the loop time is being simulated by the wait until next ms multiple function, but this can be any code or analysis routine you have in the loop. Finally, close the DAQmx task and the clear the task. In the front panel picture below you can see the tick count converted to a loop time in seconds and the simulated loop time requested in the milliseconds to wait input. 


Requirements

  • LabVIEW 2012 (or compatible)
  • DAQmx 12.0 (or compatible)

Steps to Implement or Execute Code

  1. Select counter channel and the number of milliseconds to wait.
  2. Run the code, and then check the loop count and measured time from the counter.

 Additional Information or References
VI Snippet

DAQ based Timer 2012 NIVerified.png

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

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