Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Microcontroller based applied digital control (D. Ibrahim, 2006)

.pdf
Скачиваний:
1656
Добавлен:
12.08.2013
Размер:
5.68 Mб
Скачать

268 CONTROLLER REALIZATION

12. The transfer function of a digital controller is given by

1 + 2z1 + 5z2 D(z) = 1 + 3z1 + 4z2 .

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.

11

Liquid Level Digital Control System: A Case Study

In this chapter we shall look at the design of a digital controller for a control system, namely a liquid level control system.

Liquid level control systems are commonly used in many process control applications to control, for example, the level of liquid in a tank. Figure 11.1 shows a typical liquid level control system. Liquid enters the tank using a pump, and after some processing within the tank the liquid leaves from the bottom of the tank. The requirement in this system is to control the rate of liquid delivered by the pump so that the level of liquid within the tank is at the desired point.

In this chapter the system will be identified from a simple step response analysis. A constant voltage will be applied to the pump so that a constant rate of liquid can be pumped to the tank. The height of the liquid inside the tank will then be measured and plotted. A simple model of the system can then be derived from this response curve. After obtaining a model of the system, a suitable controller will be designed to control the level of the liquid inside the tank.

11.1 THE SYSTEM SCHEMATIC

The schematic of the liquid level control system used in this case study is shown in Figure 11.2. The system consists of a water tank, a water pump, a liquid level sensor, a microcontroller, a D/A converter and a power amplifier.

Water tank. This is the tank where the level of the liquid inside is to be controlled. Water is pumped to the tank from above and a level sensor measures the height of the water inside the tank. The microcontroller controls the pump so that the liquid is at the required level. The tank used in this case study is a plastic container with measurements 12 cm × 10 cm × 10 cm.

Water pump. The pump is a small 12 V water pump drawing about 3 A when operating at the full-scale voltage. Figure 11.3 shows the pump.

Level sensor. A rotary potentiometer type level sensor is used in this project. The sensor consists of a floating arm connected to the sliding arm of a rotary potentiometer. The level of the floating arm, and hence the resistance, changes as the liquid level inside the tank is changed. A voltage is applied across the potentiometer and the change of voltage is measured across the arm of the potentiometer. The resistance changes from 430 when the floating arm is at the bottom (i.e. there is no liquid inside the tank) to 40 when the arm is at the top. The level sensor is shown in Figure 11.4.

Microcontroller Based Applied Digital Control D. Ibrahim

C 2006 John Wiley & Sons, Ltd. ISBN: 0-470-86335-8

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)

Figure 11.3 The pump used in the project

Figure 11.4 Level sensor used in the project

272 LIQUID LEVEL DIGITAL CONTROL SYSTEM: A CASE STUDY

where Qin is the flow rate of water into the tank, Q the rate of water storage in the tank, and Qout the flow rate of water out of the tank. If A is the cross-sectional area of the tank, and h the height of water inside the tank, (11.1) can be written as

dh

+ Qout.

(11.2)

Qin = A dt

The flow rate of water out of the tank depends on the discharge coefficient of the tank, the height of the liquid inside the tank, the gravitational constant, and the area of the tank outlet, i.e.

Qout = Cd a 2gh, (11.3)

where Cd is the discharge coefficient of the tank outlet, a the are of the tank outlet, and g the gravitational constant (9.8 m/s2).

From (11.2) and (11.3) we obtain

dh

+ Cd a 2gh.

(11.4)

Qin = A dt

Equation (11.4) shows a nonlinear relationship between the flow rate and the height of the water inside the tank. We can linearize this equation for small perturbations about an operating point.

When the input flow rate Qin is a constant, the flow rate through the orifice reaches a steady-state value Qout = Q0, and the height of the water reaches the constant value h0, where

Q0 = Cd a 2gh0. (11.5)

If we now consider a small perturbation in input flow rate around the steady-state value, we obtain

δ Qin = Qin Q0

(11.6)

and, as a result, the fluid level will be perturbed around the steady-state value by

δh = h h0.

(11.7)

Now, substituting (11.6) and (11.7) into (11.4) we obtain

δh

+ Cd a 2(δh + h0) = δ Qin + Q0.

 

A ddt

(11.8)

Equation (11.8) can be linearized by using the Taylor series and taking the first term. From Taylor series,

f (x) = f (x0) +

Taking only the first term,

or

d f

 

 

(x

x

0

)

 

d

2

f

 

 

 

 

 

 

 

 

 

 

 

 

 

dx

x

=

x0

1!

 

 

 

+ dx

 

x

=

x0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

f (x)

f (x0)

 

d f

 

 

(x

 

 

 

 

 

dx

 

 

 

 

x

=

x0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

δ f (x)

 

 

d f

 

 

 

 

δx.

 

dx

 

 

 

 

 

 

x

=

x0

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

(x x0)2

+

. . . .

(11.9)

2!

 

 

x0)

 

 

(11.10)

 

 

 

(11.11)

 

 

 

 

 

 

 

 

 

IDENTIFICATION OF THE SYSTEM

273

 

 

 

 

D/A

Amplifier

 

 

Pump

 

 

 

Water tank

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

h

Microcontroller

 

 

 

 

 

 

 

 

 

 

 

 

 

1

 

 

 

 

1esT

 

 

 

 

 

 

 

 

 

 

 

 

 

 

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

274 LIQUID LEVEL DIGITAL CONTROL SYSTEM: A CASE STUDY

Figure 11.6 Hardware set-up to record the step response

sensor) was recorded in real time using a DrDaq type data logger unit and the Picolog software. Both of these products are manufactured by PICO Technology. DrDaq is a small electronic card which is plugged into the parallel port of a PC. The card is equipped with sensors to measure physical quantities such as the intensity, sound level, voltage, humidity, and temperature. Picolog runs on a PC and can be used to record the measurements of the DrDaq card in real time. The software includes a graphical option which enables the measurements to be plotted.

The microcontroller program to send a step signal to the D/A converter is shown in Figure 11.7. At the beginning of the program the input–output ports are configured and then a step signal (200) is sent to port B. The D/A converter is then enabled by clearing its WR input. After writing data to the D/A converter it is disabled so that its output does not accidentally change. The program then waits in an endless loop.

Figure 11.8 shows the step response of the system, which is the response of a typical firstorder system. It will be seen that the response contains noise. Also, since the DrDaq data logger is 8-bit, its resolution is about 19.5 mV with a reference input of 5V, and this causes the step discontinuities shown in the response (the steps can be eliminated either by using a data logger with a higher resolution, or by amplifying the output of the level sensor). The figure clearly shows that in practice the response of a system is not always a perfect textbook signal.

A smooth curve is drawn through the response by taking the midpoints of the steps, as shown in Figure 11.9.

11.4 DESIGNING A CONTROLLER

The circuit diagram of the closed-loop system is shown in Figure 11.10. The loop is closed by connecting the output of the level sensor to the analog input AN0 of the microcontroller.

 

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.05e2s

(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.

DESIGNING A CONTROLLER

277

Figure 11.10 Circuit diagram of the closed-loop system

mV

Voltage

 

 

2350

 

 

 

2300

 

 

 

2250

 

 

 

2200

 

 

 

2150

 

 

Sec

0

20

40

60

Figure 11.11 Deriving the system model