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

Synchronize Analog Input Voltage and Counter Input Frequency Measurements

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 demonstrates a method of synchronizing a counter input frequency measurement with an analog input voltage measurement.

Description:
The frequency resolution of the counter input which is used to count the edge depends on the rate of the Sample Clock of the Analog Input channel.
An example of some of the use cases is when the user need to determine the frequency of the counter input signal and the voltage measurement each time the other counter input signal is on rising edge.
During run time, the user will be able to monitor the Analog Input and Counter Input readings. After the user clicks on the Stop button, all the data which have been shown in Voltage Measurements and Counter Input Frequency charts can be seen on the Analog Input Voltage and Counter Input Frequency History chart.

Requirements:
LabVIEW 2012 or compatible.
NI-DAQmx 15.5.1 or compatible.
Multifunction DAQ device.

Steps to Implement or Execute Code:

Hardware connections:

  1. Physically connect the digital signal to be measured to the counter input gate which measures the edge and also to the counter input which measures the frequency. Then, specify the Counter Input - Count Edges and Counter Input - Frequency controls corresponding to the physical channels.
  2. On the front panel, specify the other controls under the Timing Parameters and Analog Channel Parameters tab.
  3. Run the Program.

 

Block diagram steps:

  1. Creates channel(s) to measure voltage, count number of rising edges and measure the frequency of a digital signal.
  2. Sets the source of the Sample Clock, the rate of the Sample Clock, and the number of samples to acquire. By using Continuous Samples,
    this means that the channels will acquire samples until the DAQmx Stop VI runs. NI-DAQmx uses Samples per channel value to determine the buffer size.
  3. Runs the tasks to begin the measurement. To ensure that both Counter Input channels are synchronized, run both tasks simultaneously and followed by the Analog Input task.
  4. Creates references to the Queues.
  5. Reads available data. For Analog Input and Counter Input - Count Edges, number of samples per channel to be read is defined on the front panel prior to running this code. For the
    Counter Input - Frequency, this VI reads all the samples currently available in the buffer.
  6. Adds an element to the back of each queue.
  7. Removes an element from the front of each queue and returns the elements.
  8. Inserts measurements into arrays and display Analog Input Voltage and Counter Input Frequency measurements on charts.
  9. When Stop button is pressed, returns the Counter Input frequency measurements for every rising edge detected and concatenates with Voltage Measurements array. Then, display the data on the Analog Input Voltage and Counter Input Frequency History.
  10. Releases the references to each queue and aborts the tasks. Then, display any errors that occur.

 

Front Panel.PNG

 

bd.png

 

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

Dustin D

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