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: 

functional global variable to read and write data from and to parallel loops

Solved!
Go to solution

Hi!

 

Here is the following situation: I have 3 parallel while loops. I fire them at the same time. The first loop reads data from GPIB devices. The second drives PID propelled analog output (static waveform software timed, update interval cc. 3 seconds) card with DAQmx functions. The third one records data in case of certain conditions to TDMS file.

 

I create a functional global variable (FGV) with write and read options holding the measured data (cc. 30 doubles in cluster). So when I get a new readings in the GPIB loop, I put the new values into the FGV.

In the parallel loops I read the FGV when it is necessary. I know this way I just create a race condition, because when one of the loops reads or writes the data in the FGV, no other loops can access it, so they hold their run until the winner loop finishes its reading or writing on it.

 

In my case, it is not a problem to loose some measured data, and also some short hangings in certain loops are okey. (measured data including temperature values, used in the PID loop, and the record file loop, also the system has large time constants, so it is not a problem if the PID loop sometimes reads out the previous same values from FGV in case if it won the race)

 

Is it a "barbarian way" to make such a code? (later i would like to give a good GUI to my code, so probably I should use some kind of event handling...)

 

If you recommend something more elegant, please give me some links where I can learn more.

I started to read and learn trying to extend my little knowledge in LabView, but for me it looks like I can find really pro examples and documents (http://expressionflow.com/2007/10/01/labview-queued-state-machine-architecture/  ,  http://forums.ni.com/t5/LabVIEW/Community-Nugget-2009-03-13-An-Event-based-messageing-framework/m-p/... )and really simple ones, but not in the "middle range". This forum and the other NI sources are really great, but I feel like swimming in a huge "info-ocean", without directions... Smiley Surprised

I am after Core 1 and Core 2 courses, do you know some free learning material what is based on these? (to say some "intermediate" material...)

 

Thanks very much!

0 Kudos
Message 1 of 5
(4,347 Views)

In the parallel loops I read the FGV when it is necessary. I know this way I just create a race condition, because when one of the loops reads or writes the data in the FGV, no other loops can access it, so they hold their run until the winner loop finishes its reading or writing on it.


You will not end up with race condition by using FGV, because you will be reading or wrirting at a given instance.

 

As far as the links you have metioned, you are heading in the right direction (of using events and queues)

 

Guru

Regards
Guru (CLA)
0 Kudos
Message 2 of 5
(4,333 Views)

okey, my mistake, it is not a race condition, but because the data producer and data consumer has a different loop rate, sometimes the PID loop can read obsolete previous data again, and sometimes looses data, because the GPIB loop writes data for examples 2 times to the FGV, and no read out from the PID loop between these 2 readings. 

 

But if my PID control is not sensitive for loosing some data or reading the same data more then once, so is the FGV implementation in this way an acceptable solution in my case...?

 

And also my question is still about if I can find some not too pro either not too simple tutorial materials for different programming designs (more complex then built in labview templates, less complex then the above links)? Smiley Happy

 

0 Kudos
Message 3 of 5
(4,325 Views)
Solution
Accepted by topic author Blokk

I would use queues instead of a FGV in this particular case.

You could change your FGV to an Action Engine which would provide a signal saying that data is ready, readme..  And maybe have an array of clusters to hold more values while waiting to be read, etc...  It gets complicated...

 

A queue on the other hand will do the trick nicely.  You could have a producer/consumer arrangement.  You may not need that 3rd loop.  If you setup a state machine, that has (among other states) :  wait for data (this is where the queue is read), write to file, drive PID. 

Your idle state would be the "wait for data". 

 

Is the PID dependent upon the data?  If not and it has to run on its own, then yes, you could have a seperate loop for it.  If it need to run at a different rate than the loop reading the data, you could have another queue or some other means to pass the data to that loop. 

 

Another trick would be to set the PID state as the default state and verify for new data at regular intervals, thus reducing it to 2 loops (producer / consumer).  The new data would be shared over wires using a shift register.

 

There are many tricks.  However, I would not recommend using a basic FGV as your solution.  An Action Engine, would be okay if it includes a mechanism to flag what data has been read (ie index, etc) or once the data has been read, it is deleted from the AE. 

There are many ways to implement a solution, you just have to pick the right one that will avoid loosing data.
0 Kudos
Message 4 of 5
(4,320 Views)

thanks, now I have a direction, where to look...actually the PID could be in the same loop, I think I just overcomplicated the whole thing...

In any case, I will need a state machine with events, to interact with the GUI...

thanks again and best regards

0 Kudos
Message 5 of 5
(4,315 Views)