STM32 General Purpose Timer Update Event and glitch problem
I use STM32F102 and TIM2 timer in PWM1 mode to generate defined frequency and duty cycle
square wave. I have some questions and I hope can get some help from experienced colleagues.
1. I update the ARR/CCR1 register in an interrput which is defined by the communication
cycle and independent form timer frequency , which means I write the ARR/CCR1 asynchronusly
form Timer Update Event. I was afraid that the update event happens between the writing of
ACC and CCR1 and the content of two registers became inconsistent. But if I disable the
update event I got a missing pulse. How can I use the Timer to have always consistent ARR/CCR1 pairs and no missing pulses?
TIM2->EGR &= ~TIM_EGR_UG;
/* ... */
TIM2->ARR = periodCh1; // If the UpdateEvent happens here the pulse is missing!
TIM2->CCR1 = pulseCh1;
/* ... */
TIM2->EGR |= TIM_EGR_UG;
2. If the ARR and CCR1 registers are equal (which means for me the 100% duty cycle) I expected constant level on the timer output,
but I noticed there is a one timer clock long glitch on the output (one glitch per update event).
Is it the normal behavior? Should I manually force the output in constant state in this situation?
3. How can I force the output of the compare module in known state? The best way to change the Output compare 1 mode (OC1M)
to forced mode or should I configure the pin back to GPIO output?
Thank you.
