7 Replies Latest reply on Nov 14, 2017 11:13 PM by m.roth_2243201

    Switch Low frequency clock (LFC) Source from ILO to WCO at Cyble022001-00

    m.roth_2243201

      Hello, I'm writing a program for BLE on the  Cyble022001-00

       

      When using the WCO timer as clock source for LFC at startup a 500ms Wait is implemented in auto generated Code.

      In this 500ms more than 70 percent of my application power is consumed due to the reset and the 500ms idle wait.

       

      in order to solve this problem I decided to enable ILO and WCO and configure ILO as LFC source.

      500ms after startup i want to switch from ILO to WCO as clock source and disable ILO totally.

      Enabling BLE afterwards and handle Blue tooth communication.

      After changing the clock source, i'm able to discover the BLE device, but no connection is possible.

       

      Whenever I start with WCO as clock source everything works fine.

      On other Code changes are made!

       

      In order to switch clock source I used the AN95089 example.

       

      any advice would be appreciated.

      Thanks

       

      my Code:

       

      /*******************************************************************************

      * Function Name: WDT_Start

      ********************************************************************************

      *

      * Summary:

      *  Configures WDT to trigger an interrupt.

      *

      *******************************************************************************/

       

      void WDT_Start(void)

      {

          /* Unlock the WDT registers for modification */

          CySysWdtUnlock();

          /* Setup ISR */

          WDT_Interrupt_StartEx(&Timer_Interrupt);

          /* Write the mode to generate interrupt on match */

          CySysWdtWriteMode(WDT_COUNTER, CY_SYS_WDT_MODE_INT_RESET);

          /* Configure the WDT counter clear on a match setting */

          CySysWdtWriteClearOnMatch(WDT_COUNTER, WDT_COUNTER_ENABLE);

          /* Configure the WDT counter match comparison value */

          CySysWdtWriteMatch(WDT_COUNTER, WDT_TIMEOUT);

          /* Reset WDT counter */

          CySysWdtResetCounters(WDT_COUNTER);

          /* Enable the specified WDT counter */

          CySysWdtEnable(WDT_COUNTER_MASK);

          /* Lock out configuration changes to the Watchdog timer registers */

          CySysWdtLock();   

      }

       

       

      /*******************************************************************************

      * Function Name: WDT_Stop

      ********************************************************************************

      *

      * Summary:

      *  This API stops the WDT timer.

      *

      *******************************************************************************/

      void WDT_Stop(void)

      {

          /* Unlock the WDT registers for modification */

          CySysWdtUnlock();

          /* Disable the specified WDT counter */

          CySysWdtDisable(WDT_COUNTER_MASK);

          /* Locks out configuration changes to the Watchdog timer registers */

          CySysWdtLock();   

      }

       

       

      int main()

      {

          /* Unfreeze IO-Cells */

          CySysPmUnfreezeIo();   

          WDT_Start();

             

         

          Wakeup_Interrupt_StartEx(&WakeupInt);

          CyGlobalIntEnable;

         

          if (CySysPmGetResetReason() == CY_PM_RESET_REASON_WAKEUP_HIB) {           

              //disableI2C(0u, 0);       

              WAKEUP_ClearInterrupt();

              Wakeup_Interrupt_ClearPending();

          }

        

          dbug1_Write(1u);

         

          while(1)

          {

              cycleCounter++;

             

              if ( u16WcoCycleCount == 0 && state == 0){ // wait 500ms realized with timer interrupt

                CyGlobalIntDisable;

                (void)CySysClkWcoSetPowerMode(CY_SYS_CLK_WCO_LPM);    /* Switch to the low power mode */

                CySysClkSetLfclkSource(CY_SYS_CLK_LFCLK_SRC_WCO);     /*Select WCO as the clock source*/

             

                /*Stop ILO*/

                CySysClkIloStop();

                WDT_Stop();

       

                WDT_Start();

                CyGlobalIntEnable;

       

                /* Stack Initialization */

                state = 1;

                CyBle_Start(AppCallBack);          

                //CyBle

              }

             

              /* CyBle_ProcessEvents() allows BLE stack to process pending events */

              CyBle_ProcessEvents();

      }