NB: This manual refers to a very old version of EPICS, see the EPICS Wiki for updated record reference documentation.

[Next] [Previous] [Top] [Contents] [Index]

EPICS Record Reference Manual

Chapter 24: PID Control

1. Introduction


The PID record is used to maintain a setpoint that affects the output according to the difference between a controlled value and the setpoint. The record reads the controlled value and the setpoint when the record is processed, and then the PID expression computes the result, which is stored in a field (DM) that can be accessed via another record, usually an analog output record.

There are three terms of the PID expression: the proportional, the integral, and the derivative. Using the gain that exists for each of these terms, the user can weight each contribution according to the characteristics of the controlled variable.

The fields in this record fall into several categories:

scan parameters

controlled variable

setpoint parameters

expression parameters

operator display parameters

alarm parameters

monitor parameters

run-time parameters

2. Scan Parameters


The PID record has the standard fields for specifying under what circumstances it will be processed. Note, however, that the integral and derivative parts of the algorithm are affected by the SCAN field, i.e., the scanning algorithm. For Passive, I/O Interrupt, and Event, or a period of 0.1 seconds, the interval is set to 1. For periods of 0.2, 0.5, 1, and 2 seconds, the interval is set to 2, 3, 4, and 5.

These fields are listed in Scan Fields, Chapter 2, 2. In addition, Scanning Specification, Chapter 1, 1, explains how these fields are used.

The minimum delta time field (MDT) is a processing field particular to the PID record. It can be configured by the user or modified at run-time. It contains a floating point value which represents the minimum amount of time between record processing. If the amount of time between the last time the record was processed an the current time is less than MDT, than the record is not processed. If MDT is left at its default value (0), the minimum delta will be equal to one clock tick.
FieldSummaryTypeDCTInitialAccessModifyRec Proc MonitorPP
MDTMinimum Delta TimeFLOATYes0YesYesNoNo

3. Controlled Variable Parameters


The control variable link field (CVL) is used to obtain the value of the controlled process variable, i.e., the value read into the CVAL field. The link must be a database link. If it is not a database link a MAJOR alarm is triggered when the record is processed. See Address Specification, Chapter 1, 2, for information on how to specify database links.
FieldSummaryTypeDCTInitialAccessModifyRec Proc MonitorPP
CVLControlled Value Location (an input link)INLINKYes0NoNoN/ANo
CVALValue of controlled variableFLOATNo0YesYesNoNoNo

4. Setpoint Parameters


The setpoint mode select (SMSL) and the setpoint location (STPL) fields determine where the setpoint value is obtained, which is held in the VAL field. The SMSL and STPL fields work just like the OMSL and DOL fields found in many output records (analog output, binary output, etc.).

The SMSL field has two choices: supervisory and closed_loop. When supervisory, the setpoint, i.e., VAL, can be set via database access. When closed_loop, the setpoint value is retrieved from the link specified in STPL, which must be a database link. See Address Specification, Chapter 1, 2, for information on how to specify database links. STML can also be a constant in which case VAL is set equal to the constant value when the record is initialized.
FieldSummaryTypeDCTInitialAccessModifyRec Proc MonitorPP
STPLSetpoint Location (an input link)INLINKYes0NoNoN/ANo
SMSLSetpoint Mode select.GBLCHOICEYes0YesYesNoNo
VALSetpoint valueFLOATNo0YesYesYesYes

5. Expression Parameters


The discrete from of the PID expression is as follows:

where

M(n) = value of manipulated variable at nth instant.

KP = Proportional gain

KI = Integral gain

KD = Derivative gain

E(n) = Error nth sampling instant

SUMi = Sum from i=0 to i=n

dT(n) = Time difference between n-1 instance and nth instance

Mr = Midrange adjustment.

Taking the first difference between instances yields the following equation:

The terms KP, KI, and KD are the only terms configured by the user. These terms represent the gain for the proportional (KP), integral (KI) and the derivative (KD). A field exists for each of these terms (the KP, KI, and KD fields). KP should be configured according to the characteristics of the controlled variable; KI should be set equal to the number of times that the integral contribution repeats the proportional contribution; and KD should equal the number of minutes until the derivative contribution repeats the proportional contribution.

The PID record calculates the other terms of the expression:

En
Error at nth sampling instant, where the Error equals the setpoint minus the value of the controlled variable (VAL - CVAL).

delM(n)
This is the end result of the PID expression--the change in the manipulated value. The DM field holds this value.

dT(n)
This is the time difference between n and n-1, between current and last samplings. It is stored in the DE field.

