Skip to main content
CHay.1
Associate
March 26, 2020
Question

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.

  • March 26, 2020
  • 6 replies
  • 1531 views

0693W000000UqWJQA0.png

This topic has been closed for replies.

6 replies

CHay.1
CHay.1Author
Associate
March 26, 2020

@Community member​ 

waclawek.jan
Super User
March 26, 2020

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
CHay.1Author
Associate
March 26, 2020

@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.

waclawek.jan
Super User
March 26, 2020

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
CHay.1Author
Associate
March 26, 2020

@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?

waclawek.jan
Super User
March 26, 2020

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

JW