Skip to main content
VRapa
Associate II
June 20, 2020
Solved

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%)?

  • June 20, 2020
  • 3 replies
  • 1200 views

 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

This topic has been closed for replies.
Best answer by Tesla DeLorean

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.

3 replies

waclawek.jan
Super User
June 20, 2020

You mean, changing duty cycle?

That's changed by changing value of TIMx_CCRx.

Read the Timer chapter in Reference Manual.

JW

berendi
Principal
June 21, 2020

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
VRapaAuthor
Associate II
June 21, 2020

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

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
June 21, 2020

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 VenmoUp vote any posts that you find helpful, it shows what's working..