Effacer les filtres
Effacer les filtres

NI-DAQ issue: addlistener is triggering before signal. Also, do I need to start a new session to output data after trigger?

3 vues (au cours des 30 derniers jours)
I'm using a USB-6259, 64 bit Matlab and my code is included below. I want to monitor one input channel, and when it drops below a threshold, start acquisition on three other channels, and also output data on one channel. I have two problems.
1. Although I'm pretty sure it worked at first, now the addlistener is behaving as though the threshold has been crossed as soon as it starts to listen. So, when I start the code, it triggers the output signal, even though I can see (via an oscilloscope) that the threshold has not been crossed. Can anyone help with why this happens? The trigger is a falling signal - are there spurious zeros getting in at the start?
2. How do I queue data to be sent once that threshold has been crossed? I can see that I could use the addlistener to close that session, and then open a second session with the inputs and outputs that I want. But there's a 0.7 second delay if I do that, which I don't want. Is there a way of doing that within a single session?
Thanks!
> devices = daq.getDevices; % Laser photodiode must be plugged into channel ai0. s = daq.createSession('ni'); s.addAnalogInputChannel('Dev1', 0, 'Voltage'); % Laser photodiode DAQ_rate = 50000; % this is the number of samples per second s.Rate = DAQ_rate;
lh = s.addlistener('DataAvailable',@StopWhenExceedTriggerLevel); s.NotifyWhenDataAvailableExceeds = DAQ_rate./20; % Listener called when number of points exceeds this value
s.startBackground; % Start monitoring laser
delete(lh) s.stop
devices = daq.getDevices; % start a new data acquisition session
s = daq.createSession('ni'); s.addAnalogInputChannel('Dev1', 0, 'Voltage'); % Laser photodiode s.addAnalogInputChannel('Dev1', 1, 'Voltage'); % Hydrophone s.addAnalogInputChannel('Dev1', 2, 'Voltage'); % Flash photodiode
DAQ_rate = 50000; % this is the number of samples per second s.Rate = DAQ_rate; s.addAnalogOutputChannel('Dev1',0,'Voltage'); % This will only stop the first acquisition when the trigger level has % been crossed. Then run the proper data acquistion
DELAY_TO_FLASH = 0.001; % in seconds (not sure about minimum.... 0.0001?)
outputSignal = 10*[ zeros(1,DELAY_TO_FLASH*DAQ_rate) ones(1,1000) zeros(1,50) ]; % flash should trigger as it goes from 1 to 0
s.queueOutputData([outputSignal]');
[data, time] = s.startForeground;
>
function StopWhenExceedTriggerLevel(src,event)
%plot(event.TimeStamps,event.Data)
if any(event.Data < 0.05) % Currently, the trigger level is 0.03, on a falling edge
src.stop()
end
  1 commentaire
Helen
Helen le 4 Août 2014
I think I've solved the first problem by adding this line:
s.IsContinuous = true;
But the output issue is still a problem. Can I queue data to output while it's still listening? I'd be happy to delete the listener once it's time for the output.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Multichannel Audio Input and Output dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by