cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F072: issue changing PWM period and pulse

Filippo Spalla
Associate
Posted on July 16, 2018 at 13:30

The original post was too long to process during our migration. Please click on the attachment to read the original post.
3 REPLIES 3
Posted on July 16, 2018 at 14:33

This is probably not going to work the way you want

TimHandle.Init.Period            = 100*PERIOD_VALUE;

The values are N-1, so to scale properly

TimHandle.Init.Period            = N-1;

TimHandle.Init.Period            = (10*N)-1; // 10 longer

TimHandle.Init.Period            = (100*N)-1; // 100x longer

To divide by 1000

TimHandle.Init.Period            = 999;

To divide by 10000

TimHandle.Init.Period            = 9999; // not 9900

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Filippo Spalla
Associate
Posted on July 16, 2018 at 14:49

Dear Clive,

thank you for your feedback. The period is correct. The problem is only in the first pulse after the PWM start.

It is using the old pulse value with the new period. Only from the second pulse the pwm is working as expected.

I try to give you a numerical example:

  • FAST PWM: Period 2ms. Pulse = 50%. That means that the signal is high for 1ms
  • SLOW PWM: Priod 200 ms. Pulse 50%. The output should be high for 100ms, instead the first pulse is high only for 1ms.

Is that more clear.

The easy way is to copy paste my main code in the pwm example and connect an oscilloscope to PA5. Putting a break point on the PWM_Start lines you will see the wrong generation of the first pulse.

Posted on July 16, 2018 at 16:28

You have preload enabled for the CCRx register. Don't enable it.

I don't Cube so you have to figure it yoursef how to prevent enbling the preload.

JW