From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Keeping ms precision while cycling between two states

I'm using a DAQ system (PXI-6602 w/ BNC-2121) to generate several waveforms. Two of these waveforms need to be able to change duty cycles according to user-inputted times--that is, the waveforms will have one set of duty cycles for Time High, then switch to another set for Time Low, then back. Initially, the program (I "inherited" it, so to speak) had a Wait command nested inside a case structure, which caused a persistent error where the time periods wouldn't go below 50 ms (even if the inputted time was <50 ms, the generated waveform would be 50 ms), and there'd be about a 20% overrun for time periods longer than 50 ms. Someone suggested to me that the Wait was not starting at a consistent time relative to the other functions in the loop, which seems plausible. I've tried using Timed Loops and Structures in a few different configurations (putting each cycle in a different loop, putting them in the same loop, on their own or nested in case structures, etc.), but that's gotten less-predictable results. Any advice would be very much appreciated. Thank you!

 

("Chwxy1.vi" uses Wait, "Chwxy1loop.vi" is one of my attempts at Timed Loops)

0 Kudos
Message 1 of 2
(1,971 Views)

Hi kdonahoe,

 

There are a couple of things that you should to take into consideration:

 

1.  Timed loops are not very useful unless you are using a real-time operating system.  They only run in a single thread and therefore cannot execute internal code in parallel like a regular while loop.  In your case, what I would do is use a flat sequence structure inside the while loop with two sequences, one for the high time and one for the low.  This way you do not have to process different cases depending on if the iteration of the loop is even or odd.  Placing wait functions in each sequence for high and low times, respectively will also guarantee that the sequence will execute for exactly that amount of time.  Because the wait function starts in parallel with the code inside a while loop or sequence structure, the value of the property nodes are sure not to change after the wait function runs.  See this KB for more information on how wait functions behave:

 

http://digital.ni.com/public.nsf/allkb/12B2EA9AD5B265AD86256257004DD8E2

 

2.  Having Is Task Done VIs is not useful for continous tasks, unless they are being used to do error checking.  Since the task is not done until you stop it manually, these will only slow your code down.  I would remove them.

3.  Setting triggers and the retriggerable property should be done outside of the while loop.  Continually updating these with the same settings will also slow down your execution.

4.  In general using Windows (not real-time) will introduce up to several millisecond of jitter (delay) in running software based on what other threads are running on the machine.  You can make the LabVIEW process a high priority in the Windows Task Manager and disable as many applications and processes as you can to improve performance.

Try implimenting these changes and see how the program runs.  If it is still not working properly we can try a few other things.  Good luck!

 

 

Brian

Brian G.
Message 2 of 2
(1,940 Views)