LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why the execution time increases with a while loop, but not with "Run continuously" ?

Solved!
Go to solution

Hi all,

 

I have a serious time problem that I don't know how to solve because I don't know exactly where it comes from.

 

I command two RF switches via a DAQ card (NI USB-6008). Only one position at the same time can be selected on each switch. Basically, the VI created for this functionnality (by a co-worker) resets all the DAQ outputs, and then activates the desired ones. It has three inputs, two simp0le string controls, and an array of cluster, which contains the list of all the outputs and some informations to know what is connected (specific to my application).

 

I use this VI in a complex application, and I get some problems with the execution time, which increased each time I callled the VI, so I made a test VI (TimeTesting.vi) to figure out where the problem came from. In this special VI I record the execution time in a csv file to analyse then with excel.

 

After several tests, I found that if I run this test VI with the while loop, the execution time increases at each cycle, but if I remove the while loop and use the "Run continuously" funtionnality, the execution time remains the same. In my top level application I have while loops and events, and so the execution time increases too.

 

Could someone explain me why the execution time increases, and how can I avoid that? I attached my test VI and the necessary subVIs, as well as a picture of a graph which shows the execution time with a while loop and with the "run continuously".

 

Thanks a lot for your help!

Download All
0 Kudos
Message 1 of 8
(3,125 Views)
Solution
Accepted by topic author jul7290

Your SetReset_DO VI creates a channel every time it is called.  And you never clear a task.

 

When running continuously it is like it only runs once and LabVIEW has internal mechanisms to close references which will not be used again.  When a VI is used as a subVI, LV does not know if it will be called again and does not dispose of those things until the top-level VI stops. You have a memory leak.

 

Just as you open and close your file outside the for loop, create your channel outside the loop.

 

Lynn

Message 2 of 8
(3,093 Views)

Thank you very much for your help! I added the "Clear task" vi and now it works properly.

0 Kudos
Message 3 of 8
(3,043 Views)

@jul7290 wrote:

Thank you very much for your help! I added the "Clear task" vi and now it works properly.


If you are still using the RUn Continuously you should stop. That is meant strictly for debugging. In fact, I can't even tell you the last time I ever used it. If you want your code to repeat you should use loops and control the behavior of the code.

 



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
0 Kudos
Message 4 of 8
(3,030 Views)

Ni I'm not, I was just using it to compare with the loop, I know it is not a proper way to do "loops". I haven't using it for a while too.

0 Kudos
Message 5 of 8
(3,023 Views)

I have a last question for you:

 

As I have only digital outputs, and I have to write values several time in loops in my software, could I start the task at the initialization of my software and stop and clear it at the end, or should I start it right before using it and stop it directly afterwards?

I searched in the help but did not find anything explaining what are the consequences of start (memory allocation or whatever) in this case.

0 Kudos
Message 6 of 8
(3,001 Views)

@jul7290 wrote:

... could I start the task at the initialization of my software and stop and clear it at the end, or should I start it right before using it and stop it directly afterwards?


can you show us some code? It is not obvious what the two scenarios are.

0 Kudos
Message 7 of 8
(2,980 Views)

It's hard to show you some code, because I have a hudge producer/consumer loop with events, to reproduce a statemachine comportment. But Basically when I start to run my software I have an initialization state (in which I would like to use the start task VI), then I have several different states where the user have to give informations and so on, but these ones don't use the digital outputs, and finally the user can proceed some measurements and therefore use the digital outputs. After the measurement, qhen the user quit the software I have a stop state where I would like to stop and clear the task.

In short, the digital outputs are used during half of the use time of the software, so if I start the task at the initialization, it will stay unused for a while, and I would like to know if it's bad or if it doesn't matter.

0 Kudos
Message 8 of 8
(2,961 Views)