LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How does the NI_PtbyPt.lvlib:Mean function work with Nested loops?

I am using the mean function inside another while loop. As a general rule I know due to dataflow it is a bad idea to run while loops inside while loops if you are trying to achieve parallel operation.

 

BUT...

 

I am using the mean function inside another while loop. When I open the VI up I can see that it is a while loop that runs forever. I can't figure out how labview has achieved this? Are there properties I can set to allow this if I want to replicate this type of execution?

 

Logically this should not work, but labview seem to have done it. Am I missing something?

 

Nested while loop Main.png

0 Kudos
Message 1 of 5
(3,231 Views)

No, it doesn't run forever - it runs only once. The while loop is used so you can use uninitialised shift registers to store the data between each run of the VI.

 

These two are identical:

2016-02-22_14-28-31.png

 

(top one is continue if true, bottom one is stop if true)


LabVIEW Champion, CLA, CLED, CTD
(blog)
Message 2 of 5
(3,224 Views)

Hi LegoHead,

 

Look into "Functional Global Variables" or "Action Engines" in LabVIEW. This same functionality of storing data in a shift register can be done by using a "feedback node" and by using a For Loop with number of iterations set to 1.

Message 3 of 5
(3,205 Views)

Ah thanks for the help, I was missing something. This is now starting to make sense. 

 

I have never seen this functional global variable before, and now I see it, I like it. There are a few places in my code where I could use this Instead of passing data outside the VI into shift registers.

 

Thanks for the help Smiley LOL

0 Kudos
Message 4 of 5
(3,188 Views)

You are welcome. They can be very useful, but can also be prone to give bugs which are very hard to trace (race conditions). One key to making a good Action Engine (I'll use AE but others say Functional Global or FGV), is to do the data processing inside the AE so the data never has to leave the SubVI.

 

For example, say you have two loops running and you want them to increment some counter in your AE every time they run. If your AE only has two functions, "Get" and "Set", then in each loop you will "Get" the count value, increment the value, then "Set" the count value. But what if both loops "Get" the data at about the same time? They will both "Set" a value incremented by 1, and you will miss one of the increments.

 

Consider instead you have another function besides "Get" and "Set", and it is called "Increment". You call the AE from each loop (and make sure it is non-reentrant) with the function "Increment", which takes the value out of the shift register and increments and stores it again. In this way you will capture every single loop iteration.

 

 

0 Kudos
Message 5 of 5
(3,182 Views)