Switching clock for PWM based on an IO

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

cross mob
RuGl_1600761
Employee
Employee
25 replies posted 25 sign-ins 10 replies posted

I use cy8y4124. based on a io I like to set clock for PWM module to 12MHz in one case and 1,2MHz in the other case. How to adchive this ?

rgl
0 Likes
1 Solution
NoriTan
Employee
Employee
25 sign-ins 5 questions asked 10 sign-ins

I recommend to have a variable indicating the current clock divider status not to generate a discontinuous clock..

    uint8 clock_is_12MHz = 1;

   

    for(;;) {

        if (Pin_1_Read()) {

            if (!clock_is_12MHz) {

                Clock_1_SetDivider(2); // 24MHz/12MHz

                clock_is_12MHz = 1;

            }

        } else {

            if (clock_is_12MHz) {

                Clock_1_SetDivider(20); // 24MHz/1.2MHz

                clock_is_12MHz = 0;

            }

        }

        // Other codes

    }

Regards,

Noriaki

View solution in original post

0 Likes
4 Replies
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

RuGl,

Since your PSoC 4100 has no PLD resources, switching has to be done in code:

    for(;;)

    {

       

        if (Pin_1_Read()) // set clock divider depending on pin status

        {

            clock_1_SetDivider(2); // 12 MHz

        }

        else

        {

            clock_1_SetDivider(20); // 1.2 MHz

        }

       

        CyDelay(1); //some delay 

    }

/odissey1

PWM_clock_01_A.png

NoriTan
Employee
Employee
25 sign-ins 5 questions asked 10 sign-ins

I recommend to have a variable indicating the current clock divider status not to generate a discontinuous clock..

    uint8 clock_is_12MHz = 1;

   

    for(;;) {

        if (Pin_1_Read()) {

            if (!clock_is_12MHz) {

                Clock_1_SetDivider(2); // 24MHz/12MHz

                clock_is_12MHz = 1;

            }

        } else {

            if (clock_is_12MHz) {

                Clock_1_SetDivider(20); // 24MHz/1.2MHz

                clock_is_12MHz = 0;

            }

        }

        // Other codes

    }

Regards,

Noriaki

0 Likes

Hi Noriaki,

thanks for the reply.

The method could be found in Clock_1.c. But there is no explanation inside code how to handle this divider. For there in no description of the peripherals at all and no possibility to have a look inside debugging It would be great to add some description in clock_1.h The header file just contains #define Clock_1_SetDivider(clkDivider) Clock_1_SetDividerRegister((clkDivider), 1u)but I had no chance to find clkDivider definition.

In the past I was used to have full view of peripherals , in user manual and debugger. Now, using cypress, I have no view to peripherals, and the functions that are generated automatically are not well described (eg. inside header file)

To add more function description is valid for all code generated automatically…

Best regards

Rupert

rgl
0 Likes

Rupert,

You can open a component datasheet document in PDF from the context menu as follows.

GS004845.png

The datasheet contains the API function details.

Regards,

Noriaki

0 Likes