Файл: Microcontroller based applied digital control (D. Ibrahim, 2006).pdf
ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 14.06.2025
Просмотров: 3271
Скачиваний: 1
PID CONTROLLER IMPLEMENTATIONS |
251 |
wk
Kp |
||
ek |
α |
pk |
+ |
pk−1 |
z−1 |
+ |
uk |
qk |
|||
ek |
+ |
||
β |
z−1 −1
ek−1
α = KpT/Ti β = KpTD/T
Figure 10.13 PID controller as a parallel structure
The z-transform of the PID controller was derived in (9.19), and is reproduced here for convenience:
K T |
K T (1 |
− |
z−1) |
||||||||
D(z) = K p + |
p |
+ |
p d |
. |
(10.27) |
||||||
T (1 |
− |
z |
− |
1) |
T |
||||||
i |
|||||||||||
As shown in Figure 10.13, this transfer function may be implemented as a parallel structure by summing the proportional, integral and derivative terms.
With reference to Figure 10.13 we can write the following difference equations: for the proportional section,
wk = K p ek . |
(10.28) |
for the integral section, |
|
pk = αek + pk−1; |
(10.29) |
and for the derivative section, |
|
qk = β(ek − ek−1). |
(10.30) |
The output is given by |
|
uk = wk + pk + qk . |
(10.31) |
An alternative implementation of the PID would be to find a second order transfer function for (10.27) and then use the direct structure to implement it. Equation (10.27) can be written as
D(z) = K p (1 − z−1) + K p T / Ti + (K p Td / T )(1 − z−1)2
1 − z−1
= |
K p − K p z−1 + K p T / Ti + K p Td / T + (K p Td / T )z−2 − 2(K p Td / T )z−1 |
|||||||||
1 |
− |
z |
− |
1 |
||||||
= |
K p + K p T / Ti + K p Td / T − (K p + 2K p Td / T )z−1 + (K p Td / T )z−2 |
|||||||||
1 |
− |
z |
− |
1 |
||||||
MICROCONTROLLER IMPLEMENTATIONS |
253 |
|||||||||||||||||||
By taking the z-transform of (10.34) we obtain |
||||||||||||||||||||
U (z) |
= |
z−1U (z) |
+ |
a E (z) |
+ |
bz−1 E (z) |
+ |
cz−2 E (z) |
||||||||||||
or |
||||||||||||||||||||
D(z) |
= |
U (z) |
= |
a + bz−1 + cz−2 |
. |
(10.35) |
||||||||||||||
E (z) |
1 |
− |
z |
− |
1 |
|||||||||||||||
Equation (10.35) can easily be implemented using a direct realization. Notice that if only proportional plus integral (PI) action is required, the derivative constant Td can be set to zero and we get the PI equation
D(z) |
U (z) |
a + bz−1 |
, |
(10.36) |
||||||
= E (z) |
= |
1 |
− |
z |
− |
1 |
||||
with
a = K p + K p T , Ti
b = K p .
Equation (10.36) can easily be implemented as a first-order transfer function.
10.5 MICROCONTROLLER IMPLEMENTATIONS
The final stage of a digital control system design is the implementation of the controller algorithm (set of difference equations) on a digital computer. In this section, we shall explore the implementation of digital controller algorithms on PIC microcontrollers. The PIC 16F877 microcontroller will be used in the examples since this microcontroller has a built-in A/D converter and a reasonable amount of program memory and data memory. There are many other microcontrollers in the PIC family with built-in A/D converters, and in general any of these can be used since the operation of microcontrollers in the PIC family with similar features is identical.
Microcontrollers have traditionally been programmed using the assembly language of the target hardware. Assembly language has several important disadvantages and is currently less popular than it used to be. One important disadvantage is that the code generated using the assembly language can only run on the specific target hardware. For example, the assembly program developed for a PIC microcontroller cannot be used, say, on an Intel 8051 microcontroller. Assembly language programs also tend to be more difficult to develop, test and maintain.
In this section, the Hi-Tech PICC language as described in Chapter 4 is used in the implementation of the algorithms. As described in Section 1.6 there are several methods that can be used to implement the controller algorithm. One of the most common, which has the advantage of accurate implementation, is the use of a timer interrupt to generate the required loop delay (or the sampling interval). In this method the software consists of two parts: the main program and the interrupt service routine. As shown in Figure 10.15(a) Figure 10.15, in the main program various variables, as well as the A/D converter and the timer interrupt mechanism, are initialized. The timer is set to interrupt at an interval equivalent to the sampling interval of the required digital controller. The main program then enters a loop waiting for the timer interrupts to occur. Whenever a timer interrupt occurs the program jumps the interrupt service