Changing pulse width in PWM generator without using API

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

cross mob
Anonymous
Not applicable

Hallo,

   

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,

   

    Michele

0 Likes
2 Replies
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

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.

0 Likes
Anonymous
Not applicable

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.

0 Likes