My PWM Timer of the STM32f411 generates wrong Pulses. Any Ideas?
I have migrated some Code from a STM32f103 to my new STM32f411CEU6 Microcontroller. While configuring the Timers for the PWM generation I ran into a problem, namely the pulses are about 1500us, when they should be 1000us.
Here are my Clock and Timer configurations from the STM32CubeMX:
Clock configuration:

My PWM Setup:

The Measured Signals:

So I think i have configured the systemclock to have a frequency of 100Mhz, which gets fed to Timer3. A Prescaler of 99 should divide this pulse to 1us and a Pulse of 1000 should then result in Pulses with a width of 1000us.
I do not call any functions in my code, other than
HAL_TIM_PWM_Init(&htim3);
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);The from the CubeMX generated initialisation code for timer 3 looks like this and is called at the start of my program:
static void MX_TIM3_Init(void)
{
/* USER CODE BEGIN TIM3_Init 0 */
/* USER CODE END TIM3_Init 0 */
TIM_MasterConfigTypeDef sMasterConfig = {0};
TIM_OC_InitTypeDef sConfigOC = {0};
/* USER CODE BEGIN TIM3_Init 1 */
/* USER CODE END TIM3_Init 1 */
htim3.Instance = TIM3;
htim3.Init.Prescaler = 99;
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
htim3.Init.Period = 5000;
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_PWM_Init(&htim3) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
sConfigOC.OCMode = TIM_OCMODE_PWM1;
sConfigOC.Pulse = 1000;
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
{
Error_Handler();
}
sConfigOC.Pulse = 0;
if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_3) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_4) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN TIM3_Init 2 */
/* USER CODE END TIM3_Init 2 */
HAL_TIM_MspPostInit(&htim3);
}So my question is: What is wrong with the my setup, that i get ~1500us Pulses instead of 1000us?
Some further Information:
I have the same Problem with Timer2, where i measure pulsewidths via interrupt, which differ by the same factor.
My HSE Crystal has a frequency of 25MHz, changing the clocksource to HSI and the /M divider to 16 doesnt affect the result.
I also generate a I2C Clock with 400kHz. The generated signal is correct, making me believe, that the systemclock should be correct.
(My htim2 setup)

Any help is highly appreciadet. Thank you!
Regards
Tim Köhler