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

11 views (last 30 days)
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

Accepted Answer

Chirag Gupta
Chirag Gupta on 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 Comment
Paul
Paul on 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!

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 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 Comments

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!