[ntp:questions] Capturing narrow PPS events

Richard Steedman richard.steedman at gmail.com
Sun Nov 20 19:59:20 UTC 2016

For those who might be interested, I've come up with a modification to the
Linux pps-gpio client which makes it work with GPS receivers which emit very
narrow PPS pulses (e.g. some Trimble receivers which generate pulses of only
10 microseconds width) without the need for pulse-stretching hardware.  The
reason that the current pps-gpio client can miss narrow pulse PPS events is
that it re-samples the GPIO input after an interrupt has been triggered to
determine whether a rising or falling edge triggered the input.  It is only
necessary to do this, however, if the PPS client has been configured to
capture assert and clear events.  (When capture_clear is enabled, the GPIO
interrupt is configured to trigger on both rising and falling edges.)  If
the PPS client has been configured to capture assert events only, the GPIO
interrupt will have been configured to trigger on either rising or falling
edges but not both.  It is therefore unnecessary to re-sample the signal
after an interrupt is triggered to determine what type of edge occurred.

To use my modified client, apply the following patch to
drivers/pps/clients/pps-gpio.c in your kernel source and then rebuild.

@@ -61,7 +61,12 @@
 	info = data;

-	rising_edge = gpio_get_value(info->gpio_pin);
+	/* To enable capture of short pulses, only check the level of the
+	   GPIO pin if interrupt has been enabled for both edges.         */
+	if (info->capture_clear)
+		rising_edge = gpio_get_value(info->gpio_pin);
+	else	rising_edge = !info->assert_falling_edge;
 	if ((rising_edge && !info->assert_falling_edge) ||
 			(!rising_edge && info->assert_falling_edge))
 		pps_event(info->pps, &ts, PPS_CAPTUREASSERT, NULL);

More information about the questions mailing list