# PID Controller

Navigation: Models ➔ Control Models ➔ PID Controller

## General Description

The PID unit is used to simulate simple PID plant control functions. If the user requires more complicated controls that involves data manipulation, then the General Controller can be used to assist the PID control. For example, user may want to calculate the setpoint as a function of temperature, or change the output range as a function of plant feed.

• A single PID controller unit can be used to simulate a number of independent PID controllers on the plant. The user may enter the required number of PID controllers in the Count field on the first page of the Access window.
• The control logic used to manipulate the variables is executed once at the end of each SysCAD iteration.
• The PID controller may be used in Steady State or Dynamic mode.
In Dynamic mode it closely simulates an actual plant PID loop.
In Steady State mode the time dependent factors are not used in the traditional manner, instead each iteration is treated as a "one second time increment".

### The Referenced Tags

The PID Output tag and the Measured tag, will have coloured triangles shown in the access window of those units. When the user right clicks on one of these referenced tags it will indicate which PID is referencing the tag. See Controlled and Referenced Variables.

• In Steady State, the requirement for the measured value to equal the set-point is included in the convergence criteria. Therefore, the SysCAD Steady State solver will continue with iterations until this objective is met within the defined tolerances for at lease three consecutive iterations.
• If the output of a controller is at it's minimum or maximum output limit, then the PID is excluded from these criteria and the solver can stop even though the set-point is not achieved. This is because the output can no longer influence the measured value to achieve the required set-point value. A condition error message is given to alert the user to this.
• Please refer to section Hints and Comments for more comprehensive hints on how to troubleshoots the controller, user can also have a look at the video links below for how to add and troubleshoot the controllers used in the tutorial project.

The following videos are part of the Tutorial showing users how to use PID Controllers:

### Diagram

The diagram shows the default drawing of a PID controller.

This screen dump shows variables used and calculated in the PID Controller. (Example PID from the Tutorial)

## Inputs and Outputs

There are no connections to this unit.

## Model Theory

The classical PID algorithm as shown below is used in the model:

$\displaystyle{ \mathbf {\mathrm{u(t) = K e(t)+\cfrac{1}{T_i}\int e(t)dt + T_d\cfrac{de(t)}{dt}}} }$

Where:

u(t) = the control action or output variable at time t in seconds;
e(t) = the error (or deviation) w(t) - y(t): the difference between the set point w(t) and the measured variable y(t);
K = the Gain;
Ti = the Integral time;
Td = the Derivative time.

For a full description of the theory, please see the reference below.

### References

Clarke D.W, PID Algorithms and their computer implementation, Dept of Engineering Science, University of Oxford Trans Inst M C Vol 6 No 6 Oct-Dec 1984

The Wikipedia article on PID Controllers also well describes the basic concepts, and contains a number of external links to useful sites.

### Applying the Measured and Output Range

Each PID implementation works on normalised values. So the measured and setpoint values are scaled between 0 and 1 where 0 is InMin and 1 is InMax. The PID algorithm then works in this scaled values. This scaling needs to be taken into account when computing the effective open loop gain of the process as seen by the PID controller.
• MeasScaled = (Meas-InMin)/(InMax-InMin)
• SetpointScaled = (Setpoint-InMin)/(InMax-InMin)
The PID algorithm is performed on the scaled values and calculates OutScaled.
Then OutScaled is converted to final Output value to be set based on the Output Range:
• Output = OutMin+OutScaled*(OutMax-OutMin)

### SetPoint at or near measured limits

