cancel
Showing results for 
Search instead for 
Did you mean: 

Pwm generation

Rjain.11
Associate II

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

5 REPLIES 5
TDK
Guru

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".

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

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...
Lead II

Dear @Rjain.1​ 

Do you have still this problem to solve?

Best regards

Laurent Ca...

Laurent Ca...
Lead II

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...