Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

TO change the Duty Cycle(DAQmxSetCOPulseDutyCyc)

I have an application that uses Pulse Width Modulation (PWM) to control the speed of a motor. Thus, it requires that I change the duty cycle of my square wave. My continuous pulse is being generated on the output of my counter. When I use the function "DAQmxSetCOPulseDutyCyc" to update the duty cycle when the task is run, the changes aren't reflected. What is the problem? thanks in advances!
cinzia
0 Kudos
Message 1 of 4
(4,098 Views)
Ciao Cinzia!
To modify channel properties your task has got to be on the right state.
Try to stop your pulse train generation, set your duty cycle and start the task again.
For example:

DAQmxStopTask (taskHandle);
DAQmxSetCOPulseDutyCyc(taskHandle, chan , duty );
DAQmxStartTask (taskHandle);

Hope this help.
bye.

NicolaC
0 Kudos
Message 2 of 4
(4,097 Views)
masa,
According to this article, the duty cycle change only gets "committed" if you also write to the frequency property, even if you don't actually change the frequency value. I'm assuming you're looking for "change on the fly" operation.

I hope this changes in a near-future version of DAQmx, though I have no way of knowing if it will.

-Kevin P.
ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
Message 3 of 4
(4,097 Views)
Masa-

Kevin is correct. Unfortunately, there is little we can do to change this behavior in DAQmx. There are only two options:
1) change which property updates the pulse train value, which would leave you with the same issue you are currently having if you have a situation where the frequency needs to change but not the duty cycle, or
2) add a third property that would be a "switch" command. This option would add more work for users, as a third property would have to be called.

One other thing you might trying using instead of the properties (assuming you are using DAQmx 7.2 or later) is the DAQmxWriteCtrFreqScalar() method. This write method added in DAQmx 7.2 allows you to update the frequency on-the-fly without having to use the properties.

I
hope this helps!
gus....
0 Kudos
Message 4 of 4
(4,098 Views)