[time-nuts] Clock Correction Algorithm

Attila Kinali attila at kinali.ch
Thu Nov 24 09:42:01 EST 2011


On Thu, 24 Nov 2011 14:21:37 +0000
Miguel Gonçalves <mail at miguelgoncalves.com> wrote:


> I am using an Arduino Uno that presumably is running at 16 MHz. 
> 
> I am using a 16 bit timer with a 256 pre-scaler:
> 
> 16000000 / 256 = 62500 Hz
> 
> 1 / 62500 = 16 us
> 
> 65536 - 62500 = 3036
> 
> I am setting the counter to 3036 and let it overflow after 65535.

I'm not quite sure i understood you correctly, and i dont know anything
about the arduino and the avr32. But usually, you set a timer to do a
certain repetition rate. Ie raises an interrupt ever x clock cycles.
Or to put it differently, you let the timer run freely, but let it call
you when it's time to do something.

How do you check for the overflow? If you check a flag in your main loop,
this would explain the "huge" difference, as this polling will add a
(not so) constant delay each time the timer overflows, until you start
your timer again.
 
			Attila Kinali

-- 
The trouble with you, Shev, is you don't say anything until you've saved
up a whole truckload of damned heavy brick arguments and then you dump
them all out and never look at the bleeding body mangled beneath the heap
		-- Tirin, The Dispossessed, U. Le Guin




More information about the time-nuts mailing list