Synchronise 2 independent timers in OC Toggle mode
Hello, my problem is as follows:
I am working with an STM32G484QET6 uC. I have configured two timers with two output channels as Output Compare Toggle Mode. So that I get two independent quadrature signals.
I now want to synchronise these two quadrature signals. My idea of the procedure is like this:
1. stop both timer and signal generation
2. reset both timers
3. start both timer and signal generation
This is my code:
void syncTimers(void);
{
HAL_TIM_Base_Stop(&htim1);
HAL_TIM_Base_Stop(&htim8);
HAL_TIM_OC_Stop(&htim1, TIM_CHANNEL_1);
HAL_TIM_OC_Stop(&htim1, TIM_CHANNEL_2);
HAL_TIM_OC_Stop(&htim8, TIM_CHANNEL_1);
HAL_TIM_OC_Stop(&htim8, TIM_CHANNEL_2);
TIM1->EGR |= TIM_EGR_UG;
TIM8->EGR |= TIM_EGR_UG;
HAL_TIM_Base_Start(&htim1);
HAL_TIM_Base_Start(&htim8);
HAL_TIM_OC_Start(&htim1, TIM_CHANNEL_1);
HAL_TIM_OC_Start(&htim1, TIM_CHANNEL_2);
HAL_TIM_OC_Start(&htim8, TIM_CHANNEL_1);
HAL_TIM_OC_Start(&htim8, TIM_CHANNEL_2);
}This works quite well so far, the Timers are then synchronised with each other. However, the problem is probably that, since I have configured OC mode Toggle, the start values of the quadrature signal are different and are therefore the signal is sometimes inverted.
Correct:

wrong:

My question now is this: How can I reset the pin value completely so that both timers start cleanly from 0? Or is there another way to achieve the wanted synchronisation?

