Skip to main content
Rjain.11
Associate
May 18, 2020
Question

Pwm generation

  • May 18, 2020
  • 3 replies
  • 1540 views

Hi 

I am trying to generate pwm on the stm32f411re using LL drivers . i am using a Vnh2spa30 motor driver, i am using the setcompare() and generateupdate() commands. I am trying to use the Timer2 ch1 on pa15. I have configured the timer to internal clock. I am using a prescalar of 8399 and ARR of 99. my main problem is that no matter what argument i pass (except 0) in the setcompare() my motor runs on full speed, unless i put a delay, the bigger the delay is the slower the motor rotates

i cant figure out where i am going wrong

This topic has been closed for replies.

3 replies

TDK
Super User
May 18, 2020

Post the code you're using to initialize the motors.

LL_TIM_OC_SetCompareCH1() and similar should change the PWM. Since your ARR=99, putting this anywhere from 0 to 100 should vary the duty cycle accordingly.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Rjain.11
Rjain.11Author
Associate
May 18, 2020

hi thank you for the reply

 LL_TIM_OC_SetCompareCH1(TIM2, 10); //set the new value for the duty cycle

 LL_TIM_GenerateEvent_UPDATE(TIM2);

  LL_GPIO_SetOutputPin(GPIOC,LL_GPIO_PIN_10); //INA motor1

  LL_GPIO_ResetOutputPin(GPIOC,LL_GPIO_PIN_11);// INB motor 1

this is what i am using

Rjain.11
Rjain.11Author
Associate
May 18, 2020

but no matter what value i put for X.....  LL_TIM_OC_SetCompareCH1(TIM2, x);.... the pwm is always at 100%duty cycle

Laurent Ca...
Senior III
October 14, 2020

Dear @Rjain.1​ 

Do you have still this problem to solve?

Best regards

Laurent Ca...

Laurent Ca...
Senior III
October 20, 2020

Dear @Rjain.1​ 

I guess you don't have to solve this problem anymore, therefore I consider this thread closed.

If not, feel free to reopen it by posting a new answer.

Best regards

Laurent Ca...