필터 지우기
필터 지우기

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

조회 수: 3 (최근 30일)
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
Helen
Helen 2014년 8월 4일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Multichannel Audio Input and Output에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by