KW36 trimming adjust of 32kHz RTC external oscillator

Document created by Edgar Eduardo Lomeli Gonzalez Employee on Mar 4, 2019Last modified by Edgar Eduardo Lomeli Gonzalez Employee on Jul 13, 2020
Version 9Show Document
  • View in full screen mode

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.                                                                                   
  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.

    void BOARD_EnableRtcClkOut(void)
    {
    CLOCK_EnableClock(kCLOCK_PortB); /*Enable PORTB clock gating*/
    PORT_SetPinMux(PORTB, 3u, kPORT_MuxAlt7); /*Mux the RTC_CLKOUT to PTB3*/
    SIM->SOPT1 |= SIM_SOPT1_OSC32KOUT(1); /*Select the 32kHz reference for RTC_CLKOUT signal*/
    }
  5. Call the BOARD_EnableRtcClkOut function in hardware_init function just after BOARD_BootClockRUN (board.c file).
  6. Find clock_config.c file in the board folder at the workspace.
  7. 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 */
  8. 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.
  9. 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 CapacitorsCLOADCapacitance DefinitionFrequency
-0pFRTC_OSC_CAP_LOAD_0 (bank disabled)32772.980Hz
SC2P2pFRTC_OSC_CAP_LOAD_232771.330Hz
SC4P4pFRTC_OSC_CAP_LOAD_432770.050Hz
SC2P, SC4P6pFRTC_OSC_CAP_LOAD_632769.122Hz
SC8P8pFRTC_OSC_CAP_LOAD_832768.289Hz
SC2P, SC8P10pFRTC_OSC_CAP_LOAD_1032767.701Hz
SC4P, SC8P12pFRTC_OSC_CAP_LOAD_1232767.182Hz
SC2P, SC4P, SC8P14pFRTC_OSC_CAP_LOAD_1432766.766Hz
SC16P16pFRTC_OSC_CAP_LOAD_1632766.338Hz
SC2P, SC16P18pFRTC_OSC_CAP_LOAD_1832766.038Hz
SC4P, SC16P20pFRTC_OSC_CAP_LOAD_2032765.762Hz
SC2P, SC4P, SC16P22pFRTC_OSC_CAP_LOAD_2232765.532Hz
SC8P, SC16P24pFRTC_OSC_CAP_LOAD_2432765.297Hz
SC2P, SC8P, SC16P26pFRTC_OSC_CAP_LOAD_2632765.117Hz
SC4P, SC8P, SC16P28pFRTC_OSC_CAP_LOAD_2832764.940Hz
SC2P, SC4P, SC8P, SC16P30pFRTC_OSC_CAP_LOAD_3032764.764Hz
2 people found this helpful

Attachments

    Outcomes