if( PID.RK_Uint16 > PID.RK_Uint16 ) //设定值大于实际值否?
{
if( PID.RK_Uint16 - PID.RK_Uint16 >10 ) //偏差大于10否?
{
PID.Uk_Uint16 = 100; } //偏差大于10为上限幅值输出(全速加热)
else
{
Temp[0] = PID.RK_Uint16 - PID.CK_Uint16; //偏差<=10,计算E(k)
PID.EkFlag_Uint8[1]=0; //E(k)为正数
//数值移位
PID.Ek_Uint32[2] = PID.Ek_Uint32[1];
PID.Ek_Uint32[1] = PID.Ek_Uint32[0];
PID.Ek_Uint32[0] = Temp[0];
/****************************************/
if( PID.Ek_Uint32[0] >PID.Ek_Uint32[1] ) //E(k)>E(k-1)否?
{
Temp[0]=PID.Ek_Uint32[0] - PID.Ek_Uint32[1]; //E(k)>E(k-1)
PID.EkFlag_Uint8[0]=0; } //E(k)-E(k-1)为正数
else
{
Temp[0]=PID.Ek_Uint32[0] - PID.Ek_Uint32[1]; //E(k)<E(k-1)
PID.EkFlag_Uint8[0]=1; } //E(k)-E(k-1)为负数
/****************************************/
Temp[2]=PID.Ek_Uint32[1]*2 ; // 2E(k-1)
if( (PID.Ek_Uint32[0]+ PID.Ek_Uint32[2])>Temp[2] ) //E(k-2)+E(k)>2E(k-1)否?
{
Temp[2]=(PID.Ek_Uint32[0]+ PID.Ek_Uint32[2])-Temp[2]; //E(k-2)+E(k)>2E(k-1)
PID.EkFlag_Uint8[2]=0; } //E(k-2)+E(k)-2E(k-1)为正数
else
{
Temp[2]=Temp[2]-(PID.Ek_Uint32[0]+ PID.Ek_Uint32[2]); //E(k-2)+E(k)<2E(k-1)
PID.EkFlag_Uint8[2]=1; } //E(k-2)+E(k)-2E(k-1)为负数
/****************************************/
Temp[0] = (uint32)PID.KP_Uint8 * Temp[0]; // KP*[E(k)-E(k-1)]
Temp[1] = (uint32)PID.KI_Uint8 * PID.Ek_Uint32[0]; // KI*E(k)
Temp[2] = (uint32)PID.KD_Uint8 * Temp[2]; // KD*[E(k-2)+E(k)-2E(k-1)]【转载请注明出处:https://www.5ubs.com/skill/zhuanyezhishi/450.html】 |