STM32F072: issue changing PWM period and pulse
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-07-16 4:30 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-07-16 5:33 AM
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
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-07-16 5:49 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-07-16 9:28 AM
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
