03-07-2010 09:51 AM
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.
03-07-2010 01:30 PM
03-08-2010 12:44 AM
03-09-2010 02:25 AM - edited 03-09-2010 02:28 AM
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?
03-09-2010 06:18 AM
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.