Problem with PWM generation waveform in STM32

I’m having trouble with idle state for PWM generation .

I start a PWM output(using Timer3) on a STM32 Nucleo F303K8 board using HAL with:

HAL_TIM_PWM_Start_IT(&htim3, TIM_CHANNEL_1);

And I stop the PWM at an interrupt using HAL with:

HAL_TIM_PWM_Stop_IT(&htim3,TIM_CHANNEL_1);

enter image description here

But when the PWM is not pulsating it outputs around 2.4V as you see in the above snapshot. What would set it such that the PWM output would be zero instead of 2.4V?

Here is TIM 3 settings:

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 = 72-1;
  htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
  htim3.Init.Period = 655-1;
  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 = 327;
  sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
  sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
  if (HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN TIM3_Init 2 */

  /* USER CODE END TIM3_Init 2 */
  HAL_TIM_MspPostInit(&htim3);

}

enter image description here

enter image description here

Notes: I tried setting GPIO as pulldown but it didn’t make any difference. I also tried PWM2 mode that also didn’t help. And if I use advanced timer TIM 1 this issue doesn’t appear. But I already use TIM 1 for another PWM so I need to use general purpose timer.

Read more here: Source link