07-29-2009 11:52 AM
Is there a fairly simple way to configure Labview as an analog delay generator? I need to generate an analog output that is identical to, but delayed from, an analog input signal. The delay would be fairly long, on the order of a second or so. I'm using Labview v8.6 and I have a PCI-6251. Any help would be greatly appreciated.
Regards,
Stephen
Solved! Go to Solution.
07-30-2009 04:11 AM
Hello,
Example: If you had an analog input task continually acquiring samples, set to a sample rate of 1khz, and set to collect 1000 samples, it would return 1000 samples after a second, which you could then sequentially put into your analog output task set to the same sample rate of 1khz. This would give a delay of 1 second.
I hope this helps!
07-30-2009 06:16 AM
Thanks for the reply Mark. I've been trying to do something similar to this, but the problem is that I need to continuously read and write the wave, even after the delay has started. So if I buffer 1 second of data and then spend 1 second writing it with the AO subVI, after that 1 second I don't have any more data buffered and I have to start over, leaving a gap of 1 second in my output data (the time it would take to read in another delay period on the input). Lets say that I have a continuous sine wave input with a period of 2 seconds - I want to continuously sample it in and then output the same wave with a delay of 1 second, so that the two waves would be phase shifted by 90 degrees in this case. I reality though my signal isn't a sine wave, I'm just using that as an example. Does that make any sense?
Thanks for the help,
Stephen
08-26-2009 03:37 PM
08-26-2009 06:17 PM
Hi UKslj,
I went ahead and took a stab at it--how does this look:
Use AO to Output Delayed Version of AI in DAQmx
The caveat is that you will need to set the delay high enough such that the AO task does not underflow, but I think this should be more or less what you need to do. Let me know how it goes!
-John
08-26-2009 06:29 PM
Hi John,
Thanks a lot for the quick reply. I can't download the example though (it says "queued").
Stephen
08-26-2009 06:35 PM - edited 08-26-2009 06:43 PM
Hi Stephen,
It sometimes takes a few minutes for our Community site to finish uploading example code--It shouldn't take more than an hour before the code is uploaded.
*Edit -- the code is now downloadable*
-John
08-27-2009 08:41 AM
Hi John,
Thanks again for the example code. It's exactly what I was looking for! I essentially had the same VI created, but I wasn't using the property node to not allow regeneration. I guess that's essential?
One question I do have though is how does the data buffering work inside of the while loop? There obviously has to be a buffer that is (delay time)*(sample rate) long, yet when I look at the size of the waveform being read/written in the while loop, it's only a couple of elements. So where are the data?
Thanks,
Stephen
08-27-2009 09:32 AM
Hi Stephen,
The buffering isn't actually taking place inside the while loop, but rather is a part of the DAQmx Output task. When performing an analog output, the data to be generated is stored up in a queue in memory after DAQmx Write is called. If the queue is full and DAQmx Write is called, it will wait until enough samples have been generated such that there is enough space in the output buffer to write the new samples.
Regeneration is enabled by default, meaning the output task will repeat the data continuously from the output buffer. Since we are continuously providing new samples to the buffer, it is best to disable regeneration to avoid generating old data.
So, we are just reading samples back as quickly as possible inside the while loop and writing them to the DAQmx output buffer. If you notice that the code is too processor intensive, you can slow down the loop rate by either giving DAQmx Read a number of samples to read (not -1), or by inserting a Wait function inside the loop.
-John