Example Code

Frequency Sweep Counter Output with DAQmx

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.


  • Data Acquisition (DAQ)


  • LabVIEW


  • NI DAQmx

Code and Documents



This code is an example of how to generate a frequency sweep on a counter output channel. 


This VI will generate a buffer of frequency and duty cycle pairs to output to the coutner output.  Once one cycle has been performed on that frequency duty cycle pair it goes on to the next frequency duty cycle pair.  As the frequency changes, the time to execute each cycle changes.  Because of this the frequency jumps are not linear, meaning if we jumped from 1000Hz to 1002Hz, our next step will not be to 1004Hz because the period for 1000Hz and 1002Hz is not the same.  This code should account for that.

Steps to Implement or Execute Code

  1. Enter in the physical channel for the Counter Output
  2. Enter Frequency Min which is the minimum frequency that will be set to the Counter Output
  3. Enter Frequency Max which is the maximum frequency that will be set to the Counter Output
  4. Enter Sweep Duration which is the time in seconds to go from Frequency Min, to Frequency Max, and back to Frequency Min
  5. Set Duty Cycle to use during the sweep



LabVIEW 2012 or compatible

DAQmx 9.6 or compatible


NI DAQ Hardware with a Counter Output.  Tested with a cDAQ-9188 outputting on PFI0

Additional Information

Frequency Sweep.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.