Applicable Model(s)

Maple PLCs
HMC2000
HMC3000
HMC4000
HMC7000

Title

PID Loop Configuration

Date

11/03/2022

Rev

02

P/N

0907-7013

Summary

This tech note explains the PID (Proportional Integral Derivative) instructions available in MAPware-7000 for Maple HMI  + PLC and PLC products. The PID function is used to control process variables such as temperature, pressure, liquid level, or flow rate. Because the controlled process characteristics vary widely, this guide explains basic/general methods to use the PID function. For precise PID tuning, knowledge of the process being controlled is required.

This tech note contains the following 3 sections:

Section 1: PID Basics

This section, starting on the next page, provides basic information on PID control and PID parameters. It will cover how each piece of the PID equation affects loop tuning.

Section 2: Native Ladder Implementation (MLC, HMC3000 and 7000 ONLY)

This section, starting on page 5, covers the specifics of the PID5 instruction when using Native Ladder Programming Language in MAPware-7000.

Section 3: IEC Mode Implementation (Includes HMC 2000 and 4000)

This section, starting on page 8, covers using the PID function block when using IEC 61131-3 Programming Language in MAPware-7000.


Section 1 – PID Basics

The basic idea behind a PID controller is to read a sensor, then compute the desired actuator output by calculating proportional, integral, and derivative responses and summing those three components to compute the output.

The PID controller receives the process variable (PV) and controls the manipulation variable (MV) in order to adjust the PV to match the set value (SV).

The figure below shows a typical configuration for a PID control system:

  • Process: A physical system in which manipulating an input parameter has an effect on a measured value of the system such as temperature, pressure, flow rate, position, etc.
  • Sensor: A detector that detects the controlled physical values. It can be a thermocouple, RTD, pressure gauge, flow meter, etc.
  • Signal Converter: A device that transmits a weak sensor signal to the PID controller by converting it into the signal suited for the environment, such as 4 – 20 mA, 1 – 5 VDC, pulse train, etc.
  • Actuator: A device that acts as an input to the process by regulating fluid or electric power according to the Signal generated by the PID controller. It can be a control valve, thyristor, and variable speed drive, etc.
  • Process Variable (PV): The measured observable value of the system which is to be controlled, normally 4 – 20 mA or 1 – 5 VDC analog signals.
  • Manipulation Variable (MV): The PID output which controls the actuator, normally 4 – 20 mA, 1 – 5 VDC, or a time-proportional pulse.
  • Set Point Value (SV): The desired target for the Process Variable.
  • Error (e): Difference between the PV and SV at a given measurement point.
  • PID Equation: Algorithm relating the Error, time, and PID parameters to calculate a value for MV. Controls the MV based on the magnitude of E and the PID tuning Parameters. These parameters may be more or less aggressive based on system time responses and operator preferences.

In the PLC, a PID function block and analog input/output modules are used for PID control (one PID loop). To configure two or more PID loops, two or more PID function blocks are used. However, the number of the PID loops configurable by one PLC is normally limited by the available number of analog inputs/outputs.


Proportional (P) Control Action

Proportional (P) control generates the MV in proportion to the error (E).

Here, the error (E) is the difference between the SV and the PV, and defined as follows:

E = SV – PV

In the P control action, the MV is calculated as follows:

MV = Kp * E

KP is called proportional gain. Generally, P control action works as follows:

With just P control, an offset (residual error) will remain. Therefore, P control is used with I control (PI control) to eliminate the offset.


Integral (I) Control Action

Integral (I) control will generate the MV in proportion to the time-integral of the error (E). While the error (E) exists, the I control will modulate the MV to eliminate the error (E). Generally the MV with I control is calculated as follows:

TI is called integral time, the unit of measure is ‘seconds per repeat’ When TI is large, the MV will change slowly. When TI is small, the MV will change rapidly. That is, the smaller the TI, the larger the integral gain. When TI is too small, oscillation of PV will appear as in the figure below:

The I control is not used by itself. It is used with P (PI control) or P and D (PID control).


Derivative (D) Control Action

Derivative (D) control will generate the MV in proportion to the rate of change in the error (E). By adding D control, quick corrective action can be obtained at the beginning of an upset condition. Generally MV is related to the D parameter as follows:

