Multifunction DAQ

Showing results for 
Search instead for 
Did you mean: 

There seems to be a lag in two analog channels

I use two analog output channels to control two instruments. I use a button in a while loop for each channel and use it to enable and disable each task separately. There is no lag in disable or enable one channel when the other is enabled. However, when one is disabled, there is a lag to disable the other loop. The lag lasts for 3-4 seconds. That makes me crazy! What should I do? I attached my file. Help!

0 Kudos
Message 1 of 3

Hello bestjudy,

I have looked over the code you included in the post and I have a couple questions as well as a few suggestions to try out.

Let’s tackle the questions first:

1.       What are the two devices that you are controlling with the VI?

2.       When you say there is a lag, do you mean in the code itself, or in the hardware? By this I mean are you seeing physical signals generated from the hardware longer than you expect?

3.       Does it matter which task/device is disabled initially in the case where lag is introduced?

The questions aside, I have a few suggestions off the bat in terms of how the VI is designed. I have included a screenshot with a few elements of concern which I have also listed below:

1.       Currently the two main loops are set to run infinitely with the only way to stop the application being the abort button. In general we try to shy away from using the abort button to control the application since it does not guarantee a proper shut down of the program.  Also, using two infinite loops without timing can create unstable situations such as memory leaks and latency.

My suggestion: Include a stop buttons for each outer loop so that the application can be stopped properly after both the button is pressed and the tasks are completed.

2.       As mentioned above, there is no timing structure within either of the main loops. Without a software timing structure these loops are not guaranteed to be synchronized and depending on what your computer is processing at the time (other applications, web browsers etc.) can result in noticeable latency.

My suggestion: Include the Wait Until Next ms Multiple timing VI in each outer loop and set the delay to be equal to one another (10ms for instance). This will synchronize the loops to a certain a certain multiple of the system clock reducing any asynchronous latency. You can find this timing VI by doing the follow:

Right click on the Block diagram to bring up your palettes >> Choose the Timing Palette under Programming >> Select “Wait Until Next ms Multiple”

3.       The two analog output tasks that you have created are software timed processes. This means that the reaction time of the device (starting and stopping) is entirely dependent on the processing of your computer or targeting system. If there is any latency in the system at all, this will delay the timing of the analog output tasks.

My Suggestion: Since this is a simple application, switching your tasks over to be hardware timed is not necessary. The above suggestion to include a timing VI in your external loop should minimize asynchronous behavior and latency


4.       This is similar to the 2nd issue that I mentioned in that neither of your analog write loops have timing. This means that your processer will run the loop as fast as it can without attempting to synchronize the process with the overall application. With this in mind, we can see this as being another possible source of latency.

My Suggestion: Include the “Wait Until Next ms Multiple” vi in each of your analog output loops. Since this is creating software timing, you might have to adjust the timing of the outer control loops accordingly. An example case would be to use a delay of 10ms in each of the analog output loops and then use a delay of 20ms in each of the external loops.


My final observation would be that each time one of the external loops iterates, you create, initiate, stop, and clear the analog task. This process will introduce latency into the program that could produce undesired effects without timing in place. Also, the while loop is by default a do…while loop. This means that even when your task is disabled using the Boolean switch, the analog write will occur at least once.

The second screenshot is your vi modified to include timing structures and stop button to control your outer loops. Let me know if you have any questions regarding the above topics.


Chris Behnke
Sr. RF Engineer
High Frequency Measurements
Download All
0 Kudos
Message 2 of 3
I tried your way and it works now.
Let me answer your questions.
1. I use this vi to control two power supplies
2. I mean in the code itself
3. It dosen't matter which device is disabled first in this case.

Thank you again for your kind help!
0 Kudos
Message 3 of 3