cancel
Showing results for 
Search instead for 
Did you mean: 

PWM TIM15 CH2 CCR1/CCR2 STM32CUBEIDE

grzeniux
Associate II

Hello guys

My microcontroller is: STM32L432KCU6 - nucleo board

I have a problem with PWM. I need to change TIM16 to TIM15 because TIM16 collides with I2C

conflict.jpg

So thats why I have to use TIM15... I need him to handle micro servo. When i use TIM16, everything works, the pulses and the duty cycle are correct, but when i use TIM15, unfortunately the duty cycle is still 0 

TIMx configurations:

tiim.png

Clock configuration:

clock.jpg

 

jadupce.png

 

There is a code that i use to handle micro servo, for TIM16 it works

int main(void)
{
  /* USER CODE BEGIN 1 */
  /* USER CODE END 1 */
  /* MCU Configuration--------------------------------------------------------*/
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
  /* USER CODE BEGIN Init */
  /* USER CODE END Init */
  /* Configure the system clock */
  SystemClock_Config();
  /* USER CODE BEGIN SysInit */
  /* USER CODE END SysInit */
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_TIM16_Init();
  MX_TIM15_Init();
  /* USER CODE BEGIN 2 */
 
  HAL_TIM_PWM_Start(&htim16, TIM_CHANNEL_1);
  HAL_TIM_PWM_Start(&htim15, TIM_CHANNEL_2);
 
  /* USER CODE END 2 */
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
 
 
// TIM 16 #######################
  htim16.Instance->CCR1 = 25; // 0 stopni
  HAL_Delay(2000);
   htim16.Instance->CCR1 = 50; // 45 stopni
   HAL_Delay(2000);
   htim16.Instance->CCR1 = 75; // 90 stopni
   HAL_Delay(2000);
   htim16.Instance->CCR1 = 110; // 153 stopnie
   HAL_Delay(2000);
   htim16.Instance->CCR1 = 125; // 180 stopni
   HAL_Delay(5000);
 
 
// TIM 15 #######################
  htim15.Instance->CCR2 = 25; // 0 stopni
  HAL_Delay(2000);
   htim15.Instance->CCR2 = 50; // 45 stopni
  HAL_Delay(2000);
   htim15.Instance->CCR2 = 75; // 90 stopni
   HAL_Delay(2000);
   htim15.Instance->CCR2 = 110; // 153 stopnie
   HAL_Delay(2000);
   htim15.Instance->CCR2 = 125; // 180 stopni
   HAL_Delay(5000);
 
 
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

 

Is anyone know what going on?

 

 

5 REPLIES 5
TDK
Guru

Your code doesn't output a TIM15 PWM signal until 13 seconds in. Are you waiting that long? Consider modifying TIM15 and TIM16 duty cycle at the same time.

Debug code, verify that TIM15->CNT is changing and that TIM15->CCR2 is updating appropriately.

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

At 80 MHz to get the TIM at 50 KHz you'd need a prescaler of 1600-1 not 1597

Although having a broader ARR of 20000-1 would give a lot finer resolution

Not showing initialization code, or pin configuration

Any conflicts on the pins used? Solder Bridge options, actually get to pin headers?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

 

 

CNT is changing 

cnt.jpg

 

I discovered that when I power the device via external power then duty cycle = 0%, and when I disconnect it and leave the micro usb I have duty cycle = correct

I have no idea where I might have a short circuit or something

supply.png

Seems like an issue in how the servo is connected then, or other hardware issue with it. PC3 is free on that board.

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

Read out and check/post relevant GPIO registers settings.

> PC3 is free on that board.

Why would we be talking about PC3?

JW