This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF52832 accuracy of clocks for timer synchronization

Hello,

Our design uses Laird's BL652, which uses nRF52832. I need to calculate the maximum clock drift of timers given the crystals used in our design. Our application uses a simplified version of your wireless timer synchronization blog to synchronize timers of two peripherals. I need to determine, based on clock drift, the sync period necessary to keep clocks within 1 ms of each other.

Our design uses this crystal for the low frequency clock and the BL652 data sheet specifies:

5.2.1 Clocks 

The integrated high accuracy 32 MHz (±10 ppm) crystal oscillator helps with radio operation and reducing power consumption in the active modes. 

I understand that the timers of nRF52832 run on the high-frequency clock source. Does this mean that nRF52832 timers have maximum drift of ±10 ppm? Given I am synchronizing timers of two different nRF52832s, maximum drift between the two would be ±20 ppm?

At ±20 ppm, I calculate 1 ms drift between timers of two peripherals occurs in minimum 50 seconds (1.728 seconds drift per day, 72 milliseconds drift per hour, 1 millisecond drift in 50 seconds). Currently I re-sync the timers every 30 seconds. Am I correct?

main() has this code:

err_code = sd_power_mode_set(NRF_POWER_MODE_CONSTLAT);
APP_ERROR_CHECK(err_code);

// start the high frequency clock
uint32_t is_running;
sd_clock_hfclk_request();
do {
  sd_clock_hfclk_is_running(&is_running);
} while (is_running==0);

Related question: Our low frequency external crystal is ±5 ppm. Should I change NRF_SDH_CLOCK_LF_ACCURACY in sdk_config.h from:

// <o> NRF_SDH_CLOCK_LF_ACCURACY - External clock accuracy used in the LL to compute timing.

// <0=> NRF_CLOCK_LF_ACCURACY_250_PPM
// <1=> NRF_CLOCK_LF_ACCURACY_500_PPM
// <2=> NRF_CLOCK_LF_ACCURACY_150_PPM
// <3=> NRF_CLOCK_LF_ACCURACY_100_PPM
// <4=> NRF_CLOCK_LF_ACCURACY_75_PPM
// <5=> NRF_CLOCK_LF_ACCURACY_50_PPM
// <6=> NRF_CLOCK_LF_ACCURACY_30_PPM
// <7=> NRF_CLOCK_LF_ACCURACY_20_PPM
// <8=> NRF_CLOCK_LF_ACCURACY_10_PPM
// <9=> NRF_CLOCK_LF_ACCURACY_5_PPM
// <10=> NRF_CLOCK_LF_ACCURACY_2_PPM
// <11=> NRF_CLOCK_LF_ACCURACY_1_PPM

#ifndef NRF_SDH_CLOCK_LF_ACCURACY
#define NRF_SDH_CLOCK_LF_ACCURACY 7

to:

#ifndef NRF_SDH_CLOCK_LF_ACCURACY
#define NRF_SDH_CLOCK_LF_ACCURACY 9

Many thanks,

Tim

  • Short answer: Looks good

    Long answer:

    LFXTAL: Your LFXTAL has an accuracy of 5ppm, so you should set the NRF_SDH_CLOCK_LF_ACCURACY to 9, yes. Mace sure that the NRF_SDH_CLOCK_LF_SRC is set to 1 (XTAL), which it should be by default in most (all?) of the examples. Please make sure that the capacitors that are connected to your LFXTAL have the correct value. Please refer to the reference layout.

    Please note that the X2 LFXTAL in this layout has Cl = 9 pF, while yours have 12.5 pF, according to the datasheet. The value of the capacitors C11 and C12 is:

    C = 2*Cl - Cpin - Cpcb

    in your case, Cl is 12.5 pF, Cpin is 4 pF (nRF52832 datasheet), and Cpcb is usually negligable, so:

    C = (2*12.5 - 4) pF = 21 pF. 

    If I recall correctly, you don't get capacitors with value 21 pF, but 20 and 22 are available. If you go with 20 pF, you allow for some capacitance in the Cpcb as well, but I believe you will not experience any issues with 22 pF either. 

    HFXTAL: Your main() snippet looks good. As long as you request the HF clock properly, like this, it will not be stopped e.g. when the softdevice is done using the HFCLK, so it should be running all the time, maintaining the accuracy. Also, your calculations look correct. 1ms/50 seconds if you account for 20ppm, which is the maximum possible, given that one would be 10ppm off in one direction, and the other in the other direction. 

    The challenge here is actually synchronizing the clocks, which is not trivial, but perhaps you have already found a way for this?

    Best regards,

    Edvin

  • Thanks Edvin.

    I've changed NRF_SDH_CLOCK_LF_ACCURACY to 9 (±5 ppm).

    Yes, both C11 and C12 are 20 pF.

    Thanks for confirming other things.

    To synchronize timers of multiple peripherals, I use a simplified version of this Nordic blog post.

    Thank you Edvin.

    Tim

Related