cancel
Showing results for 
Search instead for 
Did you mean: 

How to generate PWM using STM32 Nucleo L433RC?

SJose.11
Associate II

I have followed the ST tutorial on how to genterate a 1Hz PWM using timer, but for some reason its not blinking.

I configured:

1)Clock configuration to 8Mhz

2)Set PWM genration channel 3

3)Set prescaler to 127

4)Set ARR to 62499

0693W00000Bc6snQAB.png5)Selected PWM mode 1 and made the pulse value to 31250

6)Finally I set the PINB10 to tim2_ch3 and connected it to an LED in a breadboard

In the main.c I have this HAL function to start the PWM

 HAL_TIM_PWM_Start(&htim2,HAL_TIM_ACTIVE_CHANNEL_3 );

Please help ,I have been with this for some time now. But still I am not getting the output.

15 REPLIES 15

In CCMR2, you have set CH3 for output compare, but in CCER you have set the enable bit for CH2.

JW

Thanks for your help.The issue was a bug in HAL function :

HAL_TIM_PWM_Start(&htim2,HAL_TIM_ACTIVE_CHANNEL_4 )

When I gave HAL_TIM_ACTIVE_CHANNEL_4 its taken as channel 3 and giving the correct output.0693W00000BcLuKQAV.png

I don't use Cube/CubeMX, but it appears that you are supposed to use TIM_CHANNEL_3 as a parameter there https://github.com/STMicroelectronics/STM32CubeL4/blob/5e1553e07706491bd11f4edd304e093b6e4b83a4/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_tim.c#L1420

JW

I used TIM_CHANNEL_3  , then Channel 2 was enabling. Then I changed to TIM_CHANNEL_4.

> I used TIM_CHANNEL_3 , then Channel 2 was enabling. Then I changed to TIM_CHANNEL_4.

No. You were using HAL_TIM_ACTIVE_CHANNEL_3 and then you've change it to HAL_TIM_ACTIVE_CHANNEL_4 . Those are different constants than TIM_CHANNEL_3 and TIM_CHANNEL_4.

JW

You are right. When I use TIM_CHANNEL_3 its working.

Thanks for your help.