02-22-2017 10:25 AM
Dear all,
I am using NI USB-6361 DAQ card, which has a sampling rate of 1M/s according to its specification. However, when I tried to read the output signal and write to a file, the acquisition wouldn't last long with a rate more than 100k/s. For example, if I used a rate of 1M/s, the data acquisition did happen for a short period of time, then stopped. I need the process to last for at least a few seconds.
I don't know if it is a problem of the Labview program or my laptop. Please have a look at my VI. Any suggestions will be appreciated!
Thank you!
02-22-2017 10:40 AM
I don't know what your level of skill/knowledge in LabVIEW is, so if you don't understand the following, please ask. There will also be examples of these built-in to LabVIEW in the Help menu.
You'll want to do one of two things, if not both:
1. Use DAQmx VIs instead of DAQ assistant express VIs. More complicated to set up, but a lot more obvious what you're doing and easier to debug.
2. Use 2 parallel loops. Gather your samples in one, and send them to the second to be written to disk and/or displayed on screen. That way any lag on your disk access doesn't delay sample acquisition. The most common way is to create a queue reference outside both loops, and put an Enqueue in the sampling loop and a Dequeue in the disk writing loop.
02-22-2017 10:42 AM
I think it's because the writing is in your while loop. Writing to the hard drive take time, enough time for the buffer to be full. You don' have to write the data on every loop, you should stack it in memory and write it at a slower speed. Ideally in an other loop.
You should communicate between your two loop using ideally a queue. It come down to the "producer consumer" model described by NI here : http://www.ni.com/white-paper/3023/en/
You can use other mean to achieve that but that's the one i would recommend.
02-22-2017 11:16 AM
As Kyle said use the DAQmx VI's, but newer versions of the DAQmx API have logging built in, that is, no need for another loop. Look under the DAQmx examples in the example finder that contain logging.
mcduff
02-22-2017 07:09 PM
Hi Kyle,
I change the VI as shown below. It gives me some output but obviously it is not the correct one (the sampling rate in the output is not what I set for the acquisition). Would you please give me some suggestions?
02-22-2017 08:47 PM
Make your queue type a waveform instead of a single sample. Currently, you are just getting the first sample of each data read.
02-23-2017 10:43 AM
Hi Crosrulz,
I changed the data type as waveform but I am not sure if it is correct. Also, the signals are from 2 channels only the first one is written to file in the previous VI. I changed the VI like this but I am still getting only one file with the data from one channel. Would you please give me some suggestion?
I am a newbie and my questions might be naive, but your suggestions really help me learn a lot. Thanks in advance.
02-23-2017 12:48 PM
Data Flow. Your loops on the bottom cannot run until the top completes. You need to move your Enqueue for the second channel into the DAQ loop.
A much simpler solution would be to go into the DAQ Assistant and go to the "Logging" tab. You can have DAQmx stream the data straight to a TDMS file and you do not need to deal with all of this Producer/Consumer.
02-23-2017 01:30 PM
You are right. But I need a high sampling rate such as 200k/s or so. That's why I use the Producer/Consumer structure, as suggested by some of the replies in this post.
02-23-2017 02:17 PM
I am getting closer and closer to my goal, but another problem rises. Now I have 3 while loops, one for the data acquisition and enqueuing, and the other two for data logging. I want to terminate the data acquisition, while keep the logging happening until all data obtained is written into the files. So I presume that I should click the "Stop" button for the first loop (upper left one) and keep the VI running.
I can get two output files now. However the data points are only from one second. That means, when I set the sample rate at DAQ assistant to be 1M/s, I got 1M points, even if I ran the VI for several seconds. Is the VI overwriting whatever data is there in the file every time the queue gets a new batch of data?