How can I output an analog signal while acquiring background data?

3 ビュー (過去 30 日間)
Chris Carlson
Chris Carlson 2017 年 7 月 25 日
I am trying to acquire data while also sending an output signal to a external circuit using the DAQ toolbox. How can I do this? Ideally the output signal would be immediately sent out as soon as a certain condition is met in the data.
Below is my code:
s = daq.createSession('ni');
% 2 inputs and one output
addAnalogInputChannel(s,'Dev1', 'ai1', 'Voltage');
addAnalogInputChannel(s,'Dev1', 'ai2', 'Voltage');
addAnalogOutputChannel(s,'Dev1', 'ao0','Voltage');
s.Rate = 83000;
% event listener
lh = addlistener(s,'DataAvailable', @(src,event) perturb(event.TimeStamps, event.Data));
% max size in data buffer
s.NotifyWhenDataAvailableExceeds = 2000;
s.startBackground();
%% function that is called by event listener
function perturb(curTime , data)
plot(curTime, data(:,1), curTime, data(:,2));
%if some condition in the data is met, output analog signal
if (data(1300,2) < 0)
% immediately output signal here:
% my attempt:
%outputSingleValue1 = 1.5;
%outputSignal1 = [zeros(1,520) outputSingleValue1*[0:0.1:1 1:-0.1:0] zeros(1,4000)];
%queueOutputData(s,outputSignal1');
end
end

回答 (0 件)

カテゴリ

Help Center および File ExchangeAnalog Data Acquisition についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by