How to set the frequency and duty cycle of PWM in STM32? See here

Publisher:DreamySunsetLatest update time:2018-11-20 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The following is the timer logic diagram of STM32 , which helps to understand:


1.jpg


TIM3's ARR register and PSC register,


Determine the PWM frequency.


The two timers configured here determine the frequency of PWM. My understanding is that the period (frequency) of PWM is the multiplication of the ARR register value and the PSC register value, but it is not a simple multiplication. For example, to set the frequency of PWM, refer to the algorithm for setting the overflow time in the last general timer. For example, to output PWM with a frequency of 100HZ, first determine the clock of TIMx. Unless the clock division number of APB1 is set to 1, the clock of the general timer TIMx is twice the clock of APB1. At this time, the clock of TIMx is The value is 72MHz. Divide the TIMx clock 72MHz by (PSC+1) to get the timer increment every few seconds. Here, assign 7199 to PSC, and calculate that the timer increments every 0.0001 seconds, that is, the frequency is 10KHz. Multiply this value by (ARR+1) to get the PWM frequency. If the ARR value is 0, that is, 0.0001*(0+1), the output PWM frequency is 10KHz. If the output frequency is 100Hz PWM, set the ARR register to 99. If you want to adjust the PWM duty cycle accuracy, just reduce the value of the PSC register.


The TIMx_CCRx register determines the PWM duty cycle.


TIMx_CCR1-TIMx_CCR4 determine the duty cycle of the four PWM channels CH1-CH4 of the timer. Simply assign a value of 0-65535 to this register to determine the duty cycle. Duty cycle calculation method: The value of TIMx_CCRx divided by the value of the ARR register is the duty cycle. Because the duty cycle is between 0-100%, the value of the TIMx_CCRx register cannot exceed the value of the ARR register, otherwise it may cause the accuracy of the PWM frequency or duty cycle.


Keywords:STM32 Reference address:How to set the frequency and duty cycle of PWM in STM32? See here

Previous article:Newbie benefits! Detailed explanation of uCGUI transplantation for STM32 learning
Next article:Before learning ARM, you need to know these

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号