LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to increase the speed of producer-consumer architecture

Hey everyone -

 

This is a follow-up to a previous thread that I had posted (

http://forums.ni.com/t5/LabVIEW/How-to-use-a-dynamic-true-false-signal-with-a-case-structure/m-p/114...

), but my next question has taken a bit of a different direction so I have made a new thread. 

 

Following tbob's suggestion, I am trying to use a producer-consumer architecture to start and stop data acquisition from a simulated NI 9237 device.  I have attached the current version of our code to this post (Producer_Consumer_architecture.vi).  Our main problem is that there is a significant lag between when elements get added to the queue using the Enqueue function, and when they are removed from the queue using the Dequeue function. As a result, the signals from our simulated DAQ channels run for much longer than they are supposed to, and the start-and-stop of data acquisition is not keeping in time with the simulated square wave signal (we would like our NI 9237 device to acquire data when the square wave has an amplitude over 3, and stop acquiring when the amplitude is under 3).  If you allow the program to run for about 30 seconds, you will see what I mean (press the stop button twice to quit the program).

 

If anybody has any suggestions as to how we can increase the speed of the program, they would be very much appreciated!

 

Thanks in advance!

 

Download All
0 Kudos
Message 1 of 7
(4,054 Views)

hello,

 

i don't have tools needed but , i see one thing is that you enqueue 

 

every time you are greater 3 that means about every 2-3 ms so consumer is really   sought

is it really what you want ?

may be you want to start on a treshold so you can use a treshold fonction 

 

if i don't make mistake your square is 10 hz and the daq is configured 25000 sample 25000 hz

so you aquire 1s of signal every 100ms , there is something to correct

 

make tests and tell us

 

Regards

 

Tinnitus

 

CLAD / Labview 2011, Win Xp
------------------------------------------------------
Mission d'une semaine- à plusieurs mois laissez moi un MP...
RP et Midi-pyrénées .Km+++ si possibilité de télétravail

Kudos always accepted / Les petits clicks jaunes sont toujours appréciés
Don't forget to valid a good answer / pensez à valider une réponse correcte
Message 2 of 7
(4,030 Views)

some improvement ?

 

CLAD / Labview 2011, Win Xp
------------------------------------------------------
Mission d'une semaine- à plusieurs mois laissez moi un MP...
RP et Midi-pyrénées .Km+++ si possibilité de télétravail

Kudos always accepted / Les petits clicks jaunes sont toujours appréciés
Don't forget to valid a good answer / pensez à valider une réponse correcte
0 Kudos
Message 3 of 7
(3,979 Views)

Perhaps using a notifier would make more sense?

0 Kudos
Message 4 of 7
(3,965 Views)

As others have said, you need to develop some understanding of what is going on and what you want to happen.

 

It appears that the enqueuing happens at about 100 Hz, whether the data has changed or not.  The consumer loop takes at least 1 second for each iteration with the data acquisition parameters you have set.  The queue will rapidly fill up because you are enqueuing much faster than your are dequeuing.  If you want to start and stop your acquisition 100 times per second, then each acquisition must be less than 10 ms in duration.  Simple math!

 

1. Set the producer loop to only enqueue an element when the data changes.  Then your queue only gets 21 elements per second rather than 100.

2. Set the DAQ to acquire for about 2-5 ms so that the producer loop spins so that you can read the queue promptly.

3. Use a shift register in the consumer to keep track of the previous value of the start/stop signal, so that if the queue does not have new data, the program continues in the previous mode.

 

Lynn

Message 5 of 7
(3,943 Views)

Thank-you all for your suggestions!  We are currently trying some new hardware and are in the process of trying to modify our code as a result.  We may end up having to rely on our older hardware, in which case we'll try all of your suggestions. 

 

Thanks again!

0 Kudos
Message 6 of 7
(3,927 Views)

Hello everyone -

 

We have modified our program a little bit based off of an example we found in the NI Developer Zone (http://decibel.ni.com/content/docs/DOC-2431).  We have run into some new problems with the buffer size in this program, and have posted a new thread that can be found at the following link that talks about this problem:

 

http://forums.ni.com/t5/LabVIEW/Error-200257-using-DAQmx/td-p/1170471

 

Thanks for all of your help!

 

Rachel

0 Kudos
Message 7 of 7
(3,875 Views)