This article describes implementation of a PID instruction inside a function block for iQ-F PLC.
Ten artykuł opisuje blok funkcyjny dla sterownika iQ-F implementujący instrukcję PID.
1. Function Block
This function block is a iQ-F PID instruction implementation for ease of use with all functionality and parameters as inputs of fb. There is also added manual mode for setting exact Manipulated Value with PID turned off. It can be use for easier configuration of PID regulation in iQ-F PLC.
To start PID regulation you need to set parameters described below
2.1 Basic PID inputs and outputs:
Set Value is value you want to achieve in regulation, Process Value is actual value of regulated object and Manipulated Value is output of regulator.
2.2 Operation direction:
Forward operation is operation that
increases the output value (MV) when the measured value (PV) becomes larger
than the target value (SV). This operation is used when performing cooling
Backward operation is operation
that increases the output value (MV) when the measured value (PV) becomes
smaller than the target value (SV). This operation is used when performing
This option is settable from i_bOperationDirection
input. "0" is Forward (cooling) operation and "1" is Backward (heating) operation:
When enabling function block with i_bEN input you need to select and enable one of the operation modes:
2.3.1 Manual mode
In this mode value writen to i_wManualSetValue is set to o_wManipulatedValue.
2.3.2 Auto mode
In this mode o_wManipulatedValue is calculated by PID regulator.
2.4 Sampling time:
To properly use PID regulation you need to set sample frequency. In this function block you set sampling time in miliseconds. Sampling time should be at least as fast as Nyquist rate which is twice as fast as the response rate of the controlling system. But preferably sampling time should be 5 to 10 times faster then system frequency.
2.5 Overshoot Suppression Processing:
This input enables additional processing counteracting overshoot occurrence
2.6 Manipulated Value settings:
To limit manipulated value you need to set upper and lower limit value (ULV, LLV). When you set 1000 in ULV and 0 in LLV it mean that Manipulated value will not exceed 1000 nor drop below 0:
When you want to know when Manipulated Value reaches exact value you need to set Upper and Lower Limit Alarm:
When Manipulated Value reaches alarm treshold will be turned on:
2.7 Input filter:
The input filter (α) is a software filter to reduce the fluctuation of the measured value (PV) caused by noise. By setting this time constant of the filter according to the control target characteristics and noise level, the effect of noise can be reduced. If the input filter value is too small, the filter effect is small. If the input filter value is too large, the input response is bad. Setting range: 0 to 99 (%).
2.8 Regulation constants:
Before turning PID regulation ON for first time you need to set some values in registers connected to this inputs. After autotuning they will be overwitten:
3.1 Autotuning parameters:
Before starting autotuning you need to set basic parameters like: autotuning method (limit cycle or step response method) , hysteresis (in limit cycle method), lower and upper value limit in autotuning and wait time setting from end of tunning cycle to start PID control
3.2 Autotuning method:
This function block support two autotuning methods: limit cycle and step response. To select method you need to use i_bATMethod:
3.2.1 Limit cycle method:
in the limit cycle method, changes in
the input value in two-position control (in which the output Upper Limit Value
(ULV) and output Lower Limit Value (LLV) are switched according to the
deviation) are measured, and then constants in the PID control are
To properly configure lthis method you need to declare four parameters, one o them is histeresis:
It says how much Process Value will be rising and falling during autotuning. Hysteresis is declared by i_wATSHPV
Next, you need to set upper and lower limit values for autotuning which limit Manipulated Value during autotuning:
Last parameter of this method is wait setting form end of tuning cycle to start of PID control (KW):
3.2.2 Step respone method:
In step response
method, by giving stepped output from 0 to 100 % to the control system, three
constants in the PID control are obtained from the operation characteristics
(maximum ramp (R) and dead time (L) and the input value variation. The stepped
output may be obtained from 0 to 75% or from 0 to 50 %.
3.3 Starting autotuning
To start tuning process firstly you need to start standard PID control and then turn on i_bStartAutoTuning input.
When autotuning will start, output o_bInAutoTuning
will turn on:
When autotuning will end, output o_bAutoTuningComplete
will turn on:
3.4 Example autotuning results
Example autotuning result using limit cycle method (red line is Set Value and white line is Process Value) are presented below:
4. Example project
In attachment there is a example project for simulating pid regulation of temperature. There's also included PID_IQF structure for this function block. Temperatule is simulated with second inertia model to create more realistic environment: