Professional Documents
Culture Documents
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.
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.
Level
sensor
PUMP CONTROLLER
Setpoint
Level
sensor A/ D Microcontroller D/A Amp P Pump
Water tank
Q in = Q + Q out , (11.1)
271
JWBK063-11 JWBK063-Ibrahim December 22, 2005 20:3 Char Count= 0
where Q in is the flow rate of water into the tank, Q the rate of water storage in the tank, and
Q out 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
Q in = A + Q out . (11.2)
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.
Q out = 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
Q in = A + Cd a 2gh. (11.4)
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 Q in is a constant, the flow rate through the orifice reaches a
steady-state value Q out = Q 0 , and the height of the water reaches the constant value h 0 , where
Q 0 = Cd a 2gh 0 . (11.5)
If we now consider a small perturbation in input flow rate around the steady-state value, we
obtain
δ Q in = Q in − Q 0 (11.6)
and, as a result, the fluid level will be perturbed around the steady-state value by
δh = h − h 0 . (11.7)
Now, substituting (11.6) and (11.7) into (11.4) we obtain
dδh
A + Cd a 2(δh + h 0 ) = δ Q in + Q 0 . (11.8)
dt
Equation (11.8) can be linearized by using the Taylor series and taking the first term. From
Taylor series,
d f (x − x0 ) d 2 f (x − x0 )2
f (x) = f (x0 ) + + 2 + .... (11.9)
d x x=x0 1! d x x=x0 2!
Taking only the first term,
d f
f (x) − f (x0 ) ≈ (x − x0 ) (11.10)
d x x=x0
or
d f
δ f (x) ≈ δx. (11.11)
d x x=x0
Microcontroller 1 h
1−e−sT
K0 Kp As + Q0 / 2h0
A/ D s
Kl
Level sensor
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 first-
order 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.
/*-----------------------------------------------------------------
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.
File: STEP.C
Date: July 2005
------------------------------------------------------------------ */
#include <pic.h>
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
2345 − 2150
K = = 0.05.
200 × 5000/256
mV Voltage
2350
2300
2250
2200
2150 Sec
0 20 40 60
mV Voltage
2350
2300
2250
2200
2150 Sec
0 20 40 60
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:
0.05e−2s
G(s) = (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.
8/14 SANTA CRUZ - BOLIVIA 8
JWBK063-11 JWBK063-Ibrahim December 22, 2005 20:3 Char Count= 0
mV Voltage
2350
2300
2250
2200
2150 Sec
0 20 40 60
Kp
wk
pk
ek +
KpTi/T
z −1
pk−1
+ uk
11.5 CONCLUSIONS
Although the case study given in this chapter is simple, it illustrates the basic principles of
designing a digital controller, from the identification of the system to the implementation of a
suitable controller algorithm on a microcontroller. Here the classical Ziegler–Nichols PI type
CONCLUSIONS 279
/*****************************************************************************
ZIEGLER-NICHOLS PI CONTROLLER
=============================
Program : ZIEGLER.C
Date : July 2005
*****************************************************************************/
#include <pic.h>
float AD LSB, DA LSB, wk,Kp, T, Ti, b, pk, pk 1, ek, sk, yk, y high, y low;
/* This function initializes the A/D converter so that analog data can be
received from channel AN0 of the microcontroller */
{
ADCON1 = 0x8E; /* Configure AN0 for +5V reference */
ADCON0 = 0x41; /* Select A/D converter clock */
}
{
T0CS = 0; /* Select f/4 clock for the TMR0 */
PSA = 0; /* Select pre-scaler */
PS0 = 1; /* Set pre-scaler to 64 */
PS1 = 0; /* PS2,PS1,PS0 = 101 */
PS2 = 1;
TMR0 = 100; /* Load TMR0 = 100 */
T0IE = 1; /* Enable TMR0 interrupts */
T0IF = 0; /* Clear TMR0 interrupt flag */
}
/* This function reads data from the A/D converter and stores it in
variable yk */
void Read AD Input(void)
{
ADCON0 = 0x45; /* Start A/D conversion */
while((ADCON0 & 4) != 0); /* Wait until convertion completes */
y high = ADRESH; /* High 2 bytes of converted data */
y low = ADRESL; /* Low byte of converted data */
yk = 256.0*y high + y low; /* Converted data in yk */
yk = yk*AD LSB; /* Sensor output in mV */
}
{
TMR0 = 100; /* Reload TMR0 = 100 */
/* Check if 100ms has elapsed. The basic timer rate is 10ms and we
count 10 interrupts before implementing the controller algorithm */
time now++;
if(time now == 10)
{
time now = 0;
Read AD Input(); /* Read A/D input */
pk 1 = pk;
}
T0IF = 0; /* Re-enable timer interrupts */
}
/* Main Program. The main program initializes the variables, A/D converter,
D/A converter etc. and then waits in an endless loop for timer inter-
rupts to
Occur every 100 ms */
main(void)
{
Kp = 279.0; T = 0.1; Ti = 6.6;
b = Kp*T/Ti;
pk = 0.0; pk 1 = 0.0;
CONCLUSIONS 281
AD LSB = 5000.0/1024.0;
DA LSB = 256.0/5000.0;
TRISA = 1;
TRISB = 0; /* PORTB is output */
TRISC = 0; /* RC0 is output */
mV Voltage
2300
2250
2200
2150
2100
Sec
0 20 40 60 80
controller has been implemented. The Ziegler–Nichols tuning method is based on a quarter-
amplitude decay ratio, which means that the amplitude of an oscillation is reduced by a factor
of 4 over a whole period. This corresponds to a damping ratio of about 0.2, which gives rise to a
large overshoot. Ziegler–Nichols tuning method has been very popular and most manufacturers
of controllers have used these rules with some modifications. The biggest advantage of the
Ziegler–Nichols tuning method is its simplicity.
In practice one has to consider various implementation-related problems, such as:
r integral wind-up of the PID controller;
r the derivative kick of the PID controller;
r quantization errors produced as a result of the finite word-length data storage and finite
word-length arithmetic;
r errors produced as a result of the finite word length of the A/D and the D/A converters.
Quantization errors are an important topic in the design of digital controllers using microcon-
trollers and programming languages with fixed-point arithmetic. Numbers have to be approxi-
mated in order to fit the word length of the digital computer used. Approximations occur at the
A/D conversion stage. The A/D converter represents +5 V with 8, 12 or 16 bits. The resolution
is then 19.53 mV for an 8-bit converter, 4.88 mV for a 12-bit converter, and 0.076 mV for a
16-bit converter. If, for example, we are using an 8-bit A/D converter then a signal change less
than 19.53 mV will not be recognized by the system.
Approximations also occur at the D/A conversion stage where the output of the digital
algorithm has to be converted into an analog signal to drive the plant. The finite resolution of
the D/A converter introduces errors into the algorithm.
Quantization errors occur after the mathematical operations inside the microcontroller, es-
pecially after a multiplication where the result must be truncated or rounded before being
stored.
Controller parameters are not integers, and quantization errors occur when these constants
are introduced into the controller algorithm.
When floating-point arithmetic is used (e.g. when using C language) in 8-bit microcon-
trollers, numbers can be stored with very high accuracy. The effects of the quantization errors
due to mathematical operations inside the microcontroller are very small in such applications.
The errors due to the finite resolution of the A/D and D/A converters can still introduce errors
into the system and cause unexpected behaviour.