Showing results for 
Search instead for 
Did you mean: 

for loop time




I'm a depserate noob here, so it might be a silly question, but I'm having a lot of problems trouble with timing a for loop. Any help will be very welcome!


Im trying to make 2 signals with Labview, that will eventually drive a piezo stage. More over, a pockel cell will turn on and off depending on the position of the stage. But going to my main problem.. my main signal, wich will drive the stage in the X axis, is a 80Hz sinusoidal signal., and I added a linear signal to move this oscillating stage through the Y axis. The problem is, that when I try to see it in a XY chart, the time it takes to get to the desired Y, doing the desired oscillations, is much longer than what it should take a 80hz signal to do those oscillations.


For example, I want it to make 100 oscillations. It should take 1.25s, but the XY takes much more time to display it, and on the oscillator i can see that the final X signal is 3 or 4 Hz.


I will add the vi, because im not sure I'm explaining myself...


Also, Im sure there are more elegant and smart ways to do it, so any feedback will be more than appreciated.


Thank you very  much in advance!!


0 Kudos
Message 1 of 17



Since your new to LabVIEW I strongly recommend you to spend some time on the basic principles. This is a good start.


Also search the LabVIEW in built examples for good starting points.

Help/Find Examples...


good luck!


Message 2 of 17

Hi Adigator, I already read does basics, but if there was something to help me with my problem i did not notice it.


I'm sorry if this has already been answered, but I could not find it. How long it takes to complete a for loop? Or how i make it go faster?


I need it to do 2500 iterations in 0.125 (10 oscilations of the 80Hz signal ) seconds. It is taking several seconds, and I believe my program is quite simple, so, have you any idea how can I do it? I've been many days with this and I have not advanced anything..


Thank you  very much in advance

0 Kudos
Message 3 of 17

If you can post the vi in version 9.0 or older I can take a look and see what exactly the problem is.

Kudos are (always) welcome for the good post. :-)
Message 4 of 17

hello Odessy27,


It asked me for a password when i tried to convert it to 9.0, I skipped it, so I don't know if it will work. I attach the result of the conversion, but I'm not sure if it worked and it is Lv9.0.


Thanks for all

0 Kudos
Message 5 of 17

I would convert your MatcScript node to native LabVIEW primatives. It may run faster using native constructs. If you want the fastest performance from your loop I would remove the graph updates from the loop and use a ueue/notifier to post updates to a parallel loop that will handle updating the UI. UI updates can significantly impact the performance of execution. If they are performed in a parallel loop they will not impact the processing within the analysis loop. Your Wait until Next delay call may not always give you good results. You also have to be careful you are not using the wrong value there. One last thing is that while express VIs are easy to use they are often written very inefficiently. You are almost always better off implementing their functionality yourself.

Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 6 of 17

I did some minor change in vi, basically replacing express vi to plot the graph. Also took it out of the loop since you were just plotting one set of point every iteration. Apart from what Mark suggested, also keep in mind that, in your vi, you are running your generate signal vi only once, thus, you are going to get only specified amount ouf samples at the rate you requested only for one second. So if you need more than 1 second worth of data at least run it in for loop 2 times and the just grab the subset of the data based upon your requirement. Hope it makes sense.

Also use highlight mode for debugging, to locate unexpected behaviour in the code.

Hope it helps!




Kudos are (always) welcome for the good post. :-)
Message 7 of 17

Thanks for your advices and help Mark and Odessy. From what you said, The reason why the for loop is so delayed compared to the original signal is just a matter of efficiency in the code? This is the simplest part of it, i removed the part that rules the on/off of the pockel cell.

If it is just a matter of keeping the For loop simple, with the addition of the Pockel cell controll, looks impossible to make the for loop run as fast as the signal ( for me of course).


I have checked your VI odessy, and it might be faster, but it is still taking more than what it should (50 oscillations*0.0125=0.6 secs.).


Really, I'm very grateful for your tips, i'm just a student doing an internship and my supervisor is ignoring me.. ( also he doesn't know anything about labview programming) so there is no one to ask for help.


Thank you very much




0 Kudos
Message 8 of 17

All right..., so I replaced the mathscript node with labview math operations and on my computer it finishes in 0.46 seconds.  

Kudos are (always) welcome for the good post. :-)
Message 9 of 17

It is taking over a second on my PC.


It seems to be related to the Elapsed Time Express VI.  Remove that from the loop and you'll see the VI returns very quickly.

Message 10 of 17