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 25, 2019
Version 6Show 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 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 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 in 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 (also in board.c file).
  6. Find clock_config.c file in the board folder at the workspace.
  7. Add the following defines in the top of the file.
    #define RTC_OSC_CAP_LOAD_0 0x0U /*!< RTC oscillator capacity load level 0 */
    #define RTC_OSC_CAP_LOAD_1 0x2000U /*!< RTC oscillator capacity load level 1 */
    #define RTC_OSC_CAP_LOAD_2 0x1000U /*!< RTC oscillator capacity load level 2 */
    #define RTC_OSC_CAP_LOAD_3 0x3000U /*!< RTC oscillator capacity load level 3 */
    #define RTC_OSC_CAP_LOAD_4 0x800U /*!< RTC oscillator capacity load level 4 */
    #define RTC_OSC_CAP_LOAD_5 0x2800U /*!< RTC oscillator capacity load level 5 */
    #define RTC_OSC_CAP_LOAD_6 0x1800U /*!< RTC oscillator capacity load level 6 */
    #define RTC_OSC_CAP_LOAD_7 0x3800U /*!< RTC oscillator capacity load level 7 */
    #define RTC_OSC_CAP_LOAD_8 0x400U /*!< RTC oscillator capacity load level 8 */
    #define RTC_OSC_CAP_LOAD_9 0x2400U /*!< RTC oscillator capacity load level 9 */
    #define RTC_OSC_CAP_LOAD_10 0x1400U /*!< RTC oscillator capacity load level 10*/
    #define RTC_OSC_CAP_LOAD_11 0x3400U /*!< RTC oscillator capacity load level 11 */
    #define RTC_OSC_CAP_LOAD_12 0xC00U /*!< RTC oscillator capacity load level 12 */
    #define RTC_OSC_CAP_LOAD_13 0x2C00U /*!< RTC oscillator capacity load level 13 */
    #define RTC_OSC_CAP_LOAD_14 0x1C00U /*!< RTC oscillator capacity load level 14 */
    #define RTC_OSC_CAP_LOAD_15 0x3C00U /*!< RTC oscillator capacity load level 15 */
  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.

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
SC2P1pFRTC_OSC_CAP_LOAD_132771.330Hz
SC4P2pFRTC_OSC_CAP_LOAD_232770.050Hz
SC2P, SC4P3pFRTC_OSC_CAP_LOAD_332769.122Hz
SC8P4pFRTC_OSC_CAP_LOAD_432768.289Hz
SC2P, SC8P5pFRTC_OSC_CAP_LOAD_532767.701Hz
SC4P, SC8P6pFRTC_OSC_CAP_LOAD_632767.182Hz
SC2P, SC4P, SC8P7pFRTC_OSC_CAP_LOAD_732766.766Hz
SC16P8pFRTC_OSC_CAP_LOAD_832766.338Hz
SC2P, SC16P9pFRTC_OSC_CAP_LOAD_932766.038Hz
SC4P, SC16P10pFRTC_OSC_CAP_LOAD_1032765.762Hz
SC2P, SC4P, SC16P11pFRTC_OSC_CAP_LOAD_1132765.532Hz
SC8P, SC16P12pFRTC_OSC_CAP_LOAD_1232765.297Hz
SC2P, SC8P, SC16P13pFRTC_OSC_CAP_LOAD_1332765.117Hz
SC4P, SC8P, SC16P14pFRTC_OSC_CAP_LOAD_1432764.940Hz
SC2P, SC4P, SC8P, SC16P15pFRTC_OSC_CAP_LOAD_1532764.764Hz
1 person found this helpful

Attachments

    Outcomes