08 Implementation of Digital Controllers
08 Implementation of Digital Controllers
Introduction
One approach to designing a digital control system is to take an acceptable continuous-time controller for the system and
approximate it as a discrete-time controller. There are a number of approximations which can be used, two of which are
considered in this topic. It is very important to realize that the approach used in previous lectures for determining a discrete-
time transfer function of the controlled system cannot be used for the controller. The reason is that the controlled system is
actually modelled as a continuous system with ZOH; this is not applicable when modelling the controller which has no ZOH
and thus has a more complex input form.
General approach
One method of designing a digital sampled-data control system is first to design a satisfactory continuous system in the s-plane
and then convert this equivalent this into the equivalent discrete-time form in the z-plane as illustrated in figure 8.1.
Figure 8.1.
Given a performance specification for the required control system, the procedure is as follows:
1. Select a suitable sampling time T seconds.
2. Take account of the effect of the introduction of the ZOH.
3. Design a suitable controller 𝐺𝑐 (𝑠) to meet the specification.
4. Convert 𝐺𝑐 (𝑠) to a discrete form 𝐷(𝑧).
5. Express 𝐷(𝑧) as a digital algorithm.
6. Implement the algorithm and check results.
Rules of thumb
The following rules of thumb give a useful guide to suitable rates. Note that in some situations they may contradict and tria l
and error and experience will have to be used.
1. For underdamped systems, i.e. 𝜁 < 1, try sampling 8 to 12 times each damped oscillation period, e.g. put 𝜔𝑠 =
10𝜔𝑑 𝑟𝑎𝑑/𝑠.
2. For overdamped systems, i.e. 𝜁 > 1, try sampling 8 to 12 times in the 10% − 90% rise time of the step response.
3. Sample at 10 to 30 times the closed loop bandwidth 𝜔𝐵 𝑟𝑎𝑑/𝑠, e.g. put 𝜔𝑠 = 10𝜔𝐵 𝑟𝑎𝑑/𝑠.
4. Make T one tenth of the smallest significant time constant in the system.
67
This introduces a delay into the system because
𝑇𝑠
1 𝑒 (− ⁄2) 1 1−𝑇𝑠⁄ 𝑇
𝐺0 (𝑠) = 𝑠 [1 − 𝑇𝑠 ] ≈ 𝑠 [1 − 1+𝑇𝑠⁄2] = 1+𝑇𝑠⁄ (1)
𝑒 ( ⁄2) 2 2
Thus, the effect of the ZOH is approximately that of a first-order system with time constant 𝑇/2 seconds. Hence, the
approximate form of the ZOH given in equation (1) can be combined with the process 𝐺𝑝 (𝑠) before a suitable continuous
1
controller is designed in step (3) of the above procedure. Some designers use the simpler form 1+𝑇𝑠⁄ leaving the T in the
2
numerator to be calculated in the overall gain value.
Example 8.1
For a given sampled-data control system it has been determined that the following continuous-time controller will satisfy the
𝑠+𝑎
requirements: 𝐺𝑐 (𝑠) = 𝑠+𝑏
Then,
(1−𝑧 −1 )⁄
𝑠+𝑎 𝑇 +𝑎 1+𝑎𝑇−𝑧 −1 𝑈(𝑧)
𝐷 (𝑧 ) = | −1 = (1−𝑧 −1 )⁄
= = say
𝑠+𝑏 𝑠=1−𝑧 1+𝑏𝑇−𝑧 −1 𝐸(𝑧)
𝑇 𝑇+𝑏
Then,
(1 + 𝑏𝑇 − 𝑧 −1 )𝑈(𝑧) = (1 + 𝑎𝑇 − 𝑧 −1 )𝐸 (𝑧)
Take the inverse z-transform of each side and write 𝑢(𝑘) for 𝑢(𝑇), etc
(1 + 𝑏𝑇)𝑢(𝑘) − 𝑢(𝑘 − 1) = (1 + 𝑎𝑇)𝑒(𝑘) − 𝑒(𝑘 − 1)
68
Im Im Im
Re Re Re
0 0 0
Z-PLANE
Figure 8.2.
The disadvantage of the method is that the mapping approximation distorts the frequency and transient responses. This
distortion can be reduced by reducing T, i.e. by increasing 𝜔𝑠 .
Example 8.2
For a given sampled-data system it has been determined that the following continuous-time controller will satisfy the
𝑠+𝑎
requirements (same as example 8.1): 𝐺𝑐 (𝑠) = 𝑠+𝑏
Then,
2 (1−𝑧−1 )
+𝑎 2(1−𝑧−1 )+𝑎𝑇(1+𝑧 −1 )
𝑠+𝑎 𝑇(1+𝑧−1 ) 𝑈(𝑧)
𝐷(𝑧) = 𝑠+𝑏 | 2 (1−𝑧−1 ) = −1
2 (1−𝑧 )
= 2(1−𝑧−1 )+𝑏𝑇(1+𝑧−1 )
= 𝐸(𝑧)
say
𝑠= +𝑏
𝑇(1+𝑧−1 ) 𝑇(1+𝑧−1 )
Then,
[(2 + 𝑏𝑇) + (𝑏𝑇 − 2)𝑧 −1 ]𝑈(𝑧) = [(2 + 𝑎𝑇) + (𝑎𝑇 − 2)𝑧 −1 ]𝐸(𝑧)
Take the inverse z-transform of each side and write 𝑢(𝑘) for 𝑢(𝑇), etc.
(2 + 𝑏𝑇)𝑢(𝑘) + (𝑏𝑇 − 2)𝑢(𝑘 − 1) = (2 + 𝑎𝑇)𝑒(𝑘) + (𝑎𝑇 − 2)𝑒(𝑘 − 1)
69
Digital PID controllers
The general form of a continuous PID controller is
1
𝐺𝑐 (𝑠) = 𝑘𝑐 [1 + 𝑇 𝑠 + 𝑇𝐷 𝑠] (6)
𝐼
This can be approximated in digital form using either of the above methods.
𝑘
i.e. 𝐷(𝑧) = 𝑘𝑃 + (1−𝑧𝐼−1) + 𝑘𝐷 (1 − 𝑧 −1 ) (7)
𝑘 𝑇 𝑘 𝑇
where 𝑘𝑃 = 𝑘𝑐 , 𝑘𝐼 = 𝑐 ⁄𝑇 , 𝑘𝐷 = 𝑐 𝐷⁄𝑇
𝐼
𝑘𝑃
where 𝑘 = (𝑘 𝑃 + 𝑘 𝐼 ) , 𝑎= ⁄(𝑘 + 𝑘 )
𝑃 𝐼
𝑘′
𝐷(𝑧) = 𝑘 ′ 𝑃 + (1−𝑧𝐼−1) + 𝑘 ′ 𝐷 (1 − 𝑧 −1 )
𝑘𝑐 𝑇 𝑘𝑐 𝑇𝐷⁄
where 𝑘 ′ 𝑃 = 𝑘𝑐 (1 − 𝑇⁄2𝑇 ) , 𝑘′𝐼 = ⁄𝑇 , 𝑘′𝐷 = 𝑇
𝐼 𝐼
𝑧−𝑎
So, by this method also, the digital PI is of the form 𝐷(𝑧) = 𝑘 𝑧−1
Note that the PI algorithm will add a pole at 𝑧 = 1, thus improving steady-state accuracy as discussed in an earlier topic.
2𝑇𝑇𝐼 𝑢(𝑘) − 2𝑇𝑇𝐼 𝑢(𝑘 − 1) = 𝑘𝑐 (2𝑇𝑇𝐼 + 2𝑇 − 𝑇 + 2𝑇𝐷 𝑇𝐼 )𝑒(𝑘) + 𝑘𝑐 (2𝑇𝑇𝐼 + 𝑇 + 4𝑇𝐷 𝑇𝐼 )𝑒(𝑘 − 2) + 2𝑘𝑐 𝑇𝐷 𝑇𝐼 𝑒(𝑘 − 2)
𝑘𝑐 (2𝑇𝑇𝐼 +𝑇+2𝑇𝐷 𝑇𝐼) 𝑘𝑐 (2𝑇𝑇𝐼+𝑇+4𝑇𝐷𝑇𝐼 ) 𝑘𝑐 𝑇𝐷
𝑢 (𝑘 ) = 𝑢 (𝑘 − 1 ) + 𝑒(𝑘) + 𝑒(𝑘 − 2) + 𝑒(𝑘 − 2)
2𝑇𝑇𝐼 2𝑇𝑇𝐼 𝑇
70
Implementation of the digital PID
Whatever digital approximation is used the following piece of code shows the basic form of the program which implements
the algorithm. The basic structure is also common to any discrete-time controller although the details may change.
{Initialize variables}
kp := <kp>
ki := <kI>
kd := <kD>
r := <set point>
{The following continuous loop will be repeated forever or until the controller is
stopped}
WHILE true DO
y := ADCin {read y from the system}
error := r-y {calculate error}
u := output_last+(kp + ki + kd)*e-(kp +2*kd)*error_last+kd*error_last_last
{calculate the control actions, change this expression for another
algorithm}
DAC(u) {output u to the system}
error_last_last := error_last {save previous error for the next cycle}
error_last := e {save present error for the next cycle}
output_last := u {save present output for the next cycle}
delay() {delay until next sample period}
END WHILE
2. The system shown below is to have dominant poles with a damping ratio of 0.5 and a settling time of 2 seconds:
+ 1
Gc(s)
- s(s 2)
(i) What are the corresponding values of n and d? [ 4 rad/s 3.464 rad/s]
(ii) To turn this system into a discrete one, choose a sampling period which will sample 10 times each damped
period and thus give the corresponding ZOH approximation.
2
T 0.18 seconds, G 0 (s) s 11
20(s 2)
(iii) A suitable continuous controller is then G c (s) . Turn this into an equivalent digital algorithm
(s 7)
using the backward difference method. [ u(k) 12.04e(k) 8.85e(k 1) 0.44u(k 1) ]
(iv) Determine the resultant steady-state system error for unit step and ramp inputs. [ 0; 0.35]
71