|
#define uint unsigned int //ki=0.003,kd=1084.0;kp=1.3;//80度;
#define uchar unsigned char//ki=0.003,kd=1284.0;kp=0.82;//80度;
float ki=0.003;//
float kd=1084.0;//
float kp=1.3;//
float ek;//当前偏差
float ek1;//上一次偏差
float ek2;//上上一次偏差
float d_uk;//当前偏差电压
float uk1;//上一次输出电压
float uk; //本次输出电压
//float ukmax;//第一次偏差最大值
//float sumerror;//历史偏差和
/*void calcpiid(float s_temp,float now_temp) //积分分离增量式pid;
{
ukmax=5.0*(kp+kd);
ek=s_temp-now_temp;
if(ek>1.0)
d_uk=kp*(ek-ek1)+kd*(ek-2*ek1+ek2);
else
d_uk=kp*(ek-ek1)+ki*ek+kd*(ek-2*ek1+ek2);
uk=d_uk+uk1;
ek2=ek1;
ek1=ek;
uk1=uk;
} */
/*void calcpiiid(float s_temp,float now_temp)//遇限削弱积分法;
{
ukmax=5.0*(kp+kd);
ek=s_temp-now_temp;
d_uk=kp*(ek-ek1)+kd*(ek-2*ek1+ek2);
if(uk1>=ukmax)
{
if(ek>0);
else
d_uk+=ki*ek;
}
else
{
if(uk1<=ukmax)
if(ek<0);
else
d_uk+=I*ek;
}
uk=uk1+d_uk;
ek2=ek1;
ek1=ek;
uk1=uk;
} */
void calcpid(float s_temp,float now_temp)//增量式
{
//ukmax=5.0*(kp+ki+kd);
ek=s_temp-now_temp;
d_uk=kp*(ek-ek1)+ki*ek+kd*(ek-2*ek1+ek2);
uk=d_uk+uk1;
ek2=ek1;
ek1=ek;
uk1=uk;
} |
|