[time-nuts] GPS for ntp

Tom Van Baak tvb at LeapSecond.com
Tue Oct 21 21:14:53 UTC 2014


>> One solution to the problem is use two independent HW capture inputs. One
>> for a GPS 1PPS and the other for your event.
> 
>> In this case the system clock does not need to be synchronized -- since it
>> is used only to interpolate between the two events. The event timestamp is
>> little more than adding the differential of the two most recent captures,
>> which is a number from 0 to 1 second. 

> You haven't solved the problem yet.  Now you have to synchronize the HW 
> capture counters.

Hi Hal,

Nope, there's no need to synchronize HW counters (against "system time" or UTC or something). That's the beauty of time-stamping or capture counters: they are free-running (at some internal CPU frequency) and share a common clock counter register from which the capture/snapshot is taken.

> You can probably do that with some simple but delicate initialization code.  
> Maybe copy the value from the counter used for the system time?  At the 
> time-nut level, you have to worry about things like cache misses.  (There may 
> be more fine print at that level depending upon the details of the hardware.)

No, again that's the beauty of H/W capture counters. You completely avoid the OS or software rat's nest called system time. Only the capture registers keep perfect "system time" by virtue of their continuous h/w counting, unaffected by software, locks, interrupts, cache, TLB, or microcode latency issues.

> You could also do it by calibrating out the difference: just feed the same 
> pulse into both input pins.  You have to do that each time you (re)start 
> things.  That's easy for a one-off project but adds another ugly step if you 
> want to do it in production.  Collecting long term data moves a hobby project 
> a lot closer to production.

The modern CPU's with capture/compare registers I've seen use a common N-bit timer register as the capture source, so there's no issue with intra-capture synchronization. What is still critical, to align with UTC for example, is inter-clock synchronization. And that's why two h/w capture counters are needed -- one for the event (LAN packet, for example) and one for the GPS/1PPS timestamp.

/tvb




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