The SetPoint for the PID should be within the measured range. Ideally this should not be "close" to the limits as this does not give a significant error term and hence the PID action can be "inefficient". This setpoint tolerance for "close" is 10% relative to the user specified measured minimum and maximum. SysCAD gives a warning message when the setpoint value is within this tolerance of the defined measured minimum or maximum.
In SysCAD, to still give a reasonable error term to drive the PID action when the setpoint is within tolerance of the measured limits, an adjusted measurement minimum or maximum is used.
• A value equal to the setpoint value less 10% is used for measured minimum when the setpoint is close to the user specified measured minimum.
• A value equal to the setpoint value plus 10% is used for measured maximum when the setpoint is close to the user specified measured maximum.
• Therefore the MeasScaled described above is adjusted accordingly.
In the special case where the setpoint is equal to the measured limit and also equal to the measured value, then the PID output is set to the output minimum or maximum (according to measured limit and reverse action). This is because the setpoint has been met and there is no error term to drive the output (and hence any previous output may appear correct when in fact an alternate output value is expected).

## Data Sections

The default PID Controller access window consists of 3 sections. The number of sections in the access window will depend on the number of independent PID controllers required by the user.

Each independent PID controller is displayed on a separate page.

### Summary of Data Sections

1. PID tab - Contains a summary of all of the individual PIDs contained in the unit.
2. P1 tab - Each individual PID has it's own page - starting at 1 for the first PID. This page contains all of the information for each individual PID.
3. Info tab - Contains general settings for the unit and allows the user to include documentation about the unit and create Hyperlinks to external documents.

Unit Type: PID - The first tab page in the access window will have this name.

### P1: Individual PID Data Fields

Each independent PID is displayed one per page.

## Adding this Model to a Project

Insert into Configuration file

Sort either by DLL or Group.

 DLL: Control1.dll → Units/Links → Control: PID or Group: General → Units/Links → Control: PID

Insert into Project

 Insert Unit → Control → PID

See Insert Unit for general information on inserting units.

