Example Code

Counting Retriggerable Gated Pulse Using LabVIEW 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.


  • LabVIEW

Code and Documents



This VI demonstrates how to count digital events on a Counter Input Channel. 


In this VI, the Initial Count, Count Direction, and Edge are all configurable. This VI shows how to use a secondary counter and a digital input line to count events for a specified amount of time, following an external digital trigger. Edges are counted on the primary counter's default input terminal, but it could easily be modified to count edges on a PFI or RTSI line.

The input counter will count edges on the input terminal of the counter specified in the left Physical Channel I/O control.  The gating counter will generate a digital pulse on the output terminal of the counter specified in the right Physical Channel I/O control.  Connect the default output line of the gating counter to the default gate line of the input counter.  This will allow the gating counter to control when the input counter can count events. In this example the input counter will count edges on the default input terminal on ctr0, and the gating counter will generate a digital pulse on the default output terminal on ctr1.  Connect your start trigger source to the appropriate connection specified by "Start Trigger Source" on the front panel.

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.


  • LabVIEW 2012 (or compatible)

Steps to Implement or Execute Code

  1. Select the Physical Channel that corresponds to the counter you want to count edges on the DAQ device.  (This counter is called the Input Counter.)
  2. Enter the Initial Count, Count Direction, and measurement Edge to specify how you want the counter to count.  Additionally, you can change the input terminal where events are counted using the channel property node.
  3. Select the Physical Channel that corresponds to the secondary counter you want to generate a single pulse on the DAQ device. (This counter is called the Gating Counter.)
  4. Enter the Gate Length, Idle State, and Initial Delay to specify how you want the gate signal to be generated.
  5. Select the source for the Digital Start Trigger and the on which to trigger.
  6. The output pin of the Gating Counter must be wired to the gate pin of the Input Counter prior to running this program.


Additional Information or References
VI Snippet


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


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.


thank you for the detailed example, big help for a beginner like me!


Unfortunately, this example does not do what it claims - not at all.

This can be seen already by looking at step 6 on the diagram. Instead of waiting till the gate pulse is finished, the diagram just calls a sub-vi to check whether the task is done without even checking the result.

Simple tests show also that the actual time the events were counted is given by the argument of the "Wait Until Next ms", which is very unprecise.


Please see the link below for a post discussing how to get this code to function.