Adjusting the 32 kHz oscillator internal capacitance

Document created by Pablo Noriega Navarro Employee on Jun 8, 2016Last modified by Pablo Noriega Navarro Employee on Jun 14, 2016
Version 11Show Document
  • View in full screen mode

The FRDM-KW40Z includes an RTC module with a 32 kHz crystal oscillator. This module generates a 32 kHz clock source for the MCU whilst running on very low power mode. This oscillator includes a set of programmable capacitors used as the CLOAD. Changing the value of these capacitors can modify the frequency the oscillator provides.

This configurable capacitance ranges from 1 pF (which is effectively two 2 pF capacitors in series) all the way to 15 pF (30 pF capacitors in series). These values are obtained by combining the enabled capacitors. The values available are 2 pF, 4 pF, 8 pF and 16 pF. Any combination between these four can be done. It is recommended that these internal capacitors are disabled if the external capacitors are available.



Figure 1. External capacitors for the 32 kHz crystal


To adjust the frequency provided by the oscillator, you must first be able to measure the frequency. Using a frequency counter would be ideal, as it provides a more precise measurement than an oscilloscope. You will also need to output the oscillator frequency. To output the oscillator frequency, using any of the Bluetooth demo applications as an example, you should do the following:


1. Since the RTC module is going to be used to output the oscillator frequency, the RTC_CLKOUT will be the output signal. The output pin for RTC_CLKOUT is PTB3. To configure PTB3 as the oscillator output use the function configure_rtc_pins(RTC instance). Port B clock must be enabled first.


1.pngFigure 2. PTB3 pin mux


  /* hardware_init.c */
  /* enable clock for PORTs */

  /* RTC CLKOUT */
  configure_rtc_pins(0);     //This function changes the pin mux to select RTC_CLKOUT. It is included in the pin_mux.c file.


2.  Modify the System Options Register 1 (SIM_SOPT1) to select the clock source and to allow the selected clock source to be output in PTB3. The field you should change is OSC32KOUT. To select the clock source to be output on PTB3, use the function CLOCK_HAL_SetExternalRefClock32kSrc(). Remember to include the fsl_sim_hal.h file.



Figure 3. SIM_SOPT1 register fields


/* hardware_init.c */


SIM_Type *simBase = g_simBase[0];
SIM_SOPT1 = SIM_SOPT1_OSC32KOUT(kClockRtcoutSrc32kHz);                // This field in register SIM_SOPT1 allows a clock source to be output to PTB3
CLOCK_HAL_SetExternalRefClock32kSrc(simBase, kClockEr32kSrcOsc0);     // This function chooses the clock source for the RTC


3.  Make sure the oscillator is enabled. The RTC external clock configurations can be found in the board.h file. This is also where the internal capacitors are enabled.


/* board.h */

/* RTC external clock configuration. */
#define RTC_XTAL_FREQ                32768U
#define RTC_SC2P_ENABLE_CONFIG       false      // 2 pF capacitors enable
#define RTC_SC4P_ENABLE_CONFIG       false      // 4 pF capacitors enable
#define RTC_SC8P_ENABLE_CONFIG       false      // 8 pF capacitors enable
#define RTC_SC16P_ENABLE_CONFIG      false      // 16 pF capacitors enable
#define RTC_OSC_ENABLE_CONFIG        true       // Oscillator enable


4.  You should now be able to measure the oscillator frequency through the PTB3 pin. Measurements should be done with a frequency counter, as change in the output can be very subtle, and an oscilloscope might not be able to pick it up.


Remember that these capacitors give you the option to use the 32 kHz oscillator when you do not have the external capacitors. They are not supposed to be used when the external capacitors are being used.


Now, to change the internal capacitance, you can simply change the macros contained in the board.h file (step 4). It is important that the oscillator is disabled before making any changes to the enabled capacitors. The fsl_clock_manager.c file already contains the function CLOCK_SYS_RtcOscInit() that configures the oscillator with the values established in the previously mentioned macros, however, the oscillator is not disabled before attempting to change the capacitors (and therefore, no changes are made). To fix this, you can use the RTC_HAL_SetOscillatorCmd() function to disable the oscillator before making changes with the capacitors.


/* fsl_clock_manager.c */
// Disable the oscillator in case any changes are made to the capacitors
RTC_HAL_SetOscillatorCmd(RTC, false);
// If the oscillator is not enabled and should be enabled.
if ((!RTC_HAL_IsOscillatorEnabled(RTC)) && (config->enableOsc))
    /* Enable the desired capacitors */
    RTC_HAL_SetOsc2pfLoadCmd(RTC, config->enableCapacitor2p);
    RTC_HAL_SetOsc4pfLoadCmd(RTC, config->enableCapacitor4p);
    RTC_HAL_SetOsc8pfLoadCmd(RTC, config->enableCapacitor8p);
    RTC_HAL_SetOsc16pfLoadCmd(RTC, config->enableCapacitor16p);
    /* Re-enable the oscillator */
    RTC_HAL_SetOscillatorCmd(RTC, config->enableOsc);


The fsl_clock_manager.c file can be found in:



Some reference measurements with different values for the internal capacitance:


With external capacitors (internal capacitors disabled)

Board Revision


Measured Frequency

KW40Z – rev. C

C46 & C47

32,769.03 Hz

KW40Z – rev. B

C46 & C47

32,769.27 Hz


With internal capacitors (external capacitors removed)

Enabled Capacitors


Measured Frequency


1 pF

32,773.21 Hz


2 pF

32,772.06 Hz


3 pF

32,771.2 Hz


6 pF

32,769.39 Hz


7 pF

32,769 Hz


8 pF

32,768.6 Hz


9 pF

32,768.31 Hz


10 pF

32,768.05 Hz


11 pF

32,767.83 Hz


14 pF

32,767.27 Hz


15 pF

32,767.11 Hz


Please note that the capacitance is not only composed of the enabled internal capacitance, but also the parasitic capacitances found in the package, bond wires, bond pad and the PCB traces. So, while the reference measurements given before should be close to the actual value, you should also make measurements with your board, to ensure that the frequency is trimmed specifically to your board and layout.

4 people found this helpful