1. If one of the PID controllers contains a tag that is invalid, SysCAD will flag that user that there is an error in the PID controller. Check the Messages window for a list of the invalid tags.
2. If a PID controller ceases controlling, it may be that the measured or output variable is outside of the user defined minimum and maximum values.
• If this is the case, user should see warnings in the message window - solver conditions tab:
• To fix the errors, check the measured and output ranges and adjust the minimum or maximum values so that the measured/output variable falls within the limits.
3. HINT: "How to set up the PID to handle large setpoint ranges?", this may be required for scenario testing runs.
• Use a general controller (PGM file) to assist the PID control. Set up PGM logic to set some of the following based on user-defined logic:
• Measured Tag Min and Max Range (eg: use some known ratios to estimate the input range)
• Output Tag Min and Max Range (eg: use some known ratios to estimate the output range)
• Proportional band (eg: set up some user logic to change the Propband (or gain) based on error, can set the loop to be fast when it is far away from the solution, then slower then it is near the solution)
• Please note that some tags can only be adjusted when the project is not solving, such as controller on/off, SetPointTag, MeasureTag, OutputTag etc.
4. If the response of a independent PID is too fast, it will bounce around and never converge.
• User should always take advantage of the Trend Window while tuning the control loops.
• Suggest starting by increase the proportional band (or decrease the gain) until the response settles down, hint: watch the response from the trend window as you adjust the values and run the project.
For example, let's look at the acid controller from the Tutorial project (Chapter 6 of the tutorial).
• If we didn't change the PropBand from its default value (5), we will find that this controller is too sensitive, we need to use smaller step change to keep it in control. To reduce the step change, we can increase propband (reduce the gain).
• We can increase the PropBand to a value that the solution can be found quickly. We can see this from the above picture that with a slower loop, we were able to find a solution.
5. If changing the PropBand alone doesn't stabilise the solution, user should double check that:
• the control logic is correct, thus, the controlled variable (output tag) will have an effect on the measure tag.
• the measure variable and setpoint are using the same engineering units.
• the measured value is within range, and
• the output value is ranged sensibly. For example, if we only need to add 20 t/h acid, then we should not set the output maximum to 500 t/h, as this will cause the step size to be too big, and a solution may not be found.
6. Each PID implementation scales the measured variable and control output between 0-100%. The PID algorithm thus works in this scaled range. This scaling needs to be taken into account when computing the effective open loop gain of the process as seen by the PID controller.
• Process Measurement Scaling : Kin = 100/(Inmax-Inmin)
• Control Output Scaling : Kout = (Outmax-Outmin)/100
• Process Gain with Eng Units : Ku
• Unitless Process Gain as Seen by PID : K = Kout*Ku*Kin = (Outmax-Outmin)/(InMax-InMin)*Ku
• See Process Gain for an example calculation.
7. User can choose to use "P" control or "PI" control for Steady state projects.
• Some loops only require proportional control, so user may only need to adjust the Gain (or Proportional band). (The acid control above is such an example).
• Some loops can benefit by adding integral control, (thus PI control). PI control helps to remove the offset (error). (The steam control from the tutorial is such an example)
• user should watch the trend to get the desired response, such as should we allow for overshoot (can be faster see ), we can remove the overshoot, but can make the loop slower , so user should tune the loop to best suit their situation allows for small overshoot while keeping the loop relatively fast.
In the above example, we have eliminated the overshoot by using PI control.
User can adjust the P and I constants (by observing the response) until the desired output is achieved.
8. HINT: when tuning a loop, it is always a good idea to test some setpoint changes to make sure the loop can handle any expected flow changes. Also, as the flowsheet changes (by adding more complexity), user will need to revisit the control loop and tune it again.
9. Always analyse the circuit to help with control decisions, for example,
• some control loops are local, such as adding water to get certain solids fraction, these should be fast acting loops;
• some control loops such as production control will affect the entire balance, these should be slow acting loops, we need to allow the circuit enough time to adjust to the change.
• if user do not pay attention, they can end up with a project that just oscillates and never solves.
10. Users can take advantage of the controller auto-tuning functionality to help tune controllers in the project. This often result in projects converging much faster with well tuned controls and is especially useful if many controllers have been used. To find out how, please refer to Controls Window.
• Auto tuning should be used with caution. Keep in mind that auto-tune is normally carried out while holding everything else steady, so results from Auto-tune may be too fast for the project. As a rule, always do manual set point change to test the loop tuning.
• Not all loops are suitable for auto-tune. Loops with large lag time (due to recycle or control variable is very far away from the measured variable) is hard to auto-tune. Recommend manual tuning.
11. Control engineers using SysCAD may complain that the PID controller Direct / Reverse action is opposite to what they are used to. This is due to the fact that SysCAD uses the process response to determine the direction, not the process gain. For example, for this model to work properly, the line of thinking should be as such:
a) Steam is added ↑ to raise ↑ the temperature in the tank. So the process response in the same direction, thus this should be left un-ticked.
b) Cooling water is added ↑ to reduce ↓ the temperature in the tank. So the process response is in the opposite direction, thus this should be ticked.
• The problem above can be rectified by selecting the newly implemented method 4-Clark FF under Type. Reverse Acting (SP - PV) Used when the process gain is positive. Direct Acting (PV - SP) Used when the process gain is negative.

### Process Gain

For the example we have used above (proportional acid control), we can calculate the initial step size used by the controller:
InMin InMax OutMin OutMax PB Overall Process Gain
K = Kout * Ku * Kin
Comment
0 10 0 20 5 = [(20-0)/100] * [1/5] * [100/(10-0)] = 0.2 * 0.2 * 10 = 0.4 The step change is quite fast at 0.4 t/h.
0 10 0 20 25 = [(20-0)/100] * [1/25] * [100/(10-0)] = 0.2 * 0.04 * 10 = 0.08 The step change is slowed down to 0.08 t/h.

### Using functions for Setpoint / Measured Value

A subset of the PGM commands can be used in the PID Controller Model for "SetpointTag" and "MeasuredTag" fields.

For example, user may want to measure the combined flow of P_003 and P_004, so in the Measured tag field, enter = ["P_003.Qm (t/h)"] + ["P_004.Qm (t/h)"]

NOTE: we normally recommend using the PGM file to perform these calculations, as it will be easier to see and change.