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

Use Counter Input Count Edges to Measure Frequency

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 using Counter Input count edges channel to perform frequency measurement.

Description:
The accuracy is system dependent and varies with Measure Time (seconds) and the frequency of input signal. This method is not typically recommended on a board that supports frequency measurements or buffered edge counting.
The time interval of the count in this method is software-defined and is thus non-deterministic, so if you are using a board that supports frequency measurements, it you would be better to use the standard method.
Although, if the input frequency is high this method will be more accurate than the standard single counter method.

The counter will count edges on the input terminal of the counter specified in the Physical Channel I/O control.  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.

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

Steps to Implement or Execute Code:
1. Specify Channel Parameters by selecting the Physical Channel which corresponds to the counter on which the count edges measurement will take place on the DAQ device.
2. Run this VI.
2. Monitor the Frequency indicator to verify the expected input frequency.

Block Diagram Steps:
1. Creates a Counter Input channel to count number of rising or falling digital edges.
2. Calls the Start VI to arm the counter and begin counting.  The counter will be preloaded with the initial count.
3. Wait for the user-specified amount of time to start counting the edges.
4. The frequency of the input signal is the number of edges that occurred during the wait divided by the wait period.
5. Returns the value read by the counter until the stop button is pressed.
6. Aborts and clears the task.
7. Uses the popup dialog box to display any error occurs.

 

Front Panel.PNG

 

bd.png

 

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

John Passiak

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

Comments
PPattles
Member
Member
on

Hi, I am trying to implement this example using my USB-6008 and am running into trouble tying my counter input into the counter(s) purple box. I am new to labview and just need a kick in the right direction

John_P1
Trusted Enthusiast
Trusted Enthusiast
on

It should just show up as an option in the drop-down on your front panel.

The terminal that you would physically wire to for the USB 6008/6009 is PFI0 (pin 29).

John Passiak
pedrorivera
Member
Member
on

hi, well, im surprised, a guy in my university presented this code to measure frequency in his thesis work, but their attempt to adapt it was pathetic, their vi even have the same interface that yours but it doesnt work as well as yours. and they used it in a multi-loop data acquisition so they're measure failures was incredibly notorious, he used digital input and a bizarre way to detect edges insteand of counter input and another wait that stoped the other channels acquisition, im glad to find the original one

best regards

.:. Pedro Rivera .:.
i love to work and develop on labview, this is real fun!!!
Photobucket