Question
Timer synchronization offset STM32G431RB
I am trying to configure two timers (TIM3 & TIM4) to start at the same time, following the procedure in RM0440 pg. 1304. However, when I scope the output pins of my timers, there is a ~25us delay between the edges of the pulses. Is there any way to eliminate this delay to make them synchronized near-perfectly? I have attached setup functions for the timers, using a system clock of 170MHz.
RCC->APB1ENR1 |= RCC_APB1ENR1_TIM3EN;
RCC->APB1ENR1 |= RCC_APB1ENR1_TIM4EN;
/*****************************************************************************/
/* Configure Master Timer TIM3 */
/*****************************************************************************/
TIM3->PSC = 170 - 1; // 1 MHz CLK
TIM3->ARR = 5000; // 200 Hz
TIM3->CCR1 = 50; // 50us pulse to be synchronized
TIM3->CCER = TIM_CCER_CC1E; // Enable TIM3CH1 output
TIM3->CCMR1 |= (6 << 4); // Set to PWM mode
// Set MMS bits to "Enable as trgo"
TIM3->CR2 |= (1 << 4);
// Set TS bits to 00100
TIM3->SMCR |= (4 << 4);
// Set MSM bit to 1 for master
TIM3->SMCR |= TIM_SMCR_MSM;
// Set SMS bits to Trigger mode (110)
TIM3->SMCR |= (6 << 0);
/*****************************************************************************/
/* Configure Slave Timer TIM4 */
/*****************************************************************************/
TIM4->PSC = 170 - 1; // 1 MHz CLK
TIM4->ARR = 5000; // 200 Hz
TIM4->CCR1 = 50; // 50us pulse to be synchronized
TIM4->CCER = TIM_CCER_CC1E; //Enable TIM4CH1 output
TIM4->CCMR1 |= (6 << 4); // Set to PWM mode
// Set TS bits to 0
TIM4->SMCR |= (0 << 4);
// Set SMS bits to Trigger mode (110)
TIM4->SMCR |= (6 << 0);
// Turn on Timers
TIM4->CR1 |= (1 << 0);
while(!(TIM4->SR & (1<<0)));
TIM3->CR1 |= (1 << 0);
while(!(TIM3->SR & (1<<0)));