Timer 4 of stm32 generates PWM

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

Using PB9 to generate PWM signal




1. Pin initialization


        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

GPIO_Init(GPIOB, &GPIO_InitStructure);


2. Timer initialization


void TIM4_Config(void)

 // GPIO_InitTypeDef GPIO_InitStructure;

TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;

TIM_OCInitTypeDef  TIM_OCInitStructure;

 

TIM_DeInit(TIM4);

// ƵÂÊ30K

//Õ¼¿Õ±È50%

 // TIM_TimeBaseStructure.TIM_Period = 100-1; 

//TIM_TimeBaseStructure.TIM_Prescaler =24-1;

// ƵÂÊ20K

//Õ¼¿Õ±È50%

// TIM_TimeBaseStructure.TIM_Period = 100-1; 

// TIM_TimeBaseStructure.TIM_Prescaler =36-1;

// ƵÂÊ10K

//Õ¼¿Õ±È50%

//TIM_TimeBaseStructure.TIM_Period = 100-1; 

//TIM_TimeBaseStructure.TIM_Prescaler =72-1;

// ƵÂÊ1K

 

TIM_TimeBaseStructure.TIM_Period = 1000-1; 

TIM_TimeBaseStructure.TIM_Prescaler =72-1;

TIM_TimeBaseStructure.TIM_ClockDivision = 0;

 

TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

 

TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);

 

 

TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;

 

TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;

 

TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;

 

 

//TIM_OCInitStructure.TIM_Pulse = 100;

TIM_OCInitStructure.TIM_Pulse = Optical_Source_Duty;

 

 

//

// TIM_OC3Init(TIM4, &TIM_OCInitStructure);

 

// TIM_OC3PreloadConfig(TIM4, TIM_OCPreload_Enable);

TIM_OC4Init(TIM4, &TIM_OCInitStructure);

 

TIM_OC4PreloadConfig(TIM4, TIM_OCPreload_Enable);

 

TIM_CtrlPWMOutputs(TIM4,ENABLE);

 

TIM_ARRPreloadConfig(TIM4, ENABLE);

 

TIM_Cmd(TIM4, ENABLE);

 

 

}


Keywords:stm32 Reference address:Timer 4 of stm32 generates PWM

Previous article:STM32F407ZGT6 realizes input capture of RX1002 eight-channel PWM signal
Next article:stm32 PWM output based on TIM1 timer

Recommended ReadingLatest update time:2024-11-16 15:28

STM32 DMA example
DMA Introduction: DMA (Direct Memory Access) is a data access method that can reduce the workload of the CPU and is now widely used. While transmitting data, the CPU can do other things, such as data calculations or responding to interrupts, etc. DMA relieves the CPU of a lot of workload! DMA work analysis:  
[Microcontroller]
STM32 DMA example
STM32F411RE Nucleo Notes - Key Control PWM Duty Cycle
This time, the STM32F411RENucleo development board was used, and Keil MDK5.12 and STM32CubeMx software were used. First, use the STM32CubeMx software to configure the timer PWM mode and key input IO port. Figure 1 PWM configuration Figure 2 Button IO port configuration Then generate the Keil project. Open with Kei
[Microcontroller]
STM32F411RE Nucleo Notes - Key Control PWM Duty Cycle
STM32 protects the program by reading the unique ID number of the chip to prevent plagiarism
1、 STM32 Experiment Serial 4: Read the unique ID number of the chip  ---- http://blog.sina.com.cn/s/blog_b1ed84120101fmlo.html 2. Read chip ID and chip Flash Size ---- https://www.cnblogs.com/zyqgold/p/3378993.html 3. STM32 read chip ID number---- https://download.csdn.net/download/jonahan001/5342889 4. How to rea
[Microcontroller]
STM32 protects the program by reading the unique ID number of the chip to prevent plagiarism
STM32 learning six
EXTI key interrupt:  EXTI interrupt:   Note:    1. EXTI interrupt is an external interrupt, and related interrupt management devices need to be configured.    2. If it is an event interrupt, there is no need to configure and manage this register.    3. Pay special attention to this relationship: the relationship b
[Microcontroller]
About STC8A series MCU 10-bit PWM, changing duty cycle operation
#include pwm.h unsigned int Set_PWM; //10-bit duty cycle pre-stored variable 0-1023 void PWM_Init(void) {   CCON = 0x00;   CMOD = 0x08; //PCA clock is the system clock   CL = 0x00; // PCA counter initial value low 8 bits   CH = 0x00; //PCA counter initial value high 8 bits   CCAPM0 = 0x42; //PCA module 0 is PWM wo
[Microcontroller]
STM32-GPIO data collection and summary
1. GPIO Configuration (1) GPIO_Mode_AIN analog input         (2) GPIO_Mode_IN_FLOATING floating input (3) GPIO_Mode_IPD pull-down input (4) GPIO_Mode_IPU pull-up input (5) GPIO_Mode_Out_OD open drain output (6) GPIO_Mode_Out_PP push-pull output (7) GPIO_Mode_AF_OD multiplexed open-drain output (8) GPIO
[Microcontroller]
[STM32 Notes] RCC configuration function
void RCC_Configuration(void) {        ErrorStatus HSEStartUpStatus;        //Enable external crystal oscillator        RCC_HSEConfig(RCC_HSE_ON);        //Wait for external crystal oscillator to stabilize        HSEStartUpStatus = RCC_WaitForHSEStartUp();        //If the external crystal oscillator starts succ
[Microcontroller]
Simulation Study on Carrier PWM Control Method of Multilevel Inverter
Abstract: The carrier PWM control methods of multi-level inverters are discussed and their principles are introduced. In order to compare their control effects, a simulation study is carried out using Matlab software. Finally, based on the simulation results and analysis, conclusions are drawn and suggestions for
[Power Management]
Simulation Study on Carrier PWM Control Method of Multilevel Inverter
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号