LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

non-simultaneous while loops

Solved!
Go to solution

Right, I have a program in two parts. The first generates a sine wave and outputs it to an external device. The second part takes a camera input and runs some calculations on the data and outputs it in a speadsheet.

 

The problem I have is that the data is not recorded with the frame rate of the camera (17fps) but at the loop rate of the first while loop (10 per second). When I run the camera part of the program seperately I get the full 17 per second.

 

I would like both parts in one VI.

 

So my question is, how do I get the loops to run non-simultaneously?

 

I would include my VI but it has a lot of complicated functions which won't back any sense, but I think my question is quite general. Any more details I will be happy to give.

 

Thanks to anyone who can give me some advice on this.

 

James

0 Kudos
Message 1 of 16
(3,775 Views)

Two separate parallel loops should run independent and simultaneous if there is not any dependence between the two.

 

Without seeing your code it is hard to tell what the problem is.

 

Any queues or notices between the two?

Do the two loops share any non reentrant sub VI's?

Are they talking to the same hardware device?

Reading from or writing to the same file?

 

These are just same of the thinks that could effect loop timing.

Omar
0 Kudos
Message 2 of 16
(3,766 Views)

You probably want this:

 

http://zone.ni.com/devzone/cda/tut/p/id/3023

 

It is a standard producer/consumer model.

 

 

A

0 Kudos
Message 3 of 16
(3,764 Views)

Right, I think the problems stems from a simple processing power limitation.

 

When either part of the program run the processor is at around 85%. I am saving the data from a line of pixels of about 500, finding peaks in the intensity, and uses the spacing between these peaks to obtain another value which I write to file.

 

The computer I have is a single core P4 3Ghz, which I would have thought would be sufficient.

0 Kudos
Message 4 of 16
(3,742 Views)

 


@Janissaries wrote:
The problem I have is that the data is not recorded with the frame rate of the camera (17fps) but at the loop rate of the first while loop (10 per second). When I run the camera part of the program seperately I get the full 17 per second.

Ok, you have 2 loops. Loop 1 reads data once every 10ms, loop 2 every 5.88ms. These are independent, so you don't want the camera data to be going out every 10ms but at the faster rate of 5.88ms.  Sounds like you want them to run asynchronously but in the same VI.

 

If this VI is not a SubVI (not called by another), I see no problem in just putting two loops side by side (not nested) and have them run.  To stop each loop, have a stop button that is referenced by both loops to allow for termination of both of them.

 

parallel loops

 

Each loop can be a SubVI that contains a loop, but then to terminate each, you would need a common refnum to a control to be able to terminate each at about the same time.

 

For more information check out http://zone.ni.com/devzone/cda/tut/p/id/9393.

 

 


@JamesDavies wrote:

Right, I think the problems stems from a simple processing power limitation.

 

When either part of the program run the processor is at around 85%. I am saving the data from a line of pixels of about 500, finding peaks in the intensity, and uses the spacing between these peaks to obtain another value which I write to file.

 

The computer I have is a single core P4 3Ghz, which I would have thought would be sufficient.


If each part of the programme caused it to go to 85%, then yeah, you are going to run into problems.  Try reducing the CPU load by decimating the data and/or reducing the number of events being fired in the system.  LV 7 was crap with such high number of event hits, I dunno if this has improved in the more recient versions.

 

 

 

A

0 Kudos
Message 5 of 16
(3,725 Views)

Right, the thing limiting appears to be the method of writing data to a file. I was outputting as a spreadsheet but it runs faster if I output as string data to a text file.

 

This increases my write speed to around 24 per second, which will be sufficient until I can convince my boss I need a faster computer!

 

Just another quick question, will Labview 8.2 utilise 2 cores in a multicore processor when running a program with parallel while loops?

0 Kudos
Message 6 of 16
(3,693 Views)

And thank you for your help!

0 Kudos
Message 7 of 16
(3,692 Views)

 


JamesDavies wrote: 

 

Just another quick question, will Labview 8.2 utilise 2 cores in a multicore processor when running a program with parallel while loops?


 

Short answer, yes.  For more info try looking at this:

 

http://zone.ni.com/devzone/cda/tut/p/id/6099

 

 

A

0 Kudos
Message 8 of 16
(3,673 Views)

Just an addition:

Storing data to a file in very short parts is not a question of faster or slower computers, but is a bad design.

What I would do is adding up some much longer chunks of data, put it into a queue and write that much bigger chunks less frequently in an independent loop.

 

Some background:

Harddisks can store some 10-60 MB/s when streaming (writing continuous chunks of data into continuous rooms on the disk). This can be improved by far by HD's internal caches, as the OS copies data into that cache and the HD takes care of it. BUT the process of copying takes some time ( parts or multiples of ms) in itself, that is allmost independent on the size of the data chunk (as long as it short ~ Bytes to kB).  And than there's a minimal storage block for most storage devices, a sector, of size of 512B ... some multiples thereof. So writing in smaller chunks effectively means rewriting data until a complete sector is filled and the next ist used.

 

If you really try to rely on brute force, use a faster HD, an SSD or a RAID array with several physical HDs and a large cache. But again, writing larger data chunks (optimal in size of complete clusters or even much bigger) less frequently would help much better. This buffering can, however, bring the not-yet-saved dat at risk if your PC crashes. Keep that in mind!

Just my € 0.02!
Greetings from Germany!
--
Uwe

0 Kudos
Message 9 of 16
(3,664 Views)

How do I do that, adding data to a queue? At the moment the data is written after each loop iteration - is there a simple way to simple store the data in a buffer and write it all every 10 loops for example?

0 Kudos
Message 10 of 16
(3,643 Views)