[time-nuts] Re: Small NTP appliance

Hal Murray hmurray at megapathdsl.net
Sun Apr 25 19:20:44 UTC 2021


folkert at vanheusden.com said:
>> Most modern kernels have a side door used by ntpd to adjust the clock 
>> frequency.  Typical values are few 10s of PPM and it's easy to measure down 
>> 0.001 PPM or better.  The NTP world calls that drift.  If you have a PC or 
>> Raspberry Pi running Linux or *BSD and ntpd you can find the drift.

> Hmmm, I believe Eamonn is going to use a microcontroller. They usually don't
> run linux or something like that. 

You can still use the same trick.  You may have to rewrite the clock code.

If the clock code does something like
  time = time +1
where time is in ms and gets bumped from a 1000Hz interrupt, then you have to 
change that "1" to be the carry out of a slot with enough precision.  If you 
want to correct to 1 PPM, that's 1E6.  So the code becomes:
  calibrate = 1000000;
  partial + partial + calibrate;
  while (partial > 1000000) {
    time += 1;
    partial -= 1000000;
  }

Now fudge calibrate to make your clock run slower or faster.

The trick is that you have to scale things such that your equivalent of 
partial has enough working bits to match the resolution that you want in your 
correction.

A million is 20 bits so you are probably using 32 bit arithmetic.  You might 
as well use a billion.

If you want time in ms and you are getting 1024 interrupts per second, the 
code may already do something like the above.

-- 
These are my opinions.  I hate spam.






More information about the Time-nuts_lists.febo.com mailing list