欢迎来到天天文库
浏览记录
ID:37986118
大小:39.50 KB
页数:4页
时间:2019-05-23
《直流电机pi控制-pwm部分》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、直流电机PI控制-PWM部分PI_PWM部分#include#include#includebitflag=1;unsignedcharpwm=0;unsignedchara,b;sbitP21=P2^1;sbitP20=P2^0;voidsdf()interrupt3using0//定时255us,0.063s{P1=0x00;if(flag==1){a--;if(a==0){flag=0;a=1;}else{P21=0;}}if(flag==0){b--;if(b==0){flag
2、=1;b=253;}else{P21=1;}}}main(){TMOD=0x20;TH1=0x06;//对TH0TL0赋值TL1=0x06;P20=1;ET1=1;TF1=0;b=1;a=253;TR1=1;EA=1;while(1);}PID控制程序#include#include#include#includestructPID{unsignedintSetPoint;/*设定目标DesiredValue*/unsignedintProportion;/*比例常
3、数ProportionalConst*/unsignedintIntegral;/*积分常数IntegralConst*/unsignedintDerivative;/*微分常数DerivativeConst*/unsignedintLastError;/*Error[-1]*/unsignedintPrevError;/*Error[-2]*/unsignedintSumError;/*SumsofErrors*/};structPIDspid;/*PIDControlStructure*/unsignedintrout;/*PIDRes
4、ponse(Output)*/unsignedintrin;/*PIDFeedback(Input)*/sbitdata1=P1^0;sbitclk=P1^1;sbitplus=P2^0;sbitsubs=P2^1;sbitstop=P2^2;sbitoutput=P3^4;sbitDQ=P3^3;unsignedcharflag,flag_1=0;unsignedcharhigh_time,low_time,count=0;/*占空比调节参数*/unsignedcharset_temper=35;unsignedchartemper;un
5、signedchari;unsignedcharj=0;unsignedints;/********************************************************************PID计算部分********************************************************************/unsignedintPIDCalc(structPID*pp,unsignedintNextPoint){unsignedintdError,Error;Error=pp-
6、>SetPoint-NextPoint;//偏差pp->SumError+=Error;//积分dError=pp->LastError-pp->PrevError;//当前微分pp->PrevError=pp->LastError;pp->LastError=Error;return(pp->Proportion*Error//比例项+pp->Integral*pp->SumEror//积分项+pp->Derivative*dError);//微分项}low_time=(100-high_time);}}elseif(set_temper
7、<=temper){if(temper-set_temper>0){high_time=0;low_time=100;}else{for(i=0;i<10;i++){get_temper();rin=s;//ReadInputrout=PIDCalc(&spid,rin);//PerformPIDInteration}if(high_time<100)high_time=(unsignedchar)(rout/10000);elsehigh_time=0;low_time=(100-high_time);}}//else//{}}break
8、;}EA=1;}get_temper();b=temper;if(flag_2==1)a=b;if((abs(a-b))>5)temper=a;elsetemper=b;a=te
此文档下载收益归作者所有