Bug in PWM or am I missing something really obvious?

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

cross mob
Anonymous
Not applicable

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:

pastedImage_2.pngv

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!

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

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.

View solution in original post

0 Likes
1 Reply
lock attach
Attachments are accessible only for community members.
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

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.

0 Likes