当前位置:网站首页>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
边栏推荐
- 端午节快乐!—— canvas写的粽子~~~~~
- 编程思想比任何都重要,不是比谁多会用几个函数而是比程序的理解
- PRACH --- originator
- UCI and data multiplexing are transmitted on Pusch (Part VI) -- LDPC coding
- Oracle数据库 SQL语句执行计划、语句跟踪与优化实例
- 2.Elment Ui 日期选择器 格式化问题
- An executable binary file contains more than machine instructions
- Learn the contents of 5g toolbox supporting NR through the NR resources provided by MATLAB
- Basic knowledge of MySQL database (an introduction to systematization)
- 当你需要使用STM32某些功能,而51实现不了时, 那32自然不需要学
猜你喜欢

Windows下MySQL的安装和删除

STM32 serial communication principle

【男保姆式】教你打开第一个微信小程序

MySQL Data Definition Language DDL common commands

Runtime. getRuntime(). GC () and runtime getRuntime(). The difference between runfinalization()

没有多少人能够最终把自己的兴趣带到大学毕业上

Schematic diagram and connection method of six pin self-locking switch

STM32 interrupt priority management

The cyclic shift of PUCCH in NR channel is generated by MATLAB

Exception handling of arm
随机推荐
byte alignment
Electronic product design, MCU development, circuit cloning
How does the nr-prach receiver detect the relationship between prembleid and Ta
2020-08-23
01仿B站项目业务架构
Electronic product design
自动装箱与拆箱了解吗?原理是什么?
SSB Introduction (PbCH and DMRs need to be supplemented)
[untitled] proteus simulation of traffic lights based on 89C51 Single Chip Microcomputer
Happy Dragon Boat Festival—— Zongzi written by canvas~~~~~
STM32 port multiplexing and remapping
Project scope management__ Scope management plan and scope specification
(1) 什么是Lambda表达式
Nr-prach: access scenario and access process
STM32 external interrupt experiment
Project cost management__ Topic of comprehensive calculation
[Li Kou brush question notes (II)] special skills, module breakthroughs, classification and summary of 45 classic questions, and refinement in continuous consolidation
[CSDN]C1训练题解析_第二部分_Web基础
Project cost management__ Cost management technology__ Article 7 completion performance index (tcpi)
2021-09-26