Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: DAQ SamplesAvailable never >0 after getdata
Date: Thu, 11 Feb 2010 13:24:02 +0000 (UTC)
Organization: The MathWorks Inc
Lines: 19
Message-ID: <hl10di$eh7$1@fred.mathworks.com>
References: <hks0ii$p3$1@fred.mathworks.com> <hkuaq8$mhm$1@fred.mathworks.com> <hkufls$802$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1265894642 14887 172.30.248.37 (11 Feb 2010 13:24:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 11 Feb 2010 13:24:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 796075
Xref: news.mathworks.com comp.soft-sys.matlab:606425


Hi Dave,
Glad you have it working.
I see two issues with your code.

You should not use both TimerFcn and SamplesAcquiredFcn.
Choose one.

Many programs call getdata() from within a callback and find that they can't keep up when using SamplesAcquiredFcn and SamplesAcquiredFcnCount when data processing time exceeds the data inflow time.
As an alternative they should use TimerFcn and TimerPeriod.
The difference is that SamplesAcquiredFcn callbacks queue up and are never lost while if a TimerFcn callback has not yet executed and another one comes in the previous one is discarded so there is never a backlog. In either case getdata() should get enough data from the engine so that the program does not fall behind. You can check the SamplesAvailable property from within the callback to see how much data is actually available.
As with all these programs it is impossible to give an exact formula on how to set things up. It will depend on the SampleRate and the actual PC and acquisition device in use. 

Also, I would suggest removing the line:
set(ai, 'BufferingConfig',[5000*2,20]);
The Data Acquisition Engine will compute the buffering config values for you and unless you are trying to overcome a specific issue you are better off letting the engine do the calcluation.

Other than that your code looks good.
Happy acquiring!
Sherryl