Generating PWM Signal With an Analog Output Module Using NI-DAQmx

Updated Jan 3, 2024

Environment

Hardware

  • NI CompactDAQ Chassis
  • CompactRIO Chassis
  • PXI Chassis

Software

  • LabVIEW

Driver

  • NI-DAQmx

If you would like to generate a Pulse-Width modulation (PWM) signal by using an analog output module, you need to follow the steps below.

In order to generate a signal, we need to use Basic Function Generator VI which takes as inputs the type of waveform, number of samples, phase in, and the frequency of the waveform to be generated in Hz.

1. Create a cluster with 3 numerics and an unsigned word, which describe Waveform Type (Sine Wave, Sawtooth Wave, Square Wave, Triangle Wave), frequency, amplitude and duty cycle.
For this particular example, we will discuss only Square Wave Generation.
image.png

2. Develop a VI as shown in the picture below.
image.png
3. Configure the DAQmx VIs and run the VI. 
After running the VI, we have a possibility to generate square wave and change the configuration like frequency, duty cycle and amplitude.

As a result, we can read the generated square wave using the analog input module in NI MAX.
image.png