2023-05-21 03:21 PM
Imagine that:
Imaging I am using the following code:
irq_disable();
TIMx->PSC = foo;
TIMx->ARR = bar;
irq_enable();
Is it possible for the following to occur:
And now my intended simultaneous update of PSC and ARR are split -- that is, the ARR will only be really updated to bar on the next timer update event.
Can this situation occur? Is there any way to protect against this?
The only solution I can think of is waiting to update any of PSC, ARR, and CCR and writing those registers only in the next UEV interrupt handler, where I know that I have some time before the next update event occurs.
2023-05-21 10:31 PM
Another way is to use Update-initiated DMA through the DMAR/DCR mechanism.
But perhaps the easiest/laziest :) method is to temporarily disable the "natural" updates using TIMx_CR1.UDIS bit.
JW