I'm using a STM32 for PAC (phase-angle control) of a mains load (cos phi > 0.95) and I'm unsure, how I should implement the firing of the pulses.
My first try was to use two timers and a EXTI pin, which measures the zero-crossing. When I detect a zero-crossing, I start a delay timer in one-shot mode and delay according my phase angle. After the delay (output compare trigger), I trigger an interrupt, where I deactivate the delay timer (such that I don't need to finish the period) and start a puls timer in single shot-mode, that gives a 100us puls.
When I detect a zero-crossing, I start a delay timer in one-shot mode and delay according my phase angle. After the delay (output compare trigger,) I trigger an interrupt, where I deactivate the delay timer (such that I don't need to finish the period) and start a pulse timer in single shot-mode that gives a 100us pulse.
This works pretty good so far, but I have seen, that when I change the PAC angle several times, I sometimes get 2-3 mains period,periods that the delay timer does not trigger anymore. The timer is started correctly from the EXTI interrupt, but no delay timer interrupt is triggered.
I also attached the important code, where the ZC Interrupt triggers the CM_POWER_ZC_Trigger() function, that starts the delay timer with TIMER_PAC_Single_Delay_Trigger(). The delay timer interrupt should then trigger HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim) (but it does not always), which starts then a again a pulspulse.
Any ideas, how I can improve PAC? What I already tried is to use Timer3 (pulspulse timer) in slave mode of Timer2 (delay timer) and then not use any interrupts, but I could not achieve proper functions with just one-pulspulse mode. The thing is, that I cannot letleave the delay timer period constant at 10ms (50Hz), since it should also work for 60Hz and thatsthat's why I disable the timer after the output-compare interrupt.
Edit: I tried now to use only Timer3 and start it over the EXTI interrupt and depicted above. The glitch is still herethere and I don't use any interrupt except the EXTI interrupt now and the EXTI interrupt comes reliable. So somehowSomehow I think the timer runs the full period of ARR = 65535 and is not stopped in some cases. How should I properly reset the timer in one-shot mode, so that it won't glitch?

