How can I output an analog signal while acquiring background data?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Analog Data Acquisition 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!