Measuring HFCLK using LFCLK

Our design has an nRF5340 with a 32 MHz high frequency crystal and an accurate 32 kHz external rail to rail clock chip (+/- 5 ppm @ 25 C).  We would like to measure the actual frequency of the HFXO frequency using the 32 kHz clock.  I'm using the following procedure to do this:

1) Configure the low frequency clock source to be the external clock and setup to always run.

2) Configure the high frequency clock source to be the external crystal and setup to always run.

3) Setup an RTC with no prescaler.

4) Setup an RTC compare register so that it triggers a DPPI channel trigger that generates a TIMER start task.

5) Setup an RTC compare register for 32768 counts alter so that it triggers a DPPI channel trigger that generates a TIMER stop task.

6) The second compare generates an interrupt where the TIMER count is read.

This procedure seems to work.  A value of close to 16,000,000 is captured each time this is run.  The documentation says the RTC "COMPARE to COMPARE ± 62.5 ns".  So I would expect multiple runs close in time to vary by only a small amount.

However, running this procedure 10 times generates values that vary by more than I would expect.  For example, from 16,001,396 to 15,999,801.  That is a difference of about 100 ppm.  This seems quite large especially since the HFXO should be +/- 30 ppm max and the RTC specification is +/-5 ppm.

Does the above procedure look correct?  Should this be repeatable to within a few counter ticks?

Parents
  • Hi Denis,

    I do not see a fundamental problem with your approacah, as it is using digital logic and counters, which does not introduce any uncertainty. However, as the LFCLK and HFCLK are independent you have a clock crossing when you trigger PPI via the RTC. But the (average) effect of this is reduceed by increasing the time you count timer ticks, increasing the time you test could be an idea. Other than that, any additional variation should come from variations in the two oscillators.

    Out curiosity, may I ask why you are doing this?

  • We want to synchronize as much as possible the two clock domains.  The LFCLK is used for the RTC.  The HFCLK is used to generate clocks for sensors.  The goal is to align those two so that they don't drift apart over the long term.

Reply Children
No Data
Related