增量式PID控制算法

51单片机PID算法程序(三)增量式PID控制算法 -- Sheldon
当执行机构需要的不是控制量的绝对值,而是控制量的增量(例如去驱动步进电动机)时,需要用PID的“增量算法”。


增量式PID控制算法C51程序

/*====================================================================================================
PID Function
The PID (比例、积分、微分) function is used in mainly
control applications. PIDCalc performs one iteration of the PID
algorithm.
While the PID function works, main is just a dummy program showing
a typical usage.
=====================================================================================================*/

typedef struct PID

{

int SetPoint; //设定目标 Desired Value

long SumError; //误差累计

double Proportion; //比例常数 Proportional Const

double Integral; //积分常数 Integral Const

double Derivative; //微分常数 Derivative Const

int LastError; //Error[-1]

int PrevError; //Error[-2]

} PID;





static PID sPID;

static PID *sptr = &sPID;

/*====================================================================================================
Initialize PID Structure PID参数初始化
=====================================================================================================*/

void IncPIDInit(void)

{

sptr->SumError = 0;

sptr->LastError = 0; //Error[-1]

sptr->PrevError = 0; //Error[-2]

sptr->Proportion = 0; //比例常数 Proportional Const

sptr->Integral = 0; //积分常数Integral Const

sptr->Derivative = 0; //微分常数 Derivative Const

sptr->SetPoint = 0;

}



/*====================================================================================================
增量式PID计算部分
=====================================================================================================*/

int IncPIDCalc(int NextPoint)

{

register int iError, iIncpid; //当前误差

iError = sptr->SetPoint - NextPoint; //增量计算

iIncpid = sptr->Proportion * iError //E[k]项

- sptr->Integral * sptr->LastError //E[k-1]项

+ sptr->Derivative * sptr->PrevError; //E[k-2]项

//存储误差,用于下次计算

sptr->PrevError = sptr->LastError;

sptr->LastError = iError;

//返回增量值

return(iIncpid);

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值