|
基于STM32f103x实现直流电机电流、速度双闭环控
要PID算法的朋友留邮箱哦!!!!!!!!!!!
stm32单片机部分源程序如下:
#include "led.h"
#include "delay.h"
#include "key.h"
#include "sys.h"
#include "usart.h"
#include "timer.h"
#include "UserConfiguration.h"
#include "UserFunction.h"
#include "lcd.h"
#include "exti.h"
#include "adc.h"
#include "PID_Current.h"
//PWM输出实验
u32 spd_now=0;
u32 set_spd=3300,set_vol=300,PwmOne_Set;
enum {flag_add,flag_minus,flag}FLAG_SPEED;
enum {flag_zheng,flag_fan,flag_stop}FLAG_DIR;
extern char s;
u32 adcx;
float av;
int main(void)
{
// u8 i=0,key;
delay_init(); //延时函数初始化
KEY_Init();
NVIC_Configuration(); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
uart_init(9600); //串口初始化为9600
LED_Init(); //LED端口初始化
Adc_Init(); //ADC初始化
TIM1_PWM_Init(4999,71);
EXTIX_Init();
LCD_Init();
POINT_COLOR=RED;
TIM3_Int_Init(9999,719);
FLAG_DIR=flag_zheng; //开始是正转
FLAG_SPEED=flag;
while(1)
{
Motor_A=PWM_A;
// UserPIDCurrentControl(set_vol) ;
av=adcx*3.3/4096;
LCD_ShowxNum(130,100,spd_now,8,16,0); //nowspd;时时速度
LCD_ShowxNum(130,130,set_spd,8,16,0); //设定速度
LCD_ShowxNum(130,160,3600,8,16,0); //电机最大速度
LCD_ShowxNum(130,190,adcx,8,16,0);
LCD_ShowxNum(130,230,av*1000,8,16,0);
LCD_ShowxNum(130,250,PwmOne_Set,8,16,0);
LCD_ShowString(50,160,100,12,16,"Max_Speed:");
LCD_ShowString(50,100,100,12,16,"Now_Speed:");
LCD_ShowString(50,130,100,12,16,"Set_Speed:");
LCD_ShowString(50,190,100,12,16,"ADC:");
LCD_ShowString(50,230,100,12,16,"Voltage:");
adcx=Get_Adc_Average(ADC_Channel_2,10000);
//按键设置标量速度
if(FLAG_SPEED==flag_add)
{
FLAG_SPEED=flag;
set_spd+=10; //加速
}
else if(FLAG_SPEED==flag_minus)
{
FLAG_SPEED=flag;
set_spd-=10; //减速
}
if(set_spd>=3600)
{
set_spd=3600;
}
if(set_spd<=0)
{
set_spd=0;
}
//按键设置跟随电流的大小
switch(KEY_Scan(1))
{
case KEY0_PRES: set_vol+=10; break;
case KEY1_PRES: set_vol-=10; break;
default: break;
}
if(set_vol>=1000)
{
set_vol=1000;
}
else if(set_vol<=0)
{
set_vol=0;
}
// delay_ms(10);
}
}
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|