4 Replies Latest reply on Jun 19, 2013 6:15 PM by junichi.hiraoka

    How can I make 4ch PWM using CY8C24894-24LTXI

    a.b.2
              Hi, I want to make below PWM function. PSoC1 : CY8C24894-24LTXI (DBB00,DBB01,DCB00,DCB01) PWM : 4ch PWM interval : 10ms PWM resolution : 10us (Ideally 1us) PWM width : 0 - 2ms (2000us) Now I'm using Timer8 which interrupt interval is 10[us]. Timer8 Interrupt function is just increasing counter, and comparing between PWM width and counter value and switching GPIO control(high/low) are done in the main function. Just so you know, comparing value and 4ch GPIO switching don't finish within 10[us], so those code are in the main function. But the problem is accuracy of PWM isn't that great. So could you tell me how I do to solve this problem. Note: - It's impossible to place 4ch PWM16 - It's possible to place 4ch PWM8 but I'd like to set PWM resolution as 10us while PWM width is 10ms. Thanks   
        • 1. Re: How can I make 4ch PWM using CY8C24894-24LTXI
          junichi.hiraoka

          Hi a b,      

           

             

          You have difficult problem.      

           

             

          10ms period and 10us resolution. Ratio is 1000.      

           

             

          Not only that you want four.      

           

             

          It seems impossible but. doable.      

           

             

          Because, Cypress said PSoC can, MCU can't Anyway.      

           

             

                

                        

             

          How ever it's seems difficult way still.      

           

             

          Use interrupt.      

           

             

          Count a inner counter value by Each terminal interruption of PWM.      

           

             

          10us is available by that interruption process. I presume so.      

           

             

          Do you hope you can be with this way?      

           

          • 2. Re: How can I make 4ch PWM using CY8C24894-24LTXI
            user_1377889

            Since your selected device only got 4 DBBs. So your PWM can only be 8 bits wide, giving you a resolution of 1/250 period.

               

            That is 10ms/250 = 40µs. If that is sufficent you can do it in PSoC1 hardware without CPU intervention

               

            With a clock of 24MHz you can scale it down to  25kHz with the VCn dividers giving you a PWM period of 10ms when counter is set to 249.

               

            Another choice could be to use a Cy8C27243-??? which costs more, but not too much. With that chip you are able to use 16-bit PWMs that will give you sufficent resolution.

               

             

               

            Bob

            • 3. Re: How can I make 4ch PWM using CY8C24894-24LTXI
              psai

               Hi a b,

                 

              If you need to use only CY8C24894, looks like the suggestion by PSoC73 of using the PWM's interrupt would be effective, ie, here is a possible hardware-firmware processing sequence that may meet 10us pulse width during a period of 10 ms:

                 

              1) Set the PWM period parameter as 249 and clock it such that its period is 2.5 ms (instead of 10 ms).

                 

              2) Set the PWM compare type as "Less than", and pulse width as "0".

                 

              3)  Use PWM's terminal count interrupt. During each interrupt, increment a variable(starting from 0) by 1. When this variable reaches 4, change the PWM pulse width to 1 using "PWM8_WritePulseWidth" API, and also reset the variable to 0. (Also if this variable is 0 when the ISR is entered, change the PWM pulse width back to 0).

                 

              This reduces the firmware interruption to once in 2.5 ms, which should give the CPU enough time before next interrupt. But note that you would have to change the above logic based on the required pulse width of the PWM.

                 

               

                 

              Thanks & Regards,

                 

              Prem Sai 

              • 4. Re: How can I make 4ch PWM using CY8C24894-24LTXI
                junichi.hiraoka

                Hi there,      

                 

                   

                I should be add and change previous post a little.      

                 

                   

                For the interrupt, should be use COMPARE INTERRUPT.      

                 

                   

                It will get more accurate timing.      

                 

                   

                       

                 

                   

                We have to mention to use PWM module.      

                 

                   

                It is a count-down counter, start with period value(M) and end with zero.      

                 

                   

                the period is M+1, and count value is calculate as 255-(value).      

                 

                   

                       

                 

                   

                the PWM output should be control by software in interrupt routine,      

                 

                   

                If meets the conditions should be turn ON the output.      

                 

                   

                Otherwise turn OFF.      

                 

                   

                When compare interrupt was happen and inner counter      

                 

                   

                meets the condition, change The PWM output.      

                 

                   

                       

                 

                   

                Each Interrupt routine should be process enough within 10u.sec      

                 

                   

                It might could be.