MATLAB Answers

Triggering with a DAQ board--how do I pull data out of startBackground and tell MATLAB to take a few more samples?

조회 수: 24(최근 30일)
Paul
Paul 20 Dec 2011
Good afternoon,
I'm having some trouble updating some old NI interfacing code (for a PCI-6115) to the new session based interface in 2011b.
Here's the basic idea: I'd like to run my DAQ board like an oscilloscope, so I set it to passively scan, wait until my signal passes some threshold value, and then record a sample for X length of time (or NUMBEROFSAMPLES number of samples).
I've read through http://www.mathworks.com/products/daq/demos.html?file=/products/demos/shipping/daq/demo_compactdaq_background_acquisition.html and that's given me the basic idea of what needs to be done, but I'm still having trouble getting my code to work properly.
Here's my code %Initial routines for creating the daq session and initializing the channels (device = daq.createSession('ni'), etc.) % thresh = 2; % 2V threshhold value
device.NotifyWhenDataAvailableExceeds = NUMBEROFSAMPLES;
lh = device.addlistener('DataAvailable', @(src, event) stopwhenpassthresh(src, event, thresh));
device.IsContinuous = true;
device.startBackground;
function stopwhenpassthresh(src, event, thresh)
if any(event.Data > thresh)
disp('Triggered')
src.stop;
end
end
Some questions that I have: - How do I pull event.Data and event.TimeStamps out from the stopwhenpassthresh function into something I can process? - If it was at all possible, I'd like to be able to tell my code that when we pass the threshhold value, it should take one extra run of data (and then I can lop off the extra data afterwards). It'd also be nice if I could get a bit more control over the pre-trigger data as well.
Thank you for your help, Paul

  댓글 수: 0

로그인 to comment.

채택된 답변

Chirag Gupta
Chirag Gupta 21 Dec 2011
This may be of help! I proposed 3 different methods, chose whats best in your case: http://www.mathworks.com/matlabcentral/answers/6258-thread-subject-nidaq-continuous-and-background-acquisition

  댓글 수: 1

Paul
Paul 21 Dec 2011
As best I can tell, this works! I'm using Walter's approach of a circular array (so I don't overload any memory) so I'm using a global counter as well. It's kind of a kludge (still awaiting input from Mathworks about 2012a's trigger routines) but until things go horribly wrong, I'm happy with it. Thanks!

로그인 to comment.

추가 답변(1개)

Walter Roberson
Walter Roberson 20 Dec 2011
Use the same data sharing techniques as for graphic callbacks; see http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.3F

  댓글 수: 7

표시 이전 댓글 수: 4

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.


Translated by