cancel
Showing results for 
Search instead for 
Did you mean: 

How would I use the timer to generate a PWM signal - where, I can modify the width of one pulse? As an example, look at the illustration below; the red pulse is increased in width. Any help would be appreciated. Thanks Craig.

CHay.1
Associate II

0693W000000UqWJQA0.png

6 REPLIES 6
CHay.1
Associate II

@Community member​ 

Period is given by value of TIMx_ARR, while pulse length (duty) is given by TIMx_CCRy. Read the timer chapter in User Manual.

JW

CHay.1
Associate II

@Community member​ - Thanks for the answer. I am aware and know how to generate a PWM signal with a period T, and a given duty cycle. But, my question is here, how can I modify one pulse's width? The figure I gave above, the red pulse has its width modified, while the rest of the pulses are the same.

Your diagram suggests, that you want to change both the period and the duration of pulse (to maintain duty cycle).

Assuming you have both ARR and CCRx preload enabled by their respective bits (TIMx_CR1.ARPE/TIMx_CCMRx.OCyPE), you set the new value for ARR and CCRx during the period previous to the pulse to be changed, and then change back ARR and CCRx to the original value during the changed pulse.

You can do it conveniently in the Update interrupt.

JW

CHay.1
Associate II

@Community member​ 

Thanks for that. I figured that would be a option. However, I noted in the cookbook and manual that there is an ability to have a so-called break function. Could that work in this application/case?

Break is a safety feature, it does not change period but switches off the outputs.

JW