startBackground (data acquisition toolbox) blocks Matlab for 300-400 ms
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I'm using startBackground to send a sine wave through one of four output channels. startBackground blocks matlab for about 300-400 ms, but I need to execute the next command directly (max 10 ms delay, preferably less) after the output has been send.
The behavior seems independent of the size of the queued data and the number of output channels. The delay is not constant, but varies around 100 ms across repetitions.
Below is a reproducable example.
Thanks.
%set parameters
stimParams.NIdaqRate = 1000;
stimParams.NIdaqName = 'cDAQ1mod1';
stimParams.noOutputChannels = 4;
stimParams.signalFrequency = 40; %in Hz
stimParams.signalDuration = .05; %in seconds
stimParams.samplesPerPulse = stimParams.signalDuration * stimParams.NIdaqRate;
stimParams.pulse = 1 + sin(linspace(0, ...
(2*pi*stimParams.signalFrequency/stimParams.NIdaqRate * stimParams.samplesPerPulse), ...
stimParams.samplesPerPulse)');
% Initialize session and parameters
NiDaqDevice = daq.createSession('ni');
NiDaqDevice.Rate = stimParams.NIdaqRate;
% Add output channels to the session
for ii = 0:(stimParams.noOutputChannels - 1)
%create name for the channel depending on stimulator number
stimName = sprintf('ao%d', ii);
%add channel
addAnalogOutputChannel(NiDaqDevice, stimParams.NIdaqName, stimName, 'Voltage');
end
%% iterate through repetitions %%
for repetition = 1:10
%randomly select a channel
outPutChannelIdx = randi(4);
%reset current output matrix
currentOutput = zeros(stimParams.noOutputChannels, stimParams.samplesPerPulse);
%add pulse at current output channel to output matrix
currentOutput(outPutChannelIdx,1:length(stimParams.pulse)) = stimParams.pulse;
% Queue the data
queueOutputData(NiDaqDevice, currentOutput');
% make very sure the queuing is not the problem
pause(1);
%start timer
tic;
%start background execution
NiDaqDevice.startBackground;
% stop timer
toc
%pause shortly
pause(1 + rand());
end
0 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur National Instruments Frame Grabbers 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!