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.

1 ACCEPTED SOLUTION

Accepted Solutions

Read out and check/post content of TIM and relevant GPIO registers.

Make sure PB10 is connected to the header where you observe it, that there are no disconnected jumpers or solder bridges, and that there is no onboard resource connected to this pin - check this in the Nucleo's manual.

Try to set PB10 to GPIO and toggle it in a loop, with a delay. Even better, try to toggle it "manually" from debugger.

JW

View solution in original post

15 REPLIES 15

Read out and check/post content of TIM and relevant GPIO registers.

Make sure PB10 is connected to the header where you observe it, that there are no disconnected jumpers or solder bridges, and that there is no onboard resource connected to this pin - check this in the Nucleo's manual.

Try to set PB10 to GPIO and toggle it in a loop, with a delay. Even better, try to toggle it "manually" from debugger.

JW

SJose.11
Associate II

I checked it with toggling PB10 ,It was working fine. But for some reason PWM blink code is note working. I also tried debugging it and the the PWM timer was kept in if condition to check it with HAL_OK, and it was without any error.

if(HAL_TIM_PWM_Start(&htim2,HAL_TIM_ACTIVE_CHANNEL_3 )!=HAL_OK){

 Error_Handler();

 }

Read out and check/post content of TIM and relevant GPIO registers.

JW

Javier1
Principal

ST videos sometimes feel more like a powerpoint sales pitch than hands-on engineering learning material.

Try this video https://www.youtube.com/watch?v=rM7QonHkh2w&feature=emb_title

we dont need to firmware by ourselves, lets talk

0693W00000BcC1aQAF.png

0693W00000BcC3CQAV.pngThe timer registers seemed to be configured fine ,but the GPIOB10 ODR register is not toggling.

0693W00000BcCNNQA3.pngThis is the GPIOB register status.

TIM2_CR1.CEN=0, i.e. timer is not enabled, it is not running. You should also see TIM2_CNT changing, when you read in the TIM2 values repeatedly.

Also, TIM2_CCER=0, i.e. no output is enabled. But maybe because you stopped execution before calling the Cube/HAL function which would set it.

GPIO_ODR is irrelevant here; you want to have a look at GPIO_MODER and GPIO_AFR.

[EDIT] After reloading the thread I see that you've posted all GPIOB registers - MODER and AFR for PB10 look OK there.

JW

0693W00000BcHssQAF.pngI checked it and the timer is enabled and its also counting, but there is some problem with the GPIOB configuration I guess.