Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Fast data acquisition using NI USB 6218

Hi all,

 

 

Question 1:
I've programmed a GUI to communicate between USB-6218 and matlab r2009a. However the performance are relatively slow.

 

In theory the USB-6218 can support up to 250kS/s, and since i am using 16 channels the sample rate are divided with 16 = 15,625S/s thus for a single sample for each channels it will take 64microseconds. In between channel samplings a delay is introduced by the hardware which is called channel skew rate which is 4microseconds. Thus for a single channel it will take around 68microseconds to sample.

Let's say roughly a single channel will take approximately 100microseconds to acquire a single sample. Thus to sample measurements from 16 channels, it will take 1.6 miliseconds.


clc; clear;

ai = analoginput('nidaq','Dev1');
set(ai,'InputType','SingleEnded');
addchannel(ai, 0:15); %16 channels
ai.SampleRate = 15625; %supported max. sampling rate divided by 16 channels

out = zeros(1,16);

tic;
    
start(ai);
out = getsample(ai); %immediatly acquire a single sample from each channels


toc;

stop(ai);
clear ai
delete ai

 

The recorded time for this is around 40 miliseconds which is far from the calculated 1.6 miliseconds. Unfortunately Real-Time Windows Target does not support for this particular hardware (NI USB-6218).

 

is there any other way to program MatLAB to communicate with the hardware faster? did i miss or do anything wrong?

Please help and correct me if i'm wrong, Thank you.

p/s: i've also programmed a GUI using LabVIEW 2009, however the recorded time is around 35ms.

 

 

Question 2:

Using the simple program above, each time i acquire data from the DAQ, it will be in the matrix form of 1x16. However, my project is to loop the system 16 times thus the final data will be in the matrix of 16x16.

 

Is there a way for me to let the system run for 16 loops, then only at the end of the loop i acquire the data from the DAQ straight in the form of 16x16 matrix.

 

In conclusion i just have to acquire the data once this way, while using the example program as above, i have to acquire the data 16 times.

 

 

Thank you in advance.

p/s: it's okay if the proposed method are either in MatLAB or in LabVIEW, however i prefer it to be in MatLAB. Thanks again.

0 Kudos
Message 1 of 5
(5,262 Views)
You've got some misconceptions about the DAQmx driver. You are performing a single scan and before the scan can happen, the DAQmx task has to start. This is unavoidable overhead. The scan will then be done for your selected channels. In LabVIEW, there is an explicit Start Task function but I don't see anything like that in your code so the timing caclulation is way off. In order to use the hardware timed sample rate of 250 kS/s, you have to tell DAQmx to perform multiple scans. In LabVIEW, this is done by specifying NChannels NSamples for the DAQmx Read. In your case, you would also specify 16 samples per channel. I have no idea what the correct syntax is in MATLAB. There are a lot of examples that come with LabVIEW. You just have to look through them.
Message 2 of 5
(5,253 Views)
Attaced example screenshot.
Message 3 of 5
(5,239 Views)

Hi Dennis and KateB, Thank you for the reply.

 

For the Start Task function(LabVIEW), i did have it in the code i provided, it is "start(ai)".

 

If i understand correctly, u were also answering my second question which has been graphically shown in the next post by KateB, correct? For me to do that in MatLAB, i would have to configure my code like this:

 

ai = analoginput('nidaq','Dev1');            %configuring device
set(ai,'InputType','SingleEnded');
addchannel(ai, 0:15);                           %16 channels used

ai.SampleRate = 15625;                       %sample rate per channel
ai.SamplesPerTrigger = 16;                   %acquire 16 samples per channel

 

using this configuration, each time i start the DAQmx task which is "start(ai)", i will get a 16x16 matrix which is the same with the code posted by KateB. However this is not exactly what i hoped to do. I hope the the attachment will help me explain it further.

 

Flowchart A is how currently the data is acquired.

Flowchart B shows what i hoped to do.

 

 

You mentioned about the unavoidable overhead when the DAQmx task has to start. is there a lot of difference on this overhead if different interface are used, such as USB and PCI cards?

Message Edited by miskoL on 03-09-2010 02:28 AM
Download All
0 Kudos
Message 4 of 5
(5,192 Views)

Sorry about not seeing the start function.

 

I thought you were concerned about how much time it was taking between samples. That was your whole description at the beginning of your post. If you are not, then continue with your existing scheme but place the start outside the loop. You only do the start task once. You will not be using hardware timed acquisition between scans and the time between your reads will be dependent on your system. You will have to store result of each scan and build the 16x16 array as the driver will not do it for you.

0 Kudos
Message 5 of 5
(5,168 Views)