|
如题,基于STM32F407ZGT6的单片机在原子例程的基础上改动,用PID算法对减速器电机进行调速,通过匿名上位机软件传输PID的数据,在电脑上将电机速度数据可视化,并且还能通过串口实时查看数据的变化。下面是部分源码:
#include "stm32f4xx.h"
#include "usart.h"
#include "delay.h"
#include "sys.h"
#include "led.h"
#include "Motor_PWM.h"
#include "Motor_PID.h"
#include "Motor_Control.h"
#include "timer.h"
#include "NiMing.h"
#include "lcd.h"
#include "exti.h"
extern u8 TimerFlag;
extern int Motor_R_Distan;
extern int Motor_R_Speed;
extern PID_TypeDef PID_MOTOR_R;
int main(void)
{
u32 t=0;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
uart_init(115200);
delay_init(84);
LED_Init();
LCD_Init();
EXTIX_Init();
Motor_Gpio_Init();
Motor_PWM_Init();
TIM3_Int_Init(1000-1,8400-1);
PID_Init(&PID_MOTOR_R);
while(1)
{
printf("t:%d\r\n",t);
printf("Speed:%d\r\n",Motor_R_Speed);
delay_ms(50);
t++;
motorCon();
}
}
/*
void Delay(__IO uint32_t nCount);
void Delay(__IO uint32_t nCount)
{
while(nCount--){}
}
int main(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOF, &GPIO_InitStructure);
while(1){
GPIO_SetBits(GPIOF,GPIO_Pin_9|GPIO_Pin_10);
Delay(0x7FFFFF);
GPIO_ResetBits(GPIOF,GPIO_Pin_9|GPIO_Pin_10);
Delay(0x7FFFFF);
}
}
*/
|
-
-
PID电机.7z
350.95 KB, 下载次数: 150, 下载积分: 黑币 -5
PID调速
评分
-
查看全部评分
|