[time-nuts] Clock Correction Algorithm
jherrero at hvsistemas.es
Thu Nov 24 15:15:26 UTC 2011
El 24/11/2011 15:21, Miguel Gonçalves escribió:
> 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.
> If I check the error every second I see the clock getting behind correct time and after 60 seconds it's 25 ms apart from UTC.
> Perhaps I should increase the initial value from 3036 to 3036+25E6/(60/16). I will make the second shorter this way.
Can you check the real frequency of the oscillator? If it is too far
from 16MHz, there are two options: trim the capacitors that are in the
crystal oscillator circuit (I'm not familiarized with the Arduino... but
I suppose they will be there), or... software trim changing the counter
reload value as you suggest :)
Does the counter needs reloading every overflow or it is automatically
reloaded? depending on how you are done this, it can also provide some
delays that apparently slows the clock.
More information about the time-nuts