LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to communicate between two loops in LabVIEW

So I'm trying to compare two values, precisely numeric values generated by two different infinitely looped structures. I want to compare each of them everytime the loop executes (i.e infinitely) and then generate another output after the comparision, but I dont know how it should be done. I'm still novice to LabVIEW, so any help would be appreciated. Thank you very much.

0 Kudos
Message 1 of 12
(3,963 Views)
You could use global variables, but you have to think if your loops have to be syncronized. If they do, this will not be the better aproach. Some (maybe many) people here at the forum think we shoud not use globals at all! (not my case, lol). Another way to do it is to trigger an event in Loop1 everytime the variable in Loop2 has its value changed. In this case, you will not compare again until the value has been changed, and not in every loop interaction.
0 Kudos
Message 2 of 12
(3,951 Views)

Hi Sanjog,

 

From your description, there may be an easier way to solve your problem.

You seem to need to run the two loops in sync, so why not put them into one loop?

 

For example:

 

com loop.png

 

Each of your "loops" would run once for each iteration.

Just remove the looping structure from your two loops (or set them to only iterate one time).

 

steve

--------------------------------------------------------------------------------------------------------------------------
Help the forum when you get help. Click the "Solution?" icon on the reply that answers your
question. Give "Kudos" to replies that help.
--------------------------------------------------------------------------------------------------------------------------
0 Kudos
Message 3 of 12
(3,937 Views)

@Sanjog wrote:

So I'm trying to compare two values, precisely numeric values generated by two different infinitely looped structures. I want to compare each of them everytime the loop executes (i.e infinitely) and then generate another output after the comparision, but I dont know how it should be done. I'm still novice to LabVIEW, so any help would be appreciated. Thank you very much.


Since the two loops presumably run independently and at their own rate, it is not clear what kind of output you want and how ofter a comparison should be made and an output generated. Your statement only makes sense if the loops are synchronized, else there are many possible unpredictable scenarios.

 

You could synchronize the output to one of the loops and blindly compare with the current value from the other loop via a local variable.

 

Instead of specifying the problem by "operations", please explain what the program exactly does, why there are two loop, where the data comes from, and where the output is going.

 

Are these DAQ measurement? A control application? Simple logging?

0 Kudos
Message 4 of 12
(3,931 Views)
0 Kudos
Message 5 of 12
(3,921 Views)

You have a race condition between when the notifiers are fired, and when the local variables are read.  Why don't you use the value that is in the notification rather than the local variable?

Message 6 of 12
(3,886 Views)

I don't get it.

 

Why the local variables?  What are you using the U32 notifiers for, exactly?  You send a notification containing a U32 number from each of your top two loops, receive those notifications in the bottom loop, but then read and compare a couple of local variables instead of reading/comparing the data coming from the notifiers?  If you're not going to use the data you send via the notifiers, why did you go to the trouble of including them?  You're going to wind up with a race condition.

 

There's obviously some part of your solution that I don't understand.  Use either the notifiers to transfer data (my preferred way of doing things), or the locals to transfer data.  Not both.

 

If you get rid of the locals and instead compare the data transferred via the U32 notifiers, I'd say you had a pretty good solution.

0 Kudos
Message 7 of 12
(3,884 Views)

I agree that this code is very convoluted and probably not suitable in general. Due to the two-way dependence of all three notifiers, the slowest loop will determine the rate of all others, which would seriously interfere with e.g. DAQ. There are too many loops trying to be master.

 

 

0 Kudos
Message 8 of 12
(3,879 Views)

 

my last version

try it, it works 100%

 

i use U32 notifiers

no loop trying to be master ... just like a flip/flop between (A-B) and C (sorry for my bad english)

now, no race condition.

 

 

original5.png

0 Kudos
Message 9 of 12
(3,866 Views)

 

sorry, just a very small mistake

 

surrounded by red,  0 (not "1")

 

original5.png

0 Kudos
Message 10 of 12
(3,858 Views)