Timers - should I "wait" before updating ARR after UEV?
Hi =)
Short version: should there be time (cycles) between updating ARR/CCR registers and generating an update event by setting the UG bit in TIMx_EGR?
Long version:
I am using one timer, which is automatically enabled (triggered) by another timer.
I made sure that:
- The timer is not enabled and will not be started before the setup (lines below)
- Setting the UG bit will not call the interrupt (URS set in in TIMx_CR)
- Both ARR and CCR are pre-loaded (ARPE set in TIMx_CR and OC1PE set in TIMx_CCMR)
Then I do:
- set ARR and CRR values into their preload register
- generate a UEV (UG bit in TIMx_EGR) to load the values into the shadow registers
- Then change again (right away) the values of the preload registers so that the shadows are automatically updated on the next UEV
- Then - later - the timer is started
I get very strange result - if I add a nop() or pretty much any instruction anywhere in the whole code as long as it is "before" (i.e. lower address) the first line below, then the code works fine. My guess is that is just "lucky" and it should not work.... ?
So my guess is that I need to wait at least one cycle after the UEV before updating the preload registers again - but I could not find any info about that in the manuals.
Here is my code, uncommenting or not the nop():
TIM3->CCR1L = 2; // these values will be taken into account right away (see below)
TIM3->ARRL = 9;
TIM3->EGR |= TIM_EGR_UG; // generate and UEV to load the CCR and ARR values right above
//nop();
TIM3->CCR1L = 4; // these values will be taken into account on the next UEV
TIM3->ARRL = 11;When the nop() is not there, then the output acts like if the first ARR was 7 and not 9, the rest all works fine. Very strange, it is like it "did not have the time" and missed one bit? ha :D
I already checked with the Debugger and it shows all the values are fine - but I can only check the preload registers and not the shadow registers.
Thank you!
Simon
