KW36 - Trimming adjust of 32kHz RTC external oscillator

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

KW36 - Trimming adjust of 32kHz RTC external oscillator

KW36 - Trimming adjust of 32kHz RTC external oscillator

Introduction

The FRDM-KW36 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 0 pF (capacitor bank disabled) to 30 pF in steps of 2 pF. These values are obtained by combining the enabled capacitors. The values available are 2 pF, 4 pF, 8 pF, and 16 pF. Any combination of these four can be done. It is recommended that these internal capacitors are disabled if the external capacitors are available (clearing SC2P, SC4P, SCS8, and SC16 bits in RTC Control Register SFR).

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:

Adjusting Frequency Example

This example will make use of the Heart Rate Sensor demo (freertos version) from the Connectivity Software Stack and assumes that the developer has the knowledge of import or open projects from the SDK to IDE.

  1. Open or clone the Heart Rate Sensor project from your SDK.
  2. Find the board.c and board.h files in the board folder at the workspace.                                                                               pastedImage_13.png
  3. Declare a void function on the board.h file as shown below. This function will be in order to mux the RTC clock out to the PTB3 and be able to measure the frequency. 

    /* Function to mux PTB3 to RTC_CLKOUT */
    void BOARD_EnableRtcClkOut (void);‍‍
  4. Develop the BOARD_EnableRtcClkOut function inside the board.c file as below.

  5. void BOARD_EnableRtcClkOut(void)
    {
    /* Enable PORTB clock gating */
    CLOCK_EnableClock(kCLOCK_PortB);
    /* Mux the RTC_CLKOUT to PTB3 */
    PORT_SetPinMux(PORTB, 3u, kPORT_MuxAlt7);
    /* Select the 32kHz reference for RTC_CLKOUT signal */ 
    SIM->SOPT1 |= SIM_SOPT1_OSC32KOUT(1); 
    }
  6. Call the BOARD_EnableRtcClkOut function in hardware_init function just after BOARD_BootClockRUN (board.c file).pastedImage_18.png
  7. Find clock_config.c file in the board folder at the workspace.
  8. Add the following defines at the top of the file.
    #define RTC_OSC_CAP_LOAD_0 0x0U /*!< RTC oscillator, capacitance 0pF */
    #define RTC_OSC_CAP_LOAD_2 0x2000U /*!< RTC oscillator, capacitance 2pF */
    #define RTC_OSC_CAP_LOAD_4 0x1000U /*!< RTC oscillator, capacitance 4pF */
    #define RTC_OSC_CAP_LOAD_6 0x3000U /*!< RTC oscillator, capacitance 6pF */
    #define RTC_OSC_CAP_LOAD_8 0x800U /*!< RTC oscillator, capacitance 8pF */
    #define RTC_OSC_CAP_LOAD_10 0x2800U /*!< RTC oscillator, capacitance 10pF */
    #define RTC_OSC_CAP_LOAD_12 0x1800U /*!< RTC oscillator, capacitance 12pF */
    #define RTC_OSC_CAP_LOAD_14 0x3800U /*!< RTC oscillator, capacitance 14pF */
    #define RTC_OSC_CAP_LOAD_16 0x400U /*!< RTC oscillator, capacitance 16pF */
    #define RTC_OSC_CAP_LOAD_18 0x2400U /*!< RTC oscillator, capacitance 18pF */
    #define RTC_OSC_CAP_LOAD_20 0x1400U /*!< RTC oscillator, capacitance 20pF */
    #define RTC_OSC_CAP_LOAD_22 0x3400U /*!< RTC oscillator, capacitance 22pF */
    #define RTC_OSC_CAP_LOAD_24 0xC00U /*!< RTC oscillator, capacitance 24pF */
    #define RTC_OSC_CAP_LOAD_26 0x2C00U /*!< RTC oscillator, capacitance 26pF */
    #define RTC_OSC_CAP_LOAD_28 0x1C00U /*!< RTC oscillator, capacitance 28pF */
    #define RTC_OSC_CAP_LOAD_30 0x3C00U /*!< RTC oscillator, capacitance 30pF */
  9. Search the CLOCK_CONFIG_EnableRtcOsc call to a function inside the BOARD_BootClockRUN function (also in the clock_config.c file), and edit the argument by any of the defines above.
  10. Finally, disable the low power options and led support in the "preinclude.h" file located in the source folder of the project:
    #define cPWR_UsePowerDownMode 0
    #define gLEDSupported_d 0

At this point, you can measure in PTB3 and play with the frequency adjust using your frequency counter. Each time that the board is programmed, you need to perform a POR to get the correct measure. The following table was obtained from an FRDM-KW36 board rev B and it can be used as a reference to adjust the frequency. 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 below 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.

 

Enabled Capacitors CLOAD Capacitance Definition Frequency
- 0pF RTC_OSC_CAP_LOAD_0 (bank disabled) 32772.980Hz
SC2P 2pF RTC_OSC_CAP_LOAD_2 32771.330Hz
SC4P 4pF RTC_OSC_CAP_LOAD_4 32770.050Hz
SC2P, SC4P 6pF RTC_OSC_CAP_LOAD_6 32769.122Hz
SC8P 8pF RTC_OSC_CAP_LOAD_8 32768.289Hz
SC2P, SC8P 10pF RTC_OSC_CAP_LOAD_10 32767.701Hz
SC4P, SC8P 12pF RTC_OSC_CAP_LOAD_12 32767.182Hz
SC2P, SC4P, SC8P 14pF RTC_OSC_CAP_LOAD_14 32766.766Hz
SC16P 16pF RTC_OSC_CAP_LOAD_16 32766.338Hz
SC2P, SC16P 18pF RTC_OSC_CAP_LOAD_18 32766.038Hz
SC4P, SC16P 20pF RTC_OSC_CAP_LOAD_20 32765.762Hz
SC2P, SC4P, SC16P 22pF RTC_OSC_CAP_LOAD_22 32765.532Hz
SC8P, SC16P 24pF RTC_OSC_CAP_LOAD_24 32765.297Hz
SC2P, SC8P, SC16P 26pF RTC_OSC_CAP_LOAD_26 32765.117Hz
SC4P, SC8P, SC16P 28pF RTC_OSC_CAP_LOAD_28 32764.940Hz
SC2P, SC4P, SC8P, SC16P 30pF RTC_OSC_CAP_LOAD_30 32764.764Hz
Labels (3)
Tags (1)
No ratings
Version history
Last update:
‎09-14-2020 08:43 AM
Updated by: