Thread Subject: pause (n) accuracy of 1 ms

Subject: pause (n) accuracy of 1 ms

From: Martino Bacile di Castiglione

Date: 6 Dec, 2004 12:07:22

Message: 1 of 4

I would need something like the pause(n) Matlab function but with an
accuracy of 1ms and not the current ~10ms accuracy.
Any ideas would be *very* much appreciated!

Subject: pause (n) accuracy of 1 ms

From: Daniel Ennis

Date: 6 Dec, 2004 15:33:49

Message: 2 of 4

What about using "clock" ? The last entry in the vector contains
data in the 100's of nanoseconds. I don't know how accurate that
really is though.

You could write a function that polled the current clock time and
then waited until the clock met or exceeded a certain duration.

Martino Bacile di Castiglione wrote:
>
>
> I would need something like the pause(n) Matlab function but with
> an
> accuracy of 1ms and not the current ~10ms accuracy.
> Any ideas would be *very* much appreciated!

Subject: pause (n) accuracy of 1 ms

From: Daniel Ennis

Date: 6 Dec, 2004 16:50:39

Message: 3 of 4

This was interesting so I gave it a shot. In some quick testing I
don't know if you'll be able to get the accuracy you need from this
approach, but I thought the code might be useful. I can get
approxiamately 1ms±3.5ms accuracy on my machine.

% This function is a modified pause function that provides more
accruate
% time delays than PAUSE.
%
% SYNTAX: pauser(delay[,t0,sys_delay]);
%
% DELAY - a time duration in seconds.
% t0 - the cpu clocktime from which the delay should be
counted.
% sys_delay - a measured systematic delay that is used to obtain more
accurate pause durations
%
% DBE 12/06/04

function pauser(delay,t0,sys_delay)
if nargin==1
  t0=clock;
  sys_delay=0;
elseif nargin==2
  sys_delay=0;
end

while etime(clock,t0)+sys_delay<delay
  % Do nothing...
end

return

% Use this script to calibrate system delays???
% Set delay=0 OR set delay=desired_delay and compare the result to
the
% desired_delay
N=1000;
delay=0.1;
t=zeros(1,N);

for k=1:N
  tic; pauser(delay,clock); t(k)=toc;
end

sys_delay=mean(t)-delay;

Subject: pause (n) accuracy of 1 ms

From: AJ \"no z\" Johnson

Date: 7 Dec, 2004 06:19:55

Message: 4 of 4

"Martino Bacile di Castiglione" <mb253@NORUBBISH.kent.ac.uk> wrote in
message news:eef529b.-1@webx.raydaftYaTP...
> I would need something like the pause(n) Matlab function but with an
> accuracy of 1ms and not the current ~10ms accuracy.
> Any ideas would be *very* much appreciated!

You might take a look at the TIMER function/object.
-Aj

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

Contact us at files@mathworks.com