2020-02-21 03:32 PM
Below question relates to STM32F0 and STM32F1 series MCU's.
From the documentation (HAL), I have been unable to determine, whether or not on-the-fly changes are supported to the PWM period (TIM_TimeBaseInitTypeDef.TIM_Prescaler) and/or duty cycle (directly via CCR1 or via DMA: DMA_InitTypeDef.DMA_Memory0BaseAddr).
Other than whether or not on-the-fly changes (to a running PWM-configured timer) are supported, I am also interested in knowing when on-the-fly changes takes effect (immediate, at next timer cycle, ...)?
Any help and/or references to existing documentation or examples will be greatly appreciated.
/Morten
Solved! Go to Solution.
2020-02-22 07:15 AM
The prescaler PSC always uses the shadow register, changes take effect after the next update event (timer overflow or TIM_EGR_UG).
The period ARR uses the shadow register when TIM_CR1_ARPE = 1, otherwise changes take effect immediately.
The compare register CCRx uses the shadow only when OCxPE = 1.
Note that though the period will be changed when you change PSC, the duty cycle will be determined by the CCRx/ARR ratio.
DMA address can't be changed whlie running, but you can request a DMA interrupt when half of the buffer is processed, so you'd always know which half of the buffer is currently active. You can also read the number of data words remaining in the buffer from the DMA transfer counter,
Read AN4776 Application note General-purpose timer cookbook for STM32 microcontrollers if you haven't read it before.
2020-02-21 04:04 PM
1
Dma address cant be changed while active. It takes effect immediately the next time you start the dma. You could use double buffer mode.
2
The behavior can be either based on the value of the OC1PE bit. It can either be immediately or updated on the update event. Take a look at this field definition in the reference manual.
With DMA, the behavior is the same as if you change it manually, although dma can be delayed if you have a lot going on.
3
For the prescaler, I believe this is updated immediately. I dont believe it uses a shadow register.
2020-02-21 04:45 PM
Thanks for your advise. I conclude, that ...
2020-02-21 05:35 PM
2020-02-21 05:37 PM
2020-02-22 07:15 AM
The prescaler PSC always uses the shadow register, changes take effect after the next update event (timer overflow or TIM_EGR_UG).
The period ARR uses the shadow register when TIM_CR1_ARPE = 1, otherwise changes take effect immediately.
The compare register CCRx uses the shadow only when OCxPE = 1.
Note that though the period will be changed when you change PSC, the duty cycle will be determined by the CCRx/ARR ratio.
DMA address can't be changed whlie running, but you can request a DMA interrupt when half of the buffer is processed, so you'd always know which half of the buffer is currently active. You can also read the number of data words remaining in the buffer from the DMA transfer counter,
Read AN4776 Application note General-purpose timer cookbook for STM32 microcontrollers if you haven't read it before.
2020-07-11 07:12 PM
A belated "thank you" for your comprehensive and accurate answer. Much appreciated!