f



DAQ #3

hi,
how can i start a timer from the daq Toolbox.Theoretically its very
simple:

ai1 = analoginput('winsound',0);
addchannel(ai1, 1:2);
ai1.SampleRate = 11025;
ai1.SamplesPerTrigger=11025;
set(ai1,'TimerFcn',@TimerFcn_Callback)
set(ai1,'TimerPeriod',3.0)

start(ai1);
%%%%%%%%%%%%%
function TimerFcn_Callback
disp('asdasd')

But the function doesn't start loopig!

Thanks
0
7/8/2005 8:56:52 AM
comp.soft-sys.matlab 211266 articles. 14 followers. lunamoonmoon (258) is leader. Post Follow

2 Replies
222 Views

Similar Articles

[PageSpeed] 56

On Fri, 8 Jul 2005 04:56:52 -0400, Cristian M´┐Żller wrote:
> hi,
> how can i start a timer from the daq Toolbox.Theoretically its very
> simple:
> 
> ai1 = analoginput('winsound',0);
> addchannel(ai1, 1:2);
> ai1.SampleRate = 11025;
> ai1.SamplesPerTrigger=11025;
> set(ai1,'TimerFcn',@TimerFcn_Callback)
> set(ai1,'TimerPeriod',3.0)
> 
> start(ai1);
> %%%%%%%%%%%%%
> function TimerFcn_Callback
> disp('asdasd')
> 
> But the function doesn't start loopig!
> 
> Thanks

There are two problems with your code.  The first is that your timer
period is set to 3 seconds, but you are only acquiring 1 second of data.
The TimerFcn only executes while the analog input object is "running".
Since the object only runs for one second your timer function will never
get called.  You need to either decrease your timer period or increase
the time that your object is running.

The second problem is that your TimerFcn_Callback function has the wrong
syntax.  When you specify the TimerFcn property as a function handle
(@TimerFcn_Callback), then the function is passed in two arguments.  The
first is the object that generated the callback and the second is an
event structure that describes what caused the callback to happen.  You
can ignore these if you like, but you need to change the line

   function TimerFcn_Callback

to something like

   function TimerFcn_Callback(obj, event)

Hope this helps.

-Dave Tarkowski
0
dtarkows (334)
7/8/2005 12:33:53 PM
I added:

set(ai1,'TriggerRepeat',inf);
set(ai1,'TriggerType','Immediate')

and i've made the modification and it worked!

Thanks!
0
7/8/2005 1:02:11 PM
Reply: