4 Replies Latest reply on Aug 27, 2020 1:31 AM by NoriakiT_91

    Switching clock for PWM based on an IO

    RuGl_1600761

      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 ?

        • 1. Re: Switching clock for PWM based on an IO
          BoTa_264741

          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

          1 of 1 people found this helpful
          • 2. Re: Switching clock for PWM based on an IO
            NoriakiT_91

            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

            • 3. Re: Switching clock for PWM based on an IO
              RuGl_1600761

              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

              • 4. Re: Switching clock for PWM based on an IO
                NoriakiT_91

                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