The final result of the expression delM(n) and the other parts of the expression are held in several different run-time fields, which are not configurable prior to run-time, nor modifiable at run-time, but can be accessed so that their values can be used. See Section 9, Run-time Parameters, in this chapter for more information on those fields.
FieldSummaryTypeDCTInitialAccessModifyRec Proc MonitorPP
KPProportional GainFLOATYes0YesYesNoNo
KIIntegral Gain, in repeats per minute.FLOATYes0YesYesNoNo
KDDerivative Gain, in repeats per minuteFLOATYes0YesYesNoNo

6. Operator Display Parameters


These parameters are used to present meaningful data to the operator. They display the setpoint (VAL), the controlled variable (CVAL), the change in manipulated value (DM), and other fields of the PID, either textually or graphically.

EGU is a string of up to 16 characters describing the units of PID's manipulated values measures. It is retrieved by the get_units record support routine. It must be configured by the user if at all.

The HOPR and LOPR fields set the upper and lower display limits for the VAL, HIHI, HIGH, LOW, LOLO, VAL, and CVAL fields.

The PREC field determines the floating point precision with which to display VAL and CVAL. It is used whenever the get_precision record support routine is called.

See Chapter 2, Fields Common to All Record Types, for more on the record name (NAME) and description (DESC) fields.
FieldSummaryTypeDCTInitialAccessModifyRec Proc MonitorPP
EGUEngineering UnitsSTRING [16]YesnullYesYesNoNo
HOPRHigh Operating RangeFLOATYes0YesYesNoNo
LOPRLow Operating RangeFLOATYes0YesYesNoNo
PRECDisplay PrecisionSHORTYes0YesYesNoNo
NAMERecord NameSTRING [29]Yes0YesNoNoNo
DESCDescriptionSTRING [29]YesNullYesYesNoNo

7. Alarm Parameters


The possible alarm conditions for PID are the SCAN alarm, limit alarms, and an alarm that is triggered when CVL is not a database link. The SCAN and "CVL" alarms are called by the record routines and are always of MAJOR severity.

The limit alarms trigger alarms on the VAL field. They are configured by the user in the HIHI, LOLO, HIGH, and LOW fields using floating point values. For each of these fields, there is a corresponding severity field which can be either NO ALARM, MINOR, or MAJOR. See Alarm Specification, Chapter 1, 4, for a complete explanation of alarms and these fields.
FieldSummaryTypeDCTInitialAccessModifyRec Proc MonitorPP
HIHIHihi Alarm LimitFLOATYes0YesYesNoYes
LOLOHigh Alarm LimitFLOATYes0YesYesNoYes
HIGHLow Alarm LimitFLOATYes0YesYesNoYes
LOWLolo Alarm LimitFLOATYes0YesYesNoYes
HHSVHihi Alarm SeverityGBLCHOICEYes0YesYesNoYes
LLSVHigh Alarm SeverityGBLCHOICEYes0YesYesNoYes
HSVLow Alarm SeverityGBLCHOICEYes0YesYesNoYes
LSVLolo Alarm SeverityGBLCHOICEYes0YesYesNoYes
HYSTAlarm DeadbandDOUBLEYes0YesYesNoNo
Alarm Fields, Chapter 2, 3, lists other fields related to a alarms that are common to all record types.

8. Monitor Parameters


These parameters are used to determine when to send monitors placed on the VAL field. These fields contain values configured by the user. The monitors are sent when the VAL field exceeds the last monitored field (MLST, ALST, and LALM) by the appropriate delta. Otherwise, value change monitors are not called. If these fields have a value of zero, everytime the value changes, a monitor will be triggered; if they have a value of -1, everytime the record is processed, monitors are triggered. The ADEL field is the delta used for archive monitors, and the MDEL field is the delta for all other types of monitors.

The ODEL field specifies the hysteresis factor for the DM field, the field which holds the manipulated value. Unless the current value of DM is greater than the amount which the user specifies in this field, no monitors will be invoked. If zero, anytime DM is greater than zero, a monitor is triggered. If -1, each time the record is processed, a monitor is triggered. Note that when monitors are called for DM, they are also called for the following fields which comprise the PID expression: P, I, D, CT, DT, ERR, and DERR.

See Monitor Specification, Chapter 1, 5, for a complete explanation of monitors.
FieldSummaryTypeDCTInitialAccessModifyRec Proc MonitorPP
ADELArchive DeadbandDOUBLEYes0YesYesNoNo
MDELMonitor, i.e. value change, DeadbandDOUBLEYes0YesYesNoNo
ODELOutput deadbandFLOATYes0YesYesNoNo

