当前位置:网站首页>STM32 general timer output PWM control steering gear
STM32 general timer output PWM control steering gear
2022-07-03 09:55:00 【Fake iron man】
stm32 The general timers are TIM2、TIM3、TIM4、TIM5, Each timer has four independent channels that can be used as : Input capture 、 Output comparison 、PWM Output 、 Single pulse mode output, etc .stm32 In addition to the basic timer , Other timers can output PWM.PWM It is commonly used to control steering gear and motor . I learned it today stm32 How to output the general timer of single chip microcomputer PWM Control of steering gear , It is summarized as follows :
Step summary :
To configure GPIO Structure ( here GPIO It is a pin with multiplexing function )-> Configure the general timer structure -> Configure timer output PWM Structure -> Enable preload register -> Enable timer -> To configure PWM It's worth -> Control of steering gear
ServoMotor.c:
#include "stm32f10x.h"
#include "ServoMotor.h"
void ServoMotor_Config(void)
{
GPIO_InitTypeDef GPIO_MOTORInitStructure;
TIM_TimeBaseInitTypeDef Tim_MOTORInitStructure;
TIM_OCInitTypeDef Time_PWMInitStructure;
// Turn on the clock
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
// Partial remapping
GPIO_PinRemapConfig(GPIO_PartialRemap_TIM3,ENABLE);
// To configure GPIO Structure
GPIO_MOTORInitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_MOTORInitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_MOTORInitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIO_MOTORInitStructure);
// Configure the general timer structure
Tim_MOTORInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
Tim_MOTORInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
Tim_MOTORInitStructure.TIM_Period = 200-1;
Tim_MOTORInitStructure.TIM_Prescaler = 7200-1;
TIM_TimeBaseInit(TIM3,&Tim_MOTORInitStructure);
// Configure timer output PWM Structure
Time_PWMInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
Time_PWMInitStructure.TIM_OutputState = TIM_OutputState_Enable;
Time_PWMInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM_OC2Init(TIM3,&Time_PWMInitStructure);
// Enable preload register
TIM_OC2PreloadConfig(TIM3,TIM_OCPreload_Enable);
// Enable timer
TIM_Cmd(TIM3,ENABLE);
}main.c:
#include "stm32f10x.h"
#include "ServoMotor.h"
void delay(uint16_t time)
{
uint16_t i = 0;
while(time -- )
{
i = 12000;
while(i -- );
}
}
int main(void)
{
ServoMotor_Config();
uint16_t pwm = 155;
while(1)
{
for(pwm = 195; pwm >=175; pwm-=5)
{
TIM_SetCompare2(TIM3,pwm);
delay(500);
}
}
}If there is a mistake , Please criticize and correct me
边栏推荐
- Exception handling of arm
- 03 FastJson 解决循环引用
- SSB Introduction (PbCH and DMRs need to be supplemented)
- STM32 serial port usart1 routine
- 对于新入行的同学,如果你完全没有接触单片机,建议51单片机入门
- Oracle database SQL statement execution plan, statement tracking and optimization instance
- Oracle数据库 SQL语句执行计划、语句跟踪与优化实例
- MYSQL数据库底层基础专栏
- Seven sorting of ten thousand words by hand (code + dynamic diagram demonstration)
- NR PUCCH format0 sequence generation and detection mechanism
猜你喜欢

SSB Introduction (PbCH and DMRs need to be supplemented)

嵌入式本来就很坑,相对于互联网来说那个坑多得简直是难走

Oracle数据库 SQL语句执行计划、语句跟踪与优化实例

Fundamentals of Electronic Technology (III)_ Chapter 2 principle of amplification circuit__ Crystal triode and field effect triode

03 FastJson 解决循环引用
![[CSDN]C1训练题解析_第二部分_Web基础](/img/91/72cdea3eb3f61315595330d2c9016d.png)
[CSDN]C1训练题解析_第二部分_Web基础
![顺利毕业[3]-博客系统 更新中。。。](/img/91/72cdea3eb3f61315595330d2c9016d.png)
顺利毕业[3]-博客系统 更新中。。。

Embedded systems are inherently flawed. Compared with the Internet, there are so many holes that it is simply difficult to walk away from
![[Li Kou brush question notes (II)] special skills, module breakthroughs, classification and summary of 45 classic questions, and refinement in continuous consolidation](/img/06/7fd985faf8806ceface3864d4b3180.png)
[Li Kou brush question notes (II)] special skills, module breakthroughs, classification and summary of 45 classic questions, and refinement in continuous consolidation
![Successful graduation [3]- blog system update...](/img/91/72cdea3eb3f61315595330d2c9016d.png)
Successful graduation [3]- blog system update...
随机推荐
Project scope management__ Scope management plan and scope specification
Epoll read / write mode in LT and et modes
Successful graduation [2] - student health management system function development...
Nodemcu-esp8266 development (vscode+platformio+arduino framework): Part 4 --blinker_ DHT_ WiFi (lighting technology app control + temperature and humidity data app display)
顺利毕业[3]-博客系统 更新中。。。
C language enumeration type
在三线城市、在县城,很难毕业就拿到10K
The cyclic shift of PUCCH in NR channel is generated by MATLAB
Shell logic case
MySQL的简单使用(增删改查)
numpy. Reshape() and resize() functions
新系列单片机还延续了STM32产品家族的低电压和节能两大优势
要選擇那種語言為單片機編寫程序呢
Project cost management__ Topic of comprehensive calculation
Runtime.getRuntime().gc() 和 Runtime.getRuntime().runFinalization() 的区别
MySQL data manipulation language DML common commands
[Li Kou brush question notes (II)] special skills, module breakthroughs, classification and summary of 45 classic questions, and refinement in continuous consolidation
Mysql database underlying foundation column
Fundamentals of Electronic Technology (III)_ Integrated operational amplifier and its application__ Basic arithmetic circuit
Learn the contents of 5g toolbox supporting NR through the NR resources provided by MATLAB