Skip to main content

PID

The PID block executes a discrete proportional-integral-derivative controller. It calculates the controller output from the configured input variables.

Ladder Representation

PID ladder representation

Variable Table

Variable TypeNameData TypeDescription
VAR_INPUTENBOOLBlock enable.
VAR_INPUTSetPointREALAutomatic reference before control.
VAR_INPUTManualSetPointREALForced reference after control.
VAR_INPUTSelectSetPointBOOLSelects which reference to use.
VAR_INPUTFeedbackREALLoop feedback variable.
VAR_INPUTMinimumOutputREALMinimum controller output value.
VAR_INPUTMaximumOutputREALMaximum controller output value.
VAR_INPUTKpREALProportional gain.
VAR_INPUTKiREALIntegral gain.
VAR_INPUTKdREALDerivative gain.
VAR_INPUTTauSetPoint#REALTime constant for the automatic-reference input filter.
VAR_INPUTType#BYTEController type.
VAR_INPUTAction#BYTEControl action.
VAR_INPUTTs#UINTSampling period, in milliseconds.
VAR_OUTPUTENOBOOLOutput enable.
VAR_OUTPUTOutputREALController output.
VARPID_INST_0PIDInstance used to access the block structure.

Operation

On the rising edge of EN, Output receives zero. The block executes while EN remains TRUE.

When enabled, the block executes a PID control routine using the configured Kp, Ki, and Kd values. The selected Type# defines whether the academic topology or the parallel topology is used.

MinimumOutput and MaximumOutput saturate the controller output. When SelectSetPoint is FALSE, the block uses SetPoint as the reference and the controller acts on the process. When SelectSetPoint is TRUE, the controller no longer acts on the process and ManualSetPoint is used as the controller output signal.

Action# defines the feedback operation. With direct action, the operation is SetPoint - Feedback. With reverse action, the operation is Feedback - SetPoint.

Feedback receives the process variable used as the plant output. Ts# receives the controller sampling period. TauSetPoint# receives the time constant for the automatic-reference input filter.

When EN is FALSE, Output remains unchanged. After operation is complete, ENO passes the value of EN to the next Ladder block.

The following diagrams show the controller topologies referenced by the block operation.

PID academic topology

PID parallel topology

Effect Of Gain Changes

Reducing Kp usually makes the process slower, generally more stable or less oscillatory, and reduces overshoot. Increasing Kp usually makes the process respond faster, but may make it unstable or more oscillatory and increase overshoot.

Reducing Ki usually makes the process slower to reach the setpoint, generally more stable or less oscillatory, and reduces overshoot. Increasing Ki usually makes the process reach the setpoint faster, but may make it more unstable or oscillatory and increase overshoot.

Reducing Kd usually makes the process slower and reduces overshoot. Increasing Kd may increase overshoot.

Academic PID Gain Adjustment

For academic PID control, use the following adjustment guidance from the source documentation:

  • If the process is almost correct but overshoot is slightly high, try reducing Kp by 20%, reducing Ki by 20%, or reducing Kd by 50%.
  • If the process is almost correct but has no overshoot and takes too long to reach the setpoint, try increasing Kp by 20%, increasing Ki by 20%, or increasing Kd by 50%.
  • If the process performance is good but the process output varies too much, try increasing Kd by 50% or reducing Kp by 20%.
  • If the process performance is poor and the transient response lasts for several oscillation periods that decrease very slowly or do not decrease, try reducing Kp by 50%.
  • If the process moves slowly toward the setpoint, has no overshoot, is still far from the setpoint, and the process output is lower than the nominal value, try increasing Kp by 50%, increasing Ki by 50%, or increasing Kd by 70%.

Execution Flowchart

PID execution flowchart

Examples

PID ladder example

The Ladder example creates a digital academic PID loop with a 50 ms sampling time. It uses the KP, KI, and KD constants for control.

The example uses the automatic reference SETPOINT, filtered by a first-order filter with a 0.01 time constant. The error signal is calculated as the difference between the filtered reference and SAIDA_PLANTA. The controller output is saturated between 0.1 and 2.5 and written to ENTRADA_PLANTA.