資源描述:
《基于pid算法的電機控制設計(dsp)》由會員上傳分享,免費在線閱讀,更多相關內容在行業(yè)資料-天天文庫。
1、基于PID算法的電機控制設計(DSP)#include"scancode.h"#include"ctr.h"#include"PID.h"#include//定時器分頻參數(shù)------------------------------------------------------------------#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();//主函數(shù)---------------------------------------------------------------------------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板//設置顯示參數(shù)和內容LCDSetDelay(1);//設置延時等待參數(shù)LCDSetScreenBuffer(nScreenBuffer);//顯示緩沖區(qū)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();//參數(shù)顯示SetForMotorB();//設置定時器等參數(shù)、啟動中斷while(1)//主循環(huán){if(nCount==0)//讀取鍵盤標志{nScanCode=port8001;//讀掃描碼nScanCode&=0x0ff;//低8位if(nScanCode!=0){uWork=port8002;//清除鍵盤緩沖區(qū)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,