Skip to main content
VRapa
Associate II
Jun 20, 2020 7:19 PM UTC
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%)?

 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.
Tesla DeLorean
Tesla DeLoreanBest answer
Guru
Jun 21, 2020 6:13 PM UTC

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..

4 replies

waclawek.jan
Super User
Jun 20, 2020 7:46 PM UTC

You mean, changing duty cycle?

That's changed by changing value of TIMx_CCRx.

Read the Timer chapter in Reference Manual.

JW

berendi
Principal
Jun 21, 2020 6:48 AM UTC

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
Jun 21, 2020 5:33 PM UTC

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
Jun 21, 2020 6:13 PM UTC

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..