Change Duty Cycle of PWM with X-Series Without Stopping or Reconfiguring Task

Updated May 22, 2019

Reported In


  • PCIe-6321


  • NI-DAQmx


  • X-Series

Issue Details

I am working with a NI X-Series DAQ device and need to change the duty cycle of my PWM output without stopping and reconfiguring my task. How can I do that?


NI Hardware that is based on STC3 chips such as X-Series PCIe or USB devices are capable of buffered counter outputs. That way the duty cycle of the counter output can be changed without pausing or reconfiguration of the task.

The VI snippet below shows how an array of different duty cycles is written to the tasks buffer using the DAQmx API. After the task is started the PWM signal's duty cycle will iterate through duty cycle configurations specified in the buffer.

Note: This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram.

Additional Information

NI Hardware that is not STC3 based is not able of buffered counter outputs. Another option to implement a PWM signal with rapidly changing duty cycle is using a buffered digital output.
The VI Snippet below demonstrates how this can be implemented. An array consisting of high and low values is written to a digital output.  
Caveats of this approach:
  • Compared to buffered counter output the buffer needs to be bigger (1 byte per sample compared to 8 bytes per period with the buffered counter output)
  • Timing resolution decreases in most cases: counter output of an X Series device works with a 100 MHz timebase. Timing resolution of regular digital Outputs tend to be lower due to lower maximum digital output rate.

In the case that it is applicable for you to reconfigure the task while it is running you can update the duty cycle dynamically following the instructions in this KnowledgeBase


Not Helpful