LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Slow loop inside fast loop

Solved!
Go to solution

This is my first week working with LabView so the answer might be very simple.

 

Here's my question:

 

How do I include a slow loop (event B)  inside a fast loop (Event A)?

What I would like is for Event B to execute every 1000 milliseconds and Event A every 100 milliseconds.

 

 

Where Event A is a position control loop and Event B is a simple write to file of some measurement.

 

Any recommendation on how i should accomplish this?

 

 

 

0 Kudos
Message 1 of 6
(3,562 Views)

Put the slow loop outside the fast loop.

They will run in parallel.

0 Kudos
Message 2 of 6
(3,556 Views)

Generally I handle this kind of requirement with the producer-consumer architecture.

 

The Producer/Consumer pattern’s parallel loops are broken down into two categories; those that produce data, and those that consume the data produced. Data queues (which are covered more in-depth in the Queued Message Handler section) are used to communicate data between loops in the Producer/Consumer design pattern. These queues offer the advantage of data buffering between producer and consumer loops.

 

Source Link: http://zone.ni.com/devzone/cda/tut/p/id/3023

Balaji PK (CLA)
Ever tried. Ever failed. No matter. Try again. Fail again. Fail better

Don't forget Kudos for Good Answers, and Mark a solution if your problem is solved.
Message 3 of 6
(3,555 Views)
Solution
Accepted by Saguenay

You can use an Elapsed Time Express VI inside the fast loop to see if it's time to execute the slow loop.  I took the liberty of not using a loop for your "event B" because it sounded like you just want to pace it with event A.  Put event B in the True case of the Case Structure. The producer/consumer design pattern is the way to go if you're developing a complex application. This'll do if your problem is relatively simple.

 

 

 2loops.jpg

 

 

 

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 4 of 6
(3,524 Views)

Thanks for the solution

 

I also found that passing data between parallel loops with local variable could do the trick

 

 

0 Kudos
Message 5 of 6
(3,504 Views)

Saguenay wrote:

I also found that passing data between parallel loops with local variable could do the trick


Local variables can lead to race contitions, when they are be used for that reason.

Search for "race contitions" on this forum for more info.

Better use "function globals"

Do a little search

Message 6 of 6
(3,490 Views)