Output Compare Formula [STM32H7]
I'm using TIM5CH3 to toggle an I/O, but AN4013 doesn't list a formula for the Output Compare, so I'm using the Timer Base Generator in Section 2.2:
Update_event = TIM_CLK/((PSC + 1)*(ARR + 1)*(RCR + 1))
With TIM5 CLK of 60Mhz, Prescaler 60-1, and ARR 10-1 (I don't see any Repetition Counter so I'll assume that's 0.) I would expect this to toggle every 1.2usec (857k), however the actual output toggle every 5usec (200khz).
I've been playing with the numbers, but can't for the life of me see how the above can result in that frequency. Not sure if related, but if I set the 32-bit Pulse register to above 10 the output does not toggle.
htim5.Instance = TIM5;
htim5.Init.Prescaler = 60-1;
htim5.Init.CounterMode = TIM_COUNTERMODE_UP;
htim5.Init.Period = 10-1;
htim5.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim5.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim5) != HAL_OK)
{
Error_Handler();
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim5, &sClockSourceConfig) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_OC_Init(&htim5) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim5, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
sConfigOC.OCMode = TIM_OCMODE_TOGGLE;
sConfigOC.Pulse = 0x00000001;
sConfigOC.OCPolarity = TIM_OCPOLARITY_LOW;
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
if (HAL_TIM_OC_ConfigChannel(&htim5, &sConfigOC, TIM_CHANNEL_3) != HAL_OK)
{
Error_Handler();
}
__HAL_TIM_ENABLE_OCxPRELOAD(&htim5, TIM_CHANNEL_3);

