From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Example Code

Simple Counter Input Task for Event Counting

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 on continuously reading back the number of digital edges that have been counted by a counter input.

Description:
This VI shows the most basic way to set up a counter task with DAQmx to count pulses, triggers, and encoder turns-
basically any counter input task. You can specify the channel and the type of edge to count.

For instructions on how to connect your signals to the DAQ device, refer to your device documentation.

Requirements:
  1. LabVIEW 2012 or compatible.
  2. NI-DAQmx 15.5.1 or compatible.
  3. DAQ device with at least one counter.

Steps to Implement or Execute Code:

  1. Specify all controls on the front panel corresponding to the Physical Channel at which the pulse will be measured.
    The Edge defines when to start counting the pulse edge. Loop Time specifies the software delay introduced to the loop.
  2. Connect the digital pulse to be measured to the default PFI pin of the specified Counter Input.
  3. Run this VI and verify the Number of Edges counted.


Block Diagram Steps:

  1. Creates a channel to count the number of edges.
  2. Runs the task to begin the measurement.
  3. Returns the number of edges detected.
  4. Stops the task and returns it to the state the task was in before calling the DAQmx Start Task VI.
  5. Clears the task.
  6. Displays any error occurs.
 
2017-05-31_9-34-29.jpg
 
2017-05-31_9-35-57.jpg
 
**This document has been updated to meet the current required format for the NI Code Exchange.**
Product Support Engineer
National Instruments

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