3 Replies Latest reply on Oct 15, 2019 12:11 AM by LinglingG_46

    Modify clock frequency using code

    yaxi_1543386

      Hi  Sir ,

           In the project attched , the clock frequency is 4MHz .If I want change the frequency from 4MHz to 1MHz using code ,not the component,how

      shall I do ?

           Thanks.

        • 1. Re: Modify clock frequency using code
          LinglingG_46

          Hi Xiaoping,

           

          You add an empty project here.

          Please attached it again.

          Could you comment which clock you want to modify and tell us why you want to do it?

          • 2. Re: Modify clock frequency using code
            yaxi_1543386

            Hi  Lingling,

                 My customer ask me for it . He ask if it can be set while program running, or be configured using code .

                 Thanks。

            • 3. Re: Modify clock frequency using code
              LinglingG_46

              Hi Xiaoping,

               

              I have created a simple project to test the function, and add it in attached. The project only shows you how to change the TCPWM component clock.

              Hope it can be helpful for you.

               

              #include "project.h"

              int main(void)
              {
                  CyGlobalIntEnable; /* Enable global interrupts. */

                  /* Place your initialization/startup code here (e.g. MyInst_Start()) */

                  TIMER_Start();
                  for(;;)
                  {
                     
                      CyDelay(1000);
                     
                      TIMER_Stop();
                      wodada_Stop();
                     
                      //wodada_SetDividerRegister(1000,0); //把TCPWM模块的clock从4KHz 改成16KHz.
                      CY_SET_REG32(CYREG_PERI_DIV_16_CTL0,0x3E800);
                      wodada_Start();
                     
                      TIMER_Start();
                      while(1);
                     // wodada_StartEx();
                     
                     
                      /* Place your application code here. */
                  }
              }

               

              只要你原来可以让timer 跑起来,现在改变clock,只要配置寄存器:CYREG_PERI_DIV_16_CTL0