RRM 3-13 CPID Control
CPID Control
The CPID record, like the PID record, is used for making error corrections on output values in order to maintain a specified setpoint. In the CPID record, the setpoint must be retrieved from another database record. When the record is processed, it reads the controlled value and the setpoint, and then computes the error correction. Unlike the PID record, the CPID record can write this value because it has its own output link.
Another important difference is that unlike the PID record, the CPID record has four different modes: normal mode, sequencer mode, local mode, and manual mode. The normal mode causes the CPID record to function in the same way as the PID record does. The other modes significantly change how the CPID record functions. All these modes are explained in this chapter.
When in normal mode, the CPID record performs the same equation as the PID record. This equation consists of three parts: 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 response of the process being controlled.
Parameter Fields
The fields in this record fall into several categories:
- scan parameters
- controlled variable and setpoint parameters
- output, readback, and mode parameters
- expression parameters
- operator display parameters
- alarm parameters
- monitor parameters
- run-time parameters
Scan Parameters
The CPID record has the standard fields for specifying under what circumstances the record will be processed. These fields are listed in Scan Fields. In addition, Scanning Specification explains how these fields are used. Since the CPID record supports no direct interfaces to hardware, it cannot be scanned on I/O interrupt, i.e., its SCAN field cannot specify I/O Intr
.
However, the CPID record contains an additional field that affects its processing while in normal mode. The minimum delta time field (MDT) is a scanning field particular to the CPID record and PID records. 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 so that if the amount of time between the last time the record was processed and the current time is less than MDT, then DM and the output value (OVAL) are set to 0. If MDT is left at its default value (0), the minimum delta will be equal to one clock tick.
Field | Summary | Type | DCT | Initial | Access | Modify | Rec Proc Monitor | PP |
---|---|---|---|---|---|---|---|---|
MDT | Minimum Delta Time | FLOAT | Yes | 0 | Yes | Yes | No | No |
Controlled Variable and Setpoint Parameters
The control variable location field (CVL) is used to obtain the value of the controlled process variable, the value read into the CVAL field. The link must be a database link. If it is not a database link an INVALID alarm is triggered when the record is processed. See Address Specification for information on specifying links.
The setpoint value is set in the VAL field. Unlike the PID record, the setpoint value cannot be read from other records, but must be set via dbPuts. It is set equal to CVAL, the value retrieved from the CVL link, when the record is initialized.
Field | Summary | Type | DCT | Initial | Access | Modify | Rec Proc Monitor | PP |
---|---|---|---|---|---|---|---|---|
CVL | Controlled value location (an input link) | INLINK | Yes | 0 | No | No | N/A | No |
VAL | Setpoint value | FLOAT | No | 0 | Yes | Yes | Yes | Yes |
Expression Parameters
The PID expression calculated by the CPID record in Normal mode is the same as the PID record's expression. The discrete from of the PID expression is as follows:
M(n) = KP × E(n) + KI × SUMi ( E(i) × dT(n) ) + KD × ( | E(n) - E(n-1) | ) + Mr |
----------------- | ||
dT(n) |
where
- M(n) = value of manipulated variable at nth instant.
- KP, KI, and KD = Proportional, Integral, Derivative gains set by the user
- E(n) = Error at nth sampling instant
- SUMi = Sum from i=0 to i=n
- dT(n) = Time difference between n-1th instance and nth instance
- Mr = Midrange adjustment
Taking the first difference between instances yields the following equation:
delM(n) = KP × (E(n) - E(n-1)) + KI × E(i) × dT(n) + KD × ( | E(n) - E(n-1) | ) - ( | E(n) - E(n-1) | ) |
----------------- | ----------------- | |||
dT(n) | dT(n-1) |
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:
- E(n)
- 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.
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.
When in Normal Mode, the DM field contains the change in manipulated value, i.e., the result of the PID expression delM(n). For other modes, the value is different, but is always an increment which can 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
. Note that the final result to be written may not be the same as the final result of the equation; that is, DM, the result of the equation, may not equal OVAL, the output value, depending on the mode.
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
- E(n). Error at current sampling (VAL-CVAL).
- DERR
- E(n) - E(n-1). Difference between current error and error at last sampling.
- P
- This field corresponds to
KP * DERR
- I
- This field corresponds to
E(n) * dTn * KI
- D
- This field corresponds to
Kp * Kd * (err/dt(n) - derr/dt(n-1))
Field | Summary | Type | DCT | Initial | Access | Modify | Rec Proc Monitor | PP |
---|---|---|---|---|---|---|---|---|
KP | Proportional Gain | FLOAT | Yes | 0 | Yes | Yes | No | No |
KI | Integral Gain, in repeats per minute. | FLOAT | Yes | 0 | Yes | Yes | No | No |
KD | Derivative Gain, in repeats per minute | FLOAT | Yes | 0 | Yes | Yes | No | No |
DM | Change in Manipulated Value | FLOAT | No | 0 | Yes | No | Yes | No |
P | Proportional contribution to DM. | FLOAT | No | 0 | Yes | No | Yes | No |
I | Integral contribution to DM. | FLOAT | No | 0 | Yes | No | Yes | No |
D | Derivative contribution to DM. | FLOAT | No | 0 | Yes | No | Yes | No |
CT | Clock ticks when previous process occurred. | ULONG | No | 0 | Yes | No | Yes | No |
DT | Time difference in seconds between processing steps. | FLOAT | No | 0 | Yes | No | Yes | No |
ERR | Current error (VAL - CVAL). | FLOAT | No | 0 | Yes | No | Yes | No |
DERR | Delta Error | FLOAT | No | 0 | Yes | No | Yes | No |
Output, Readback, and Mode Parameters
Unlike the PID record, the CPID record has an output link so that it can write its output. The value written is the value of the OVAL field. How record processing determines this value depends on, among other things, the current mode and the limits.
Firstly, the record has two output modes, CHANGE and POSITION, set by the OMOD field. If OMOD is (0,1), then the output mode will be (CHANGE, POSITION). The OMOD field cannot be modified at run-time, so it must be configured to be either CHANGE or POSITION. It is initialized to CHANGE by default.
When CHANGE, the record sets OVAL equal to DM, the result of the PID expression. DM being itself an increment, OVAL is an incremental value in the CHANGE mode. If the record is in POSITION mode, OVAL is an absolute value obtained by adding OVAL to DM. In this case, OVAL will be the last value of OVAL when it was written unless it was changed by database access.
if CHANGE OVAL = DM if POSITION OVAL = OVAL + DM
After OVAL is adjusted in case it violates the value limits explained below, DM is set equal to OVAL when in CHANGE mode. When in position mode, after any adjustments, DM is set equal to OVAL - MLST, MLST being the value of OVAL the last time the record was processed. This way, DM is always an increment, adjusted to be within the value limits.
Secondly, there are four different modes on top of the output mode: Normal, Sequencer, Manual, and Local.
- In Normal mode, OVAL is computed as explained above. DM is also computed as usual.
- In Sequencer mode, the CPID record computes OVAL as SVAL - ORBV when in CHANGE mode, and sets OVAL equal to SVAL in the POSITION mode. DM is computed as SVAL - ORBV in CHANGE mode and OVAL - SVAL in POSITION mode. The sequencer program should determine the value of SVAL while in Sequencer mode.
- In Manual mode, the CPID record computes OVAL as MVAL - ORBV when in CHANGE mode, and sets OVAL equal to MVAL when in POSITION mode. DM is set equal to MVAL - ORBV in CHANGE mode and OVAL - MVAL in POSITION mode. MVAL is determined by the operator at run-time, via dbPuts.
- In Local mode, the CPID record sets OVAL equal to 0 when the output mode is CHANGE and ORBV when the output mode is POSITION. The Local mode was implemented to support the setting of the output by a local hardware control.
The MMOD, SMOD, and LOC field determine which of these four modes the CPID record is in. The MMOD and SMOD fields are set via database access (by the operator or the sequencer). The LOC field must specify a database link if the record is to be placed into Local mode. If the MMOD field is true (has a value other than 0), then the mode is Manual. If the SMOD field is true, then the mode is Sequencer. If the LOC field is a database link and the value retrieved from it is 0, then the mode is Local. The default mode is the normal mode so that if none of the above conditions exist, the mode is normal. An order of precedence exists so that the mode can be determined when more than one of the above conditions is true. The order of precedence is Local mode, Manual mode, Sequencer, then Normal mode, so that if the MMOD and SMOD fields are true and the value retrieved from the LOC field is not 0 (i.e., local mode is not requested), then the mode is Sequencer.
Note: DM is calculated even for modes other than Normal. This prevents the DT change in time contribution from "winding up" when the mode is other than Normal.
Finally, MAX, MIN, DMAX, and DMIN fields are used to specify limits for the output value. The MAX and MIN fields limit the value of OVAL, whereas the DMAX and DMIN fields limit the value of DM. How these fields do this for the different modes is somewhat complex. See Record Processing in this chapter for a further explanation of how these fields work.
Field | Summary | Type | DCT | Initial | Access | Modify | Rec Proc Monitor | PP |
---|---|---|---|---|---|---|---|---|
OUT | Output Link | OUTLINK | Yes | 0 | No | No | N/A | No |
ORBL | Output Readback Location | INLINK | Yes | No | No | No | No | |
OMOD | Output Mode | RECCHOICE | Yes | 0 | Yes | No | No | No |
ORBV | Output Readback Value | FLOAT | No | 0 | Yes | Yes | No | No |
MAX | Maximum Limit | FLOAT | Yes | 0 | Yes | Yes | No | No |
MIN | Minimum Limit | FLOAT | Yes | 0 | Yes | Yes | No | No |
DMAX | Maximum Change | FLOAT | Yes | 0 | Yes | Yes | No | No |
DMIN | Minimum Change | FLOAT | Yes | 0 | Yes | Yes | No | No |
LOC | Local Mode Switch | INLINK | Yes | No | No | No | ||
MMOD | Manual Mode Request | GBLCHOICE | Yes | 0 | Yes | Yes | No | No |
SMOD | Sequencer Mode Request | GBLCHOICE | Yes | 0 | Yes | Yes | No | No |
MVAL | Manual Value | FLOAT | Yes | 0 | Yes | Yes | No | No |
SVAL | Sequencer Value | FLOAT | Yes | 0 | Yes | Yes | No | No |
Operator Display Parameters
These parameters are used to present meaningful data to the operator. These fields are used to 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, P, I, D, 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 Fields Common to All Record Types for more on the record name (NAME) and description (DESC) fields.
Field | Summary | Type | DCT | Initial | Access | Modify | Rec Proc Monitor | PP |
---|---|---|---|---|---|---|---|---|
EGU | Engineering Units | STRING | Yes | null | Yes | Yes | No | No |
HOPR | High Operating Range | FLOAT | Yes | 0 | Yes | Yes | No | No |
LOPR | Low Operating Range | FLOAT | Yes | 0 | Yes | Yes | No | No |
PREC | Display Precision | SHORT | Yes | 0 | Yes | Yes | No | No |
NAME | Record Name | STRING | Yes | 0 | Yes | No | No | |
DESC | Description | STRING | Yes | Null | Yes | Yes | No | No |
Alarm Parameters
The possible alarm conditions for PID are the SCAN alarm, limit alarms, and an INVALID alarm that is triggered when CVL is not a database link. The SCAN and INVALID 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 for a complete explanation of alarms and these fields. Alarm Fields lists other fields related to a alarms that are common to all record types.
Field | Summary | Type | DCT | Initial | Access | Modify | Rec Proc Monitor | PP |
---|---|---|---|---|---|---|---|---|
HIHI | Hihi Alarm Limit | FLOAT | Yes | 0 | Yes | Yes | No | Yes |
HIGH | High Alarm Limit | FLOAT | Yes | 0 | Yes | Yes | No | Yes |
LOW | Low Alarm Limit | FLOAT | Yes | 0 | Yes | Yes | No | Yes |
LOLO | Lolo Alarm Limit | FLOAT | Yes | 0 | Yes | Yes | No | Yes |
HHSV | Hihi Alarm Severity | GBLCHOICE | Yes | 0 | Yes | Yes | No | Yes |
HSV | High Alarm Severity | GBLCHOICE | Yes | 0 | Yes | Yes | No | Yes |
LSV | Low Alarm Severity | GBLCHOICE | Yes | 0 | Yes | Yes | No | Yes |
LLSV | Lolo Alarm Severity | GBLCHOICE | Yes | 0 | Yes | Yes | No | Yes |
HYST | Alarm Deadband | DOUBLE | Yes | 0 | Yes | Yes | No | No |
Monitor Parameters
These parameters are deadbands configured by the user which determine when to send monitors on the DM field. If the value of DM is greater than ADEL, archive monitors for the OVAL, CT, and DM fields are sent. Additionally, if the record is in Normal mode, monitors for P, I, D, ERR, DERR, and DT are sent. MDEL is used the same way as ADEL for all other types of monitors.
The ODEL field is not implemented in the PID record.
See Monitor Specification for a complete explanation of monitors.
Field | Summary | Type | DCT | Initial | Access | Modify | Rec Proc Monitor | PP |
---|---|---|---|---|---|---|---|---|
ADEL | Archive Deadband | DOUBLE | Yes | 0 | Yes | Yes | No | No |
MDEL | Monitor, i.e. value change, Deadband | DOUBLE | Yes | 0 | Yes | Yes | No | No |
ODEL | Output deadband for DM | FLOAT | Yes | 0 | Yes | Yes | No | No |
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 CVAL field is the controlled variable value retrieved from the CVL link.
The LALM field is used to implement the hysteresis factor for the alarms.
The ALST field holds the last value for OVAL, but has no other function for the record.
The MLST field holds the last value for the OVAL field. It is used to calculate a value for DM when the record is in the POSITION mode. After any other calculations, DM is set equal to OVAL - MLST. Thus, even in POSTION mode, DM always holds a relative value, the difference between DM and the value of OVAL from the last time the record was processed.
The PMOD field indicates the current mode of the record:
- 0 Normal Mode
- 1 Manual Mode
- 2 Sequencer Mode
- 3 Local Control Mode
The last mode field (LMOD) implements monitors for PMOD. If PMOD is not equal to LMOD, monitors are posted for the PMOD field.
Field | Summary | Type | DCT | Initial | Access | Modify | Rec Proc Monitor | PP |
---|---|---|---|---|---|---|---|---|
CVAL | Value of controlled variable | FLOAT | No | 0 | Yes | Yes/No | No | No |
OVAL | Output Value | FLOAT | No | 0 | Yes | Yes | Yes | No |
ODM | Old DM. | FLOAT | No | 0 | Yes | No | Yes | No |
LALM | Value from when last monitors for alarm were triggered | FLOAT | No | 0 | Yes | No | No | No |
ALST | Value when last monitors for archiver were triggered | FLOAT | No | 0 | Yes | No | No | No |
MLST | Value when last monitors for value changes were triggered | FLOAT | No | 0 | Yes | No | No | No |
LOVL | Last Readback Value | FLOAT | No | 0 | Yes | No | No | No |
PMOD | Current Mode | RECCHOICE | Yes | 0 | No | Yes | No | |
LMOD | Last Mode | RECCHOICE | Yes | 0 | yes | No | No | No |
ODM | Old DM Value | FLOAT | No | 0 | Yes | No | No | No |
Record Support
Record Support Routines
init_record
Set UDF to false. Return 0.
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 if field is CVAL or VAL. Otherwise, calls recGblGetPrec().
get_graphic_double
Sets the following values if field is VAL, HIHI, HIGH, LOW, LOLO, P, I, D, or CVAL:
upper_disp_limit = hopr lower_disp_limit = lopr
get_control_double
Sets the following values if field is VAL, HIHI, HIGH, LOW, LOLO, P, I, D, or CVAL:
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
Record Processing
Routine process implements the following algorithm:
- Set PACT to TRUE.
- If CVL is not a database link an INVALID alarm is declared, PACT is set to FALSE, and the routine returns (0).
- The current value of CVAL is obtained from CVL.
- If ORBL is a database link, the current value of ORBV is obtained.
- Determine the mode:
- mode = normal
- if SMOD true
- mode = Sequencer mode
- if MMOD true
- mode = Manual mode
- if value retrieved from LOC is 0
- mode = Local Mode
- Compute time difference between current and last processing; that is , compute DT.
- Set DM = 0.
- If Mode is Normal and DT < MDT, calculate DM using PID expression.
- If Mode is Normal and OMOD is CHANGE:
- if (ORBV + DM) is less than MAX
- set OVAL = MAX - ORBV
- else if (ORBV + DM) < MIN
- set OVAL = MIN - ORBV
- else set OVAL = DM
- if (ORBV + DM) is less than MAX
- If Mode is Normal and OMOD is POSITION and OVAL > MAX:
- if (OVAL - MAX) > DMAX
- set OVAL = OVAL - DMAX
- if (OVAL - MAX) >= DMIN
- set OVAL = MAX
- if (OVAL - MAX) > DMAX
- If Mode is Normal and OMOD is POSITION and OVAL < MIN.
- if (MIN - OVAL) > DMAX
- Set OVAL = OVAL + DMAX
- if ( MIN - OVAL) >= DMIN
- set OVAL = MIN
- if (MIN - OVAL) > DMAX
- If Mode is Manual and OMOD is CHANGE
- set DM and OVAL to MVAL - ORBV.
- If Mode is Manual and OMOD is POSITION
- set DM and OVAL to MVAL - ORBV.
- if Mode is Local Control and OMOD is CHANGE
- set OVAL equal to 0.
- If Mode is Local Control and OMOD is POSITION
- set OVAL equal to ORBV.
- If Mode is Sequencer and OMOD is CHANGE
- set DM and OVAL to SVAL - ORBV
- If Mode is Sequencer and OMOD is POSITION
- set DM and OVAL to SVAL.
- If OMOD is CHANGE
- set DM equal to OVAL.
- If OMOD is POSITION
- set DM equal to OVAL - MLST.
- Write OVAL to output location.
- Check alarms and post if any.
- Check monitors and post if any.
- Process FLNK.
- Set PACT equal to FALSE and return 0.
Device Support
The CPID record has no associated device support.
EPICS Record Reference Manual - 19 MAY 1998