LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

General Newbie Questions About Producer - Consumer Design

I am not new to Labview, but am very inexperienced with the Producer - Consumer model of program design.

For example, in one frame of a stacked sequence structure I have a while loop with a GUI event structure, a DAQ timed loop and a process timed loop. I want to run the DAQ loop at 100ms at the highest priority. I don't really care what rate the process loop runs, but it seems if it runs slower than the DAQ loop, it delays the acquisition. If the process loop runs at the same rate as the DAQ, the process loop will finish late. I am not too concerned with it finishing late as long as everything was completed.

What is a general guideline for running multiple timed loops in parallel?

Many Thanks,
Jim Flip

LV 7.1
0 Kudos
Message 1 of 9
(3,917 Views)

Before going into details of the loops, may I ask why you are using a Stacked Sequence Structure?  And what are in the other frames? 

When I use the Producer - Consumer model, I follow the NI guidelines.  Typically, I have 2 or 3 while loops.  The top one contains an Event Structure.  The other 2 loops wait for queued events to poceed (ie: one to handle front panel controls and the other to do computations, analysis, non-display-related functions).

I typically stay away from the Stacked Sequence Structure...  especially when using the Producer - Consumer model.

I know this reply didn't cover the timed DAQ loop issue, but first, let's have a look at the global implementation. 

RayR

Message 2 of 9
(3,913 Views)
I'm sure a stacked sequence is a bit of old fashioned programming, but I have some things I want to have happen before the loops begin processing. Just to be completely clueless about this, I also have some stacked sequences in the timed loops themselves 😉

Jim
0 Kudos
Message 3 of 9
(3,902 Views)
A state machine is part of the Producer Consumer concept. Simply put an Initialization state (or several, if needed) in the loop and set it to run them before it even looks for an input from the Producer.

Similarly, the nested sequence can be replaced by additional states. Sometimes a subsidiary state machine may be used.

Lynn
Message 4 of 9
(3,892 Views)

Excellent advice, Lynn!

You can simply port the contents of the stacked sequence to the state machines. 

 

0 Kudos
Message 5 of 9
(3,878 Views)
The program flow will be a state machine when the real program is coded, but for now my question is concerning multiple parallel timed loops.

Thanks Lynn and Joe!
0 Kudos
Message 6 of 9
(3,864 Views)
Jim,

I cannot comment on the timed loop issue directly as that function is not supported on my platform.

However, running parallel and independent loops at different rates is no problem.
1. Make sure that each loop has a delay or wait function. This to allow LabVIEW's internal scheduler to switch tasks. This may be inherent in the timed loop.
2. Make sure that the high priority loops (the DAQ loop) do not run in the UI thread. This means that these loops do not write data to front panel indicators and do not use proerty nodes (which force a switch to the UI thread).
3. Make sure that the method of data communications between the loops does not block execution while waiting for access to resources. Some form of buffering may be needed to accomdate the different rates of generating and using data. Queues or LV2 style functional globals are generally good choices.

Lynn
0 Kudos
Message 7 of 9
(3,855 Views)
You can create a while loop at the top containing an Event Structure. Using Queues is a way of triggering when events are serviced.
A 2nd While Loop can be used to process the queue and by type of queue, for instance, by using an enum as selector for the Case Structure.
 
I'll try to whip up an example later tonight if sleep doesn't beat me to it.  🙂
 
RayR
0 Kudos
Message 8 of 9
(3,841 Views)
Thanks again, Joe and Lynn!

I have a three loop design currently and it seems to work pretty well, but it's the timing between loops I am having trouble with.

The gui loop reads the front panel and sends the commands to the process loop.

The DAQ loop is where the time critical acquisition and control is centered. It acquires three samples from the DAQ card every 100 ms. It also acquires data from a serial device every second. It then accepts the commands from the process loop and writes to a serial device ( timing to be determined).

The process loop accepts a queue from the DAQ containing the two types of data acquired. It then parses the strings, converts the array of doubles to discreet doubles and writes the data to a file every second. It also updates the front panel indicators. It would probably be better to send the data back to the gui, but I am not tat far along.

The DAQ loop is running at 100ms with a priority of 100. The process loop is running at 100ms with a priority of 99. The DAQ rarely finishes late, but the process loop finishes late ...mostly at the beginning.

Am I on the right track?

Thanks,
Jim


0 Kudos
Message 9 of 9
(3,814 Views)