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

What low-frequency clock sources can I use?

When initializing the S110 softdevice, I can choose between the different clock sources as defined by the nrf_clock_lfclksrc_t enum:

/**@brief Possible lfclk oscillator sources. */
enum NRF_CLOCK_LFCLKSRCS
{
  NRF_CLOCK_LFCLKSRC_SYNTH_250_PPM,                       /**< LFCLK Synthesized from HFCLK.                    */
  NRF_CLOCK_LFCLKSRC_XTAL_500_PPM,                        /**< LFCLK crystal oscillator 500 PPM accuracy.       */
  NRF_CLOCK_LFCLKSRC_XTAL_250_PPM,                        /**< LFCLK crystal oscillator 250 PPM accuracy.       */
  NRF_CLOCK_LFCLKSRC_XTAL_150_PPM,                        /**< LFCLK crystal oscillator 150 PPM accuracy.       */
  NRF_CLOCK_LFCLKSRC_XTAL_100_PPM,                        /**< LFCLK crystal oscillator 100 PPM accuracy.       */
  NRF_CLOCK_LFCLKSRC_XTAL_75_PPM,                         /**< LFCLK crystal oscillator 75 PPM accuracy.        */
  NRF_CLOCK_LFCLKSRC_XTAL_50_PPM,                         /**< LFCLK crystal oscillator 50 PPM accuracy.        */
  NRF_CLOCK_LFCLKSRC_XTAL_30_PPM,                         /**< LFCLK crystal oscillator 30 PPM accuracy.        */
  NRF_CLOCK_LFCLKSRC_XTAL_20_PPM,                         /**< LFCLK crystal oscillator 20 PPM accuracy.        */
  NRF_CLOCK_LFCLKSRC_RC_250_PPM_250MS_CALIBRATION,        /**< LFCLK RC oscillator, 250ms  calibration interval.*/
  NRF_CLOCK_LFCLKSRC_RC_250_PPM_500MS_CALIBRATION,        /**< LFCLK RC oscillator, 500ms  calibration interval.*/
  NRF_CLOCK_LFCLKSRC_RC_250_PPM_1000MS_CALIBRATION,       /**< LFCLK RC oscillator, 1000ms calibration interval.*/
  NRF_CLOCK_LFCLKSRC_RC_250_PPM_2000MS_CALIBRATION,       /**< LFCLK RC oscillator, 2000ms calibration interval.*/
  NRF_CLOCK_LFCLKSRC_RC_250_PPM_4000MS_CALIBRATION,       /**< LFCLK RC oscillator, 4000ms calibration interval.*/
  NRF_CLOCK_LFCLKSRC_RC_250_PPM_8000MS_CALIBRATION,       /**< LFCLK RC oscillator, 8000ms calibration interval.*/
  NRF_CLOCK_LFCLKSRC_RC_250_PPM_TEMP_1000MS_CALIBRATION,  /**< LFCLK RC oscillator. Temperature checked every 1000ms, if changed above a threshold, a calibration is done.*/
  NRF_CLOCK_LFCLKSRC_RC_250_PPM_TEMP_2000MS_CALIBRATION,  /**< LFCLK RC oscillator. Temperature checked every 2000ms, if changed above a threshold, a calibration is done.*/
  NRF_CLOCK_LFCLKSRC_RC_250_PPM_TEMP_4000MS_CALIBRATION,  /**< LFCLK RC oscillator. Temperature checked every 4000ms, if changed above a threshold, a calibration is done.*/
  NRF_CLOCK_LFCLKSRC_RC_250_PPM_TEMP_8000MS_CALIBRATION,  /**< LFCLK RC oscillator. Temperature checked every 8000ms, if changed above a threshold, a calibration is done.*/
  NRF_CLOCK_LFCLKSRC_RC_250_PPM_TEMP_16000MS_CALIBRATION, /**< LFCLK RC oscillator. Temperature checked every 16000ms, if changed above a threshold, a calibration is done.*/
};

