Skip to main content
AKrup
Associate III
November 14, 2018
Solved

Trim clock from pulse-per-second GPS signal?

  • November 14, 2018
  • 6 replies
  • 2201 views

Using STM32F030 / F042. I have a GPS receiver onboard which produces a very accurate pulse-per-second signal (~40ns). I want to use this timing source to keep the system clock, or at least the RTC accurate. The user may wander in and out of GPS reception, so the pulses may come at odd intervals, but when they come, their rising edges always align with the top of the second.

I should add that I'm using an 8MHz crystal resonator (HSE).

    This topic has been closed for replies.
    Best answer by Tesla DeLorean

    I'm doing something a bit more exotic, but if you wanted to mark 1 second ticks with the HSE/PLL you've previously quantified, you could use the ARR setting for the timer to count off your ~32,000,000 ticks to get the integer portion of the error managed, and then modulate that count +/-1 cycle occasionally to account for the accumulating fractional error/bias. This would give you a 31ns saw-tooth, and the ability to read the CNT value to get the fractional second at that resolution.

    6 replies

    Tesla DeLorean
    Guru
    November 14, 2018

    Lack of 32-bit TIM, and very crude dividers does make it a bit difficult. I used an L4

    Seem to recall the F0 only provides trim for the RTCCLK, you'd need to quantify the HSE and use a combination of HSE/32, the prescalers, and the trim to clock.

    Some GPS can generate a persistent frequency which could clock the STM32 in place of a resonator. And most current ones use a TCXO, so even in hold-over a better bet. Others provide an EVENTIN where you could actually time your HSE via a TIM/MCO pulse, likely much more accurately than the STM32 is capable of.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    AKrup
    AKrupAuthor
    Associate III
    November 14, 2018

    Thank you, Clive. I'd consider moving up to L4 if it supports my use case. How did you do it on an L4?

    Tesla DeLorean
    Tesla DeLoreanBest answer
    Guru
    November 14, 2018

    I'm doing something a bit more exotic, but if you wanted to mark 1 second ticks with the HSE/PLL you've previously quantified, you could use the ARR setting for the timer to count off your ~32,000,000 ticks to get the integer portion of the error managed, and then modulate that count +/-1 cycle occasionally to account for the accumulating fractional error/bias. This would give you a 31ns saw-tooth, and the ability to read the CNT value to get the fractional second at that resolution.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..