Modify clock frequency using code

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
XiaoPing_Yang
Level 4
Level 4
25 replies posted 10 replies posted 10 questions asked

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.

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.

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

View solution in original post

0 Likes
3 Replies
LinglingG_46
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 10 questions asked

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?

0 Likes
lock attach
Attachments are accessible only for community members.

Hi  Lingling,

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

     Thanks。

0 Likes
lock attach
Attachments are accessible only for community members.

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

0 Likes