04-14-2016 02:44 PM
Hi Labview forum,
I wrote a Labview program (attached below) to generate 3 PWM, square wave, signals that has the same frequency and right delay phase (so that when one signal is off, the other signal turns on. Then the next signal). Everything seems to work correctly except that the frequency of the generated PWM signals seems to twice as much as the frequency given to the basic function generator. Anybody has any idea as to why this is happening? Anyhelp would be greatly appreciated.
Thank you!
Solved! Go to Solution.
04-14-2016 03:06 PM
Hi waterox,
the (update) frequency of those digital output signals is determined by the wait functions in your loops!
Which hardware do you use?
When it supports (output) counters you should use them to output PWM signals.
When it supports hardware timed digital outputs you use this feature to output signals with accurate sample rates!
04-14-2016 03:30 PM
Hi GerdW,
I have a NI PXIe-1078 chassis, with NI-PXIe8135 embended controller. I'm using a SCB-68a connector pannel attached to PXI-6225 slot.
04-14-2016 04:20 PM
Even with 1ms wait time, my for loop should not have taken 2 seconds to finish each iteration. The size of each of the array input is 1000. The for loop should be running around 1 second per loop, not 2
04-15-2016 02:14 AM - edited 04-15-2016 02:16 AM
Hi waterox,
The for loop should be running around 1 second per loop, not 2
Why do you think so?
You have a loop that iterates 1000 times. In each iteration you write a value to your device - this takes time and probably more than you expect! Additionally you wait for a millisecond and check the execution time two times. (Why two times?)
To sum up:
- using DAQmxWrite with "1 Channel 1 Sample" is the slowest option you can use for this function.
- it should be even the wrong option as you want to set 3 channels, not just one!
- all timings on your PC are influenced by the OS - and Windows will influence your loop with a big jitter!
Recommendation: use hardware timing as much as possible, either counter outputs or hardware-timed DOs!
04-15-2016 09:31 AM
Fully agree with all GerdW's advice that hardware timing from your daq device will be much more reliable. That said, part of what you're probably bumping into is a little quirk of the msec delay primitives. Requests for 1 msec have long been particularly unreliable (though they *seem* to have improved in recent years, probably due to better OS support in Win 7 or something).
I made minimal mods to your code with comments to switch you over to a Timed Loop. My quick testing showed it to be pretty good at hitting the 1 msec target loop period.
-Kevin P
04-15-2016 10:39 AM
Hi Kevin,
would you kindly save your adjusted program to Labview version 2012 (12.0.1) or older? Greatly appreciated.
04-15-2016 10:43 AM
HI GerdW,
Thank you for solidifying my suspicion. I thought that was maybe the case that cause the loop to run 2 seconds. This is a good lesson. I will follow your recommendations. Thank you! 🙂
04-15-2016 06:05 PM
Hi Kevin,
Your modified version worked. Thanks for your help!