Skip to main content
Visitor II
September 7, 2023
Question

How to change NUCLEO-G431KB PWM duty cycle

  • September 7, 2023
  • 2 replies
  • 3021 views

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.

    2 replies

    ST Employee
    September 7, 2023

    Hello Jason,

    You can simply change the PULSE_VALUE in the main.h

    StassenC_0-1694078991632.png

    Regards,
    Stassen

    Jason_fxAuthor
    Visitor II
    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?

    Explorer
    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

    Graduate II
    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