Setup PWM on TIM12 for trailing edge or leading edge
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-08-06 10:06 PM - edited ‎2024-08-06 10:39 PM
Dear all,
I have a custom pcb with a STM32H753 on it.
There I'm already using the TIM12 function for generating a PWM output signal
This is my init function - generated from CubeMX:
void MX_TIM12_Init(void)
{
/* USER CODE BEGIN TIM12_Init 0 */
/* USER CODE END TIM12_Init 0 */
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
TIM_OC_InitTypeDef sConfigOC = {0};
/* USER CODE BEGIN TIM12_Init 1 */
/* USER CODE END TIM12_Init 1 */
htim12.Instance = TIM12;
htim12.Init.Prescaler = 225;
htim12.Init.CounterMode = TIM_COUNTERMODE_UP;
htim12.Init.Period = 1000;
htim12.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim12.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim12) != HAL_OK)
{
Error_Handler();
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim12, &sClockSourceConfig) != HAL_OK)
{
Error_Handler();
}
if (HAL_TIM_PWM_Init(&htim12) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim12, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
sConfigOC.OCMode = TIM_OCMODE_PWM1;
sConfigOC.Pulse = 500;
sConfigOC.OCPolarity = TIM_OCPOLARITY_LOW;
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
if (HAL_TIM_PWM_ConfigChannel(&htim12, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN TIM12_Init 2 */
/* USER CODE END TIM12_Init 2 */
HAL_TIM_MspPostInit(&htim12);
}
So the normal operation of PWM with a trailing edge is working (see attached image for seeing the waveform).
Now I want to adjust parameters to get - based on same frequency and duty cycle - the leading edge pwm wave form.
What needs to be adjusted on the sConfigOC, or what else needs to be adjusted / manipulated if I switch from trailing edge to leading edge?
- Labels:
-
STM32CubeMX
-
STM32H7 Series
-
TIM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-08-07 01:32 AM
sConfigOC.OCMode = TIM_OCMODE_PWM2;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-08-07 02:15 AM
Anything else to be considered?
E.g. _PWM[ch].TimHandler->Init.CounterMode = TIM_COUNTERMODE_DOWN;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-08-07 05:34 AM
I think you need to change the pulse value and the polarity.
sConfigOC.Pulse = 500; sConfigOC.OCPolarity = TIM_OCPOLARITY_LOW;
Your current waveform is 50% duty cycle, so changing the pulse doesn't do much.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-08-07 09:27 AM
Hi @julred
This post has been escalated to the ST Online Support Team for additional assistance. We'll contact you directly.
Regards,
Billy