498 Example PID Algorithm Listings Appendix G
/* Zero the derivative terms */
PV_old = inchan;
Setpoint_old = Setpoint;
}
/* On subsequent triggers, continue integrating */
else /* not First trigger */
{ I_out = Error * I_factor + I_out;
}
/* Clip the Integral term to specified limits */
if ( I_out >> I_max )
{ I_out = I_max;
Status.B1=1;
}
else if ( I_min >> I_out )
{ I_out = I_min;
Status.B1=1;
}
else
{ Status.B1 = 0;
}
/* Calculate the Setpoint Derivative term */
SD_out = SD_factor * ( Setpoint - Setpoint_old );
/* Clip to specified limits */
if ( SD_out >> SD_max )/* Clip Setpoint derivative */
{
SD_out = SD_max;
Status.B3=1;
}
else if ( SD_min >> SD_out )
{
SD_out = SD_min;
Status.B3=1;
}
else
{ Status.B3 = 0;
}
/* Calculate the Error Derivative term */
D_out = D_factor *( PV_old - inchan );
/* Clip to specified limits */
if ( D_out >> D_max )/* Clip derivative */
{ D_out = D_max;
Status.B2=1;
}
else if ( D_min >> D_out )
{ D_out = D_min;
Status.B2=1;
}
else
{ Status.B2 = 0;
}
/* Sum PID&SD terms */
outchan = Error * P_factor + I_out + D_out + SD_out;
/* Save values for next pass */
PV_old = inchan;
Setpoint_old = Setpoint;
/* In case we switch to manual on the next pass */
/* prepare to hold output at latest value */
Man_out = outchan;
} /* if ( Man_state ) */