cancel
Showing results for 
Search instead for 
Did you mean: 

I am usinng STM32H7 nucleo board. I want to generate 20KHz pwm wave. How can I control the resolution (that is a value from 0-10000 that corresponds to 0-100%)?

VRapa
Associate II

 So I adjusted the ARR and Prescalar values to adjust the pwm frequency(20KHz). Timer Clock is 200MHz

I want to change the resolution in the run time with a function. How can I change it?

Changing the ARR value will change the resolution?

Thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions

You change the CCRx for the CHannel of the TIM you are outputting too. ie TIM1->CCR2 = 5000; // 50/50 duty on a TIM where ARR=10000-1

You can have 4 PWM channels per TIM. They will share a common FREQUENCY.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

4 REPLIES 4

You mean, changing duty cycle?

That's changed by changing value of TIMx_CCRx.

Read the Timer chapter in Reference Manual.

JW

berendi
Principal

Changing ARR changes the resolution and the frequency at once.

Changing either ARR or CCRx presents a race condition unless you enable the corresponding preload flags.

VRapa
Associate II

Hey, Thanks for the quick response

  

I would like to change the duty cycle(0-100%) with a resolution of 0-10000. Please suggest which register to change in the run time

You change the CCRx for the CHannel of the TIM you are outputting too. ie TIM1->CCR2 = 5000; // 50/50 duty on a TIM where ARR=10000-1

You can have 4 PWM channels per TIM. They will share a common FREQUENCY.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..