Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Real Time Data Acquisition - Why doesn't it stop?

Subject: Real Time Data Acquisition - Why doesn't it stop?

From: Seth

Date: 24 Jul, 2007 20:58:06

Message: 1 of 3

The script below is based on the SLM program written by Douglas R. Lanman and posted to the file exchange. I have consolidated it in an effort to figure out why the data acquisition doesn't stop, even though TriggerRepeat is set to 1 and peekdata doesn't remove samples from the buffer.

This works quite nicely, but I don't know why. It seems to me that when peekdata has read the second set of samples from the single trigger repeat that it would stop, yet it doesn't. It requires manual triggering to work, does this have something to do with why it works?

Cheers,
Seth
+------------------------------------+

function aidata
% House Keeping
clear all
close all
clc

%Remove Running Daqs
daqs = daqfind;
for i = 1:length(daqs)
    stop(daqs(i));
    delete(daqs(i));
end

% create analog input object
ai = analoginput('winsound');
chan = addchannel(ai,1);

% without these next two options it will only give one triggerings worth of data
set(ai,'TriggerType','Manual');
set(ai,'TriggerRepeat',1);

set(ai,'TimerPeriod',.25); % shorter may return warnings

% start acquisition
start(ai); trigger(ai);

% get the initial data
x = getdata(ai);

% plot the initial data
figure(1)
h = plot(x);

set(ai,'TimerFcn',{@update,h}); % pass the handle for the line to the update function

function update(obj,event,h);

% get the last data extracted
x = peekdata(obj,obj.SamplesPerTrigger);

% plot the data
set(h,'YData',x);

% To stop the process cut and paste the "
%Remove Running Daqs" code into the command window

Subject: Real Time Data Acquisition - Why doesn't it stop?

From: Seth

Date: 25 Jul, 2007 17:24:55

Message: 2 of 3

For those of you interested in the answer to my question, Daniel Lee has a good explanation in his "3D Waterfall Plot Demo" loaded on the file exchange. It follows this message.

Daniel, thanks for annotating your code so well!

Cheers,
Seth

% Configure the analog input object to trigger manually twice.
% We do this because we are using peekdata to acquire the data in
% a timer callback function.
% The first trigger will fill the buffer with handles.samplesPerTrigger
% number of samples. We'll know we have enough samples to start
% processing data when the analog input object's SamplesAvailable property
% is equal to handles.samplesPerTrigger.
% The analog input object will then wait for
% another manual trigger, and while it is waiting the object will still be
% in its running state, which means the timer event will run. To keep the
% object in the running state, we need only never manually trigger this
% second trigger.
% Had we set the TriggerRepeat to 0, the analog input object would stop
% after the first trigger and the timer functions would stop running.

Subject: Real Time Data Acquisition - Why doesn't it stop?

From: Ricardo

Date: 9 Jul, 2010 15:54:04

Message: 3 of 3

> % Configure the analog input object to trigger manually twice.
> % We do this because we are using peekdata to acquire the data in
> % a timer callback function.
> % The first trigger will fill the buffer with handles.samplesPerTrigger
> % number of samples. We'll know we have enough samples to start
> % processing data when the analog input object's SamplesAvailable property
> % is equal to handles.samplesPerTrigger.
> % The analog input object will then wait for
> % another manual trigger, and while it is waiting the object will still be
> % in its running state, which means the timer event will run. To keep the
> % object in the running state, we need only never manually trigger this
> % second trigger.
> % Had we set the TriggerRepeat to 0, the analog input object would stop
> % after the first trigger and the timer functions would stop running.

Hello,

I am using some of the code in daqwaterfall.m written dy Daniel and I want to create a start and stop button instead of the exit button. The start button works fine but the stop button doesn't stop the analog input. My stop callback is simply stop(ai) and delete(ai). I think it has to do with that second manual trigger but I am not shure how to stop the acquisition. In other words, my application would be the same as the demoai_fft but adding the waterfall plot to it. I want my start and stop buttons to wrk the same way it works in demoai_fft.

Thank you.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us