PID is a function that is used in many PLC applications for controlling a process variable near the setpoint. If PID is configured properly and used according to the application, then we can maintain a certain process within its predefined limits.
How to Program PID Control?
For example, if we set the AC temperature to 24 deg.C, then the controller inside will maintain the current temperature near this setpoint for efficient cooling. This same function is called a PID or proportional-integral-derivative. In this post, we will see how to write a PLC program for PID using structured text in the Siemens TIA Portal.
Let us understand the case scenario first. We have a flow transmitter that gives us the value of flow in a gas pipeline. The motive is to control the flow amount in the pipeline through a flow actuator valve. This valve will pass the exact amount of gas flow and control the process accordingly.
For this, we have used S7-1500 PLC and require a PID function block in this process. When the flow goes above the setpoint, the valve should close and when the flow goes below the setpoint, the valve should open. In this way, the gas flow will be maintained around the setpoint.
Structured Text PLC Program
Let us see the program below now.
First, we need to add an OB in the program which will be a cyclic interrupt. A cyclic interrupt will trigger the function block of PID in periodic intervals, irrespective of the main program scan time.
This ensures timely action and a safe process. If we take this PID block in main program OB (also known as main OB1 in TIA Portal), then it would have been executed according to scan time; and if the program is lengthy, then it would have taken some time for the block to execute and take corrective action.
So, place this function block in cyclic interrupt OB30. Do not forget to choose the language as SCL because we are writing the program in structured text language. Refer to the below image.
Next, you have to drag the technology object of PID as shown in the below image. Select the PID_Compact block and drag it in the OB you took earlier.
When you drag the object, you will be asked to name the instance name as shown below. Name it as Flow_PID.
After that, the code will be seen as shown in the below image. Here, you have to define the input and output variables, because as you can see, the by-default names have occurred which are indicated with red underlines.
_In indicates input variables and _Out indicates output variables.
For simplicity, we will create a DB or data block named Flow_PID_Val in the program.
In this DB, we will name all the parameters with exact names and data types as in the function block for simplicity. Then, we will just map these parameters in the program as shown below.
Also, as seen in the last two lines, we are directly moving PLC analog input raw counts into input_per variable and output_per variable from PID into PLC analog output raw counts.
(The variables input and output in the FB are used when you want to link scaled values done in the PLC program and not raw count values; because per stands for peripherals which is nothing but PLC IO’s).
Now, our program is compiled and free from any errors.
Now, the next important part comes in the configuration and commissioning PID block. Refer to the images one by one below for setting the values (in the configuration window).
Apart from these, no values need to be changed. The output values and PID values will be adjusted automatically.
Now, when you have downloaded the program in PLC, you need to go to the commissioning window of the PID tab.
Refer to the below images for more information. As the raw count of the flow sensor varies, the output counts of the valve will automatically be adjusted to keep it near the setpoint.
You can refer to the pin description for inputs and outputs of the PID Compact block in the software help file for more information.
In this way, we saw the PLC program for PID using structured text.
Read Next:
- Structured Text PLC Logic for Motor Interlock
- Automatic Curtain Control PLC Programming
- Car Wash Program Functional Block Diagram
- PLC Timer Exercise Coffee Machine Program
- Configure PID Controller in Schneider PLC