TD is called derivative time, the unit of measure is ‘repeats per second’. When TD is large, MV is relatively large for any E. That is, the larger the TD, the larger the derivative gain. If TD is 0 (zero), the D control does not function. When TD is too large, short periodic oscillations of PV will appear:

The D control is not used by itself. It is used with P and I (PID control).D control is poorly suited for processes which oscillate rapidly and is seldom used in processes which have a fast response time (most pressure or flow loops). For processes with long lag times (many temperature and some level loops), D control can reduce both the magnitude of E and the potential for large overshoots caused by a given upset condition.

Note that these same processes often act as mechanical integrator and the I tuning parameter can actually stimulate a worsening of the overshoot or oscillation problem.


Section 2 – Native Ladder Implementation

Input (B30)OperationOutput
OFFInitialize/No OperationOFF
ONExecute PID every setting intervalON when Executing

Algorithm Used:

PID5 is the preferred PID instruction when using Native Ladder in MAPware-7000. Three assigned registers (Operands A, B, and C) point to the locations of 24 registers that are used by the PID5 instruction. Using the parameters stored in the 9 registers starting with the register specified by operand B, and the values stored in the 11 registers starting with the register specified by operand C, the PID calculation is executed as described above on the present value PV and the set value SV stored in the 4 registers starting with the register specified by operand A. The increments of manipulation value MV is calculated and stored in the register specified by the Operand C. Registers marked as Reserved below are used internally by the PID5 instruction and should not be otherwise used in your program.

Input Data (Operand A)Control Parameters (B)Output Data (C)
AD10Process Input Value (PV)BD20Proportional Gain (KP)CD30Manipulation Value (MV)
A+1D11Set Value (SV)B+1D21Integral Time (TI)C+1D31Previous error (en-1)
A+2D12ReservedB+2D22Derivative Gain (KD)C+2D32Previous error (en-2)
A+3D13ReservedB+3D23Active Range (AR)C+3D33MV in float
 B+4D24ReservedC+4D34MV in float
 B+5D25ReservedC+5D35Reserved
 B+6D26ReservedC+6D36Reserved
 B+7D27ReservedC+7D37Reserved
 B+8D28Action Type (ACT)C+8D38Reserved
   C+9D39Iterm in float
      C+10D40Iterm in float

Parameter Notes:

A: Process Input Value (PV)

A+1: Set Value (SV)

B: Proportional Gain (KP)

B+1: Integral Time (TI) (sec)

B+2: Derivative Gain (KD)

B+3: Active Range (AR) (percentage)

Data Range: -32768 to +32767

Data Range: -32768 to +32767

Data Range: -32768 to +32767

Data Range: 0 to 32767

Data Range: -32768 to +32767

Data Range: 0 to 100

Active Region value = AR * SV / 100

Active Region value is calculated from the Active Range (AR) percentage of the set value (SV). The PID5 instruction is executed only if error (en) is less than the Dead band value. When the PID5 instruction is not executed, the MV is set automatically to either 0 or 4095 (MVMAX) depending on comparison between SV and PV.

NOTE: Set the Active Range to 100 to execute the PID instruction over the full span. If the Active Range is set to 0, the PID5 output will toggle between 0 and 4095.

B+8: Action (ACT)

Data Range: 0 to 1

0: Direct Action, MV increases when the error becomes more positive.

1: Reverse Action, MV decreases when the error becomes more positive.

There are two basic actions of PID with respect to the control direction of MV, direct action and reverse action. Direct action will lead the MV to increase when the PV is larger than the SV (for example, a cooling application). Reverse action will lead the MV to decrease when the PV is larger than the SV (for example, a heating application).

C: Manipulation Value (MV)

C+1: Previous error Value (en-1)

C+2: Previous error Value (en-2)

Data Range: 0 to 4095

Data Range: -32768 to +32767

Data Range: -32768 to +32767

NOTE: You must ensure that the PID5 instruction is executed once every scan interval in the Ladder Logic. Multiple PID5 instructions can be used in a program.

NOTE: The PID4 instruction has been deprecated. It used the same PID equation as the PID5 instruction covered here, but variables are configured in slightly different locations. See the MAPware-7000 help files for PID4 configuration information if using an older version of MAPware-7000.

NOTE: The PID1 instruction is not covered in this tech note and is not recommended for PID control. It uses the following PID equation:

