11-05-2007 07:08 PM
11-06-2007 09:11 AM
11-06-2007 09:25 AM
11-06-2007 11:56 PM
Hello Lynn and tst,
Thanks for your suggestions. I have attached a screen shot of a vi that has the enqueue function. As Lynn pointed out, it was the enqueueing size that was reflected in the size of the dequeueing. I tried various ways to control the enqueue element size in order to control the dequeue element size. Many of my tricks failed. I had set the data acquisition to be continuous at 2kHz with 10Ks buffer size. You may want to look at the attached image of the subvi "Analog Acquisition" while I explain my attempts. The first thing that I noticed was the 'dt' value in the input node of the timed loop which had been set by somebody to 100. I thought that was part of the reason why my dequeue size was always worth 100msec data points. So I changed it to 1 msec. This definitely made a difference in the chunk size of the dequeued element. Now dequeueing removes only data points worth 1 - 5msec. I also noticed that my data reading timer loop(the while loop in "Analog Acquisition" picture) takes about 20 -25 msec instead of the set 1 msec.
Why does the loop take so long? I have set the 'number of samples per channel' to -1 so that DAQmx read.vi (see it in Analog Acquisition subvi block diagram) can grab whatever data is available currently and put that into the queue. Can this be a reason why the loop takes more than 20 msec? I also tried to set the number of samples per channel to 2. I reasoned that with the sampling rate of 2KHz, 1ms loop should be able to pull 2data points and enqueue them. But it gave me the much-often-seen error code ":Error -200279 occurred at DAQmx Read (Analog 1D Wfm NChan NSamp).vi:1->Timed structure(s): DAQ Loop". I tried various combinations of loop time and number of samples per channel. I get Error-200279 very often. Note that I have several state transitions and only in a couple of them during every cycle of state transitions, I remove elements and flush the data queue (one place where I remove elements is shown in my original message in the picture-'Acquire Response.jpg').
How do I set the data acquisition loop to enqueue elements for exactly 1 msec or n msec so that I can control my dequeue size?
Thanks a lot, I am getting really tired of fixing this problem. Please help.
Mani
11-07-2007 08:10 AM
A few comments. Probably not all of them will help, but hopefully at least one does...
1. I'd gently suggest that you may be focusing on solving the wrong problem. You're sampling at 2 kHz in hardware and trying to service the AI data in software at 1 kHz. I don't think that's necessary. Also, the AI data acq task itself can give you more relevant and more precise timing info than the "tick count". As long as you are sure to accumulate *all* the samples, you know that their "dt" spacing is 0.5 msec (1 / 2 kHz) and you don't rely on the OS to give you timing info.
The software processing rate should be driven by answering: "When the subject moves the joystick, how fast must my program detect it and react / respond?". You probably don't need to respond any faster than 50-100 msec or more.
2. Putting your calls to DAQmx Read inside a Timed Loop structure may complicate things. If you want want to collect data in 100 msec chunks, you can use a simple while loop and specify that DAQmx Read should read 200 samples. The call to DAQmx Read will yield CPU while waiting for those samples to accumulate. An advantage of this method is fixed-size data chunks which are often easier for processing. The disadvantage is that you need to make sure your software keeps up with the hardware so you don't overrun the buffer.
3. When you read the AI data, the fact that you fork the wire to both the "data" indicator and to the "Enqueue" function forces LV to copy the array of data every loop. If you were to wire straight from Read to Enqueue with no forks (i.e., remove the "data" indicator), LV can do the enqueue without any memory copying at all.
4. When you enqueue there is a red dot meaning that the waveforms are being coerced into whatever datatype was defined when the queue was created. Coercions can slow your code so try to resolve this.
5. Despite all these nits, I want to also add that the code looks impressively well-designed for a LabVIEW newcome. Good work!
-Kevin P.