You are on page 1of 11

Basic simulation of digital standard-PID-controller

Yoshihiko Takase and George Ibrahim

Department of Mechatronics Engineering, Faculty of Mechanical and Electrical Engineering, Tishreen


University, Lattakia, Syria
Abstract
Minimum essentials of simulation of the PID controller to carry out a series of experiments
related to the DC motor motion control were prepared. The effect of PID parameters to process
variable was examined step by step. The result was consistent with Ziegler-Nichols and others
method. The P controller showed a big improvement of the step response, while it never eliminated
steady-state error. The PI controller showed every good feature of P controller and in addition
eliminated the steady-state error. The PID controller showed every good feature of PI controller
and in addition stable control capability. However, the noise problem appeared by the digital
differentiation. Practical PID controllers to eliminate the noise problem was discussed.

1 Introduction
A proportional-integral-derivative controller (PID controller) is a common feedback loop component in
industrial control systems. It is widely used in industries to improve the control system instead of simple
On-Off controller. The main disadvantage of the On-Off controller is that a persistent oscillation of the
process variable occurs.[1] In the absence of knowledge of the underlying process, a PID controller is the
best controller.[2],[3]
The practice project to understand the base of the process control plainly was planned for the student
who studies the mechatronics engineering. The project consists of: 1. Characteristics of PIC PWM con-
troller measured by USB based data acquisition system,[4] 2. Basic simulation of digital standard-PID-
controller,[5] 3. DC-motor speed control by PIC-based digital PID-controller, 4. DC-motor simulation
and verification of the result by experiment, 5. Locked anti-phase PWM PID-control of DC-motor speed,
and 6. DC-motor position PID-control by simulation and experiment.
The purpose of this study is to prepare minimum essentials of software of the PID controller to carry
out a series of experiments related to the DC motor motion control. The study process is to prepare a
basic simulation system of the digital standard-PID-controller, to examine the effect of PID parameters
(proportional gain, integral time and derivative time) to the process variable, and to discuss the optimum
behavior by comparing it with the Ziegler-Nichols and others method.

2 Theoretical basis
Block diagram of traditional PID controller is shown in Figure 1.[3]
Manipulated variable M V (t) as a function of time t, the output from the controller (i.e. the input to
the process) is given by

M V (t) = POU T + IOU T + DOU T (1)

where POU T , IOU T and DOU T are the contributions to the output from the PID controller, each of
which is defined below.

1
PID Controller

POUT = K P e(t )

SP + e(t ) t + + MV (t )
I OUT = K I ∫ e(τ )dτ Process
0
− +
PV (t )
de Measurement
DOUT = K D
dt (Sensor)

Fig. 1 Block diagram of PID controller and process

POU T = KP e(t), (2)


∫ t
IOU T = KI e(τ )dτ , (3)
0
de
DOU T = KD , (4)
dt
where

e(t) = SP − P V (t) (5)

is the error, SP the setpoint and P V (t) the process variable. Proportional gain KP , integral gain
KI and derivative gain KD are constants that are used to tune the PID control loop. Normally KI is
expressed as being related to KP by introducing integral time TI which is a time where IOU T is equal
to POU T against e(t) being changed as a step function with amplitude e0 :
∫ TI
KI e0 dτ = KP e0 . (6)
0

From equation 6, KI is given by

KI = KP /TI . (7)

Similarly KD is replaced by a derivative time TD which is a time where DOU T is equal to POU T against
a linear function of e(t) = αt where α is the slope:

αKD = αKP TD . (8)

From equation 8, KD is given by

KD = KP TD . (9)

As a result M V (t) is expressed in terms of KP , TI and TD as follows:


( ∫ t )
1 de
M V (t) = KP e(t) + e(τ )dτ + TD . (10)
TI 0 dt
This form of PID controller is referred to as the standard form and is more common in industry. In
this form, TI and TD relate only to dynamics of the process, and KP relates to the gain of the process.

2
For a digital implementation of a PID controller, the standard form of the PID controller has to be
discretised. Approximations for first-order derivatives are made by backward finite differences. Thus,
the discretised PID controller is obtained as:
( )
1 ∑n
TD
M Vn = KP en + ∆t ei + (en − en−1 ) , (11)
TI i=0
∆t

