- Would it make sense to log the data and count it later?
- pre-calculate the zeros() and store them in a variable instead of having the zeros() inside the loop
- You appear to have only one input channel. In that case,
Asychronous Data Acquistion with the data acquisition toolbox and NI PCI-e 6320
조회 수: 3 (최근 30일)
이전 댓글 표시
I'd like to run an Asychronous background acquistion via the data acquistion toolbox session based interface using a NI PCI-e 6320.
I have a usb device which I command via matlab. I want to sychronise this device's actions like so:
- activate the device
- wait a user defined period (20 - 100 ms)
- software trigger a background acquistion (5ms - 1s)
- run matlab function attached to a listener which again activates the usb device
- repeat
I cannot find a way to do this efficiently. I currently have two work-arounds, both with their disadvantages:
- ForeGround Acq. This is great in that i can be sure the usb device has finished it's task before acquiring more data. The problem is the lag time! The code i have goes something like:
%%Prepare DAQ for foreground sessions
acquisition = daq.createSession('ni');
acquisition.addCounterInputChannel('Dev1','ctr0','EdgeCount');
acquisition.addAnalogOutputChannel('Dev1', 'ao0', 'Voltage');
acquisition.Rate = sampling;
outPattern = zeros(1e5,1);
for iAcq = 1:nAcq
acquisition.queueOutputData(outPattern);
acqData = acquisition.startForeground();
photonCounts = diff(acqData);
% Here i put an arbitrary function to process
% 'photonCounts' which is rapid (< 10ms) and this computes the
% next command for the usb device
end
but the time for each iteration in the for loop is ~400ms longer than the acquisition itself. This wait time is SOLELY induced by the function to load the buffer and start the acquisition, not what i do with the data after. So when my acquistion is 10 ms i have a massive wait time for the next set of data
- *Continuous background acquistion*i don't have the time to put the code in for this method, in short:
- start a continuous background acq
- in the listener function for the available data; activate the usb device and start a timer (tic)
- in subsequent calls to the listener function I if the timer values is too short i throw away the data.
In this case i have very little synchronisation. I don't know if the data available arrived immediately or if it was sitting on a buffer. The timer has to be much longer to account for this and the fact that the usb device is activated at an unknown time during the susbsequent acquistion.
I'd prefer a solution with a software trigger. If not, is there a solution with a hardware trigger?
many thanks
Joe
댓글 수: 0
답변 (1개)
Walter Roberson
2016년 5월 26일
mean(diff(acqData))
is going to be identical to
(acqData(end) - acqData(1)) / (length(acqData) - 1)
If your length() is going to be constant then to optimize you could just save the difference in the counter and do the division later.
참고 항목
카테고리
Help Center 및 File Exchange에서 Signal Integrity Kits for Industry Standards에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!