How to solve the frequency of pwm generated by Stm32?

Publisher:老王古玩店Latest update time:2018-06-28 Source: eefocusKeywords:Stm32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Question one:

//TIM2 pre-scaling setting: 1MHZ, APB1 division factor 2, input to TIM3 clock is 36MHzx2 = 72MHz  

TIM_PrescalerConfig(TIM2,71, TIM_PSCReloadMode_Immediate);

 

void TIM_PrescalerConfig(TIM_TypeDef* TIMx, uint16_t Prescaler, uint16_t TIM_PSCReloadMode)

{

  /* Check the parameters */

  assert_param(IS_TIM_ALL_PERIPH(TIMx));

  assert_param(IS_TIM_PRESCALER_RELOAD(TIM_PSCReloadMode));

  /* Set the Prescaler value */

  TIMx->PSC = Prescaler;

  /* Set or reset the UG Bit */

  TIMx->EGR = TIM_PSCReloadMode;

}


When set to change immediately, that is, UG is set to 1, an update event is generated immediately and the frequency division coefficient changes.

The previous statement is equivalent to

TIM_TimeBaseStructure.TIM_Prescaler = 71;

At this time, the counting frequency of CNT is 1MHZ

 

Question 2:

TIM_TimeBaseStructure.TIM_Period = 1000;  //1KHz

The above statement sets the auto-reload value to 999, which is the ARR value.

After this statement, the frequency of pwm is 1kHz

How to calculate it? It is very simple, 1M/1000 = 1kHz

One cycle of PWM is when the counter counts from 0 to ARR, that is, it takes 1000 times to complete one cycle.

 

Question 3:

 uint16_t TIM_Pulse;         /*!< Specifies the pulse value to be loaded into the Capture Compare Register.

                                   This parameter can be a number between 0x0000 and 0xFFFF */

 

Equivalent to

void TIM_SetCompare2(TIM_TypeDef* TIMx, uint16_t Compare2)

Both set the value of the CCR register


Keywords:Stm32 Reference address:How to solve the frequency of pwm generated by Stm32?

Previous article:STM32F407ZET6 Detailed explanation on using PWM (making breathing light)
Next article:STM32F407 advanced timer dead zone complementary PWM (operation register)

Recommended ReadingLatest update time:2024-11-25 13:22

ARM Learning "Seven" - A brief discussion on STM32 interrupt settings
Regarding interrupt settings, I couldn't find any description of NVIC-related registers in the PDF document of STM32. I don't know why. Is it to make people confused? Or is it pretending to be profound? I really don't understand. Finally, I found the NVIC-related registers in the book "Cortex-M3 Definitive Guide". This
[Microcontroller]
ARM Learning
The startup code of STM32 learning is very important!
I'm writing a human-machine interface recently. Due to the layout problem of my hardware colleagues, I have to use serial port 4. At first I thought it was nothing, just changing USART1 to 4 and turning on the clock and configuring the pins. But it turns out that my idea is stupid. After 2 days of debugging, UART4 s
[Microcontroller]
STM32 input capture mode setting and receiving data using DMA
Reference: STM32 PWM input mode setting and receiving data using DMA Input capture mode The input stage samples the corresponding TIx input to generate a filtered signal TIxF. Then, an edge detector with polarity selection generates a signal (TIxFPx) which can be used as trigger input by the slave mode control
[Microcontroller]
STM32 input capture mode setting and receiving data using DMA
Configuration and use of GPIO in STM32
In fact, the first thing to be familiar with when learning microcontrollers is the operation of the I/O port. The GPIO of STM32 is also easy to understand, with only 8 modes. Just understand which function uses which mode and how to configure it. Without further ado, let's learn about the GPIO port. Everyone should ha
[Microcontroller]
Based on STM32 serial port ring buffer queue processing mechanism - entry level (single byte)
1.1 Experimental Introduction   The simplest serial port data processing mechanism is to receive data and send it back as is: successfully receive a number, trigger an interrupt, read the data in the interrupt function, and then immediately. This data processing mechanism is a "non-buffered interrupt mode". Althou
[Microcontroller]
Based on STM32 serial port ring buffer queue processing mechanism - entry level (single byte)
How to control the brightness of LED using PWM in ARM7-LPC2148 microcontroller
As we all know, microcontrollers take analog inputs from analog sensors and process these signals using ADC (Analog-to-Digital Converter). But what if the microcontroller wants to generate analog signals to control analog operating devices such as servo motors, DC motors, etc.? Microcontrollers do not generate output
[Microcontroller]
How to control the brightness of LED using PWM in ARM7-LPC2148 microcontroller
STM32 code debugging on RAM in Keil MDK environment
I haven't touched Keil since 51. I started using Keil MDK again yesterday afternoon, but this time it's for ARM. The STM32W108 debugging in the past few days was all done on IAR. I just debugged a routine on STM32F103ZE-EK, and found that there is a way to configure code debugging in RAM. I knew there was an iar-cfg.i
[Microcontroller]
Design and application of CAN bus repeater based on STM32
Introduction CAN bus is a multi-master serial communication bus with excellent stability, real-time performance, remote communication capability, and super hardware CRC error correction. The application of CAN bus technology is no longer limited to the automotive industry, but has expanded to the machinery, text
[Microcontroller]
Design and application of CAN bus repeater based on STM32
Latest Microcontroller Articles
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号