where ∆t is the sampling time and n the sampling number corresponds the present time. Equation 11
is referred to as the positional algorithm.[1],[6]
The previous value of M Vn is

( )
1 ∑
n−1
TD
M Vn−1 = KP en−1 + ∆t ei + (en−1 − en−2 ) . (12)
TI i=0
∆t

Difference of the present M Vn is obtained by subtracting equation 12 from equation 11.

( )
∆t TD
∆M Vn = KP en − en−1 + en + (en − 2en−1 + en−2 ) (13)
TI ∆t
M Vn = M Vn−1 + ∆M Vn (14)

Equations 13 and 14 are referred to as the velocity algorithm.[1],[6]

3 Standard PID controller program


The standard PID velocity-algorithm was implemented by the C while loop as follows. For the purpose
of displaying the results graphically the Windows API were used.

SP = 200.0; PV = MV = 0.0; en_1 = en_2 = 0.0; DT = 0.1;


// Processing loop of the standard PID controller of velocity algorithm
while (true) {
// Equation (5)
e = SP - PV;
// Equation (13)
dMV = Kp*(e - en_1) + Kp*DT/Ti*e + Kp*Td/DT*(e - 2*en_1 + en_2);
// Equation (14)
MV = MVn_1 + dMV;
// inport from measurement
PV = inport(PV, MV);
// Update previous value to current value
MVn_1 = MV;
// Update previous value to current value
en_2 = en_1;
// Update previous value to current value
en_1 = e;
}

The inport(PV, MV) function in the program returns the process variable. The process model and its
C program is described in the discussion section.

3
4 Step response of the process under PID control
First, the step response of the process under the P control was examined by changing KP and setting
integral and derivative contributions zero. The step responses at KP = 0.1, 1.0, 1.5 and 2.5 are shown
in Figures 2, 3, 4 and 5, respectively. Two variables, P V and M V , are shown. Middle thin line indicates
the setpoint SP .

Fig. 2 Step response under P control at KP = 0.1 Fig. 3 Step response under P control at KP = 1.0

Fig. 4 Step response under P control at KP = 1.5 Fig. 5 Step response under P control at KP = 2.5

Second, effect of KP on the step response under the PI control was examined by changing KP and
setting TI constant and TD zero. Values of KP , TI and TD are listed in Table 1. The step responses
are shown in Figures 6, 7, 8 and 9. Five variables, P V , M V , POU T , IOU T and DOU T , are shown. The
middle thin line indicates SP .
Third, effect of TI on the step response under the PI control was examined by changing TI and setting
KP constant and TD zero. Values of KP , TI and TD are listed in Table 2. The step responses are shown
in Figures 10, 11, 12 and 13. Five variables are shown as same as the above examination. The middle
thin line indicates SP .
Forth, effect of TD on the step response under the PID control was examined by changing TD and
setting KP and TI constant. Values of KP , TI and TD are listed in Table 3. The step responses are

4
KP TI TD
1 0.1 3.0 0.0
2 1.0 3.0 0.0
3 1.5 3.0 0.0
4 2.0 3.0 0.0
Table. 1 Examined values of KP , TI and TD under PI control

Fig. 6 Step response under PI control at KP = 0.1 Fig. 7 Step response under PI control at KP = 1.0

Fig. 8 Step response under PI control at KP = 1.5 Fig. 9 Step response under PI control at KP = 2.5

KP TI TD
1 1.2 5.0 0.0
2 1.2 3.0 0.0
3 1.2 1.5 0.0
4 1.2 0.7 0.0
Table. 2 Examined values of KP , TI and TD under PI control

5
Fig. 10 Step response under PI control at TI = 5.0 Fig. 11 Step response under PI control at TI = 3.0

Fig. 12 Step response under PI control at TI = 1.5 Fig. 13 Step response under PI control at TI = 0.7

shown in Figures 14, 15, 16 and 17. Five variables are shown as same as the PI controller. The middle
thin line indicates SP .

KP TI TD
1 1.2 3.0 0.01
2 1.2 3.0 0.05
3 1.2 3.0 0.10
4 1.2 3.0 0.15
Table. 3 Examined values of KP , TI and TD under PID control

5 Discussion
A first-order-plus-dead-time (FOPDT) process model is often used to represent the step response
characteristics of simple systems.[1] The transfer function of the model is expressed by the following
equation.[2],[6]

