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

5 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Chirag Gupta
Chirag Gupta il 21 Dic 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 Commento
Paul
Paul il 21 Dic 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!

Accedi per commentare.

Più risposte (1)

Walter Roberson
Walter Roberson il 20 Dic 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 Commenti

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by