Dynamic Signal Acquisition

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmx analog acquisition with MATLAB Data acquisition toolbox is extremely slow?

Hello,

 

I would like to acquire data from an analog input of a NI DAQ PCI-6221 with the MATLAB Data acquisition toolbox. I got one voltage of which I would like to take a repeated triggerend measurement, however, this turns out to be rather slow. The code I use is:

 

 

s=daq.createSession('ni');
s.Rate = 25e3;
s.DurationInSeconds = 0.001;
chAI1=addAnalogInputChannel(s,'Dev1','ai1','Voltage');
chAI1.TerminalConfig='Differential';
addTriggerConnection(s, 'External', 'Dev1/PFI12',  'StartTrigger');
s.Connections(1).TriggerCondition = 'FallingEdge';
s.addlistener('DataAvailable', @Data2Buffer);
s.TriggersPerRun = 10;
%%
global Buffer
Buffer = [];
prepare(s);
startBackground(s); 
for idx = 1:10
    % CODE THAT TRIGGERS ACQUISTION
end
s.stop;

 

 

using the Data2Buffer function
function Data2Buffer(src,event)
    global Buffer
    Buffer = [Buffer; event.Data];
end
Although the measurement time is 1ms I can only go up to a trigger frequency of around 7Hz before I start to lose data. If I do the same thing addressing the DAQ in C I can go up to 200Hz. Anybody know what I am doing wrong here?
0 Kudos
Message 1 of 6
(4,670 Views)

Are you trying to capture each trigger, or are you trying to trigger successive blocks such that your are acquiring a continuous stream of data?

 

In either case, I might suggest that you acquire continuous data and perform trigger detection on the stream of data. You can be sure to process all data rather than trying to make sure that you have restarted a finite, triggered acquisition repeatedly fast enough not to miss any triggers.

Doug
NI Sound and Vibration
0 Kudos
Message 2 of 6
(4,625 Views)

Here I was trying to capture each trigger and obtain the recorded data individually. Triggering consecutive acquisitions where the data is stored in the buffer of the DAQ and is then read out all at once does not seem to be possible with Matlab's Data Acquisition Toolbox.

 

For the continuous acquisition, you propose to measure both the analog input and trigger channel for a continuous time frame containing many trigger events, then read out the entire data and do post processing to select the data-of-interest? This would be a viable workaround but my problem is that I need to get the data continuously to feed it to another device. Its part of a control/optimization loop.

0 Kudos
Message 3 of 6
(4,619 Views)

Can the application acquire continuously (analog and trigger channels) and process in chunks?

 

You mentioned that C application could retrigger acquisition to make sure that events occurring at 200 Hz could be processed losslessly. What is the maximum rate at which the triggers could occur?

Doug
NI Sound and Vibration
0 Kudos
Message 4 of 6
(4,603 Views)

What is the maximum rate at which the triggers could occur?


As in: what is the maximum rate of triggers in the real system? Is 200 Hz fast enough to guarantee that all triggers are captured and processed, or does the application need to go even faster?

Doug
NI Sound and Vibration
0 Kudos
Message 5 of 6
(4,575 Views)

The maximum trigger rate is 'only' 75-100Hz, limited by another device.

 

In the application, the data of four trigger events could be acquired and read out together. Acquiring bigger chunks of data before readout would limit the flexibility of the application.

 

Another problem is that the trigger pulse is sub-microsecond long. This means even when acquiring at a sampling rate of 250 kS/s, which is the maximum rate for the DAQ used, some triggers would be missed when recording the trigger channel to find the events in post processing (This could be solved by some additional electronics to prolong the trigger pulse but would be annoying since the DAQ can in principle be triggered by these short pulses).

0 Kudos
Message 6 of 6
(4,565 Views)