cancel
Showing results for 
Search instead for 
Did you mean: 

TIM12 CH2 doesn't generate a PWM...

EGonc.3
Associate II

Hi

Using CubeMX on a STM32H7B3I I have generated this initialisation function for the TIM12 CH2

/**

 * @brief TIM12 Initialization Function

 * @param None

 * @retval None

 */

static void MX_TIM12_Init(void)

{

 /* USER CODE BEGIN TIM12_Init 0 */

 /* USER CODE END TIM12_Init 0 */

 TIM_ClockConfigTypeDef sClockSourceConfig = {0};

 TIM_OC_InitTypeDef sConfigOC = {0};

 /* USER CODE BEGIN TIM12_Init 1 */

 /* USER CODE END TIM12_Init 1 */

 htim12.Instance = TIM12;

 htim12.Init.Prescaler = 27;

 htim12.Init.CounterMode = TIM_COUNTERMODE_UP;

 htim12.Init.Period = 1023;

 htim12.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

 htim12.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;

 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();

 }

 sConfigOC.OCMode = TIM_OCMODE_PWM1;

 sConfigOC.Pulse = 0;

 sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;

 sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;

 if (HAL_TIM_PWM_ConfigChannel(&htim12, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)

 {

  Error_Handler();

 }

 /* USER CODE BEGIN TIM12_Init 2 */

 /* USER CODE END TIM12_Init 2 */

 HAL_TIM_MspPostInit(&htim12);

}

Then this is called as:

 MX_TIM12_Init();

 HAL_TIM_PWM_Start(&htim12, TIM_CHANNEL_2);

But I don't see any PWM coming out.

Could someone point out what could be wrong?

thanks

1 REPLY 1
TDK
Guru

>  sConfigOC.Pulse = 0;

You have set up a 100% duty cycle PWM, which is a DC signal.

Change this to something between 0 and the Period value to get a square wave.

If you feel a post has answered your question, please click "Accept as Solution".