1 Reply Latest reply on Jun 14, 2018 10:55 AM by user_342122993

    Bug in PWM or am I missing something really obvious?

    jeremy_3270776

      Heh, hello again, everyone!

       

      It turns out that PWM period only updates when the TC is reset (which explains some of the previous issues I'm having).  I found that you can set the counter to 0 and it will update the period.  Information on the WriteCounter() command can be found here (pg 23):

       

      http://www.cypress.com/file/184296/download

       

      Unfortunately, when I'm calling the command, it doesn't seem to work.  In fact, the command isn't even visible in Intellisense, which I thought was odd:

       

      v

      Is there a bug in the PWM module in terms of the WriteCounter() function or am I missing something really, really obvious?

       

      My code (and details about my design, if it helps) can be found in the following thread:

      Trouble Migrating a PSoC4 Project to PSoC5 - Variable PWM

       

      Any help you can give me would be greatly appreciated.  Thanks a lot!  Sorry for all the posts, I'm still learning (and doing my best to fill in the knowledge gaps where I can).  I don't expect anyone to do the work for me, just running into a lot of issues I'm having trouble finding ways around.  Thanks!

        • 1. Re: Bug in PWM or am I missing something really obvious?
          user_342122993

          Jeremy,

           

          Attached is updated project for PSoC5. The only difference is single line of code, where original code for P4 is wrong (uint->int):

           

          //uint16_t result = offset + (uint16_t)(amplitude * sine);  // incorrect calculation

          uint16_t result = offset + (int16_t) (amplitude * sine);    // OK

           

          So, apparently, PWM duty cycle was never set below 50%.

           

          The way PWM works, the Compare value is updated on PWM rollover, and writing Compare has no immediate effect. So ISR timing is not important - the update happens on hardware timing.

           

          /odissey1

          P.S. Sorry for delay, I was busy last week and now developers community is down.