6
Fig. 14 Step response under PID control at TD = 0.01 Fig. 15 Step response under PID control at TD = 0.05

Fig. 16 Step response under PID control at TD = 0.10 Fig. 17 Step response under PID control at TD = 0.15

1
GP (s) = K e−LP ·s , (15)
1 + TP · s
where K is the equivalent gain, TP the equivalent time constant and LP the equivalent dead time of
the process. Changing the transfer function to differential equation the following relation is obtained.
yn − yn−1
yn + TP = Kxn−l , (16)
∆t
where x and y are input and output of the process, respectively, and l is integer given by

LP = l∆t. (17)

From equation 16 the following formula is obtained.


TP ∆t · K
yn = yn−1 + xn−l (18)
∆t + TP ∆t + TP
Equation 18 was calculated by the following C function. The dead time was expressed by a first-in
first-out type buffer.

7
// pv: process variable
double inport(double pv, double x)
{
int i;
// y: output of the process
double y;
// l: integer index of the dead time
static double buff[l];
// x: input of the process in equation (18)
buff[l-1] = x;
y = T / (DT + T) * pv + buff[0] * DT * K / (DT + T);
// shift left of the buffer element
for (i = 0; i < l - 1; i++) {
buff[i] = buff[i+1];
}
return y;
}

The step response of this program against unit step input is shown in Figure 18 at K = 5.0, TP = 3.0,
l = 3 and DT = 0.1. Gray dotted line is the step function and black dotted line is the response. Thin
lines indicate the gain K and the time constant TP .

Fig. 18 Step response of a process

There are some important proposals to determine the PID parameters as listed in Table 4.

KP TI TD Test point
Ziegler&Nichols 1.2T/(KL) 2.0L 0.5L Decay ratio 25 %
CHR Case 1 0.95T/(KL) 2.4L 0.4L No overshoot
CHR Case 1 1.2T/(KL) 2L 0.42L Overshoot 20 %
CHR Case 2 0.6T/(KL) T 0.5L No overshoot
CHR Case 2 0.95T/(KL) 1.35T 0.47L Overshoot 20 %
CHR: Chein, Hrones and Reswick method
Case 1: Most suitable to external disturbance
Case 2: Most suitable to follow the set point
Table. 4 Proposals to determine the parameters of PID controller [3], [6]

In the present case of K = 5.0, TP = 3.0 and LP = 0.3, the values of KP , TI and TD become as shown

8
in Table 5.

KP TI TD Test point
Ziegler&Nichols 2.4 0.60 0.15 Decay ratio 25 %
CHR Case 1 1.9 0.72 0.12 No overshoot
CHR Case 1 2.4 0.60 0.13 Overshoot 20 %
CHR Case 2 1.2 3.0 0.15 No overshoot
CHR Case 2 1.9 4.0 0.14 Overshoot 20 %
Table. 5 Determined PID parameters

The step response under the P control, Figures 2 - 5, indicates that the time constant at rising edge
becomes small as KP increases. Figure 3 shows a good step response, however, certain amount of error,
e(t) = SP − P V (t), remains even after the steady state. This is the well known steady-state error
problem of the P controller.[7] The error still exists even for KP = 2.5 where the response curve becomes
oscillatory. P controller is useful for simple and qualitative control.
The step response under the PI control, Figures 6 - 9, indicates that the response is similar to that of
the P controller except the steady-state error problem. The steady-state error, e(t), is now almost zero.
This is the most significant effect of the integral term. The best curve among the four simulation results
is Figure 7 where KP = 1.0, TI = 3.0 and TD = 0.0. These values are close to the CHR case 2 on no
overshoot condition in Table 5. The improvement is significant when this result is compared with the
insufficient control result in Figure 6.
The step response under the PI control, Figures 10 - 13, indicates that the integral contribution
decreases the error as TI decreases. For smaller value of TI than 0.7, however, the curve begins to
oscillate.
The step response under the PID control, Figures 14 - 17, indicates that DOU T affects as negative
feedback especially in initial time region. As a result initial overshoot is suppressed and becomes stable
in all time region as can be seen by comparing Figure 11 (PI controller) and Figures 14 and 15 (PID
controller). The best curve among the four simulation results is Figure 15 where KP = 1.2, TI = 3.0 and
TD = 0.05. These values are close to the CHR case 2 on no overshoot condition in Table 5. Application
of exact value, however, of the CHR case 2, KP = 1.2, TI = 3.0 and TD = 0.15 in Table 5, revealed
noise problem as shown in Figure 17. The PID controller has every good feature of PI controller and in
addition stable control capability. On the other hand, Figure 17 exhibits a noise problem of the digital
PID controller.
The digital noise problem of the standard PID controller is examined by a step response of M V (t),
POU T , IOU T and DOU T against step functional change of the error e(t). The result is shown in Figure
19.

