cancel
Showing results for 
Search instead for 
Did you mean: 

I'm using a STM32F429I discovery with HAL drivers. Is there a sample code showing how to change the duty cycle of a timer working in PWM output mode at run-time? Thanks, Piero

Hicss.2033
Associate III
 
1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

You can just change the CCRx register directly. I don't think HAL has a function for doing only this. Pretty sure the LL library does.

For 50% duty:

TIMx->CCRx = (TIMx->ARR + 1) / 2;

For 25%/75% duty:

TIMx->CCRx = (TIMx->ARR + 1) / 4;

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

4 REPLIES 4
TDK
Guru

You can just change the CCRx register directly. I don't think HAL has a function for doing only this. Pretty sure the LL library does.

For 50% duty:

TIMx->CCRx = (TIMx->ARR + 1) / 2;

For 25%/75% duty:

TIMx->CCRx = (TIMx->ARR + 1) / 4;

If you feel a post has answered your question, please click "Accept as Solution".

thanks for your answer, it works!!

I've find the solution in the following reply. Thanks for your support.