Electronic – Count cycles from oscillator clock to get time

clockcountergpsmicrocontrollertimer

first time on stackexchange, hope I'm in the right place. I am working on a project where I need to timestamp an event (which will be detected from an electrical pulse) down to a few tens of nanoseconds and synchronized with GPS (because there will be a couple of those modules that need to be synced together). I looked for a simple arduino/raspberry solution but it seems it won't do better than 1-2 us, far from ~30 ns.

I was thinking of using the 1PPS output (1Hz) of the GPS to get a very accurate time and then find the time interval between this pulse and the sensor's pulse by counting cycles of an external, high precision clock. I have found a clock which will get me under 30ns innacuracy over the 1s PPS(40MHz, 10ppb, 1ps jitter).

Now, the problem is how do I go about counting these clock cycles? My experience on the subject is very close to 0 and so is my teammate's. Any help is very much appreciated.

EDIT: It seems this is very complicated for someone who's only experience with microcontroller is sending data through serial. The perfect product for my application would be something like this: http://www.ti.com/product/TDC7201/description Just connect the two pulses to START and STOP pins and it returns the time interval. The only difference is I would need a 1s measurement (vs 8ms) but with 10-50ns precision (vs 50ps). Basically 1000x longer measurement with 1000x less precision.

Best Answer

Counting cycles between PPS pulses is not a good approach. Even using clocks with 10ppb stability, you still need to evaluate the skew between different units.

Using an integrated GPS Receiver with timestamping is a good approach. Note however that it will not be easy to get these 30ns RMS accuracy in real life conditions. 30ns translate to only 9m position accuracy. While most receivers reach this easily for kalman filtered position, you will see more disturbance to your timestamps (where the receiver cannot employ a hidden markov model) unless you also average over multiple events.

Multipath reception is your main adversary (for units some tens of km apart and events within fractions of a second). Multipath will be mitigated somehow by the receiver, but the best thing you can do is use a good antenna (choke ring or similar) and choose a good place. Putting it on a tripod can also help.

Group delay calibration will typically not be needed for 30ns if all your modules use a similar Setup (antenna cable length matters, also amplifiers or similar).

Far better accuracy can be reached if you are able to measure the event in band with the GPS Signals, that means trough the RF frontend of the reveiver. This will relate the timing directly to the received signals and offers the opportunity to cancel off several error sources. If you do not need the result in near real time, you may record GPS signals together with your trigger and postprocess them. This will give high accurary of relative position and time (differential GPS).