Fig. 19 Step response against step functional change of the error e(t).

9
POU T is proportional to the step function and becomes constant. IOU T becomes a straight line with
a slope. DOU T shows a sharp spike at the rising edge. For the purpose of constructing practical PID
controller at industrial use it is important to eliminate this kind of digital noise problem.
Hiroi and Miyata[6] have summarized the practical PID controller with derivative contribution having
the first order lag as follows.
Type 1 practical PID controller:
Block diagram of this type is shown in Figure 20. This type of controller has low pass filter in front of
the derivative contribution.

SP + e(t ) I 1 + +
MV (t )
KP G p (s )
− TI ⋅ s +
PV (t )
D TD ⋅ s
1 + ηTD ⋅ s

Fig. 20 Block diagram of Type 1 practical PID controller and process

Type 2 practical PID controller:


The Type 1 still has ability to generate spike against steep change of SP . The derivative contribution
is the most effective to the steep change of SP . In order to reduce this effect, the term (en − en−1 ) is
replaced by (P Vn−1 − P Vn ). Block diagram of this type is shown in Figure 21.

SP + e(t ) I 1 + +
MV (t )
KP G p (s )
− TI ⋅ s −
PV (t )
D TD ⋅ s
1 + ηTD ⋅ s

Fig. 21 Block diagram of Type 2 practical PID controller and process

Type 3 practical PID controller:


The proportional contribution is the second effective part to the steep change of SP . In order to
reduce further this effect, all of the terms (en − en−1 ) are replaced by (P Vn−1 − P Vn ). Block diagram of
this type is shown in Figure 22.
Examination of some practical PID controllers will be presented later including both simulation and
experiment.

6 Conclusion
Minimum essentials of simulation of the PID controller to carry out a series of experiments related to the
DC motor motion control were prepared. The effect of PID parameters to process variable was examined

10
P

SP + e(t ) I 1 + −
MV (t )
KP G p (s )
− TI ⋅ s −
PV (t )
D TD ⋅ s
1 + ηTD ⋅ s

Fig. 22 Block diagram of Type 3 practical PID controller and process

step by step. The result was consistent with Ziegler-Nichols and others method. The P controller showed
a big improvement of the step response, while it never eliminated steady-state error. The PI controller
showed every good feature of P controller and in addition eliminated the steady-state error. The PID
controller showed every good feature of PI controller and in addition stable control capability. However,
the noise problem appeared by the digital differentiation. Practical PID controllers to eliminate the noise
problem was discussed.

References
[1] A. Visioli: Practical PID control, p.3, Springer-Verlag London Limited (2006).
[2] M. Araki: CONTROL SYSTEMS, ROBOTICS, AND AUTOMATION - Vol. II - PID Control,
Encyclopedia of Life Support Systems (Copyright 2002-2010).
[3] Wikipedia: PID controller (last modified on 6 November 2010), http://en.wikipedia.org/wiki/
PID controller.
[4] Y. Takase and George Ibrahim: Characteristics of PIC PWM Controller Measured by USB Based
Data Acquisition System, The Forth Report of Senior Volunteer of JICA (April 16, 2008).
[5] Y. Takase and George Ibrahim: Basic simulation of digital standard-PID-controller, The Forth Report
of Senior Volunteer of JICA (April 16, 2008).
[6] K. Hiroi and A. Miyata: Introduction to Control Engineering using Simulation System (in Japanese),
CQ Publishing Co., Ltd. (October 2004).
[7] University of Michigan: Control Tutorials for Matlab, PID Tutorial (August 1997), http://www.
engin.umich.edu/group/ctm/PID/PID.html.

11

You might also like