PWM TIM15 CH2 CCR1/CCR2 STM32CUBEIDE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-01-04 12:03 PM
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
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:
Clock configuration:
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?
- Labels:
-
STM32CubeIDE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-01-04 12:13 PM - edited ‎2024-01-04 12:17 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-01-04 12:25 PM
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?
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-01-04 12:39 PM
CNT is changing
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-01-04 1:15 PM
Seems like an issue in how the servo is connected then, or other hardware issue with it. PC3 is free on that board.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-01-04 11:24 PM - edited ‎2024-01-04 11:28 PM
Read out and check/post relevant GPIO registers settings.
> PC3 is free on that board.
Why would we be talking about PC3?
JW
