1.什么是PID?
PID知识学习指南:
https://www.bilibili.com/video/BV1Ds411t7Hr
2.为什么要用PID来对电机进行控制?
https://www.zhihu.com/question/353181256/answer/883991821
3.PWM输出配置
通过以上两个链接的学习,我们知道了使用PID对电机速度进行控制,就是通过调节PWM方波的占空比来对电机的速度进行调节。接下来我们就介绍PWM输出是如何配置的。
void TIM8_PWM_Init(u32 arr,u32 psc)//运用TIM8输出PWM方波
{
GPIO_InitTypeDef GPIO_InitStructure; //定义初始化GPIO口的结构体
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8,ENABLE); //TIM8时钟使能
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); //使能PORTC时钟
GPIO_PinAFConfig(GPIOC,GPIO_PinSource8,GPIO_AF_TIM8); //GPIOF8复用为定时器
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; //GPIOF8
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //复用功能
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; //速度100MHz
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //推挽复用输出
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //上拉
GPIO_Init(GPIOC,&GPIO_InitStructure); //初始化PF8
TIM_TimeBaseStructure.TIM_Prescaler=psc; //定时器分频 初始化定时器的时基单元
TIM_TimeBaseStruct

最低0.47元/天 解锁文章
5万+

被折叠的 条评论
为什么被折叠?



