Microcontroller based applied digital control (D. Ibrahim, 2006)
.pdf268 CONTROLLER REALIZATION
12. The transfer function of a digital controller is given by
1 + 2z−1 + 5z−2 D(z) = 1 + 3z−1 + 4z−2 .
Draw a flow diagram to show how this controller can be implemented on a microcomputer. Write a program in C to implement this algorithm on a PIC microcontroller.
13.Draw a flow diagram to show and explain how a second-order transfer function can be implemented on a PIC microcontroller using the C programming language.
14.Explain how second-order direct canonical functions can be cascaded to obtain higherorder transfer functions.
15.Explain how the sampling time can be selected in a first-order system.
16.Repeat Exercise 15 for a second-order system.
17.Describe the problems that may occur when very large or very small sampling times are selected.
18.Explain how the system stability is affected when the sampling time is increased.
FURTHER READING
˚ |
˚ |
[Astrom¨ and H¨agglund, 1995] |
Astrom,¨ K. and H¨agglund, T. PID Controllers: Theory, design and tuning, 2nd |
|
edn., International Society for Measurement and Control. Research Triangle |
|
Park, NC, 1995. |
[Cannon, 1967] |
Cannon, R.H. Jr., Dynamics of Physical Systems. McGraw-Hill, New York, |
|
1967. |
[Cochin, 1980] |
Cochin, I. Analysis and Design of Dynamic Systems. Harper & Row, New |
|
York, 1980. |
[Crochiere and Oppenheim, 1975] Crochiere, R.E. and Oppenheim, A.V. Analysis of linear digital networks. Proc.
|
IEEE, 63, April 1975, pp. 581–595. |
[D’Souza, 1988] |
D’Souza, A. Design of Control Systems. Prentice Hall, Englewood Cliffs, NJ, |
|
1988. |
[Fettweis, 1971] |
Fettweis, A. Some principles of designing digital filters imitating classical filter |
|
structure. IEEE Trans. Circuits Theory, March 1971, pp. 314–316. |
[Franklin and Powell, 1986] |
Franklin, G.F. and Powell, J.D. Feedback Control of Dynamic Systems. |
|
Addison-Wesley, Reading, MA, 1986. |
[Houpis and Lamont, 1992] |
Houpis, C.H. and Lamont, B. Digital Control Systems: Theory, Hardware, |
|
Software, 2nd edn., McGraw-Hill, New York, 1992. |
[Hwang, 1974] |
Hwang, S.Y. An optimization of cascade fixed-point digital filters. IEEE Trans. |
|
Circuits Syst. (Letters), CAS-21, January 1974, pp. 163–166. |
[Jackson, 1970] |
Jackson, L.B. Roundoff-noise analysis for fixed-point digital filters in cascade |
|
or parallel form. IEEE Trans. Audio Electroacoust. AU-18, June 1970, pp. 107– |
|
122. |
[Katz, 1981] |
Katz, P. Digital Control Using Microprocessors. Prentice Hall, Englewood |
|
Cliffs, NJ, 1981. |
[Leigh, 1985] |
Leigh, J.R. Applied Digital Control. Prentice Hall, Englewood Cliffs, NJ, 1985. |
[Nagle and Nelson, 1981] |
Nagle, H.T. Jr. and Nelson, V.P. Digital filter implementation on 16-bit micro- |
|
computers. IEEE MICRO, 1, 1, February 1981, pp. 23–41. |
[Ogata, 1990] |
Ogata, K. Modern Control Engineering, 2nd edn., Prentice Hall, Englewood |
|
Cliffs, NJ, 1990. |
[Phillips and Nagle, 1990] |
Phillips, C.L. and Nagle, H.T. Jr. Digital Control Systems: Analysis and Design, |
|
2nd edn., Prentice Hall, Englewood Cliffs, NJ, 1990. |
270 LIQUID LEVEL DIGITAL CONTROL SYSTEM: A CASE STUDY
Level sensor
PUMP |
CONTROLLER |
Setpoint
Figure 11.1 A typical liquid level control system
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Level |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
P Pump |
||
|
|
|
sensor |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||
|
|
|
|
|
|
|
|
|
A/D |
Microcontroller |
|
|
D/A |
|
Amp |
|||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Water tank
Figure 11.2 Schematic of the system
Microcontroller. A PIC16F877 type microcontroller is used in this project as the digital controller. In general, any other type of microcontroller with a built-in A/D converter can be used. The PIC16F877 incorporates an 8-channel, 10-bit A/D converter.
D/A converter. An 8-bit AD7302 type D/A converter is used in this project. In general, any other type of D/A converter can be used with similar specifications.
Power amplifier. The output power of the D/A converter is limited to a few hundred milliwatts, which is not enough to drive the pump. An LM675 type power amplifier is used to increase the power output of the D/A converter and drive the pump. The LM675 can provide around 30 W of power.
11.2 SYSTEM MODEL
The system is basically a first-order system. The tank acts as a fluid capacitor where fluid enters and leaves the tank. According to mass balance,
Qin = Q + Qout, |
(11.1) |
|
|
|
|
|
|
|
|
|
IDENTIFICATION OF THE SYSTEM |
273 |
||||||||
|
|
|
|
D/A |
Amplifier |
|
|
Pump |
|
|
|
Water tank |
|
|
||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
h |
||
Microcontroller |
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
|
|||
|
|
|
1−e−sT |
|
|
|
|
|
|
|
|
|
||||||
|
|
|
|
|
K0 |
|
|
|
||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||
|
|
|
|
|
|
|
|
|
|
Kp |
|
|
|
As + Q0 / 2h0 |
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||
|
|
|
|
s |
|
|
|
|
|
|
|
|
|
|||||
A/D |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Kl
Level sensor
Figure 11.5 Block diagram of the system
Linearizing (11.8) using (11.11), we obtain
A |
dδh |
+ |
Q0 |
δh = δ Qin. |
(11.12) |
dt |
2h0 |
Taking the Laplace transform of (11.12), we obtain the transfer function of the tank for small perturbations about the steady-state value as a first-order system:
h(s) |
= |
1 |
. |
(11.13) |
Qin(s) |
As + Q0/2h0 |
The pump, level sensor, and the power amplifier are simple units with proportional gains and no system dynamics. The input–output relations of these units can be written as follows: for the pump,
Q p = K p Vp;
for the level sensor,
Vl = Kl h;
and for the power amplifier,
V0 = K0 Vi .
Here Q p is the pump flow rate, Vp the voltage applied to the pump, Vl the level sensor output voltage, V0 the output voltage of the power amplifier, and Vi the input voltage of the power amplifier; K p , Kl , K0 are constants.
The block diagram of the level control system is shown in Figure 11.5.
11.3 IDENTIFICATION OF THE SYSTEM
The system was identified by carrying out a simple step response test. Figure 11.6 shows the hardware set-up for the step response test. The port B output of the microcontroller is connected to data inputs of the D/A converter, and the converter is controlled from pin RC0 of the microcontroller. The output of the D/A converter is connected to the LM675 power amplifier which drives the pump. The value of the step was chosen as 200, which corresponds to a D/A voltage of 5000 × 200/256 = 3.9 V. The height of the water inside the tank (output of the level
|
DESIGNING A CONTROLLER |
275 |
/*----------------------------------------------------------------- |
|
|
|
STEP RESPONSE TEST |
|
|
================== |
|
This program sends a STEP input to the D/A converter. The value |
|
|
of the input is set to 200, which corresponds to a voltage of |
|
|
5 × 200/256V. The output of the D/A is connected to a power |
|
|
amplifier which has an overall gain of G = 2.5. Thus, the step |
|
|
voltage applied to the pump is 5 × (200/256) × 2.5 = 9.76V. |
|
|
The hardware consists of a PIC16F877 microcontroller, where PORT B |
|
|
is conencted to an AD7302 type D/A converter. The output of the D/A |
|
|
is connected to an LM675 type DC power amplifier. |
|
|
File: STEP.C |
|
|
Date: July 2005 |
|
|
------------------------------------------------------------------ |
*/ |
|
#include <pic.h> |
|
|
#define AD7302 WR RC0 |
|
|
/* Start of main program */ |
|
|
main(void) |
|
|
{ |
|
|
TRISB = 0; |
/* PORTB is output */ |
|
TRISC = 0; |
/* RC0 is output */ |
|
AD7302 WR = 1; |
/* Disable D/A */ |
|
/* Send a STEP input to the D/A */ |
|
|
PORTB = 200; |
/* Send the STEP */ |
|
AD7302 WR = 0; |
/* Enable D/A */ |
|
AD7302 WR = 1; |
/* Disable D/A */ |
|
wait: goto wait; |
/* Wait here forever */ |
|
} |
|
|
Figure 11.7 Microcontroller program to send a step to D/A
A controller algorithm was then implemented in the microcontroller to control the level of the water in the tank.
One of the requirements in this case study is zero steady-state error, which can be achieved by having an integral type controller. In this case study a Ziegler–Nichols PI controller was designed.
The system model can be derived from the step response. As shown in Figure 11.11, the Ziegler–Nichols system model parameters are given by T1 = 31 s, TD = 2 s and
K |
= |
2345 − 2150 |
= |
0.05. |
||
|
200 |
× |
5000/256 |
|
||
|
|
|
276 LIQUID LEVEL DIGITAL CONTROL SYSTEM: A CASE STUDY
mV |
Voltage |
|
|
2350 |
|
|
|
2300 |
|
|
|
2250 |
|
|
|
2200 |
|
|
|
2150 |
|
|
Sec |
0 |
20 |
40 |
60 |
Figure 11.8 System step response
mV |
Voltage |
|
|
2350 |
|
|
|
2300 |
|
|
|
2250 |
|
|
|
2200 |
|
|
|
2150 |
|
|
Sec |
0 |
20 |
40 |
60 |
Figure 11.9 Step response after smoothing the curve
Notice that the output of the microcontroller was set to 200, which corresponds to 200× 5000/256 = 3906 mV, and this was the voltage applied to the power. We then obtain the following transfer function:
G(s) = |
0.05e−2s |
(11.14) |
||
1 |
+ |
31s |
||
|
|
|
|
The time constant of the system is 31 s. It was shown in Section 10.6 that the sampling time should be chosen to be less than one-tenth of the system time constant, i.e. T < 3.1 s. In this case study, the sampling time is chosen to be 100 ms, i.e. T = 0.1 s.