|
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;
|