nrf51822 ---协议栈时钟源选择(32.768khz)

1.目的

   分析32.768khz时钟选择,以及功耗

2.分析

 SDK: SDK_10.0.0

   在协议栈初始化的时候,可以看到时钟源的选择

 

void ble_stack_init(void)
{
    uint32_t err_code;
    // Initialize the SoftDevice handler module.
    SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_CONFIG_VALUE, NULL);
 NRF_CLOCK_CONFIG_VALUE的选择有

/**@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 cali  bration is done.*/
  NRF_CLOCK_LFCLKSRC_RC_250_PPM_TEMP_2000MS_CALIBRATION,  /**< LFCLK RC oscillator. Temperature checked every 2000ms, if changed above a threshold, a cali  bration is done.*/
  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 cali  bration is done.*/
  NRF_CLOCK_LFCLKSRC_RC_250_PPM_TEMP_2000MS_CALIBRATION,  /**< LFCLK RC oscillator. Temperature checked every 2000ms, if changed above a threshold, a cali bration 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.*/
};

 协议栈需要一个低频的时钟源,时钟源有3个选择

 a.外部时钟 

 b.内部RC时钟

 c.合成的时钟

在外部时钟中 NRF_CLOCK_LFCLKSRC_XTAL_x_PPM,这个x是指外部晶体的精度。

在背部rc时钟 NRF_CLOCK_LFCLKSRC_RC_250_PPM_xMS_CALIBRATION,x是多少ms矫正一次时钟,因为内部rc时钟误差交大,

                      NRF_CLOCK_LFCLKSRC_RC_250_PPM_TEMP_xMS_CALIBRATION,温度没隔xms检测一次(芯片自带的内部温度传感器,本人猜测),因为晶体受温度的影响较大,温度没超过0.5摄氏度,校验一次RC。


功耗描述 如下:

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.

摘抄:https://devzone.nordicsemi.com/question/953/what-low-frequency-clock-sources-can-i-use/

你可能感兴趣的:(nrf51822 ---协议栈时钟源选择(32.768khz))