10-27-2021 11:55 AM
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)
Solved! Go to Solution.
10-27-2021 12:03 PM
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
10-27-2021 04:15 PM
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)
10-27-2021 04:16 PM
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?
10-27-2021 04:24 PM
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)
10-27-2021 05:47 PM
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
10-28-2021 01:14 AM
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)
10-28-2021 04:24 AM
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
10-28-2021 11:29 AM
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