1 PPS pulse from Sytem Time

I am trying to get GPS time within a tiny fraction of a second of NTP time. the problem with GPS timing is seen in the attached photo:

the yellow trace is the GPS 1 PPS timing pulse. it occurs within 20 ns of the start of a second, depending on which source you believe.

the blue trace below is GPS serial data pertinent to the trace above. Not "at the tone, the time will be", but "at the leading edge of the pulse the time was"

I'm trying to get the clock to sync to GPS, within a small fraction of a second, to use the Arduino as an NTP server that is not dependent on an internet connection. I am doing this by setting the RTC to GPS time, and adjusting Seconds+1, with the leading edge of that pulse. then the clock runs off the RTC until the next RTC sync

I have it honed down to where I can't see a difference by holding the tablet running www.time.gov up next to the display. I can see I'm close, but I'm not sure I'm there

what I need is a way to trigger a pulse on a digital pin when the seconds changes, so I can compare that with the GPS 1 PPS, and determine how much time I lag. I don't need precise time, I need to know what the difference is, and the variation in the difference.

the plan is to start counting milliseconds at GPS 1 PPS, stop counting at System Time 1 PPS, and measure that duration

does anyone know of a way to start a pulse at the moment Seconds rolls over? a software driven interrupt? a library with this function?

the program is 27.5 K and requires a lot of hardware, so I see no reason to post the whole thing
w8bh gps timing photo.png

w8bh gps timing photo.png

You can post images inline:
w8bh gps timing photo.png

I did this. You don't have to mess with pins. Just take a snapshot of the millis() or micros() counter whenever you need to register an event - incoming GPS PPS and/or RTC PPS. If you set the RTC from the GPS PPS, you can be confident that the RTC PPS will lag by only the time it took to set it (until it drifts, of course). Once you know that interval you can also compensate for it and get even closer.

I've made other sketches that compare the CPU clock or RTC time to incoming GPS PPS, using millis() as I said, and those experiments gave me all the drift and sync data I needed. It's really not complicated.

Using micros() you can get an even closer measurement.