⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pid.c

📁 PID.c 新型PID控制及其应用 先进PID控制及其MATLAB仿真 STEP7中PID控制的实现方法.
💻 C
字号:
#include <REG52.H>
#include <MATH.H>
/*******************************************************************************/
int idata p,ti,td,t,gd;  /*p--比例度, ti--积分时间, td--微分时间,t--采样时间,gd--给定值*/
                         /*时间的单位均为0.1S*/
int idata cel,cel1,shchshx,shchxx,u0;
                         /*clshx--满度对应的上限值,clxx--满度对应的下限值*/
                         /*cel--用clshx,clxx,jzhshx,jzhxx校准后的测量值,用来计算偏差*/
                         /*shchshx--D/A输出对应5V时的数字量,shchxx--D/A输出对应1V时的数字量*/
                         /*u0--输出的位置信号*/
int idata jzhshx,jzhxx,celiang;
                         /*jzhshx--输入5V对应的A/D数字量,jzhxx--jzhshx--输入5V对应的A/D数字量*/
                         /*celiang--实际测量的A/D值 */
int idata de,de1;        /*本次偏差(测量值-给定值)和上次偏差*/
int idata df1;            /*pid运算中要保留的中间量*/
bit zdbit,dshbit,zhfzy;        /*zdbit--手动自动切换标志,dshbit--等分采样时间到标志*/
/*******************************************************************************/
void d_a(unsigned int x)
{
}
/*******************************************************************************/
void pid()
{
int de2,dpv;
float tdf,tf,tif,uf;
if(dshbit==1)
             {
      		dshbit=0;
		de2=de1;
        	de1=de;
                de=cel-gd;
                dpv=cel-cel1;
		cel1=cel;
     if(zdbit==1)
                {
                tf=t;
                tdf=td;
                tif=ti;
                uf=tdf*(de+de2-2*de1)/(tdf+10*tf)+tf*df1/(10*(tf+tdf));
                df1=uf;
                uf=uf+dpv+tf*de/tif;
                uf=uf*1000;
                uf=uf/p;
                uf=uf/1000;
                uf=uf*(shchshx-shchxx);
	if(zhfzy==0)
  	           {
                   u0=u0+uf;
                   }
	if(zhfzy==1)
		   {
                   u0=u0-uf;
                   }
                 }
                 if(u0>shchshx+0.05*(shchshx-shchxx)){u0=shchshx+0.05*(shchshx-shchxx);}
                 if(u0<shchxx-0.05*(shchshx-shchxx)){u0=shchxx-0.05*(shchshx-shchxx);}
		d_a(u0);
   }
}
/*******************************************************************************/
void shjchl()
{
float x;
x=celiang-jzhxx;
x=x/(jzhshx-jzhxx);
cel=1000*x;
}
/*******************************************************************************/
void timer0(void) interrupt 1
{
  	TH0=-(2252/256);
 	TL0=-(2252%256);
}
/*=============================================================================*/
void main()
{
        TMOD=0x11;
  	TH0 =-(2240/256);
 	TL0 =-(2240%256);
        ET0 =1;
        TR0=1;
        EA=1;
        p=1000;
        ti=600;
        td=0;
        t=10;
        gd=500;
        celiang=2400;
        jzhshx=4000;
        jzhxx=1000;
        shchshx=4000;
        shchxx=800;
        u0=2400;
        df1=0;
        zhfzy=0;
        cel1=466;
        zdbit=1;
        dshbit=1;
        while(1)
                {
                dshbit=1;
                shjchl();
                pid();
                }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -