cancel
Showing results for 
Search instead for 
Did you mean: 

TIM2 PWM Output goes to zero unexpectedly

Eric5
Visitor

I am using the STM32F207ZG MCU, and I started a new project in STM32CubeIDE. I wrote the following code, which changes the state of TIM2 PWM output CH1:

 

 /* USER CODE BEGIN 2 */

  HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1);
  HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);


  TIM2->ARR = 48000;
  TIM2->CCR1 = 16000;

  HAL_Delay(3000);

  TIM2->CCR1 = 3200;

  HAL_Delay(3000);

  TIM2->ARR = 8000;


  /* USER CODE END 2 */

 

 

I expected the last line (TIM2->ARR = 8000) affect the period of the PWM output but not change the pulse width. However, after the last line executes, the PWM output goes to zero on my oscilloscope. Is this expected behavior?

If I use TIM3, the behavior is as I would expect.

 

Below are some screenshots of my configuration in the .ioc file:

Eric5_0-1724102789980.png

Eric5_1-1724102821067.png

 

 

1 REPLY 1
gbm
Lead III

Set the timer clock source to Internal clock. Set the preload option for ARR and timer channel. Set the initial period to the desired value in timer config tab, before starting the timer. Note that TIM2 is a 32-bit timer, so its initial period is over 4 billion ticks.