一個溫控項目,用到PID運算,歷史誤差累加值,經常無規律的變為接近0,不知道問題出在哪里
#define Proportion 0.05
#define Integral 0.0002
#define Derivative 4
int xdata dError,LastError,num_counter,open_duty;
int setPoint;
float xdata SumError=0.0;
int Error;
float xdata real_error;
每3秒值執行一下PID調整運算,SumError經常無規律變為0,可是沒有理由啊,加熱也還未到設定點。
============================================*/
void auto_adjust(int NextPoint)
{
int i;
int xdata i1,i3,i4,i5;
float xdata i6;
long xdata i6a;
float xdata i2;
long xdata i2a;
Error = setPoint - NextPoint; // 偏差
if(Error > 500)
{
open_duty = 50;//全開通
}
else
{
SumError += Error; // 積分
dError = Error - LastError; // 當前微分
LastError = Error; CLWDT;
real_error = SumError*Integral + Proportion*Error+ Derivative * dError; CLWDT;
i1=Proportion*Error;i2=(SumError*Integral);i3=Derivative * dError;i5=real_error;CLWDT;
open_duty = (int)(real_error+0.5);
}
|