cancel
Showing results for 
Search instead for 
Did you mean: 

PWM and ARPE

BG1
Senior

I was trying to figure out what datasheet says with the following sentence highlighted bold for STM32F303R8T6

The PWM mode can be selected independently on each channel (one PWM per OCx 

output) by writing ‘0110’ (PWM mode 1) or ‘0111’ (PWM mode 2) in the OCxM bits in the 

TIMx_CCMRx register. You must enable the corresponding preload register by setting the 

OCxPE bit in the TIMx_CCMRx register, and eventually the auto-reload preload register (in upcounting or center-aligned modes) by setting the ARPE bit in the TIMx_CR1 register.

Do we have to set the ARPE bit for a basic PWM generation .. ? I experienced setting or clearing it in debug mode but I can't see the difference , It still generates the same PWM wave form .

In my application I will be working with a fixed PWM frequency with a variable duty cycle , and I don't know if I should set or reset the ARPE bit ..

I meant basic by Edge Aligned mode .. But I want to know what it changes with Center Aligned mode ..

1 ACCEPTED SOLUTION

Accepted Solutions

> You must enable the corresponding preload register

I understand your confusion. *Must* is inaequate there - you *can* of course use PWM mode without enabling the TIM_CCEx register's preloading. If you do, and then during runtime, if TIM_CNT is lower than current TIM_CCEx you change TIM_CCEx to a value below current TIM_CNT, there will be no compare event thus no "pulse" in that particular cycle. But there may be applications which may be fine with this. for example if they never change TIM_CCEx for some reason.

The same goes with enabling TIM_ARR preload by TIM_CR1.ARPE - if you don't, you may run into a risk of a cycle running "around the whole clock" if you change TIM_ARR to below TIM_CNT; but there's no such problem if you never intend to change TIM_ARR during runtime.

It's better to try to understand the working of the timer than to follow blindly the narrative in the TIM chapter(s), which is (are) relatively poorly written.

The working of the preloads does not depend on edge- or center-aligned mode.

JW

View solution in original post

2 REPLIES 2

> You must enable the corresponding preload register

I understand your confusion. *Must* is inaequate there - you *can* of course use PWM mode without enabling the TIM_CCEx register's preloading. If you do, and then during runtime, if TIM_CNT is lower than current TIM_CCEx you change TIM_CCEx to a value below current TIM_CNT, there will be no compare event thus no "pulse" in that particular cycle. But there may be applications which may be fine with this. for example if they never change TIM_CCEx for some reason.

The same goes with enabling TIM_ARR preload by TIM_CR1.ARPE - if you don't, you may run into a risk of a cycle running "around the whole clock" if you change TIM_ARR to below TIM_CNT; but there's no such problem if you never intend to change TIM_ARR during runtime.

It's better to try to understand the working of the timer than to follow blindly the narrative in the TIM chapter(s), which is (are) relatively poorly written.

The working of the preloads does not depend on edge- or center-aligned mode.

JW

BG1
Senior

Thank you so much !