Example Code

Measuring Elapsed Time Using Counter Input with 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

Overview:

Demonstrates on counting digital events on a Counter Input channel.

Description:
The counter input counts edges of a digital signal at the specified Physical Channel I/O control on the counter's default input terminal (refer to section IV, I/O Connections Overview, below for more information).
In this example, the source of digital signal comes from the Counter Output which is routed internally to the counter input terminal.
The Initial Count, Count Direction, and Edge are all configurable.

Requirements:
LabVIEW 2012 or compatible.
NI-DAQmx 15.5.1 or compatible.

Steps to Implement:

  1. Select the Physical Channel which corresponds to the counter input at which edge counting will take place and also the counter output terminal to generate the digital signal to be measured.
  2. Specify the Frequency (Hz) of the Counter Output generation. This determines smallest interval of Elapsed Time(s).
  3. Run the VI.  Observe that the number of edges being counted is converted to an 'Elapsed time'.
  4. Stop the VI.


Block Diagram Steps for Counter Output:

  • 1a.  Creates a Counter Output channel to produce pulse train. If the Idle State of the pulse is set to low, the state of the line will begin low and remain low after the generation is stopped.
  • 1b. Uses the DAQmx Timing VI (Implicit) to configure the duration of the pulse generation.
  • 1c. Calls the Start VI to arm the counter and begin the pulse train generation.
  • 1d. Queries the status of the task and check for error. If there is any error, the loop will be stopped.
  • 1e. Clear the task and display any error occurs.


Block Diagram Steps for Counter Input:

  • 2a. Create a Counter Input channel to count digital edges..  The Edge parameter is used to determine if the counter will increment on rising or falling edges.
  • 2b. Internally route the pulse generation from Counter 0 (ctr0 OUT)  to the input of Counter 1 (ctr1 SRC).
  • 2c.  Call the Start VI to arm the counter and begin counting.  The counter will be preloaded with the Initial Count.
  • 2d.  The counter will be continually polled until the Stop button is pressed on the front panel.
  • 2e. Clear the task and display any error occurs.

 

Front Panel.PNG

 

Front Panel.PNG

 

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

George T.
Senior Applications Engineer
National Instruments UK and Ireland

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