What does the different sources here mean, and what is the consequence of using them?

Parents
  • The softdevice needs a low-frequency clock to be able to do the protocol timing. With this enum, you tell the softdevice what kind of clock source you use, and the accuracy of it. In general you have 3 options for this source:

    • External crystal: Using an external 32.768 kHz crystal is the option that gives the lowest current consumption. If you have this on your board, you should use it. You have to choose the appropriate accuracy for your crystal, so that the softdevice can take the accuracy into consideration to know how much the clock may drift over a certain period. It will use this information to make sure it compensates correctly and wakes up the chip just when needed.

    Enums used for this mode with softdevice: NRF_CLOCK_LFCLKSRC_XTAL_x_PPM, where x is the accuracy of your crystal.

    When not using softdevice, external 32kHz crystal is started with the following code:

    When not using a softdevice, starting external 32kHz crystal is done with the following code:

    	NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos);
    	NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
    	NRF_CLOCK->TASKS_LFCLKSTART = 1;
    	
    	// Wait for the low frequency clock to start
    	while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0) {}
    	NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
    
    • Internal RC oscillator: The chip have an internal RC oscillator that has an accuracy of 250 ppm when calibrated. The only thing you can choose through this enum for the RC is the calibration interval. As given in the nRF51822 PS, the accuracy is specified when the temperature is relatively stable, and it is calibrated every 4 seconds, so this is the calibration interval that should be used for most (all?) applications.

    When the RC is calibrated, the 16 MHz clock must run while calibration is ongoing, which causes an increase in the average current consumption of about 6-7 µA with a 4 s interval. The RC also uses more current than a crystal, so the total increase will most likely be 8-10 µA, compared with a 20 ppm crystal.

    Enums used for this mode: NRF_CLOCK_LFCLKSRC_RC_250_PPM_xMS_CALIBRATION, where x is the wanted calibration interval, typically 4000 ms.

    In recent SDK's, there has been added options with calibration relative to temperature change which has the enum NRF_CLOCK_LFCLKSRC_RC_250_PPM_TEMP_xMS_CALIBRATION. This will have lower current consumption than NRF_CLOCK_LFCLKSRC_RC_250_PPM_xMS_CALIBRATION options as the RC is only calibrated if there is a temperature change of 0.5 deg C or more. The frequency drift of the RC is in fact a result of temperature change. The internal TEMP peripheral on the nRF51 is used to make a temperature measurement. If there is a temperature change of 0.5 deg C or greater since the last calibration, then the nRF51 is re-calibrated. If the temperature change is <0.5 deg C, then the RC is not calibrated. The calibration of the RC takes 17ms but measuring the temperature only takes 35us, which explains why measuring the temperature consumes less current then when calibrating. If there are frequent temperature changes, the current consumption increase will be worst case 8-10 uA compared to a 20ppm crystal. If there are infrequent temperature changes, then the current consumption increase is around ~2uA best case compared to a 20ppm crystal.

    • A synthesized 32.768 kHz clock: This tells the softdevice to use the 16 MHz clock to synthesize a low-frequency clock. Since the low-frequency clock is used in the sleeping periods between for example conneciton evetns, this means that the 16 MHz must always run, giving a substantial increase in current consumption (most likely mA average current consumption instead of µA).

    In general, there should never be a reason to use this clock source, and you should always be able to use the RC oscilator instead of the synthesized clock.

    Enums used for this mode: NRF_CLOCK_LFCLKSRC_SYNTH_250_PPM, which should not be used.

  • What do you mean "which should not be used" ?

    What are the options for LFCLKSRC if I want to use S110? Reference designs in nRF51822 data sheet show single crystal 16MHz, no 32KHz additional XTAL. To use BLE do I have to have the 32KHz xtal? Thanks.

Reply Children
No Data
Related