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: 

Timed loop versus While loop

Solved!
Go to solution

Most of the machine control software that I design have the following structure :

1. There is a MAIN which runs inside a TIMED LOOP with 50ms timing and priority of 100. Its only job is to read / write data from / to  DAQMx I/O cards .

2. The MAIN can call many SUBs based on user choice and once a SUB is called the MAIN FP is closed and the SUB FP opens. All SUBs have a Queued State Machine running inside a TIMED LOOP again with 50ms timing but with priority at 50. 

3. Data transfer between MAIN / SUB is through function globals - there are many of them based on the data being passed. 

4. All woks fine so far. No need for any RTOS. and WIN7 platform is alomost standard. I have even run with 20ms timing without crashing anything....

 

Problem : When there is lot of File I/O operations in a partciluar SUB , then i get to see many missed iterations. Possibly the TIMED LOOP Is hogging resources. 

 

What I want to do : Convert both the TIMED LOOPs in the MAIN asnd SUB to simple WHILE LOOPs.  But i am concerned about the priority - since teh MAIN interacts with HW it has highest priority. But with WHILE LOOP how do i ensure this ?? 

 

Or is there any alterantive / efficient way of doing what i am doing now ?? 

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 1 of 8
(4,371 Views)

@Raghunathan wrote:

 

Problem : When there is lot of File I/O operations in a partciluar SUB , then i get to see many missed iterations. Possibly the TIMED LOOP Is hogging resources. 

 

What I want to do : Convert both the TIMED LOOPs in the MAIN asnd SUB to simple WHILE LOOPs.  But i am concerned about the priority - since teh MAIN interacts with HW it has highest priority. But with WHILE LOOP how do i ensure this ?? 

 

Or is there any alterantive / efficient way of doing what i am doing now ?


 

First, I'm not sure why you have the SUB QSMs running in timed loops. Why do you pass the data through functional globals rather than directly to the QSM via a message?

 

Secondly, IMO, you shouldn't be doing File I/O inside a timed loop at the rates you specified. This sounds like a producer/consumer problem where the "consumer" would normally pass the data to a "worker" thread, that is, a buffered, parallel task dedicated to the File I/O in your case. That minimizes the code execution time in the consumer loop.

 

Of course, I'm assuming some things here and could be missing the point completely since there was no code attached.

0 Kudos
Message 2 of 8
(4,349 Views)

In general, timed loops are next to worthless in a Windows situation.  They cause all kinds of overhead for very little gain.

 

I would put your main loop inside of a subVI and set the priority of that subVI to High.  It will then have priority over the "normal" VIs.

 

File I/O just sends to be slow.  Therefore, you really have to use a Producer/Consumer setup if you need to keep your timings, keeping the File I/O in its own loop that runs as fast as the data comes in via the queue.

 

What do your FGVs look like?  If they are nothing more than a Get and Set, then just use normal Global Variables.  They are A LOT faster and easier to maintain.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 8
(4,324 Views)

Crossrulz,

 

To answer your queries I have enclsoed a small project with one MAIN and one SUB. It passes data from MAIN to SUB via a Function Global.

 

Of course  the example is rather simple - in the actual application  I have to move various types of data - Numeric Array, Boolean Array and String data. Is  there any better method to pass data across VIs ? 

 

So what would you feel is a glaring thing that can be improved upon ??  I know you will want to replace the TIMED LOOPS with WHILE LOOPS but then how do you ensure that the SUB while loop runs with a low priority ? 

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 4 of 8
(4,306 Views)

Based purely on what I see in that code, the FGV should be thrown out the window.  For your current setup, I would use User Events to send information between the VIs.  The Event Structures could also "time" your loop by using the Timeout event case.

 

I still no need to timed loops.  Your loops are running slow enough, it should not be an issue on a normal Windows machine.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 8
(4,297 Views)

@crossrulz wrote:

Based purely on what I see in that code, the FGV should be thrown out the window.  For your current setup, I would use User Events to send information between the VIs.  The Event Structures could also "time" your loop by using the Timeout event case.

 

I still no need to timed loops.  Your loops are running slow enough, it should not be an issue on a normal Windows machine.


....FGV should be thrown out the window...Smiley Surprised

Well have been using it for quite some time based on many KB articles. One such is enclosed .. and it does not portray the Action Engine or FGV as a villian to avoid. 

 

Of course I do agree that the language is evolving and new optimized methods are coming out. But then there is no end to this process and the learning never stops - which calls for a non available resource - time !! 

 

One of the reasons I post even mundane issues here is to get eductaed by the experts for whom LV is life. Thanks...

 

So in the sample I had attached, what do you think would happen if I simply replaced both Timed Loops in MAIN and SUB with the SAME wait ms value. Would there be any order of execution then ?

 

 

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 6 of 8
(4,261 Views)
Solution
Accepted by topic author MogaRaghu

Raghunathan wrote:

....FGV should be thrown out the window...Smiley Surprised

Well have been using it for quite some time based on many KB articles. One such is enclosed .. and it does not portray the Action Engine or FGV as a villian to avoid. 


The Action Engine is one of the greatest constructs in LabVIEW.  The FGV that does nothing but Get and Set (or Write and Read) is worthless and a waste of resources.  Why?  It does nothing to fix the possible race conditions (does not protect critical sections) and it is a lot slower than just using a global variable.  See this example I put together to see what I mean: A Look at Race Conditions.

 


Raghunathan wrote:

So in the sample I had attached, what do you think would happen if I simply replaced both Timed Loops in MAIN and SUB with the SAME wait ms value. Would there be any order of execution then ?


When things are in parallel, there is no such thing as order of execution.  But like I said, it looks like your loop rates are quite slow, so it is something I would not worry about.  Just make sure you do not have a loop that uses up all of the CPU.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 7 of 8
(4,240 Views)

Thanks Crossrulz.  The link had a good article on GV and FGV.

 

However I could not utilize the code as it was in LV14. I am still a dinosour  running LV12. Smiley Wink Frankly i have the  LV14 DVD as part of offical upgrade but have not mustered enough courage to start using it. ( worried about upgrades at client installations and any changes that might result ) 

Raghunathan
LabVIEW to Automate Hydraulic Test rigs.
0 Kudos
Message 8 of 8
(4,232 Views)