Hi If you are doing this on a micro, handling the network stack is *probably* not something you will do from scratch. Often bringing in a network stack brings in an RTOS with it. You may well get some fancy time code “for free” with the RTOS.
Once upon a time this RTOS / network stack stuff cost you money. That’s becoming less and less true as time marches on. Free makes it a *lot* easier to drop into a project :) Bob > On Apr 25, 2021, at 3:20 PM, Hal Murray <[email protected]> wrote: > > > [email protected] 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. > > > _______________________________________________ > time-nuts mailing list -- [email protected] -- To unsubscribe send an > email to [email protected] > To unsubscribe, go to and follow the instructions there. _______________________________________________ time-nuts mailing list -- [email protected] -- To unsubscribe send an email to [email protected] To unsubscribe, go to and follow the instructions there.
