|
如題,基于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
2019-10-30 17:42 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
350.95 KB, 下載次數: 150, 下載積分: 黑幣 -5
PID調速
評分
-
查看全部評分
|