3 Replies Latest reply on Aug 13, 2019 9:48 AM by RodolfoG_11

    Trouble Setting Multiple PWMs




      I am having trouble using the PWMs on the PSoC 6 in ModusToolbox. In my main project I attempted to drive four LEDs off of different PWM counters and could only reliably get one to work. So I set up a test on the PSoC 6 Pioneer CY8PROTO board. I attempted to get all 24 counters on TCPWM[1] to run at the same time using standard settings. In the device configurator I enabled all 24 counters as PWMs with the same source clock and standard settings otherwise. I then initialized them all, enabled them all, TriggerStart()'ed them all, and then checked their status. Only the first five counters could be seen as running.


      My questions are:

      1) Is there a limit to how many counters in the TCPWM block can run at once?

      2) Do the individual counters have any connection to one another? Does enabling one counter disable the others? I know there are commands let let you use masks to manipulate multiple counters at once, but I'm talking about calling for a specific timer to change period (or compare value or something) and having other counters change state.

      3) Any guidance for enabling specific TCPWM counters and ensuring they function?


      To this post I have attached my sample project that simply sets up the 24 TCPWM[1] counters and prints out the status of each afterwards. I also attached my terminal output as a text file. The 0x00000000 value means that the counter is not running, an 0x8000000X means the counter is running in some direction with 0x80000002 meaning that it counts up.

        • 1. Re: Trouble Setting Multiple PWMs

          When you use the TriggerStart() function, it requires a MASK, instead of a counter. You actually just need to call TriggerStart() once, triggering all 24 PWMs with 0xFFF as argument.

          • 2. Re: Trouble Setting Multiple PWMs

            This is exactly what I'm doing wrong. Thank you very much!


            Since you seem to have some knowledge here, I have a followup question if you don't mind: What is the proper procedure for changing the period and compare values of a PWM once it's running? I settled in on this as to set it, but it doesn't work consistently:

                 // for a given PWM instance called LED for example

                Cy_TCPWM_TriggerStopOrKill(LED_HW, LED_MASK);



                Cy_TCPWM_PWM_SetCounter(LED_HW, LED_NUM,0);

                Cy_TCPWM_PWM_SetPeriod0(LED_HW, LED_NUM, 400);

                Cy_TCPWM_PWM_SetCompare0(LED_HW, LED_NUM, 400/2);



                Cy_TCPWM_TriggerReloadOrIndex(LED_HW, LED_MASK);

                Cy_TCPWM_TriggerStart(LED_HW, LED_MASK);


            On some of the PWMs this works as expected, but on others it does not. I expect there's something else w/r/t the MASK vs NUM problem I had previously, but it very well could be something else. I can't use the period and compare swap, as I need four potential settings (off, on, fast, slow).


            Thanks again for the help.

            • 3. Re: Trouble Setting Multiple PWMs

              The flow looks OK, as long you are passing the correct parameters (which I think you are).

              Another think I will look at is if all the PWMs were assigned to the same block (LED_HW). Because if they are not, you have two different bases to pass as argument. The PSoC 6 has two TCPWM blocks and each block has several channels (LED_NUM).