DDC單回路PID閉環(huán)控制系統(tǒng)的設計及實時仿真課程設計_第1頁
DDC單回路PID閉環(huán)控制系統(tǒng)的設計及實時仿真課程設計_第2頁
DDC單回路PID閉環(huán)控制系統(tǒng)的設計及實時仿真課程設計_第3頁
DDC單回路PID閉環(huán)控制系統(tǒng)的設計及實時仿真課程設計_第4頁
DDC單回路PID閉環(huán)控制系統(tǒng)的設計及實時仿真課程設計_第5頁
已閱讀5頁,還剩22頁未讀 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、課程設計(綜合實驗)報告( 2011- 2012 年度第 二學期)名 稱: 過程計算機控制系統(tǒng) 題 目:ddc單回路pid閉環(huán)控制系統(tǒng)的設計及實時仿真院 系: 控制與計算機工程學院 班 級: 自動0905 學 號: 學生姓名: 指導教師: 朱耀春 設計周數(shù): 一周 成 績: 日期:2012 年 6 月 20 日一、 課程設計的目的與要求1.設計目的在計算機控制系統(tǒng)課程學習的基礎上,加強學生的實際動手能力,通過對ddc直接數(shù)字閉環(huán)控制的仿真加深對課程內容的理解。2.設計要求本次課程設計通過多人合作完成ddc直接數(shù)字閉環(huán)控制的仿真設計,學會a/d、d/a轉換模塊的使用。通過手動編寫pid運算式掌握

2、數(shù)字pid控制器的設計與整定的方法,并做出模擬計算機對象飛升特性曲線,熟練掌握ddc單回路控制程序編制及調試方法。二、 設計正文1.設計思想 本課程設計利用turboc2.1開發(fā)環(huán)境,通過手動編寫c語言程序完成pid控制器的設計,a/d、d/a轉換,繪出pid階躍響應曲線與被控對象動態(tài)特性曲線。整個設計程序模塊包含了pid配置模塊,plcd-780定時采樣、定時輸出模塊,pid手/自動切換模塊(按鍵控制)及繪圖顯示模塊。設計中,通過設定合理的pid 參數(shù),控制plcd-780完成模擬計算機所搭接二階慣性環(huán)節(jié)數(shù)據(jù)的采集,并通過繪圖程序獲得對象階躍響應曲線。 2. 設計步驟(1)前期準備工作 (1

3、.1)配備微型計算機一臺,系統(tǒng)軟件windows 98或dos (不使用無直接i/o能力的nt或xp系統(tǒng)), 內裝turbo c 2.0/3.0集成開發(fā)環(huán)境軟件;(1.2)配備模擬計算機一臺(xmn-1型), 通用數(shù)據(jù)采集控制板一塊(plcd-780型);(1.3)復習turboc2.0并參照說明書學習plcd-780的使用(2) pid的設計(2.1)pid的離散化理想微分pid算法的傳遞函數(shù)形式為:采用向后差分法對上式進行離散,得出其差分方程形式為:uk=uk-1+q0*e2+q1*e1+q2*e0;其中各項系數(shù)為:q0=kp*(1+t/ti+td/t); q1=-kp*(1+2*td/t

4、); q2=kp*td/t;實際微分pid算法的傳遞函數(shù)形式為:采用向后差分法對上式進行離散化,寫成差分方程的形式為: uk=c0*(uk-1)+c1*ek+c2*ek-1+c3*ek-2+uk-1;其中各項系數(shù)為:c0=tf/(t+tf);c1=kp*t/(t+tf)*(1+t/ti+td/t); c2=-kp*t/(t+tf)*(1+2*td/t); c3=kp*td/(t+tf); (2.2)數(shù)字pid算法的改進積分分離算法積分分離算法通過控制pid輸入偏差e達到優(yōu)化目的,當偏差較大時停止積分作用,只有當偏差較小時才投入積分,算法如下表示:當|e(k)|時,采用pd控制; 當|e(k)|