9. Run-time Parameters


These parameters are used by the run-time code for processing the PID. They are not configurable prior to run-time. They represent the current state of the PID and/or the terms of the PID expression. Many of them are used to process the PID record more efficiently.

The DM field contains the change in manipulated value, the result of the PID expression (delM(n)). It is an increment which will usually be accessed by the desired output link (DOL) of an analog output record. Since its value represents an increment, the OIF field of the analog output record should be set to Incremental. There is no output field with which the PID record can itself send output.

The P, I, D, CT, DT, ERR, and DERR fields are used to calculate the PID expression. They are not configurable prior to, nor modifiable during, run-time, but may be of interest when fine tuning the gains of each contribution (KP, KI, KD). The following lists the fields as they relate to the expression:

ERR
En Error at current sampling (VAL-CVAL).

DERR
En - En-1 Difference between current error and error at last sampling.

P
This field corresponds to KP * (En - (En-1))

I
This field corresponds to En * dTn * KI

D
This field corresponds to Kp * Kd * (err/dt(n) - derr/dt(n-1))

The LALM, ALST, and MLST fields are used by record processing to implement the monitors for this record. These fields hold the values for the VAL field from the last time the record was processed. When the record is processed again the difference between these fields and current value of VAL exceeds the appropriate delta (MDEL for instance), then the appropriate monitors are triggered.
FieldSummaryTypeDCTInitialAccessModifyRec Proc MonitorPP
DMChange in Manipulated ValueFLOATNo0YesNoYesNo
ODMOld DM. FLOATNo0YesNoYesNo
PProportional contribution to DM.FLOATNo0YesNoYesNo
IIntegral contribution to DM.FLOATNo0YesNoYesNo
DDerivative contribution to DM.FLOATNo0YesNoYesNo
CTClock ticks when previous process occurred.ULONGNo0YesNoYesNo
DTTime difference in seconds between processing steps.FLOATNo0YesNoYesNo
ERRCurrent error (VAL - CVAL).FLOATNo0YesNoYesNo
DERRDelta ErrorFLOATNo0YesNoYesNo
LALMValue when last monitors for alarm were triggeredFLOATNo0YesNoNoNo
ALSTValue when last monitors for archiver were triggeredFLOATNo0YesNoNoNo
MLSTValue when last monitors for value changes were triggeredFLOATNo0YesNoNoNo

10. Record Support Routines


init_record

If STPL is a constant link, initialize VAL with it's value and set UDF to false.

process

See next section.

get_value

Fills in the values of struct valueDes so that they refer to VAL.

get_units

Retrieves EGU.

get_precision

Retrieves PREC.

get_graphic_double

Sets the following values:

upper_disp_limit = hopr

lower_disp_limit = lopr

get_control_double

Sets the following values

upper_ctrl_limit = hopr

lower_ctrl_limit = lopr

get_alarm_double

Sets the following values:

upper_alarm_limit = hihi

upper_warning_limit = high

lower_warning_limit = low

lower_alarm_limit = lolo

11. Record Processing


Routine process implements the following algorithm:

1. If CVL is not a database link a major alarm is declared and the algorithm completes.

2. The current value of CVAL is obtained from CVL.

3. If STPL is a database link and SMSL is CLOSED_LOOP then VAL is obtained from STPL and UDF is set to false.

4. The time difference since the last time step is calculated. If it is less than MDT or if no ticks have occurred since the last time the algorithm was executed, process just completes without raising any alarms, checking monitors, or scanning the forward link.

5. The new values of P, I, D, OUT, CT, DT, ERR, and DERR are computed.

6. Check alarms. This routine checks to see if the new VAL causes the alarm status and severity to change. If so NSEV and NSTA and LALM are set. It also honors the alarm hysteresis factor (HYST). Thus the value must change by at least HYST before the alarm status and severity changes.

7. Checks to see if monitors should be invoked:

Archive and value change monitors are invoked if ODEL conditions are met. If monitors are triggered from DM, they are also triggered for P, I, D, CT, DT, E

1. - Introduction
2. - Scan Parameters
3. - Controlled Variable Parameters
4. - Setpoint Parameters
5. - Expression Parameters
6. - Operator Display Parameters
7. - Alarm Parameters
8. - Monitor Parameters
9. - Run-time Parameters
10. - Record Support Routines
init_record
process
get_value
get_units
get_precision
get_graphic_double
get_control_double
get_alarm_double
11. - Record Processing

EPICS Record Reference Manual - 19 MAY 1998
[Next] [Previous] [Top] [Contents] [Index]

Generated with Harlequin WebMaker