"If" statements for NI daq functions!? Help?

Hi all,
I am trying to get matlab to output some signals via my NI card, but I would like to turn on and off the signal via a timer using "if" statements.
For example,
experimentStartTime = tic;
niSession = daq.createSession('ni');
niSession.addAnalogOutputChannel('dev1','ao0','voltage');
niSession.queueOutputData([stimulus']);
stimStartTime = toc;
if toc-stimStartTime < 5
niSession.startBackground();
elseif toc-stimStartTime > 5
niSession.stop()
end
However, MATLAB doesnt seem to run through the if loops and stop the analog Output. Any help would be great. Thanks!

 Respuesta aceptada

Image Analyst
Image Analyst el 14 de Feb. de 2013

0 votos

You need to make experimentStartTime a "persistent" variable so it will retain its value each time you enter this timer callback. Right now you're resetting it with tic each time and so "toc-stimStartTime" never gets very big.

Más respuestas (0)

Categorías

Más información sobre Data Acquisition Toolbox Supported Hardware en Centro de ayuda y File Exchange.

Preguntada:

el 13 de Feb. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by