5、c時,|e(k)|=|e(k)|; 當|e(k)|c時,|e(k)|=0 其中c代表不靈敏區(qū)值;(2.3) 手動/自動雙向無擾切換自動切手動:系統(tǒng)處于自動時,手操器實時跟蹤自動pid調節(jié)器的輸出,切換瞬間由于手操器內部電路起保持作用,使得切換沒有擾動產(chǎn)生,此時對象處于手操器的開環(huán)控制,調節(jié)器跟蹤手操器的輸出。手動切自動:手動到自動的切換過程主要由計算機軟件實現(xiàn),一方面pid調節(jié)器獲得手操器輸出,同時軟件使得算法中的uk-1)、ek、ek-1、ek-2等歷史狀態(tài)清零。 程序中通過設置鍵盤,使的按下手動鍵h時,系統(tǒng)處于手動狀態(tài),按下自動鍵a時,系統(tǒng)處于自動狀態(tài)。(3)硬件二階慣性環(huán)節(jié)搭建利用模擬計

6、算機中的電容電阻及運算放大器,搭接二階慣性環(huán)節(jié),仿真一個被控對象。其傳遞函數(shù)為,硬件電路如下:圖中各元件參數(shù)如下:r3=r2=510k;r1=r4=r5=r6=r7=1m ;c1=c2=c=4.7uf;則可得:k=(r5/r1)*(r6/r4)=1 t1=t2=r5*c1=r6*c2=1000000*0.0000047=4.7s所以g(s)=1/(4.7s+1)*(4.7s+1)搭建好硬件電路后,將plcd-780插入ipc機箱插槽,用導線將plcd-780中的a/d、d/a、電源的接線端子與所搭二階慣性環(huán)節(jié)的輸出、輸入端口及機箱上的電源連接,組成一個完整的pid閉環(huán)控制系統(tǒng),為通信做好準備。

7、(4)pid參數(shù)的整定運用過程控制中pid參數(shù)的工程整定方法,運用衰減曲線法對pid參數(shù)進行整定。在matlab中,設置pid參數(shù)為td=0,ti=,設置合適的比例帶使得對象閉環(huán)階躍響應曲線衰減率為0.9,從而確定pid的整定參數(shù)為:p=0.8,ti=1.2tr , td=0.4tr ;matlab中對象響應曲線為:由曲線可得pid參數(shù)為:p=0.8=0.85=4,ti=1.2tr=1.210=12 ,td=0.4tr=0.410=4(5)實驗結果輸出通過在程序中編寫相應的繪圖模塊子程序,在需要畫圖時調用相應的子程序實現(xiàn)曲線的繪制。同時在程序中,本小組采用按鍵實現(xiàn)了pid手自動切換,理想pid

8、與實際pid的切換,以及在手自動狀態(tài)下由按鍵改變pid參數(shù),使得調節(jié)方式更加的靈活。 3.設計結果(1)pid階躍響應曲線調用程序,向pid模塊輸入一個階躍信號,繪出pid階躍響應曲線如下:(1.1)理想pid階躍響應圖: (1.2)實際pid階躍響應圖:(2)被控對象(慣性環(huán)節(jié))階躍響應曲線上圖通過d/a輸出一個1伏左右的信號輸入模擬的被控對象(慣性環(huán)節(jié)),a/d采集對象的輸入信號及其響應,再使d/a輸出一個幅度為2伏左右的階躍信號,同時采集輸入輸出信號。然后,d/a再反向在輸出一個幅度為2伏左右負的階躍信號,同時采集輸入輸出信號,得出仿真對象飛升特性曲線。程序中,通過按鍵實現(xiàn)模擬對象輸入信

9、號的加減。當按下h按鍵時,且按下u鍵時,d/a輸出一個1伏階躍信號,再次按下按鍵時階躍信號累加。每次按下d鍵時,d/a輸出的階躍信號遞減1。(3)設定值r、控制量u和被控對象輸出y的響應曲線:4.程序清單/*-頭文件定義-*/ #include #include #include #include /*-定義繪圖坐標-*/ #define ox 8 /*-原點橫坐標-*/ #define oy 440 /*-原點縱坐標-*/ #define xx 620 /*-x軸頂點橫坐標-*/ #define xy 440 /*-x軸頂點縱坐標-*/ #define lenx 580 #define le

10、ny 400 #define yx 8 /*-y軸頂點橫坐標-*/ #define yy 15 /*-y軸頂點縱坐標-*/ /*-定義繪圖區(qū)域-*/ #define left 20 #define top 20 #define right 620 #define bottom 460 /*-坐標軸注釋-*/ #define xtext1x 550 #define xtext1y 450 #define ytext1x 10 #define ytext1y 60 #define xtext2x 610 #define xtext2y 450 #define ytext2x 10 #define

