Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Low speed transfer when using "daq.ni.NIDAQmx.DAQmxReadAnalogF64"

Solved!
Go to solution

Dear Matlab & NI users,

when I launch the instructions set below, in order to acquire samples from one channel (using the USB6229 ADC Card), it takes quite a while (11 sec) to acquire 1e4 sample at 50 kS/s.

I would have expected around less than 1sec.

Is this connected to my "poor" USB link?

Any way to speed up ?

Many thanks for your help

 

Best regards

Frederic

 

[status_sta] = daq.ni.NIDAQmx.DAQmxStartTask(TaskHandle);
[status_read, inputData, sampsPerChanRead, reserved] = daq.ni.NIDAQmx.DAQmxReadAnalogF64(XXXXX);
[status_sto] = daq.ni.NIDAQmx.DAQmxStopTask(TaskHandle);

 

(with XXXXX in place of = TaskHandle, int32(ADC.NumberOfScans), timeout, fillMode, inputData, arraySizeInSamps, sampsPerChanRead, reserved)

 

0 Kudos
Message 1 of 9
(1,436 Views)

I don't know any of the text API's in any detail, but you haven't shown nearly enough of the details for me to even try to assess what the problem might be.  You should show all the task-related code and variable values.

 

USB is a little more limited than desktop boards, but not 11 seconds worth.  It might be the case that you have a Finite Sampling task, you're trying to read more samples than it's configured for, and you're running up against the default timeout of 10 seconds.  That's my only wild guess.

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 2 of 9
(1,434 Views)

My apologie Kevin,

I thought the issue was mainly due to the USB rather than the code.

Here is an example which stands 10 sec while reading 2 channels (10000 samples, 50 KHz)

May thanks for your advises

Regards

Frederic

(the script is attached, with .txt rather than .m extension)

0 Kudos
Message 3 of 9
(1,392 Views)

How did you configure the task? There should be more code than what you've presented. Did you get good data from the read? Or did you receive an error after execution?

0 Kudos
Message 4 of 9
(1,390 Views)

here is the script (I can't attach it to the msg I get an error msg related "to the file content which does not fit the file extension"

 

% Check data transfer duration
%
ADC = daq.createSession('ni');
aiCh(1) = ADC.addAnalogInputChannel('Dev2', 'ai0', 'Voltage'); % Channel 1 definition
aiCh(2) = ADC.addAnalogInputChannel('Dev2', 'ai1', 'Voltage'); % Channel 2 definition
aiCh(1).Name = 'V1'; % Name of the Channel 1
aiCh(2).Name = 'V2'; % Name of the Channel 2
aiCh(1).Range = [-10 10]; % Voltage Range for Channel 1
aiCh(2).Range = [-10 10]; % Voltage Range for Channel 2

%% Parameters of Acq
ADC.NumberOfScans = 1e4;
ADC.Rate = 5e4;
fillMode = uint32(0);
activeEdge = int32(0);
sampleMode = int32(0);
timeout = 15;

% Initialization
TaskHandle = aiCh.TaskHandle;
num_ch = 2;
numSampsPerChan = uint64(ADC.NumberOfScans);
[status_clk] = daq.ni.NIDAQmx.DAQmxCfgSampClkTiming(TaskHandle, 'OnboardClock', ADC.Rate , activeEdge, sampleMode , numSampsPerChan);
numSampsPerChan = int32(numSampsPerChan);
inputData = zeros(1,num_ch*ADC.NumberOfScans);
arraySizeInSamps = uint32(num_ch*numSampsPerChan);
sampsPerChanRead = numSampsPerChan;
reserved = uint32(0);
tic
[status_sta] = daq.ni.NIDAQmx.DAQmxStartTask(TaskHandle);
[status_read, inputData, sampsPerChanRead, reserved] = daq.ni.NIDAQmx.DAQmxReadAnalogF64(TaskHandle, int32(ADC.NumberOfScans), timeout, fillMode, inputData, arraySizeInSamps, sampsPerChanRead, reserved);
[status_sto] = daq.ni.NIDAQmx.DAQmxStopTask(TaskHandle);
toc
size(inputData)
inputData(end)

0 Kudos
Message 5 of 9
(1,385 Views)
Solution
Accepted by topic author FredCl

As I said before, I really don't know the text API in detail.  But nothing about the posted script jumps out at me as a root cause.  I wonder some about sampleMode=0 (Finite Sampling?), and the interactions of fillMode and the use of a 1D array for inputData.   I'm also unclear what the relationship is between the "session" ADC and the variable TaskHandle.  In LabVIEW, we'd use a 2D array and something like a TaskHandle, but not a separate thingy like your ADC object.

 

All that said, none of those things seem like they should be able to account for 11 seconds.  Are you able to set up debug watches on your variables and execute one line at a time?   Have you double-checked the order of the arguments being passed into your DAQmx Timing and Read calls?

 

 

-Kevin P

 

 

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 6 of 9
(1,375 Views)

Well, as I am not an expert I am not sure on whether the script is an optimal one (sure not).

The time consuming line is the

[status_read, inputData, sampsPerChanRead, reserved] = daq.ni.NIDAQmx.DAQmxReadAnalogF64(TaskHandle, .....)

 

I have no way to understand what is going inside (watches or debug variables)

 

0 Kudos
Message 7 of 9
(1,359 Views)

Kevin,

It seems the call to the DAQmxCfgSampClkTiming function has not been well completed and therefore the sampling frequency rate is set by default to 1 kHz. This explains why I need 10 s for 10 000 samples.

I need to work on the proper way to pass the parameters to the functions

 

Frederic

 

0 Kudos
Message 8 of 9
(1,356 Views)

I have closed this thread since the issue was connected to some wrong configuration parameters given to the DAQms functions.

Now I have corrected the script and the commands are succesfully sent and received by the ADC as mentionned by the "status" parameter. But still I can't get any proper signals from the ADC, only zeros. I will open a new thread related to this point.

Thanks for you help

Regards

Frederic

 

0 Kudos
Message 9 of 9
(1,345 Views)