Only one PID1 instruction can be used in a program. See the MAPware-7000 help files for configuration instructions if this formula is desired.

Configure a PID5 Instruction

1. Create new application using Native Ladder as the programming language.

2. Add and configure your selected I/O module.

3. Create tags to reference in the PID5 instruction. Use the chart in the previous section to ensure parameters are created at the correct addresses.

4. Select the Main Block of ladder. Move your analog input to the Process Input Value.

5. Add a PID5 instruction.

6. Move the Manipulation Value to your analog input.

NOTE: In most cases, additional manipulation of the analog input and output signals will be required. This example shows a very simple loop.

7. Create a screen to allow the tuning parameters to be adjusted.


Section 3 – IEC Mode Implementation

Ladder Diagram

Function Block

Structured Text

The PID instruction in IEC 61131-3 Mode is supported in Ladder Diagram (LD), Function Block Diagram (FBD), and Structured Text (ST) programming languages as pictured above. Additional inputs allow for more PID features.

Input OperandData TypeDescription
AUTOBOOLTRUE = normal mode – FALSE = manual mode.
PVREALProcess value
SPREALSet point
Xout_ManuREALOutput value in manual mode
KPREALProportional gain.
TIREALIntegration factor
TDREALDerivation factor
TSTIMESampling period, must be larger than PLC cycle time
XMINREALMinimum allowed output value
XMAXREALMaximum output value
  I_SELBOOLIf FALSE, the integrated value is ignored. Must be set to TRUE for Integral Control to fuction.
INT_HOLDBOOLIf TRUE, the integrated value is frozen
I_ITL_ONBOOLIf TRUE, the integrated value is reset to I_ITLVAL
I_ITLVALREALReset value for integration when I_ITL_ON is TRUE
  DEADB_ERR  REALHysteresis on PV. PV will be considered as unchanged if greater than (PVprev – DEADBAND_W) and less than (PRprev + DEADBAND_W)
FFDREALDisturbance value on output

XMIN and XMAX are required inputs for the PID instruction to function and when used with the FFD disturbance value can scale your output. If Xout is saturated to either limit, the Integration output is frozen. If the PID loop is set to manual mode, Xout is set to Xout_Manu + FFD.

Output OperandData TypeDescription
XoutREALOutput command value (Manipulation Value)
ERREALLast calculated error
Xout_PREALLast calculated proportional value
Xout_IREALLast calculated integrated value
Xout_DREALLast calculated derived value.
Xout_HLMBOOLTRUE if the output value is saturated to XMIN
Xout_LLMBOOLTRUE if the output value is saturated to XMAX

Configure an IEC PID Instruction

1. Create new application using IEC61131-3 as the programming language.

2. Add and configure your selected I/O module.

3. Create tags to reference in the PID5 instruction.

4. You have the option to set initial values as tags are created.

This can alternatively be done in a Power-up Task. The SP, KP, TI, TD, TS, XMIN, XMAX, FFD, and I_SEL values are all good candidates for preset values, as this will allow you to begin testing the PID loop quickly.

5. Open Main Block1. Select the any_to_real instruction from the Conversions folder of the Instruction List section in the bottom right corner of MAPware-7000 to move your analog input into the Process Input Value (PV) tag.

6. Add a PID (**) instruction.

7. Double-click the ??? to create an instance of the PID instruction and then assign the tags created above.

8. Move the Manipulation Value (Xout) to your analog output.

NOTE: In most cases, additional manipulation of the analog input and output signals will be required. This example shows a very simple loop.

9. Create a screen to allow the tuning parameters to be adjusted.

Short Sample Project Description

The IEC PID Sample Project takes a Thermocouple temperature input as the PV input, and outputs a PWM signal to adjust the external heating element. The Thermocouple and PWM are configured in the IO Allocation Expansion Configuration Settings.

XMIN (preset to 100), XMAX (preset to 9900), and FFD (preset to 5000) are used to scale Xout into a value that is easily processed to a duty cycle for the PWM output. The Eno (Output Enabled) signal from the PID instruction’s ladder output is used to enable the PWM output when the instruction is enabled. TS is preset to 1000 (sample time of 1 second), and I_SEL is preset on to enable the Integral Control. Initial values of 100, 1000, and 1 are used for KP, TI, and TD respectively. These will be adjusted during runtime as the PID loop is tuned.

Scroll to Top