11、ytext2y 20/*-理想pid運算式-*/float lxpid(float kp,float td,float ti,float e3,float u1) int t=1; float u; float q0=kp*(1+t/ti+td/t); float q1=-kp*(1+2*td/t); float q2=kp*td/t; u=q0*e0+q1*e1+q2*e2+u1; return u; /*-實際pid運算式-*/float sjpid(float kp,float tf,float td,float ti,float e3,float du1,float u1) int t

12、=1,k=1000; float u2; float c1=tf/(t+tf); float c2=kp*t*(1+t/ti+td/t)/(t+tf); float c3=-kp*t*(1+2*td/t)/(t+tf); float c4=kp*td/(t+tf); u2=c1*du1+c2*e0+c3*e1+c4*e2+u1; return u2; /*-繪圖初始化-*/void initial_sys(void) int graphdriver; int graphmode; detectgraph(&graphdriver,&graphmode); initgraph(&graphdri

13、ver,&graphmode,c:tc201ebgi); cleardevice(); /*-繪制坐標系-*/void drawaxis(void) int i; setbkcolor(15); setcolor(5); line(ox,oy,xx,xy); /*x_axis*/ line(xx-5,xy-5,xx,xy); line(xx,xy,xx-5,xy+5); line(ox,oy,yx,yy); /*y_axis*/ line(yx-5,yy+10,yx,yy); line(yx+5,yy+10,yx,yy); for(i=0;i51;i+) line(ox+10*i,oy,ox+

14、10*i,oy-10); line(ox+10*i+5,oy,ox+10*i+5,oy-5); for(i=1;i=8;i+) line(ox,oy-50*i,ox+10,oy-50*i); outtextxy(ox+50*0-7,oy+20,0); outtextxy(ox+50*1-7,oy+20,5); outtextxy(ox+50*2-7,oy+20,10); outtextxy(ox+50*3-7,oy+20,15); outtextxy(ox+50*4-7,oy+20,20); outtextxy(ox+50*5-7,oy+20,25); outtextxy(ox+50*6-7,

15、oy+20,30); outtextxy(ox+50*7-7,oy+20,35); outtextxy(ox+50*8-7,oy+20,40); outtextxy(ox+50*9-7,oy+20,45); outtextxy(ox+50*10-7,oy+20,50); outtextxy(ox-10,oy-50*1,1); outtextxy(ox-10,oy-50*2,2); outtextxy(ox-10,oy-50*3,3); outtextxy(ox-10,oy-50*4,4); outtextxy(ox-10,oy-50*5,5); outtextxy(ox-10,oy-50*6,

16、6); outtextxy(ox-10,oy-50*7,7); outtextxy(ox-10,oy-50*8,8); settextstyle(small_font,horiz_dir,5); outtextxy(xtext1x,xtext1y,time); outtextxy(xtext2x,xtext2y,t/s); settextstyle(small_font,vert_dir,5); outtextxy(ytext1x,ytext1y,the output (response); outtextxy(ytext2x,ytext2y,u(t)/v);main() float kp,t

17、i,td,tf,e3=0,ee3=0,u6=0,au1=0; int r=1,k=1; initial_sys(); drawaxis(); while(k100) u0=lxpid(1,3.0,10,e,u1); e0=r; /*printf(%fn,u0);*/ u3=sjpid(1,5,3.0,10,ee,au1,u4); setcolor(5); line(k-1)*10,130-u1*100,k*10,130-u1*100); line(k*10,130-u1*100,k*10,130-u0*100); delay(10000); u2=u1; u1=u0; e2=e1; e1=e0

18、; ee0=r; setcolor(3); line(k-1)*10,150-u4*100,k*10,150-u4*100); line(k*10,150-u4*100,k*10,150-u3*100); delay(10000); u5=u4; u4=u3; ee2=ee1; ee1=ee0; au1=u4-u5; k+;/*-頭文件定義-*/#include stdio.h#include math.h#include graphics.h/*for graph driver installing,only can be called in turbo c*/#include string

19、.h#include dos.h#include bios.h#include conio.h/*for interrupt program 頭文件定義* /#include stdlib.h#include io.h/*-按鍵地址區(qū)定義-*/*statements*/double key_esc=0x011b;/*define can not suit the length of bioskey 鍵盤內存定義*/double key_e=0x1265;double key_a=0x1e61;double key_h=0x2368;double key_u=0x1675;double key_

