Example Code

Edge Counting with a Specific Time Window

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 VI shows how to use two counters two create a specific edge counting window.

Description:
This VI demonstrates how to use two counters to create a specific edge counting window. Counter 2 pauses counting when Counter 1 output is low and counts when high. Counter 1 duration of high is based on pulse duration setting.

Steps to Implement or Execute Code:
1. Define the control values under the Counter Output and Counter Input tabs.
2. Run this VI.
3. Monitor the result of the counted edges from the indicator.

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

Block Diagram Steps:

  1. a. Creates channel(s) to generate digital pulses defined by the amount of time the pulse is at a high state and the amount of time the pulse is at a low state. The pulses appear on the default output terminal of the counter unless you select a different output terminal.

    b.  Specifies the terminal of the timebase to use for the counter. Typically, NI-DAQmx uses one of the internal counter timebases when generating pulses. Use this property to specify an external timebase and produce custom pulse widths that are not possible using the internal timebases.

    c. Runs the configured task.

    d. Use this VI to ensure that the specified operation is complete before you stop the task.

    e. Stops the task and returns it to the state the task was in before the DAQmx Start Task VI ran and clears the task. Then, displays any error that occurs.
  2. a. Creates a channel to count the number of rising and falling edges of a digital signal.

    b. Specifies the input terminal of the signal to measure.

    c. Specifies the trigger type to Digital Level, whether the task pauses while the signal is low and the name of the terminal where there is a gigital signal to use as the source of the Pause Trigger.

    d. Runs the configured task.

    e. Read a number of samples per channel and display them in a form of array. This array shows the number of edges detected.

    f. Stops the task and returns it to the state the task was in before the DAQmx Start Task VI ran and clears the task. Then, displays any error that occurs.

Front Panel.PNGbd.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.