Skip to main content
Associate
September 7, 2023
Question

How to change NUCLEO-G431KB PWM duty cycle

I use the PWM output example code of STM32CubeIDE,

how do I modify the duty cycle of the PWM, I can't find a way to modify it

This topic has been closed for replies.

8 replies

Stassen.C
ST Employee
September 7, 2023

Hello Jason,

You can simply change the PULSE_VALUE in the main.h

StassenC_0-1694078991632.png

Regards,
Stassen

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Jason_fxAuthor
Associate
September 8, 2023

Hi Stassen, 

Thanks for your reply.

But I have a question,

I find this code but I can't understand how to change the PULSE_VALUE,

example code is output PWM has a 90% duty cycle, if change 50% duty cycle how to set the PULSE_VALUE?

Associate II
September 8, 2023

hello @Jason_fx 

you can simply set "duty * counter-base-period" to "Compare Register" just like followings..

mxo_1-1694137721511.png

 where V_TIM_Cbase is defined in configration as below.

mxo_0-1694137571774.png

hope this could help

regards

Issamos
Super User
September 7, 2023

Hello @Jason_fx 

TIMx channels duty cycle = (TIMx_CCR1/ (TIMx_ARR + 1))*100.

top.PNG

You can change the values off TIMx_CCR1 and TIMx_ARR to modify the duty cycle value.

Best regards.

II