20、d=0x2064;double key_i=0x1769;double key_p=0x1970;double key_up=0x4800;double key_down=0x5000;double key_left=0x4b00;double key_right=0x4d00;double key_pgup=0x4900;double key_pgdown=0x5100;/*-plcd780基址定義-*/#define base 0x220/*-pcl812g need 16 addresses in a row,from 220h to 3f0h*/#define reg 0/*-定義繪圖

21、坐標-*/#define ox 40/*-原點橫坐標-*/#define oy 440 /*-原點縱坐標-*/#define xx 600/*-x軸頂點橫坐標-*/#define xy 440/*-x軸頂點縱坐標-*/#define yx 40/*-y軸頂點橫坐標-*/#define yy 40/*-y軸頂點縱坐標-*/*-pid參數(shù)定義-*/float kp=1.0;float ti=10.0;float td=3.0;float tf0=15.0;float tf=0; float t=0.1; /*-采樣時間-*/float ad,e,pv0;float u=0.0;float pv=0

22、.0;float sp=0.0;char a_h=h;char manu;int key=0;int time_counter=0;/*times of interrupt中斷的次數(shù)*/int cj_counter=0;/*sampling counter采樣次數(shù)*/int q_counter=800;/* 采集步長 賦初始值*/int stepdata800;int slopedata800;int error800;/*-函數(shù)聲明 -*/void interrupt (*fadd1c)(void); /*中斷函數(shù)聲明*/void loop(); /*定值采樣輸出程序聲明*/float ad

23、(unsigned char channal);/*a/d*/void da(float pv1);/*d/a*/void interrupt int_1c(void);/*8259,reset interrupt controller*/int scankey();float delayaction(float y0); /*延遲*/void pidset(void);/*pid設置聲明*/float pid(float sp1,float pv1,float kp1,float ti1,float td1,float tf1,char a_h1,float t1);/*pid計算聲明*/f

24、loat object(float u1,float t1); /*二階慣性環(huán)節(jié)聲明*/void initial_sys(void);/*initiate graph display*/void axis(void);void drawline(int cj,float pv1,float sp1,float u1,float e1);/*主函數(shù)*/void main(void)int i;for(i=0;i500;i+)stepdatai=10;slopedatai=i;errori=0; /* set new int_1c and save old */disable(); /*屏蔽中斷*

25、/fadd1c=getvect(0x1c);/*1c為定時器控制的軟中斷,平均一秒發(fā)生18.2次,即周期為55ms 中斷程序,getvect用于取得中斷向量入口*/* 開啟中斷服務*/setvect(0x1c,int_1c);/*設置中斷矢量入口*/enable();axis(); /*畫坐標軸*/loop(); /*定時采值輸出程序*/*主函數(shù)結束 下面為定時采值輸出程序*/void loop() doif(cj_counter*t)0)printf(parallal,mode:%c,sp=%.1f,pv=%2.1f,u=%.1f,error=%.1f,kp=%.1f,ti=%.1f,td=

26、%.1ftr,a_h,sp,pv,u,e,kp,ti,td);else printf(tttf got a wrong value! please exit and restart this program.r);cj_counter+;while(cj_counter500);disable();/* 恢復中斷*/setvect(0x1c,fadd1c);enable();/*d/a conversion program,0 to 4095 - 0to +5*/float ad(unsigned char channal)float result=0;int i;unsigned char

