You are here

Changing pulse width in PWM generator without using API | Cypress Semiconductor

Changing pulse width in PWM generator without using API

Summary: 2 Replies, Latest post by H L on 26 Mar 2014 06:30 AM PDT
Verified Answers: 0
Last post
Log in to post new comments.
user_33142774's picture
4 posts


I go straight to the point:

I need to know how to 'change' the pulse width (compare value) of 16 bit PWM generator at run time without using the PWM16_WritePulseWidth() function (I'm using a CY8C29466).

Now if anyone want to know more here's 'why':

 I'm writing a simple app that should act as follow:

  • should generate 8 pulses each of a variable width of 1 to 2 ms
  • all the pulses should be 'enclosed' in a frame that need to 'last' for no more than 20ms
  • each pulse (the first in the frame as the second or any else) should 'repeat' with a period of 20ms

I used a 16 bit PWM generator clocked @ 2MHz with a 'period' of 5000 ticks -> 2.5ms

I set the interrupt type of the PWM16 as 'terminal' count. When the 'interrupt' is triggered I take the width of the nth pulse from an array and pass it to PWM16. I'm using PWM16_WritePulseWidth but, since it's an API call, it will lead to a certain overhead that should translate into delays.

If anyone would suggest a different approach I'm open to any suggestion.

Best Regards,


user_14586677's picture
7646 posts

At the bottom of the module datasheet are the registers you can direct write

to change values. The naming convention for the specific register can be found in

the TRM, in the register chapter. There the specific register bits and layout are des-

cribed. Pay particular attention to effects of writes, eg. need to stop something,

additional considerations.


You can also find register addresses in PWM16.h, register names in m8c.h


Regards, Dana.



user_460349's picture
1362 posts

You can use two PWMs, PWM1 with a fix period of 2.5ms and a pulse width of 0.5ms. With the compare output trigger PWM2 which has 0.5 to 1.5ms. the actual ouput is PWM1 OR PWM2 The loading of the 2nd PWM should be done during the first 0.5ms pulse of PWM1.

Log in to post new comments.