Change Duty Cycle on a Continuous Pulse Train of NI-DAQmx Task

Updated Apr 25, 2018

Reported In

Driver

  • NI-DAQmx

Issue Details

I have an application that uses Pulse Width Modulation (PWM) to control the speed of a motor. I need to be able to change the duty cycle of my square wave while my task is running. My continuous pulse is being generated on the output of my counter. When I use an NI-DAQmx Channel Property Node to update the duty cycle, the changes aren't reflected. Why is the duty cycle not changing?

Solution

NI-DAQmx requires that when you update the duty cycle of a pulse train, you must update the frequency at the same time. To do this, create a NI-DAQmx Channel Property Node by going to Functions Palette»Measurement I/O»DAQmx-Data Acquisition»DAQmx Channel Property Node.
On the DAQmx Channel Property Node, right-click Property and select Change to Write. Expand the DAQmx Channel Property Node to have two inputs. Create a CO.Pulse.DutyCyc AND CO.Pulse.Freqproperty by right-clicking Property»Select Property»Counter Output»Pulse»Frequency and select Duty Cycle. Repeat the last step for the second property and select Frequency.

Create a new control for the duty cycle and the pulse frequency. Pass the new value for the duty cycle, as well as the desired frequency (even if it has not changed) to the property node. Since LabVIEW will execute a property node in a top-down manner, the duty cycle must be modified before the frequency value is changed.

The duty cycle can also be changed using the DAQmx Write VI when the instance of the VI is set to Counter Freq 1Chan 1Samp . To do this, place a DAQmx Write VI on your block diagram by going to Functions Palette»Measurement I/O»DAQmx-Data Acquisition»DAQmx Write.vi. From the pull-down menu of the DAQmx Write VI, select Counter»Single Channel»Single Sample»Frequency. 

Then create three controls for the task, frequency and duty cycle and wire them to the DAQmx Write VI.

See the Attachments section for examples on how to to perform both of the above methods using event structures.

WAS THIS ARTICLE HELPFUL?

Not Helpful