资源描述:
《基于pid算法的电机控制设计(dsp)》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、基于PID算法的电机控制设计(DSP)#include"scancode.h"#include"ctr.h"#include"PID.h"#include//定时器分频参数------------------------------------------------------------------#defineT10099//100个时钟周期中断一次#defineT2Hz20000//20000个时钟周期读取速度一次//工作变量--------------------------------------------------------------------
2、-----unsignedintuWork,uN,nCount,nCount1,nCount2,nCount3;intnSSS,nJSSpeed,pwm;intmd,wc;floata=0.6f,b=0.2f,c=0.1f,duk;intek,ek1,ek2,tz;intnInput;voidPrintParameters();//主函数---------------------------------------------------------------------------main(){unsignedintnScanCode;unsignedcharcKey;intspe
3、ed[100],sp,lj;floatljh;charstrInput[4];inti,w1,w2,w3;//初始化工作变量for(sp=0;sp<100;sp++)speed[sp]=0;sp=nSSS=nCount=nCount1=nCount2=nJSSpeed=0;cKey=0;nInput=tz=wc=0;ek=ek1=ek2=0;for(uWork=0;uWork<4;uWork++)strInput[uWork]=0;uN=100;md=83;pwm=0;InitDSPBoard();//初始化ICETEK-VC5416-A板InitCTR();//初始化ICETEK-C
4、TR板//设置显示参数和内容LCDSetDelay(1);//设置延时等待参数LCDSetScreenBuffer(nScreenBuffer);//显示缓冲区LCDTurnOn();//打开显示LCDCLS();//清除显示内存LCDPutCString(str1,0,63,8,0);LCDPutCString(str2,0,47,2,1);LCDPutCString(str3,68,47,2,1);LCDPutCString(str6,0,31,2,1);LCDPutCString(str5,68,31,2,1);LCDPutCString(str7,0,15,3,1);LCDPu
5、tCString(str4,68,15,2,1);ShowParameters();//参数显示SetForMotorB();//设置定时器等参数、启动中断while(1)//主循环{if(nCount==0)//读取键盘标志{nScanCode=port8001;//读扫描码nScanCode&=0x0ff;//低8位if(nScanCode!=0){uWork=port8002;//清除键盘缓冲区if(nScanCode==SCANCODE_Num)break;//NUM键退出else{if(nScanCode==SCANCODE_Enter)//按回车键输入速度{uWork=st
6、rInput[0]*10+strInput[1];//计算调整速度md=uWork;for(uWork=0;uWork<2;uWork++)strInput[uWork]=0;nInput=0;LCDPutString(numbers,104,15,1,1);LCDPutString(numbers,112,15,1,1);LCDPutString(numbers,120,15,1,1);LCDRefreshScreen();PrintParameters();}else{cKey=ConvertScanToChar(nScanCode);if(cKey>='0'&&cKey<='9'
7、)//输入速度值{strInput[nInput]=cKey-'0';nInput++;if(nInput>=2)nInput=0;uWork=strInput[0]*10+strInput[1];//计算调整速度w1=uWork%1000/100;w2=uWork%100/10;w3=uWork%10;LCDPutString(numbers+w1*8,104,15,1,1);LCDPutString(numbers+w2*8,112,15,