Skip to main content
GNSS HAT Library Documentation
Shop GitHub Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Timepulse Interrupt

Synchronize your application to the PPS signal from the GNSS module.

Source: examples/cpp/timepulse-interrupt/, examples/c/timepulse-interrupt/, examples/python/timepulse_interrupt.py

Signal Shape

This example waits for the configured PPS edge on GPIO 5. The waveform below starts with an annotated 1 Hz signal so it is easy to see whether your code is synchronizing to the edge where the pulse starts or the edge where it ends. The remaining rows show how the same wait behaves with faster pulses and with a waveform that changes once the receiver has a fix.

Timepulse waveform examples showing an annotated 1 Hz waveform with polarity-aligned edges, simplified 5 Hz and 10 Hz waveforms with period and pulseWidth labels, and a fourth example that switches from 5 Hz without fix to 10 Hz with fix. Timepulse waveform examples showing an annotated 1 Hz waveform with polarity-aligned edges, simplified 5 Hz and 10 Hz waveforms with period and pulseWidth labels, and a fourth example that switches from 5 Hz without fix to 10 Hz with fix.
Use this mental model when matching your application timing to the configured PPS polarity, pulse settings, and no-fix versus fixed behavior.

Code

hat->enableTimepulse();
while (true)
{
    hat->timepulse();  // blocks until next PPS
    auto nav = hat->navigation();
    printf("PPS: %s\n",
        Utils::utcTimeFromGnss_ISO8601(nav.pvt).c_str());
}
hat->disableTimepulse();
hat.enable_timepulse()
while True:
    hat.timepulse()  # blocks until next PPS
    nav = hat.get_navigation()
    print(f"PPS: {gnsshat.utc_time_iso8601(nav)}")
hat.disable_timepulse()

Running

sudo examples/bin/timepulse-interrupt
sudo build/examples/c/timepulse-interrupt/timepulse-interrupt
python3 examples/python/timepulse_interrupt.py
Note
Do not use this example simultaneously with kernel PPS (/dev/pps0) — both claim GPIO 5.