LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Multithreaded Signal Acquisition and Processing Code Layout and Signal Buffering?

I've been writing LabVIEW for about 4 years now, but mostly programatic user-driven programs where operations could process data sequentially. Recently I've been writing a lot of code that I want to run in parallel, such as a DAQ andmultiple Signal Processing loops. I currently have a few questions and observations I hope the community can give me insight to.

Code Layout:

Traditionally, I could always make my block diagram code fit reasonably on the screen. My favorite structure was a while loop that encompassed a case structure, which had cases for various purposes such as user input or data processing. The while loop would iterate until program state, and the case was selected by an enumerated constant in two shift registers, which essentially gave me the ability to give the program a current and next instruction.

With the code I'm writing now, I want everything to run in parallel, and what I've ended up with is quite a few while loops. I've got a loop for DAQ, a loop for signal processing methods (I've got quite a few I want to all run in parallel on the same signal and analyze their results independently,) and a few loops to just handle buffering, etc. My problem with this is that I seem to end up with code that's all over the place, somewhat messy, and rarely fits onto one screen sized portion of the block diagram. Does anyone have any suggestions as to what I could do? Am I coding incorrectly? What I would love is a structure visually similar to a case structure, but which would allow code to be run in parallel.

Signal Buffers:

I currently have a DAQ loop running that captures a signal at 300Points/Sec, and the result of this is a DDT. In order to make this data available to my other processing loops, I create an individual queue for each loop with the DDT type, and simply enqueue the incoming DDT with each iteration of my main DAQ loop. In the processing loops, I simply dequeue the element and use a collector to create a longer buffer. Why do I do this? I need the signal to be available for independent manipulation by each processing loop. I cannot use local variables to "preview" a global buffer because all of my DAQ loops run at different speeds due to demands on processing power. Is there a better way to do this?

Thank you for your time, it's really appreciated!

Regards,
Kenneth Miller
0 Kudos
Message 1 of 2
(2,701 Views)

Hi Kenneth

Thank you for using our discussion forums.

 

It sounds like you are programming everything correctly.  In order to get parallel execution you my employ parallel loops and sometimes this will lead to large block diagrams.  One thing that can suggest is logically group chucks of code into subVIs.  This will reduce the amount of code on the main calling VI’s block diagram.  Please note that just grouping chucks of code into subVIs will not always result in identical operation because of the dataflow model that LabVIEW is based on.  Remember that a subVI will not start executing until it has received all its inputs, and it will not output any data until it has totally finished executing.  This could lead to problems if the subVI’s  output is needed for another process, or if there is a while loop within the subVI.  However with proper use you can have subVI operating in parallel.

Have a look at the following example on the DeveloperZone.

http://zone.ni.com/devzone/cda/epd/p/id/5891                  

This example employs multiple producer consumer loops all running in parallel.  There are many things going on in the block diagram and it is too large to be placed on one screen of the block diagram, however it is logically orientated and easily readable. 

Another thing I want to point you to is the templates that LabVIEW offers.  If you go to File>>New you can browse through the From Template folder and see all the premade templates that are available.  These include the State Machine (case structure inside a while loop that you mentioned in your post) to more sophisticated templates like the producer consumer parallel loop design.

Lastly I want to point you to a few very helpful links that I have come across regarding parallel design.   I think you will find them interesting.

http://forums.ni.com/ni/board/message?board.id=170&message.id=276634&requireLogin=False

http://forums.ni.com/ni/board/message?board.id=170&message.id=211149&requireLogin=False

http://forums.ni.com/ni/board/message?board.id=170&message.id=223309&requireLogin=False

 

Chris_K

0 Kudos
Message 2 of 2
(2,671 Views)