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

Measure the Frequency of an Analog Signal using a Counter in LabVIEW

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 allows you to use a counter in order to measure the frequency of an analog signal.

Description

An analog signal can be acquired and analyzed in software to determine its frequency. However, in many situations it is desirable to measure the frequency of an analog signal in hardware. A counter cannot be used to directly measure the frequency of an analog signal. Using an analog comparison event, you can generate a digital trigger that can measure the frequency and period of an analog signal using a counter. This VI performs the following:


  1. Creates an analog input task and utilizes an analog trigger in order to create a digital pulse every time the analog signal crosses a threshold.
  2. Reads in the analog signal and also routes the generated digital pulse to the source of the counter.
  3. Reads the number of digital edges that have been generated by the analog comparison event.
  4. Clears both tasks and displays any errors that have occurred.

Requirements to Run

Software

LabVIEW 8.6 or compatible

DAQmx 8.8 or compatible

Hardware

NI Multifunction DAQ Device with at least two counters that also supports analog triggering.



Steps to Implement or Execute Code

  1. Download and Unzip the Files Below
  2. Select an applicable counter and analog input channel on your device
  3. Select the trigger threshold and hysteresis level 
  4. Run the VI

Additional Images


Block Diagram

Frequency of a Analog Signal using a Counter.png

Additional Information or References

Measuring the Frequency of an Analog Signal in Hardware

Analog Input Period Counts Using Analog Comparison Event

**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.

Contributors