You are here

How to change PWM duty cycle in code... | Cypress Semiconductor

How to change PWM duty cycle in code...

Summary: 1 Reply, Latest post by danaaknight on 01 Feb 2013 12:38 PM PST
Verified Answers: 0
Last post
Log in to post new comments.
dtvonly's picture
8 posts

Hi.  I looked at the API's explanation but don't really understand how to update my PWM duty cycle.  Please provide sample code for PSoC5 (fixed) 8/16 bit PWM duty cycle update (in code).  thanks.

user_14586677's picture
7646 posts

The compare value register is what controls duty cycle.


PWM_WriteCompare() (for a one output PWM)


For 8 bit part it can range from 0 to 255, 0 produces a DC value of 0%, 255 100%,

and in between the DC ranges from 0+ - 100- %.


The PWM output is driven by the compare logic, as PWM counter is running, the compare

register values is compared to the period counter value, and depending on the compare type,

" less than", "less than or equal"..... it sets or resets the PWM output terminal, there by

controling the duty cycle.


Regards, Dana.

Log in to post new comments.