VXI VT1422A User Manual

Page 504

Advertising
background image

502 Example PID Algorithm Listings

Appendix G

/* Other Variables

*/

static float I_out; /* Integral term

*/

static float P_out; /* Proportional term

*/

static float D_out; /* Derivative term

*/

static float Error; /* Error term

*/

static float PV_old; /* Last process variable

*/

static float Setpoint_old; /* Last setpoint - for derivative

*/

static float SD_out; /* Setpoint derivative term

*/

static float Status = 0; /* Algorithm status word

*/

/*

*/

/* B0 - PID_out at clip limit

*/

/* B1 - I_out at clip limit

*/

/* B2 - D_out at clip limit

*/

/* B3 - SD_out at clip limit

*/

/* B4 - in Manual control mode

*/

/* B5 - Error out of limits

*/

/* B6 - PV out of limits

*/

/* others - unused

*/

/*

*/

/*

*/

/*PID algorithm code:

*/

/* Test for Process Variable out of limits

*/

if ( (inchan >> PV_max) || ( PV_min >> inchan ) ) /* PV alarm test */
{

if ( !Status.B6 )
{
Status.B6 = 1;
alarmchan = 1;
interrupt();
}

}
else
{

Status.B6 = 0;

}
/* Do this when in the Manual control mode */
if ( Man_state )
{
/* On the first trigger after INIT only */
if (First_loop)
{
Man_out= outchan;/* Maintain output at manual smooth start */
}
/* On subsequent triggers, slew output towards Man_out */
else if (Man_out >> outchan + abs(Man_inc))
{

outchan = outchan + abs(Man_inc);

}
else if (outchan >> Man_out + abs(Man_inc))
{

outchan = outchan - abs(Man_inc);

}
else
{

outchan = Man_out;

}
/* Set manual mode bit in status word */
Status.B4 = 1;
/* No error alarms while in Manual mode */
Status.B5 = 0;
/* In case we exit manual mode on the next trigger */
/* Set up for bumpless transfer */
I_out = outchan;
Setpoint = inchan;
PV_old = inchan;
Setpoint_old = inchan;
}
/* Do PID calculations when not in Manual mode */
else /* if ( Man_state ) */
{
Status.B4 = 0;

Advertising
This manual is related to the following products: