How to get live analog input to digital output with little delay using Data translation box (dtol)?

3 views (last 30 days)
I am working on reading in live analog signals and using those signals to control a live digital output with as little delay between the analog input to digital output as possible. MATLAB seems to require a buffer size of 128 samples, and the time it takes to process each of those samples and output the results to the digital output is quite large (about .1-.2 seconds). This means I have to use a very low sample rate (about 500Hz) to give the program enough time to process the previous 128 samples before it gets the next set of samples. In total the digital output lags about .2 seconds behind the analog input.
Is there a way to do this more efficiently to decrease my delay? Or can I decrease the buffer size to read in and process each sample individually, thus decreasing my delay?
I am using a data translation DT9804-EC-I BNC box and the data translation legacy interface in MATLAB.
Here is the code: ai = analoginput('dtol');
chans = addchannel(ai,0);
global dataTot
global timeTot
global dio
dataTot=[];
timeTot=[];
set(ai,'SampleRate',800)
set(ai,'SamplesPerTrigger', Inf)
set(ai,'LoggingMode','Disk&Memory')
set(ai,'LogFileName','data.daq')
set(ai,'TimerFcn',@getDat)
set(ai,'TimerPeriod',.001)
set(ai,'BufferingMode','Auto')
start(ai)
dio=digitalio('dtol');
addline(dio,8:15,'out');
function [] = getDat( obj, ~)
if (get(obj,'SamplesAvailable') >= 128)
[newdata, newtime]=getdata(obj,obj.SamplesAvailable)
led(newdata,newtime);
end
end
led is a function that decides which LEDs to turn on based on the value of newdata (the analog input data).
Any help would be appreciated!

Answers (0)

Categories

Find more on Analog Input and Output in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!