Example Code

NI-DAQmx: M Series Pulse Width Modulation (PWM)

Code and Documents

Attachment

Overview


This VI creates a Pulse Width Modulation (PWM) signal on any number of Digital Output (DO) lines available on the hardware. You may specify the duty cycle and frequency of the PWM. Only one Counter Output (CO) is used as the sample clock for multiple Digital Outputs (DO), rather than using one counter per PWM signal. This example was intended for use with National Instruments' M Series devices.

Setup

  1. Select the device name of the M Series device.
  2. Select the correlated Digital I/O lines to use.  On an M series, this is port0.
  3. Expand the array of Duty Cycle Controls so that you have one control for each line you have specified.
  4. Make a connection to any of the digital lines on the selected port.

Notes

The Frequency value is the frequency of one complete square wave pulse. The sample clock rate is actually 1000 * Frequency, and each complete square wave consists of 1000 points. Hence, the maximum frequency that can be achieved is dependent on the maximum update rate of the hardware, calculated as follows:

MAX Frequency = MAX Digital Rate/1000

You can increase the maximum value of Frequency by editing the VI to create a square wave array of size less than 1000.

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

Contributors