Professional Documents
Culture Documents
Two-Tank Liquid Level Control Using A BASIC Stamp Microcontroller and A MATLAB-based Data Acquisition and Control Toolbox
Two-Tank Liquid Level Control Using A BASIC Stamp Microcontroller and A MATLAB-based Data Acquisition and Control Toolbox
5.1. Introduction
A variety of PC-based data acquisition and control (DAC) boards are currently available
in the market. These DAC boards can be broadly classified in two categories: i) high-end
DAC boards, which provide a wide range of advanced hardware capabilities along with a
sophisticated software environment; and ii) low-end DAC boards, which are primarily used for
With the emergence of MATLAB [6] as a widely used scientific computing tool in industry
and academia, many users seek a DAC platform that can interface with and exploit advanced
within the last decade, new developments in automated code generation programs have allowed
users to utilize interactive icon-based control system simulation tools such as Simulink [44] for
real-time control. In particular, using the Simulink block library and Real-Time Workshop
(RTW) along with Simulink block libraries for vendor-specific DAC boards, one can generate
C code from Simulink-based feedback control diagrams for real-time controller implementation
on PC-based DAC boards. The ability to rapidly and efficiently design and implement complex
enhance productivity.
In Chapter 4, we developed a low-cost DAC platform which allows Parallax Inc.’s BASIC
Chapter, we illustrate several important features of the DAC platform developed in Chapter
4 by performing liquid level control of a coupled, two-tank system. Liquid level control is
ubiquitous in industrial applications, e.g., food processing, effluent treatment, power gener-
56
57
ation plants, pharmaceutical industries, water purification systems, and industrial chemical
processing. Thus, the study of liquid level control encompasses many engineering disciplines,
In this Chapter, we employ the classical proportional-plus-integral (PI) controller for liquid
level control of a coupled, two-tank system [63]. To effectively utilize this control methodology,
the system parameters, e.g., tank dimensions and pump characteristics, must be known exactly.
However, this may not be feasible since system parameters may change due to the effects
of scaling in tanks and orifices, aging of pump, and wear. Thus, to determine the system
parameters, we conduct an experimental system identification study which uses the inherent
The rest of the Chapter is organized as follows. In Section 5.2, we describe the coupled,
two-tank system model and formulate system identification and control design objectives. In
Section 5.3, we outline a method to perform system identification. In Section 5.4, we design
Figure 5.1 shows a two degree-of-freedom, state-coupled, two-tank system. This system
consists of two tanks with orifices and liquid level sensors at the bottom of each tank, a pump,
and a liquid basin. The two tanks have the same diameters and can be fitted with differing
diameter outflow orifices. In this experimental setup, the pump provides the infeed to Tank 1
and the outflow of Tank 1 becomes the infeed to Tank 2. The outflow of Tank 2 is emptied
into the liquid basin. The following conditions, with regard to the system dynamic model, are
i) the liquid levels in Tanks 1 and 2, denoted as L1(t) and L2(t), respectively, are measured
ii) L1(t) is always greater than 0cm and less than 30cm;
iv) the desired liquid level in Tank 2 is greater than 0cm and less than 20cm for t > 0 ; and
58
v) the voltage applied at the input terminals of the pump, denoted by Vp(t), is between 0 and
The nonlinear mathematical model describing the liquid levels of Tanks 1 and 2 is given
by [63]
q
L̇1 (t) = −A L1 (t) + BVp (t), (5.1)
q q
L̇2 (t) = C L1 (t) − D L2(t), (5.2)
a1 √ Kp 4 a1
√ 4 a2
√
where A 4
= A1 2g, B 4
= A1 , C = A2 2g, and D = A2 2g, ai is the cross-sectional area of the
outflow orifice at the bottom of the Tank i, Ai is the cross-sectional area of the Tank i, Kp is
ai , Ai , Kp , and g, for i =1, 2, are not known exactly. As previously discussed, the uncertainty
about system parameters may arise due to corrosive buildup in the liquid level system or the
deterioration of the pump motor. Thus, a control design based on the idealized values of the
system parameters may lead to performance deterioration for the closed-loop system. In a
subsequent section, we outline a series of experiments, which exploit the nonlinear dynamics
Given a desired, constant, liquid level for Tank 2, denoted as L2d, design a control input
Vp(t) such that lim L2 (t) = L2d . This objective is to be achieved with the assumption that
t→∞
L1 (t) and L2 (t) can be measured. Furthermore, the control design is to utilize estimates of the
system parameters.
To quantify this control objective, we define the liquid level tracking error for Tanks 1 and
where L1d is some desired, constant liquid level for Tank 1, which using (5.2) is characterized
a2 2
as L1d 4
= ( a1 ) L2d .
begin by describing the linearized error system model (see reference [63] for details)
4
where u(t) = Vp(t) − Vpd and Vpd is the desired pump voltage, which using (5.1) is characterized
√
2gL1d
as Vpd 4
= a1 Kp . Furthermore, the parameters α1 , β1 , α2 , and β2 in (5.5) and (5.6) are defined
60
as, respectively,
A D C
α1 4
= − √ , β1 4 4
= B, α2 = − √ , and β2 4
=√ . (5.7)
4L1d 4L2d 4L1d
Next, we develop the transfer function models for the linearized error system of (5.5) and (5.6)
by taking the Laplace transform of (5.5) and (5.6) and rearranging terms to yield
l1(s) β1
= , (5.8)
u(s) s − α1
l2(s) β2
= , (5.9)
l1(s) s − α2
4 L[l (t)], l (s) 4 L[l (t)], and u(s) 4 L[u(t)] with L denoting the Laplace operator
where l1(s) = 1 2 = 2 =
[64].
coupled two-tank system given in (5.1) and (5.2). Specifically, motivated by the nonlinear
dynamics of (5.1) and (5.2), we outline a set of experiments that yield the system parameters
A C
A, B, C, and D. In experiment 1, we first obtain numerical values for the ratios B and D. In
experiment 2, we obtain the numerical value for the parameter A, which using the numerical
A
value of B obtained in experiment 1 yields B. In experiment 3, we obtain the numerical value
for the parameter D using the same procedure as in experiment 2, which using the numerical
C
value of D obtained in experiment 1 yields C.
5.3.1. Experiment 1
A C
In this experiment, we obtain expressions that relate the ratios B and D to steady state
conditions of the pump and the liquid levels of Tanks 1 and 2. Specifically, we begin by noting
that if a fixed voltage is applied to the pump, then the liquid levels of Tanks 1 and 2 will reach
steady state after a sufficient amount of time. This characteristic can be proven by directly
solving the differential equations (5.1) and (5.2) given that Vp(t) is constant. Next, the solution
of (5.1) and (5.2) under steady state conditions, i.e., with L̇1 (t) = 0 and L̇2 (t) = 0 yields
A Vpss
=√ , (5.10)
B L1ss
61
s
C L2ss
= , (5.11)
D L1ss
respectively, where L1ss, L2ss, Vpss are the steady state liquid levels of Tanks 1 and 2, and the
steady state pump voltage, respectively. From (5.10) and (5.11), by applying a fixed voltage
Vpss to the pump and directly measuring the liquid levels of Tanks 1 and 2 after a sufficient
A C
amount of time, i.e., L1ss and L2ss , we can determine numerical values of B and D.
5.3.2. Experiment 2
In this experiment, we fill Tank 1 with a fixed amount of liquid and record the time history
of the liquid level in Tank 1 as it is discharged. Using this time history, we can determine
a relationship between the system parameter and the liquid level in Tank 1 at a given time
instant. To do so, we solve the differential equation (5.1) with Vp(t) = 0 and obtain
q q 1
L1 (t) = L1(t0 ) − A(t − t0 ), (5.12)
2
where t0 is the initial time and L1 (t0) is the initial liquid level in Tank 1. Note that equation
(5.12) is only valid when the right hand side of (5.12) is nonnegative, i.e., prior to full discharge
of Tank 1 since once Tank 1 is fully discharged the right hand side of (5.12) becomes negative.
To determine when the liquid in Tank 1 is fully discharged, we set L1(t) = 0 in (5.12) and
where t∗ is the time of full discharge of Tank 1. Using (5.13), the analytic expression for the
in Tank 1 is still discharging, then (5.12) can be rewritten to yield the parameter A as follows
p p
L1 (t0 ) − L1(t̄)
A=2 . (5.15)
(t̄ − t0 )
62
Next, substituting (5.15) into (5.10), we can determine the parameter B as follows
p p √
L1(t0 ) − L1(t̄) L1ss
B= 2 . (5.16)
(t̄ − t0 ) Vpss
Note that the determination of the numerical value for B in (5.16) requires the use of the
experimental data obtained from experiments 1 and 2, i.e., the steady state values L1ss, Vpss
5.3.3. Experiment 3
In this experiment, we fill Tank 2 with a fixed amount of liquid and then obtain the time
history of the liquid level in Tank 2 as it is discharging. Using this time history, we can obtain
a relationship between the system parameter D and the liquid level in Tank 2 at a given time
instant. Similar to experiment 2, using the solution of (5.2), we obtain a relationship between
where t̂ is a time instant before Tank 2 is fully discharged. Now, substituting (5.17) into (5.11),
Note that the determination of the numerical value for C in (5.18) requires the use of the
experimental data obtained from experiments 1 and 3, i.e., the steady state values L1ss , L2ss
In this section, we outline a PI liquid level control design that is based on the linearized
model of (5.8) and (5.9). As described previously, the liquid level control problem consists
of controlling the liquid level of Tank 2 to a desired, constant liquid level L2d . From (5.9),
to control the liquid level in Tank 2, we must use the liquid level of Tank 1, i.e., l1 (t) as a
pseudo control input. This necessitates control of liquid level of Tank 1 to a desired liquid level
63
L1d, which serves as a command signal for the Tank 1 controller u(t), or equivalently Vp (t).
Referring to Figures 5.2 and 5.3, we design PI controllers for Tank i, i =1, 2, as follows
KIi
Ci (s) = KPi + , (5.19)
s
where KPi is the proportional gain and KIi is the integral gain. To aid in determining the
controller gains KPi and KIi, the desired closed-loop responses for Tank i are specified in
terms of a settling time Tsi and percent overshoot oi performance criterion. It then follows
from reference [64] that the settling time and percent overshoot criterion can be related with
the closed loop damping ratio ξi and natural frequency ωni for Tank i, as follows
bi
ξi = q , (5.20)
2
bi + π 2
4
ωni = , (5.21)
Tsiξi
oi
where bi = log( 100 ). Thus, using (5.20) and (5.21), the controller gains KPi and KIi that
achieve the desired closed-loop responses for Tank i are obtained as follows [63]
1
KPi = (2ξiωni + αi ), (5.22)
βi
2
ωni
KIi = , (5.23)
βi
where αi and βi given in (5.7) depend on the parameters A, B, C, and D, which are obtained
In this section, we explore the experimental system identification and liquid level control
of a two-tank system using the BS2 microcontroller and the BS2 DAC toolbox developed in
Chapter 4. The two-tank, liquid level system is a commercial laboratory equipment developed
and marketed by Quanser Consulting Inc. [65]. The PC-based BS2 DAC platform developed in
Chapter 4 allows MATLAB and Simulink to seamlessly interact with the BS2 microcontroller.
In particular, this DAC platform provides a library of Simulink functions, which allows for di-
rect interaction between user-defined Simulink block diagrams and sensors/actuators connected
The PC-based BS2 DAC platform is composed of two main components, hardware and
software. The hardware required for this platform is the BS2 microcontroller, and user se-
lectable sensors and actuators. The software required for this platform is the MATLAB-based
DAC toolbox.
The BS2 DAC toolbox supports several different types of input and output signals. How-
ever, in this Chapter, only analog input and output signals between ±5VDC are considered.
To convert an analog input signal to a digital format for use on a PC, we utilize the 12-bit
digital format, to an analog output signal, we utilize the 12-bit MAX537 D2A IC. Both ICs
are natively supported in the BS2 DAC toolbox. See Chapter 4 for more details of the BS2
The BS2 DAC toolbox allows users to implement control designs and to develop DAC
panels within Simulink block diagrams. This toolbox provides a Simulink custom library
(BS2Library), which contains blocks that interface with sensors and actuators connected to
the BS2. In this Chapter, we use only the IOBlock, AtoD LTC1296, and DtoA MAX537. The
As described earlier, the liquid levels of Tanks 1 and 2 are measured using pressure sensors,
where the output signal of the sensor is a voltage in the range of 0 to 5VDC corresponding
to the liquid levels in Tanks 1 and 2. A calibration gain for the pressure sensors is then
determined, i.e., the gain that converts the sensor output voltage to centimeters of liquid is
20
computed as 4.2 ( Vcm
olt ) . The pressure sensor analog signals are supplied to the LTC1296 A2D
and are utilized in the Simulink block diagram, as shown in Figures 5.2 and 5.4. Using the
MAX537 D2A, the BS2 supplies a controlled voltage signal to the pump, which controls the
the pump Vpss , which produced a steady state liquid level in Tanks 1 of L1ss = 10.75cm and
a steady state liquid level in Tank 2 of L2ss = 11.40cm. Next, we performed experiment 2
65
Figure 5.2: Simulink block diagram of the PI controller for Tanks 1 and 2
outlined earlier by filling Tank 1 with 16.46cm of water, i.e., L1(t0 ) = 16.46cm, and obtained
the liquid level of Tank 1 as it was discharged. Figure 5.5(a) shows the liquid level time
history of Tank 1. From Figure 5.5(a), the initial time of discharge t0 is 11.5sec and the time
of full discharge t∗ is 26sec. To compute the system parameter A, we chose t̄ = 16sec, which
corresponds to a liquid level in Tank 1 of L1 (t̄) = 10cm. Using (5.15) and (5.16), A and B are
Next, we performed experiment 3 outlined earlier, by filling Tank 2 with 15.80cm of water,
i.e., L2 (t0 ) = 15.80cm, and obtained the liquid level of Tank 2 as it was discharged. Figure
5.5(b) shows the liquid level time history of Tank 2. From Figure 5.5(b), the initial time
67
of discharge t0 is 59.5sec and the time of full discharge t∗ is 76sec. To compute the system
7.8cm. Using (5.17) and (5.18), C and D are computed numerically to be 0.4056 and 0.3938,
respectively.
Next, we used the liquid level time histories given in Figure 5.5 to obtain numerous time
instances t̄ and t̂, corresponding to many estimates of the system parameters A, B, C, and D.
We then averaged, individually, the estimates of A, B, C, and D and obtained the following:
of the Tanks 1 and 2 cross-sectional areas and orifices areas produce the nominal system
(a) (b)
Figure 5.5: (a) Experiment 2–L1(t) response and (b) Experiment 3–L2(t) response
Next, we implement the PI control architecture discussed earlier to control the liquid level
of Tank 2. Referring to Figure 5.2, two A2D blocks labeled Tank 1 Liquid Level and Tank 2
Liquid Level, are used to import the signals L1 (t) and L2 (t). These sensor signals are then
used for the PI controller of Tanks 1 and 2, wherein the control signal Vp(t) is sent to a D2A
In this experiment, we specify the desired liquid level of Tank 2 to be L2d = 12cm. Next,
68
we design the control gains KPi, KIi, i = 1, 2 using (5.22) and (5.23) given a set of settling
time and overshoot performance criterion. The resulting control gains are shown in Table 5.1.
Table 5.1: Settling time and percent overshoot requirements and PI controller gains
Figures 5.6–5.8 show the time history of L1 (t) and L2 (t) using the control gains given in
Cases 1–3 given in Table 5.1. Note that the controller design for the system is obtained by
linearizing the nonlinear model near the predetermined steady state level of Tank 2. Therefore,
(a) (b)
Figure 5.6: Response of (a) L1 (t) and (b) L2(t) using the PI controller gains of case 1
5.6. Conclusion
In this Chapter, we utilized the MATLAB and Simulink-based DAC platform developed in
tracking controller to control the liquid level of the two-tank system. In addition, we exper-
imentally validated the system identification method by using the BS2 DAC toolbox, which
69
(a) (b)
Figure 5.7: Response of (a) L1 (t) and (b) L2(t) using the PI controller gains of case 2
(a) (b)
Figure 5.8: Response of (a) L1 (t) and (b) L2(t) using the PI controller gains of case 3
the response of the set-point tracking controller, which showed good tracking performance
using several sets of performance criterion. This Chapter illustrates that the integration of a
low-cost BS2 microcontroller and the MATLAB and Simulink based DAC toolbox can be used
for data acquisition, experimental system identification, and advanced feedback control.