AnsweredAssumed Answered

STM32F401RE PWM run time frequency, duty  cycle and prescalar change

Question asked by Siddhesh Dani on Nov 21, 2017
Greetings !
I have been working for STM32F401RE controller.
I am using timer for generation of PWM which is  interrupt based and  frequency change is desired during run time.
This is to achieve  a trapezoidal type profile for controlling motor.
The PWM frequency range is 1 to 10 kHz with 1 Hz resolution. To achieve the same I have divided the Tick Frequency of timer into 31.203 kHz and 84 MHz by keeping separate prescalars.
The prescalar would change at a frequency beyond 1350 Hz.
I have observed that at frequencies near to 1350 Hz (between 1350 and 1380 Hz) the timer is suddenly stopping for about 2s and resuming from the next frequency point. This stopping of PWM is undesirable .
The timer works fine in cases where the frequency band between 1350 Hz and 1400 Hz is not encountered.
I have also enabled the preloading and immediately disabled after loading  at the time of change in period.
I believe that the issue is due to change of all three parameters at the same time.
The exact synch of ARR, CCR and PSC  is not being achieved.
Is there any way in which the synchronization  be achieved?
htim3.Instance->CR1|=0x80; //ARR Preload enable
__HAL_TIM_SET_AUTORELOAD(&htim3, FrequencyCount) ;
htim3.Instance->CR1 &= ~(0x80);// ARR Preload disable
__HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_3, DutyCycleCounts);
if(Frequency <= 1350){
__HAL_TIM_SET_PRESCALER(&htim3, 2691);


Please note the above code is part  ISR.
Thanking you in advance for your help.