Thursday, December 9th, 2010
Producer/Consumer loop (PC loop) is one of the most important architectures in LabVIEW. It gives a good solution when your data producing rate is faster than your consuming rate. A typical example is analysing/storing the data while acquiring new ones. We dont want any slowness or jag of the post-process interrupt the acqusition. Thus PC loop create a space from the memory and uses it as a buffer to deal with the asynchronous tasks.
In this architecture, the consumer loop will wait (for timeout period) until there is a new element in the queue. What if we want to run the consumer loop regardless the queue is empty or not? Sometime, we want to output waveforms until new waveform is generated. I modified the PC loop as following:
Note: Since the consumer loop runs all the time, we need a ‘wait until‘ node in it to save the CPU. It is not shown in the figure and sorry about that.
So the consumer loop does the normal things (like output pre-defined signals) when there is no element in the queue (determined by state of queue.vi). And when there is, the consumer loop dequeues it and updates the state (like updating signals). I think this thought is logical and similar to human thought. An alternative method is to enqueue the same element after we de-queue it. In this case the loops will be keeping enqueuing and de-queuing. I don’t quite like this method, of which the thought is not straightforward.
Friday, November 26th, 2010
These days my supervisor and I have been working on some amazing (and silly) things. Briefly, using LabVIEW to synchronize a movie, a piece of music and a Jacob’s Ladder. The goal is to demo an interesting show to the school kids. And I would like to share a piece (cause it’s not done yet) of the LabVIEW code, which loads the music and plays it.
So what you need is a data acquisition card (analog output rate greater than 44k Hz, at least 2 AO channels if you like stereo), a speaker or an earphone, LabVIEW and your music. In LabVIEW we read the music file and send the waveform file to 2 analog output channels. If you chop your earphone and connect the three (L, R and ground) lines to the corresponding AO ports, you will hear the sound.
What’s the point of doing that rather than inserting the earphone straightly to your laptop? Because WE CAN.
Note: 1. In my test, reading a block of music won’t slow down your DAQ loop, since the AO task is only 44.1k Hz. I used a Producer/Consumer loop just to make it scalable.
2. To prevent the music from section repeated, I selected ‘Do not allow regeneration‘ mode.
3. Enable ‘auto start’ for ‘Analog write‘ VI.
4. Future work can be done on stopping the AO task automaticly once the music is over. To do this, we can simply bundle the ‘end of file?‘ state of ‘sound file read.vi‘ to the queue element, and use the state to stop the consumer loop.
5. Tell me if you really have done this. 🙂