27、hb=0,lb=0,ok=0x10;/*12bit ad/high 4 bits and low 8 bits*/outportb(base+11,reg);/*軟件程序觸發(fā)*/delay(10); /*here,delay(int ms) is used long before,and we just need some time for hardware working*/outportb(base+10,channal);/*進行通道設置.選擇通道0*/delay(10);outportb(base+9,1); /*設置增益通道增益*/delay(10);outportb(base+12

28、,0);/*觸發(fā)a/d轉換*/delay(10); dook=inportb(base+5);while(ok&0x10);hb=inportb(base+5);delay(10);lb=inportb(base+4);result = lb + (hb&0x0f)5) /* make the output real */ pv1=5; else if (pv10) pv1=0; temp=(int)(4095*pv1/5.0); hb=temp8; lb=temp-(hb8); outportb(base,1); delay(10); outportb(base+4,lb); /* low

29、8 */ delay(10); outportb(base+5,hb); /* high 4 */void interrupt int_1c(void)time_counter+;outportb(0x20,0x20); /*鍵盤控制*/int scankey(void)int key0;key0=bioskey(1);/* function 1 returns 0 until a key is pressed */if(key0!=0)key0=bioskey(0);/* function 0 returns the key that is waiting */return key0;/*d

30、elayaction*/*tao=(int)(18.2*2) delay action=2 seconds*/float delayaction(float y0)float y_out;static float y_old36=0;int cyc;y_out=y_old36-1;for(cyc=1;cyc36;cyc+)y_old36-cyc=y_old36-cyc-1;y_old0=y0;return y_out;/*pid 主程序*/void pidset(void)key=scankey();if(a_h=h)if(key=key_up)kp+=0.2;else if(key=key_

31、down)kp-=0.2;else if(key=key_left)ti-=0.2;else if(key=key_right)ti+=0.2;else if(key=key_pgup)td+=0.2;else if(key=key_pgdown)td-=0.2;else if(key=key_u)manu=+;else if(key=key_d)manu=-;if(a_h=a)if(key=key_u)sp+=10;if(key=key_d)sp-=10;if(key=key_e|key=key_esc)exit(1);if(key=key_a)a_h=a;if(key=key_h)a_h=

32、h;if(key=key_i)tf=0;if(key=key_p)tf=tf0;/*pid-default:idealpid*/float pid(float sp1,float pv1,float kp1,float ti1,float td1,float tf1,char a_h1,float t1)float delta_u,u0,e,c1,c2,c3,c4;static float e1,e2,u1,delta_u1;/*here,u1 stands for the previous value of u*/if(kp10)printf(kp becomes a negative nu

33、mber,please restart.);else if(ti10) printf(ti becomes a negative number,please press restart.);else if(td10) printf(td becomes a negative number,please press restart.);elsec1=tf1/(t1+tf1);c2=kp1*t1*(1+t1/ti1+td1/t1)/(t1+tf1);c3=-kp1*t1*(1+2*td1/t1)/(t1+tf1);c4=kp1*td1/(t1+tf1);/*自動控制*/if(a_h1=a)e=sp

34、1-pv1;delta_u=c1*delta_u1+c2*e+c3*e1+c4*e2;/*here,delta_u1 stands for the previous value of delta_u*/u0=u1+delta_u; e2=e1;e1=e;delta_u1=delta_u;u1=u0;errorcj_counter=sp1-pv1;return u0;/*手動控制*/else if(a_h1=h)if(manu=+)u+=10;if(manu=-)u-=10;sp1=pv1;u1=u;sp=pv1;e1=0;e2=0;delta_u1=0;errorcj_counter=sp1-

35、pv1;return u;/*object:二階慣性環(huán)節(jié)*/float object(float u1,float t1)/*g(s)=1/(4.7s+1)2,k=1,tp1=tp2=4.7*/static float y1,y2;float y;y=1/(31.49+t1)*(-22.09*y2+53.58*y1+t1*u1);y2=y1;y1=y;return y;/*顯示與畫圖*/*初始化 crt*/void initial_sys(void)int graphdriver; int graphmode; detectgraph(&graphdriver,&graphmode); ini

36、tgraph(&graphdriver,&graphmode,c:tc201ebgi);/*draw basic coordinate axis*/void axis(void)int i;initial_sys();setbkcolor(15);/*white0/black15*/setcolor(9);/*linght blue*/rectangle(10,20,630,470);/*zone of drawing*/line(ox,oy,xx,xy);/*axis and arrow*/line(xx-5,xy-5,xx,xy);line(xx,xy,xx-5,xy+5);line(ox

37、,oy,yx,yy);line(yx-5,yy+5,yx,yy);line(yx+5,yy+5,yx,yy);settextstyle(2,1,5);/*small font,vert,5 times bigger*/outtextxy(20,100,the output (response);outtextxy(20,40,u(t);settextstyle(2,0,5);/*small font,horiz,5 times bigger*/outtextxy(300,455,time);outtextxy(590,455,t/sec);setlinestyle(1,0,1);/*dot line,none,width*/for(i=1;i4;i+)/*each inport starting position*/line(ox,oy-100*i,ox+500,oy-100*i);outtextxy(ox-16,oy-100*0,0);outtextxy(ox-16,oy-100*1,1);outtextxy(ox-16,o

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論