Sunteți pe pagina 1din 70

Computer Engineering Dept.

CCIS- King Saud University

COLLEGE OF COMPUTER & INFORMATION SCIENCES

COMPUTER ENGINEERING DEPARTMENT

CEN 456
Digital Control Lab.

Prepared by: Dr. R. HEDJAR

Version II

CEN456- Digital Control Lab 1


Computer Engineering Dept. CCIS- King Saud University

Contents:

Part I: Soft Experiments:

1- Introduction to SIMULINK ………………………………………….4


2- MATLAB command list …………………………………………….22
3- Exercises …………………………………………………… ……..24
4- Control of mechanical systems……………………………………….26
5- Introduction to digital control …………………………………….. ...28
6- Control of DC motor …………………………………………………29
7- Control of inverted pendulum…………………………………….…..31

Part II: Hard Experiments

1- Control of temperature system …………… ………………… ……34


2- Control of water level process ……………………… ……………..41
3- Traffic light system …………………………. . …………… .. ….46
4- PC Temperature controller …………………………………… .. …49
5- Motor speed control …………………………………………….. .. . 54

References:
- MATLAB ver.6.5. The math Works. Inc.
- SIMULINK 3. : Dynamic system simulation for MATLAB. The Math Works, Inc.
- Kuo, B. C. “ Digital control systems”, P. H., 1997.
- Franklin, G. F. , Powell, J. D. and Workman, M. L. “ Digital control of dynamic
systems” Addison-Wesley, 1996.
- Dorf, R. C. and Bishop, R. H. “ Modern control systems” Addison-Wesley, 1998

CEN456- Digital Control Lab 2


Computer Engineering Dept. CCIS- King Saud University

Part I: SOFT EXPERIMENTS

Simulation With
MATLAB & SIMULINK

CEN456- Digital Control Lab 3


Computer Engineering Dept. CCIS- King Saud University

1- Introduction to SIMULINK
SIMULINK (formally SIMULAB) is a software package for modeling, simulating and
analyzing dynamical systems and is an extension of MATLAB. SIMULINK differs from
MATLAB in that it has a windows-based (using block diagrams) graphical user interface. It
also adds much functionality to MATLAB.
It supports linear and nonlinear systems, modeled in continuous time, sampled time, or a
hybrid of the two. Systems can be also multi-rate, i.e., have different parts that are sampled or
updated at different rates.

For modeling, a graphical user interface (GUI) is used for building models as block diagrams,
using click-and-drag mouse operations. With this interface, you can draw the models just as
you would with pencil and paper (or as most textbooks depict them). This is a far from
previous simulation packages that require you to formulate differential equations and
difference library of sinks, sources, linear and nonlinear components, and connectors. You can
also customize and create your own blocks.
Models are hierarchical, so you can build models using both top-down and bottom-up
approaches. You can view the system at a high-level, then double-click on blocks to go down
through the levels to see increasing levels of model details. This approach provides insight into
how a model is organized and how its parts interact.

After you define a model, you can simulate it, using a choice of integration methods, either
from the SIMULINK menus or by entering commands in MATLAB’s command window. The
menus are particularly convenient for interactive work, while the command-line approach is
very useful for running a batch of simulations (for example, if you are doing Monte Carlo
simulations or want to sweep a parameter across a range of values). Using scopes and other
display blocks, you can see the simulation results while the simulation is running. In addition,
you can change parameters and immediately see what happens, for “what if” exploration. The
simulation results can be put in the MATLAB workspace for post processing and visualization.

Model analysis tools include linearization and trimming tools, which can be accessed from the
MATLAB command line, plus the many tools in MATLAB and its application toolboxes. And
because MATLAB and SIMULINK are integrated, you can simulate, analyze, and revise your
models in either environment at any point.
This tutorial presents some basic steps in using SIMULINK.

Based steps in model building:


First, you need to access SIMULINK. This is done by typing its name at the MATLAB prompt
(you must first be in MATLAB) or by clicking on SIMULINK icon. After the program has
been invoked, the main block library of SIMULINK will be displayed in a new window.
To see the content of the toolbox, click on the + sign at the beginning of each toolbox.

Most of the block types that you need to build a block diagram are already available in this
library. All you need to do is to pick the blocks you need, connect them together and set their
parameters. The main block look like:

CEN456- Digital Control Lab 4


Computer Engineering Dept. CCIS- King Saud University

The content of Sources library is:

1
Constant
Signal Step Ramp Sine Wave Repeating Discrete Pulse Pulse Chirp Signal
Generator Sequence Generator Generator

12:34 [T,U]
untitled.mat
Clock
Digital Clock From Uniform Random Band-Limited
From File Random
Workspace Number White Noise
Number

CEN456- Digital Control Lab 5


Computer Engineering Dept. CCIS- King Saud University

The content of Sinks library is:

0 simout STOP
untitled.mat
Scope XY Graph Display To File To Workspace Stop Simulation

The content of Discrete library is:


1
T y(n)=Cx(n)+Du(n) 1 1 (z-1)
z z-1 x(n+1)=Ax(n)+Bu(n) z+0.5 1+2z-1 z(z-0.5)
Unit Delay Zero-Order First-Order
Discrete-Time Discrete State-Space Discrete Discrete Filter Discrete
Hold Hold
Integrator Transfer Fcn Zero-Pole

The content of Linear library is:

1 1 1 (s-1) x' = Ax+Bu


du/dt K 1
s s+1 s(s+1) y = Cx+Du
Gain Sum Dot Product Derivative Matrix
Integrator Transfer Fcn Zero-Pole State-Space Slider
Gain Gain

The content of Nonlinear library is:


u
|u| sin e floor min AND <=

Abs TrigonometricMath Rounding MinMax Product Combinatorial Logical Relational Sign Rate LimiterSaturation
Function Function Function Logic Operator Operator

f(u)
Quantizer Coulomb & Backlash Dead Zone Look-Up Look-Up Memory Transport Variable
Hit Fcn
Viscous Friction Table Table (2-D) Delay Transport Delay
Crossing
MATLAB
Function system Solve
f (z) z
f(z) = 0
MATLAB Fcn S-Function Switch Relay
Manual Switch Algebraic Constraint
Multiport
Switch

The content of Connections library is:

1 1 Mux Demux [A] {A} [A] A A


In1 Out2
Mux1 Demux1 From1 Goto Tag Goto1 Data Store Data Store
Read1 Memory1
Visibility1
0 [1]
A
Ground1 Terminator1 Merge
Width1 IC2 Subsystem1 Selector1 Data Store
Merge1 Write1

CEN456- Digital Control Lab 6


Computer Engineering Dept. CCIS- King Saud University

To start a model click on the New Document icon as shown:

A new window will appear on the screen. You will be constructing your model in this window.
Also in this window the constructed model is simulated. A screenshot of a typical working
(model) window that looks like one shown below:

Now you may begin to construct your model. To become familarized with the structure and the
environment of Simulink, you are encouraged to explore the toolboxes and scan their contents.
You may not know what they are all about but prehaps you could catch on the organization of
these toolboxes according to the category. For instant, you may see Control System Toolbox to
consist of the Linear Time Invariant (LTI) system library and the MATLAB functions can be
found under Function and Tables of the Simulink main toolbox. A good way to learn Simulink
(and MATLAB or computer programs/packages in general) is to practice and explore. Making
mistakes and know how to correct the mistakes is also a way to learn.
A simple model is used here to introduce some basic features of Simulink. Follow the steps
below to construct a simple model.

STEP 1: CREATING BLOCKS: Open (Expand) the Simulink toolbox by clicking on the + sign
infront of the Simulink entry in the Simulink Library Browser. Further expand Sources sub-
library. You should see a Sine Wave entry in the list of sources as show in the screenshot
below.

CEN456- Digital Control Lab 7


Computer Engineering Dept. CCIS- King Saud University

Mouse action: Click on the Sine Wave block to select and drag it to the model Window as
shown:

Now you have established a source of your model. In similar fashion, create additional blocks
in your model window.
NOTE: It is advisable that you save your model at some point early on so that if your PC
crashes (runing MATLAB under Linux OS is much more stable!) you don' t loose so much
time to reconstruct your model.
I am going to save this model under the filename: "simexample1". To save a model, go to the
pulldown File menu in the model window and select Save As. A extension named ".mdl" will
be automatically appended to the filename (just enter the filename). Simulink will recognize
file with .mdl extension as a simulation model (similar to how MATLAB recognizes files with
the extension .m as an MFile).
Continue to build your model by adding more components (or blocks) to your model window.
We' ll continue to add a scope from Sinks library, an Integrator block from Continuous library,
and a Mux block from Signals & Systems library. Once all the blocks are dragged over to the
model window, you would have a window that looks like one shown below.

CEN456- Digital Control Lab 8


Computer Engineering Dept. CCIS- King Saud University

You may remove a block that you don' t want by clicking on the block to turn it to the select
mode (with four squares at the corners) and use the DEL key or keys combination CTRL-X
(control key and X key at the same time) to remove the block. For example, say that I want to
change my mind and want to use repeating pattern or sequence as the source instead of sine
wave. I simply select the Sine Wave block and do a CTRL-X to remove it then do a click-n-
drag on the Repeating Sequence block.

STEP 2: MAKING CONNECTIONS


To establish connections between the blocks, simply move the cursor to the output port
(represented by ">" sign at the right side of the block) of a block (the cursor will become a
cross "+" as you move the cursor over the input or output port) and left-click (pressing the left
mouse button) to begin a connection. With the left mouse button depressed, drag the mouse to
the input port of another block (output port is represented by a ">" at the left side of the block).
To branch a connection, use the right mouse button in a similar fashion. A connected system is
shown in the screenshot below:

CEN456- Digital Control Lab 9


Computer Engineering Dept. CCIS- King Saud University

STEP 3: RUNNING SIMULATION


You now can run the simulation of the simple system above by clicking on the play button (
, alternatively, you may use key sequence CTRL+T, or choose Start submenu under Simulation
menu) . The signal generated by the Repeating Sequence block will be displayed on the Scope
block. This signal will also be integrated by the Integrator block and to be display
simultaneously on the Scope block. Double click on the Scope block to display of the scope. A
typical display is shown below.

Note that if the derivative of the signal can be obtained using the Derivative block instead of
the Integrator block. The result would be

as expected.

CEN456- Digital Control Lab 10


Computer Engineering Dept. CCIS- King Saud University

The above steps demonstrated some basic functions and structure of Simulink. It is strongly
recommended that you take some time to explore the toolboxes and familiarize yourself with
the parameters associated with each block. To view/edit the parameters, simply double click on
the block of interest.

Handling of Blocks and Lines


The table below describes the actions and the corresponding keystrokes or mouse operations
(Windows versions).

Actions Keystokes or Mouse Actions


Copying a block from a Drag the block to the model window with the left button
library on the mouse OR use select the COPY and PASTE from
EDIT menu.
Duplicating blocks in a Hold down the CTRL key and select the block with the
model left mouse drag the block to a new location.
Display block'
s paramters Double click on the block
Flip a block CTRL-F
Rotate a block (clockwise
CTRL-R
90 deg @ each keystroke)
Changing blocks'names Click on block'
s label and position the cursor to desired
place.
Disconnecting a block hold down the SHIFT key and drag the block to a new
location
Drawing a diagonal line hold down the SHIFT key while dragging the mouse with
the left button
Dividing a line move the cursor to the line to where you want to creat the
vertex and use the left button on the mouse to drag the
line while holding down the SHIFT key

Annotations
To add an annotation to your model, place the cursor at an unoccupied area in your model
window and double click on the left mouse button. A small rectangular area will appear with a
cursor prompting for your input.
To delete an annotation, hold down the SHIFT key while selecting the annotation, then press
the DELETE or BACKSPACE key. You may also change font type and color from the
FORMAT menu.

Some Examples
Example 1. Simulation of an Equation.
In this example we will use Simulink to model an equation. Consider the equation given by:

x(t ) = A cos(ϖ t + ϕ) (1)

CEN456- Digital Control Lab 11


Computer Engineering Dept. CCIS- King Saud University

where the displacement x is a function of time t, frequency w, phase angle ϕ, and amplitude A.
In this example the values for these parameters are set as follows: frequency=5 rad/sec;
phase=pi/2;A=2.

1. From Simulink'
s library drag the following blocks to the model window

Blocks to be Where located in Simulink


dragged to the library browser
model window
Ramp Sources
Constant Sources
Gain Math
Sum Math
Product Math
Trigonometry
Math
Function
Scope Sinks
Mux Signals & Systems

2. The next step is to connect these blocks as shown in Figure E1-1.

Figure E1-1

3. Double click on the blocks and enter the appropriate values as prompted by the pop-up
dialog windows. Note that the cosine function can be selected from the pull-down
menu in the pop-up window. In the arrangement shown above, the input signal (a ramp
function) is to be displayed along with the output (displacement) via the use of the mux
tool as demonstrated earlier in this tutorial. To view the plots, double click on the
scope.

4. Make sure all blocks are connected correctly then run the simulation (CTRL+T). You
may need to select the Autoscale button on the scope display window to obtain a
better display of the plots.

You may find the sinusoidal plots to be a bit "jaggy". You may want to improve the
resolution of the displayed plot by redefining the Max Step Side value ("auto" is set a

CEN456- Digital Control Lab 12


Computer Engineering Dept. CCIS- King Saud University

default value) in Simulation Parameters window (with keystrokes CTRL+E in the model
window). Just for fun, you may want to experiement with different choice of solver.
ODE45 is a default choice. You are encouraged to learn more about the solver methods by
checking out the help files in Matlab command window. For instance, help ODE45 for
parameters in non-stiff differential equations.

This example has demonstrated the use Simulink with built-in mathematical functions and
other supporting toolboxes to simulate an equation. The same output/result can also be
obtained with the following set of instructions entered in Matlab command window:

>>t=(0:.01:10);A=2;phi=pi/2;omega=5;
>>xt=A*cos(omega*t+phi);
>> plot(t,xt);grid

Example 2. Mass-Spring-Dashpot System Simulation

Consider a mass-spring-dashpot system as shown in Figure E2-1. The mathematical model for
this system is described by:
m x + c x + k x = f (t ) (2)
where m is the equivalent mass of the system, c is the damping ratio, k is the spring stiffness,
and f(t) is the forcing function in the x-direction. Where m is the equivalent mass of the system,
c is the damping ratio, k is the spring stiffness, and f(t) is the forcing function in the x-
direction.

In Simulink, create a new model window (CTRL+N) and drag the following blocks from the
Simulink library window

CEN456- Digital Control Lab 13


Computer Engineering Dept. CCIS- King Saud University

S
T
E
P

1
Blocks to be Where located in Simulink
dragged to the library browser
model window
Step Sources
Gain Math
Sum Math
Integrator Continuous
Scope Sinks
To Workspace Sinks
SBy re-arrange Eqn 2 to yield an expression for the acceleration term as:
T
E 1
P x(t ) = ( f (t ) − c x − k x ) (3)
m
2 Based on Eqn 3, we connect the blocks in the diagram as shown in Figure E2-2. Use
CTRL+F and CTRL+R to flip and rotate the blocks as necessary (select the block first
then execute the key sequence). Note that you can use CTRL+right mouse button to
create branches of the connecting lines. Don' t worry about the parameter values and the
signs for these blocks at this point as we'
ll take care of this in STEP 3. Just get them
connected first.

Figure E2-2

SEnter the values of the parameters for each block. In this example, we will set m = 2.0;
Tc=0.7; k=1. You are encouraged to try different values and observe the system' s
Eresponse to step input.
PTo show that you may obtain different form of output, I included another block (in

CEN456- Digital Control Lab 14


Computer Engineering Dept. CCIS- King Saud University

addition to the scope block) called "simout". This block can be found in the Sinks
3group from the Simulink Library browser. The output from this block is used in Matlab
workspace. To illustrate how this block works, I will select a name for the output called
"simout" as the variable name in the block' s parameter setting (double click on the
"simput" block to bring up the parameter dialog window). In additon, I will need a time
array from the simulation. This can be specifed as a parameter in the Simulation
Parameter window (CTRL+E) under the Workspace I/O tab as shown in Figure E2-3.

Figure E2-3

SRun the simulation by clicking on the button (alternately you may use keyboard
Tcommand CTRL+T ). The screenshot of the output from the Scope block is show in
EFigure E2-3.
P

Figure E2-3
That's it! You have successfully modeled and simulated a second-order under-damped
dynamic system. To exam different responses, please feel free to change different
values for m, c, and k in the gain blocks.
To see how you can use the output from the "simout" block (by the way, you may
name the block whatever you wish), go to Matlab Command window and type:
>> who
You should receive an echo from Matlab listing the following variables: "simout" and
"time" (and perhaps others variables in the current workspace memory).

CEN456- Digital Control Lab 15


Computer Engineering Dept. CCIS- King Saud University

Now, you may create a plot of the system response identical to that shown in the Scope
output. The command for creating this plot is:
>>plot(time,simout);grid

Note that the outout format used in the example above is matrix type. The output sent
to workspace can be used for further analysis and storage in ascii format. Output to
workspace allows more options in plot presentation and further data analysis as the
arrays are in ascii format.

Example 3. Using the same system presented in Example 2, we will simulate the response
using transfer function block (frequency domain). This example will illustrate an alternate
approach to one shown above.
S
T
In a new Simulink model window, drag the following blocks from the Simulink library
E
window: Step (from Sources), Transfer Function (from Continuous), Scope (from
P
Sinks), and Save File to Workspace (from Sinks).
1
SArrange the blocks as shown in Figure E3-1 below.
T
E
P

Figure E3-1

SEntering blocks'parameters values.


T
EWe' ll use the same values for m, c, and k as in Example 2. Double click on the transfer
Pfunction to bring up the parameter diaglog window and enter the values for the
coefficients in the denominator as shown in Figure E3-2. Note that the Transfer
3function block has a defaut form of first order in the denominator (s+1). You may
specify different order for the numerator and the denominator by entering the
coefficients associated with the polynomials.

CEN456- Digital Control Lab 16


Computer Engineering Dept. CCIS- King Saud University

Figure E3-2

Click OK to close the dialog.

Double click on the Save Output To A File block to open the dialog window as shown
in Figure E3-3. In the Filename box specify the path and the name of the file you wish
to save. The saved file will be in .MAT format (yes, it' s in binary format! So don' t try
to read it). You will be able to load this file to Matlab workspace later on. Make sure to
remember where you save the file to. In this example, I' ll put the file in my D drive
under "temp" directory and name the file "example3out.mat". You may choose other
convenient location on your computer.

In the Variable name box, enter a name of your choice. Here I name the variable
"simout".

Leave other parameters in defaut settings unless you wish to obtain more plot points by
changing the Sample Time setting.

Figure E3-3
SRun the simulation by clicking on the button (alternately you may use keyboard

CEN456- Digital Control Lab 17


Computer Engineering Dept. CCIS- King Saud University

Tcommand CTRL+T ). The screenshot of the output from the Scope block is show in
EFigure E3-4.
P

Figure E3-4

Now by comparing Figure E2-3 and Figure E3-4 you will see that the reponses are
identical. No surprise here since Figure E3-1 effectively performs the same simulation
as thatcarried out in Figure E2-2, only with fewer number of blocks!

LOADING MAT FILE

Use the load command to "import" the save *.mat file generated from the simulation.

Note: In this example, I set the path to the directory where the file "example3out.mat"
is saved. If you do not set the path in Matlab, you have to specify the full path in the
load command,e.g.,
>>load D:/temp/example3out.mat .

In Matlab command window, enter the followings:


>> load example3out

You may want to verify the loading by asking Matlab to list all of the variables in the
current workspace:
>> who

If the loading is successful, you should see the variable you specified earlier listed the
current workspace. In this example, Matlab echos:

Your variables are:


simout

"simout" is a 2 x m matrix, where m is number of columns reflecting the number of


data points generated from the simulation. The first row contains the time array.

To generate a plot of the step input response from the simulation, simply use the plot
command on "simout" matrix. For this example, the following command produces the

CEN456- Digital Control Lab 18


Computer Engineering Dept. CCIS- King Saud University

plot shown in Figure E3-5.

>> plot(simout(1,:),simout(2,:));grid

Figure E3-5

Example 4: Consider the double integrator system G(s), which is open, loop unstable. To
stabilize this plant, we use a lead compensator, K(s), as shown in figure 1.

K(s) G(s)

Figure 1. Block diagram

1 s +1
with: G ( s) = ; K ( s) = 10 .
s 2
s+5

Our goal is to obtain the step response of this system. We will use nine objects in this diagram:
two transfer functions, one summing junction, one gain, one clock (time), one input source
(step), and three objects for viewing the output and the control signal.
Input source elements are located in the SOURCES library. Double click this library to open
its window and note its contents. We are interested in the step fcn source. To select this block,

CEN456- Digital Control Lab 19


Computer Engineering Dept. CCIS- King Saud University

put the mouse cursor on it, click and hold the mouse while you drag the object into your
working window.
The transfer function, summing junction and gain blocks are located in the linear library. Open
the linear library (by double clicking on it). Drag the transfer fcn block into your working
window. Repeat this step for the second transfer function; also drag the sum and the gain.
Close the linear library.

The simulation output and the control signal are obtained using the sinks library. Open this
library and you will see that there are six objects available. The scope acts as an oscilloscope
and gives you a live display of any signal during the simulation. To Workspace block passes
the output vectors to the MATLAB workspace as matrices. This allows you to analyze and plot
your data using MATLAB. The To file block passes the data to a file and saves then under a
given name. Drag three workspace blocks to your working window. Close the sinks library.

You should have now nine blocks in your working window. The next step after block selecting
is setting the block parameters. If you double click on any block a window open to show the
parameters of that block. The window displays brief information on that block. A help option
is also available for more detailed information. Most blocks have default parameters that can
be changed.

Open one of the transfer function block (double click on it). There are two fill-in boxes for
Numerator and Denominator. Enter [1 1] and [1 5] in these boxes respectively. Select ok. Open
the second function and enter [1] and [1 0 0] and select ok. Open the gain block and enter 10
and select ok. Open the sum block and enter +- for the list of signs. If the summing element
has more than two inputs, simply enter all their signs. The block will expand to accommodate
all the inputs.

Open the step fnc block. There are three fill-in boxes. The step time is the initial starting time
for the step function (enter 0). Enter the initial value and the final value (0 and 1) respectively.
Open the To workspace blocks, enter different variable names y for the output, u for the
control signal and t for the time.

The final step in model building is connecting the blocks. All blocks, with the exception of
sources and sinks blocks have at least one angle bracket (>) pointing out of them. This is their
output port. They also an angle bracket pointing toward them, which is their input port. The
sources blocks have no inputs, so they only have output ports. Similarly, the sinks blocks only
have input ports. Multiples input port blocks (e.g sum or Mux blocks) have more than one
input port.

To connect two blocks, click on the output port of one block, drag the mouse to the input port
of the other block, and release the mouse button. The angle brackets will disappear, and a line
(with an arrowhead) will be drawn, making the connection. As you move the mouse up or
down, the line will be drawn in multiples of 45 degrees. To draw a line at any angle, hold the
right and the left buttons together while you drag the mouse. Use the above procedure to
connect all the blocks of you working window.
The block diagram is complete now.

CEN456- Digital Control Lab 20


Computer Engineering Dept. CCIS- King Saud University

t
Clock To Workspace

s+1 1
10 y
Step s+5 s2
Sum Gain To Workspace1
Transfer Fcn Transfer Fcn1

To Workspace2

Figure 2. Simulink block diagram

You can embellish it by going to the style menu and change the screen color, background
color, fonts drop shadows around blocks, etc.. If you click the title of a block, it will be
highlighted and you can type in a new name. From the option menu, you can also flip and
rotate the blocks.

The final step is simulation. This is done from the Simulation menu. There are two items to
choose. You can either select Start to start the simulation, or you can set the simulation
parameters to open the seven integration algorithms. For linear system choose Linsim and for
nonlinear system choose ODE45( Dormand-Prince). Enter 0 for the start time, 10 for stop time,
0.001 for relative error, 0.1 for the minimum step size, and 0.1 for the maximum step size.
Select ok to leave the dialog box.

Now select start from the simulation menu. You will hear a beep when the simulation is
finished. To view the results of this simulation, you type MATLAB’s statements below:

» subplot(211),plot(t,y), title('the ouput-response'


)

» subplot(212),plot(t,u), title('the control signal'


),xlabel('
Time(s)'
)

You will obtain:

CEN456- Digital Control Lab 21


Computer Engineering Dept. CCIS- King Saud University

the ouput-response
1.5

0.5

0
0 1 2 3 4 5 6 7 8 9 10

the control signal


10

-5
0 1 2 3 4 5 6 7 8 9 10
Time(s)

Figure 3. Example plot

CEN456- Digital Control Lab 22


Computer Engineering Dept. CCIS- King Saud University

Matlab Commands list


The following list of commands can be very useful for the Simulation. Use "help" in Matlab
for more information on how to use the commands.

In this part, we use commands both from Matlab and from the Control Systems Toolbox, as
well as some commands/functions, which we wrote ourselves. For more information on
writing Matlab functions, see the function page.

Command Description
Abs Absolute value
acker Compute the K matrix to place the poles of A-BK, see also place
Axis Set the scale of the current plot, see also plot, figure
Bode Draw the Bode plot, see also logspace, margin, nyquist1
c2dm Continuous system to discrete system
clf Clear figure (use clg in Matlab 3.5)
Conv Convolution (useful for multiplying polynomials), see also deconv
Ctrb The controllability matrix, see also obsv
deconv Deconvolution and polynomial division, see also conv
det Find the determinant of a matrix
dimpulse Impulse response of discrete-time linear systems, see also dstep
Dlqr Linear-quadratic regulator design for discrete-time systems, see also lqr
Dlsim Simulation of discrete-time linear systems, see also lsim
Dstep Step response of discrete-time linear systems, see also stairs
eig Compute the eigenvalues of a matrix
eps Matlab'
s numerical tolerance
feedback Feedback connection of two systems.
figure Create a new figure or redefine the current figure, see also subplot, axis
for For, next loop
format Number format (significant digits, exponents)
function Create function m-files
grid Draw the grid lines on the current plot
Gtext Add a piece of text to the current plot, see also text
help HELP!
hold Hold the current graph, see also figure
if Conditionally execute statements
Imag Return the imaginary part of a complex number, see also real
impulse Impulse response of continuous-time linear systems, see also step, lsim, dlsim
input Prompt for user input

CEN456- Digital Control Lab 23


Computer Engineering Dept. CCIS- King Saud University

inv Find the inverse of a matrix


Generate grid lines of constant damping ratio (zeta) and settling time (sigma), see
Jgrid
also sgrid, sigrid, zgrid
legend Graph legend
length Length of a vector, see also size
linspace Return a linearly spaced vector
lnyquist1 Produce a Nyquist plot on a logarithmic scale, see also nyquist1
log Natural logarithm, also log10: common logarithm
loglog Plot using log-log scale, also semilogx/semilogy
logspace Returns a logarithmically spaced vector
Lqr Linear quadratic regulator design for continuous systems, see also dlqr
Lsim Simulate a linear system, see also step, impulse, dlsim.
margin Return the gain margin, phase margin, and crossover frequencies, see also bode
Norm Norm of a vector
Draw the Nyquist plot, see also lnyquist1. Note this command was written to
nyquist1
replace the Matlab standard command nyquist to get more accurate Nyquist plots.
Obsv The observability matrix, see also ctrb
Ones Return a vector or matrix of ones, see also zeros
place Compute the K matrix to place the poles of A-BK, see also acker
Plot Draw a plot, see also figure, axis, subplot.
poly Return the characteristic polynomial
Polyadd Add two different polynomials
polyval Polynomial evaluation
Print Print the current plot (to a printer or postscript file)
Pzmap Pole-zero map of linear systems
rank Find the number of linearly independent rows or columns of a matrix
real Return the real part of a complex number, see also imag
Rlocfind Find the value of k and the poles at the selected point
Rlocus Draw the root locus
Roots Find the roots of a polynomial
rscale Find the scale factor for a full-state feedback system
Set(gca,'
Xtick',xticks,'
Ytick'
,yticks) to control the number and spacing of tick
set
marks on the axes

CEN456- Digital Control Lab 24


Computer Engineering Dept. CCIS- King Saud University

1- Exercises

Exercise No1: Build up SIMULINK scheme for the system:


x + 0.5 x + 2 x + x 2 = u
and study the response to unit step.
Hint: the coefficients of the above expression may be seen as gain.

Exercise No2: Analyze the response (plot x(t)) of the system described by the equation:
.
x = −x + x 2
Hint: The system is stable with respect to origin if x(0) < 1 .

Exercise No3: Build the SIMULINK scheme of the system:

x = − 1 + sin 2 ( x) x . ( )
and plot the solution of this nonlinear differential equation with x(0)=10.
Hint: Use just one Integrator block and just one Fcn block.

Exercise No 4: The level control of a Tank may be done by two-position controller (use rely).
In this case a very easy model is the following:

U max if href − h > ε


h = u (t ) where u (t ) = .
U min if href − h < −ε

Where h(t) is the Tank level and href is the reference level. Analyze the behavior of the
system, for different values of Umax and Umin (10,-10; 10,0; 5,-5) and for different values of
ε(0.01;0.1 ;0.2), both with respect to time and in the phase plane. Plot h(t) and u(t) for
different values of ε.
Hint: Use the relay block.

Exercise No5: Using MATLAB and SMULINK, plot the unit step response for the systems
represented by:
s+3 s + 2.5 s + 2.1
a- G1 ( s) = b- G2 ( s) = c- G3 ( s) =
(
(s + 2) s 2 + 3s + 10 ) (
(s + 2) s 2 + 3s + 10 ) (
(s + 2) s 2 + 3s + 10 )
s + 2.01 s +1
d- G4 ( s) = e- G5 ( s) =
(
(s + 2) s 2 + 3s + 10 ) (
(s + 2) s 2 + 3s + 10 ).
• From the plot determine %OS, Ts, Tr and Tp.
• Find (use ≠ formula) %OS, Ts, Tr and Tp for the system (d).
• Find the response that is close to the system represented by (d)? Comment?

Exercise No.6: Using MATLAB, sketch the root locus and find the range of stability for the
unit feedback systems:

CEN456- Digital Control Lab 25


Computer Engineering Dept. CCIS- King Saud University

a- G1( s) =
k (s + 3)
b- G2 ( s) =
(
k s 2 − 2s + 2 )
(s + 1)(s + 2)(s + 3) s (s + 2 )(s + 2 )
In the marginally stable case, find (by hand) the frequency of oscillation and all poles of the
system?

Exercise No.7 Consider the temperature control system for a chemical process:

Chemical heat
Process
Amplifier Actuator and valve
Desired Temperatue
1 0.7
PID K Temperature
s+0.4 s2 +1.7s+0.25
Step PID Controller Gain Transfer Fcn2 To Workspace
Transfer Fcn1

Temperature Sensor

0.5
s+0.5

The uncompensated system is operating with a rise time approximately the same as a
second order system with a peak time of seconds?? and 5% overshoot. There is also
considerable steady state error. Design a PID controller so that the compensated system
will have a rise time approximately equivalent to a second order system with a peak time 8
seconds and 5% overshoot and zero steady state error for a step input.

Exercise No 8: Use the Routh-Hurwitz criterion and the unity feedback of the system
modeled by:
K
G (s) =
s(s + 2 )(s + 4 )(s + 6 )
• Find the range of K for stability ( 0< K < Kmax).
• Find the value of K for marginal stability.
• Find the actual location of the closed loop poles when the system is marginally
stable.
• Plot the response of the closed loop system when K=Kmax/2 and K=Kmax.

CEN456- Digital Control Lab 26


Computer Engineering Dept. CCIS- King Saud University

2- Control of Mechanical Systems


System 1: A simple mass, spring and damper compose the mechanical system shown below:

where M is the mass, b is the damper, k is spring, x (t) is the position of the cart
and F(t) is the force applied to the system.

a- Find the dynamic equation (differential equation) of this system.


b- Let M=0.1Kg , b=1.5Ns/m and k=10 . Determine the transfer function of this system
X ( s)
( G(s) = ).
F (s)
c- Calculate (from the transfer function) the %OS, Tr, Ts, Tp and ess.
d- Plot the step response of the system and from the curve find %OS, ess, Ts Tr and Tp.
e- Show that the P controller cannot reduce anymore the overshoot.
f- Design a PD controller to decease the settling time by a factor of 2 without affecting
the percent overshoot. Use MATLAB to verify that your design works.
g- Use Block SIMULINK to draw the displacement x(t) and the control force F(t) of the
system in the closed loop. Analyze the time response of the system.

System 2:

- Mathematical model: If the inertia of the wheels is neglected, and it’s assumed that
the friction is opposing the motion of the car, then using Newton’s law, the model of
this system is:
mv+bv = u
where: m=1000kg; b=50 Nsec/m and u=500N.
y=v

The design criteria : - Rise time < 5 sec,


- Over shoot < 10%
- Steady state error < 2 %.

CEN456- Digital Control Lab 27


Computer Engineering Dept. CCIS- King Saud University

a- Find the transfer function of the system.


b- Draw the step response by using MATLAB statements and SIMULINK. Comment the
results.
c- What proportional control gain Kp is required to reduce the rise time. Draw the control
signal u(t) and the output y(t) of the closed system.
d- Design a PI controller with the parameters Kp and Ki that improve the response.

NB: When you adjust the integral gain Ki, we suggest to start with a small value since large Ki
most likely unstabilizes the response.

CEN456- Digital Control Lab 28


Computer Engineering Dept. CCIS- King Saud University

3-Introduction to Digital control

• Effect of sampling period:


Use SIMULINK to draw the above block diagram:

Sine Wave Zero-Order


Hold Scope

Set the frequency of the sine wave to 10Hz and vary the sampling period of the zero Order
Hold from Ts=0.1s , 0.2s, 0.3s, 0.4, 0.5s.
Plot the response for each sampling period and comment the results?
Hint: simulation is from 0 to 2s.

• Given a system with the transfer function G(s)

+ D(s) G(s)
-

1 s+2
Where G ( s) = and D( s) = 70 .
s (s + 1) s + 10
1. Analyze the open loop system (without controller)
2. Plot the step response and determine the performance achieved by the controller in
closed loop (%OS, Tr, Ts , ess).
3. Find a Digital* controller D(z) to implement the lead compensator D(s). Use the
sample rate 20Hz and 40 Hz.
4. Compare the step responses of the digitally controlled system with the step
response of continuous controlled system.

u (k + 1) − u (k )
*Hint: Use Euler’s method to approximate the continuous controller u ≈ and
Ts
de e(k + 1) − e( k )
≈ where Ts is the sampling period.
dt Ts

CEN456- Digital Control Lab 29


Computer Engineering Dept. CCIS- King Saud University

4- Control of DC Motor
A common actuator used in control systems is DC motor. The electric circuit of the
armature and the free body diagram of the rotor are shown in the following figure:

Mathematical model of Dc motor:


The motor torque T is related to the armature current i by a constant factor Kt. The back emf
T = Kt i
e is related to the rotational velocity by the following equations:
e = Ke θ
The combination of Newton’s and Kirchoff’s laws give the following equations:
J θ + bθ = K i
di
L + R i = V − Kθ
dt
where:
- J = 0.0364 kgm2/s2 is the moment of inertia of the motor,
- b= 2.510 –4 Nms is the damping of the mechanical system,
- K= Ke =Kt =0.1 Nm/Amp is the electromotive force constant,
- R = 4 Ω is the resistance,
- L= 2.75 H is the electric inductance,
- V : is the input voltage (volt),
- θ is the position of the shaft (rad).

The rotor and the shaft are assumed to be rigid.

Design requirement:
Position Control: Speed Control:
- Settling time less than 2s. -Settling time less than 40ms
- Overshoot less than 5%. - Overshoot less than 16%
- No steady state error. - No steady state error

a- If the position θ is the output and the voltage V is the input, find the transfer function.
b- Use the second Ziegler-Nichols tuning method to design a continuous PID controller.
c- If the speed θ is the output and the voltage V is the input, find the transfer function.
d- Design a continuous P controller to have 10% of overshoot.

CEN456- Digital Control Lab 30


Computer Engineering Dept. CCIS- King Saud University

e- Use the Bilinear transformation to design a digital controller from the continuous
controller obtained in (b and d). Discuss the instability phenomena and how you can
compensate it.

f- Compare all results (control signal and the output response by using SIMULINK).
Change the control parameters (b & d) to achieve the performance specified to position
control and speed control.

Note: The second method of Ziegler and Nichols tuning of P.I.D regulators is based on
evaluating the system at the limit of stability. The proportional gain is increased until you
observe oscillations, that is, until the system becomes marginally stable. The corresponding
gain Ku (ultimate gain) and the period of oscillation Tu (ultimate period) are determined
from the response.

Then for the continuous system, the controller parameters are taken:
Kp= 0.6 Ku; Ti=0.5 Tu and Td=0.125 Tu , and the transfer function of the PID controller
is :
1
D ( s ) = K p (1 + + Td s) .
Ti s

For the discrete system, the parameters are taken:


K pπ K pω m
K p = 0. 6 K u , K d = and K i = .
4ω m π
Where ωm =angle (pole)/Ts, Ts is sampling period and the transfer function of the controller
is:
z −1 Tz
D( z ) = K p + K d + Ki s .
Ts z z −1
Or we can directly obtain this digital PID controller from the analogue PID by using the
Backward approximation.

NB. Show all steps in your reports.

CEN456- Digital Control Lab 31


Computer Engineering Dept. CCIS- King Saud University

4- Control of Inverted Pendulum

Mathematical model:

The dynamic equation of motion of the cart in the horizontal direction is given by:

( M + m) x + b x + mlθ cos θ − mlθ 2 sin θ = F

The second equation of motion, i.e sum of the torques, is given by:

( I + ml 2 ) θ − mgl sin θ + mlx cos θ = 0

As the global system is nonlinear, this set of equations should be linearized about θ ≈ π + φ ,
where φ represents a small change in the pendulum’s position.

For this system, let’s assume that:


- M=0.5kg is the mass of the cart,
- m=0.5 kg is the mass of the pendulum,
- b=0.1 Nm/sec is the friction of the cart,
- l= 0.3m is the length to pendulum center of mass,
- I= 0.006 kg m2 is the inertia of the pendulum,
- F is the force applied to the cart,
- x is the cart position coordinate,
- θ is the pendulum angle from the vertical.

For this section, we will assume that the system starts at equilibrium point, and experiences an
impulse force F=1N. The pendulum should return to its upright position within 5 seconds, and
never move more than 0.05 rad away from the vertical. Thus, the design requirements for this
system are:
- Settling time less than 5 seconds
- Pendulum angle never more than 0.05 rad from the vertical.

CEN456- Digital Control Lab 32


Computer Engineering Dept. CCIS- King Saud University

a- Find the transfer function of the linearized system, y ( s ) = φ ( s) and


u ( s ) = F ( s) . Study the stability of the linear system and what can you
deduce for the nonlinear system.

b- Draw the system’s response to an impulse force applied to the cart. Create
the MATLAB m. file for the linear system and use SIMULINK for the
nonlinear system. Comment the result.

The control of this problem is a little different than the standard control problems, since
you are trying to control the pendulum’s position, witch should return to the vertical after the
initial disturbance. The reference signal you are taking should be zero. The force applied to the
cart can be added as an impulse disturbance. The schematic for this problem should look like
the following:

y ( s)
c- Find the transfer function closed loop system ( ).
F ( s)

d- Determine the PID controller D(s) to meet the design requirements. Draw
the response of the closed loop system by MATLAB statements.

e- Implement the above controller in closed loop with the nonlinear system by
using SIMULINK. Draw the position of the pendulum and the control signal
u(t).

f- Draw the cart’s position x(t). Comment the results.

g- Assume that the closed-loop bandwidth frequencies are around 1 rad/sec for
both cart and pendulum. Let the sampling time to be 1/100. Determine a
Digital controller that maintains the specified performance. Draw the
position θ(t) of the linear system (MATLAB statements) and of the
nonlinear system (SIMULINK).

h- Use the TUSTIN Transformation to design the digital controller from the
analog controller obtained in (d). Draw the position θ(t) of the linear system
(MATLAB statements) and of the nonlinear system (SIMULINK).

i- Comment the results obtained in d, g and f.

CEN456- Digital Control Lab 33


Computer Engineering Dept. CCIS- King Saud University

Part II

HARD EXPERIMENTS

CEN456- Digital Control Lab 34


Computer Engineering Dept. CCIS- King Saud University

1- Control of Temperature System

Introduction :
The objective of any automation is to be able to efficiently and reliably control the behavior of
the process.. Temperature systems are widely used in real life as in industrial applications,
domestic domain (home, office) , medical and biological process engineering

The basic operation of a temperature-controlled system is analyzed in this experiment.


Further, we should understand the system and determine the mathematical model of the
process (Transfer function) . This transfer function is used to design a PID controller that
improves the performance of the system in closed loop.

Since a model is a mathematical relation that describes the behavior of the process and
forecasts the reaction to the system to certain environmental influence. The dynamic model of
the temperature process can be described by the transfer function:

K
G ( s) = e −L s
1+τ s
where K is the DC gain defined as the ratio of output voltage to input voltage.
y (∞ )
K=
u (∞ )

τ : time constant when the output reaches 63% of the final value.
L : velocity lag (time delay) as shown in Figure below:

Components and Equipments:


Set point potentiometer 73402
Power Amplifier 73413
Temperature controlled system 73412
Power Supply +/- 15V 72686
Voltmeter
Set of bridging plug.

CEN456- Digital Control Lab 35


Computer Engineering Dept. CCIS- King Saud University

A- Transient Response:

Experimentation Instructions:
- Set-up the experimental arrangement according to the plug-in diagram shown in Figure
1
- Set the flap to 2-division scale and the motor potentiometer to 2 div.
- Connect the Cassy Interface to temperature process as shown in Figure 1 :

Y X C B
CASSY

C should be connected to X

Figure .1
Different steps:
Switch on the computer:
1-C:\CBC-8-2\start
2- Ok
3- Set up/ Disturbance Var…/ Channel X / Quiescent level=0 and Disturbance level = set point
(8V)
4- Time scale / Screen Sweep 120
5-Operation / Step responses.
To print the Figure: File / print.

From the transient response deduce the transfer function of the temperature system.
Identify the steady state gain, the time constant and time delay.

Use the SIMULINK package to check the behavior of the temperature process model
(transfer function).
B- Two-position controller:

CEN456- Digital Control Lab 36


Computer Engineering Dept. CCIS- King Saud University

The previous experiment emphasized the basic concepts of the temperature process. This
experiment will introduce the idea of closed loop control. The only control objective that we
will try to meet is maintaining the output temperature at a reference value (just like the way
our heaters at home work).
There are many controllers that could be used to perform the task. They differ in
simplicity and configuration.
In this part, the two-position controller is introduced as the regulator. This controller will
recognize only two states and will have only two actions: On or OFF.

Figure 2 shows a block diagram of the circuit under study:


+ e Two-Position u Temperature
Controller Process
Output
Reference (r) Temperature (y)

Figure 2.
The controller that we will study can have hysteresis effects, by examining the block
diagram, we can easily deduce that:
e(t) = r(t) – y(t)
If there is no switching hesteresis (h = 0), the two stales of the controller are:

e>0 u : ON
e<0 u : OFF
However, if there is switching hysertersis h, the two states:

e>h u : ON
e<h u : OFF
B-1 Simulation:
- According to the block diagram given in figure 2, use the two-position controller
(Relay in Simulink) with the hysteresis (0, ±0.5 and ±2) and the reference U=6V. Plot
the output and control signal. Deduce the frequency of the control signal. Comment
your results.

B-2 Experiment:
Connect the cassy interface to the two-position controller (X) and then to the temperature
process (sensor). Connect the feedback path from the output (sensor) to the input of the
controller (-).
1) Setting fan potentiometer to 2-scale division and the flap to 2-scale.
2) Set the reference to 6 V.
3) Repeat the question B-1 by using the Leybold two-position controller.
4) Plot the control signal and deduce the frequency of the control signal.
5) Discuss the effects of the hysteresis on the output and control signal.
6) Compare the experimental and simulation results.

NB. Always allow the system to level down to room temperature before starting.

CEN456- Digital Control Lab 37


Computer Engineering Dept. CCIS- King Saud University

C- PID- Controller:
So far, a simple control technique has been evaluated: the two-position control. This part will
introduce another type of controller; which is called PID (Proportional, Integral and
Derivative). This control approach is one of the oldest and most popular techniques used in the
industry, because it is simple and effective.
Figure 3 shows a block diagram of this control.

+ e PID u G(s)

Output
Reference (r) Temperature (y)

Figure 3

In this part, we will see two methods to design a PID controller.

Reaction Curve Method


Many plants, particularly the ones arising in the process industries, can be satisfactory
described by the model:
K
G ( s) = e− L S
τ s +1

Output response
10
Ref
9 Output

0
0 20 40 60 80 100 120
Time(s)

A linearized quantitative version of this model can be obtained with an open-loop experiment,
by using the following procedure:

CEN456- Digital Control Lab 38


Computer Engineering Dept. CCIS- King Saud University

1. With the plant in open loop, take the plant manually to a normal operation point.
Assume that the plant output settles at y (t ) = y 0 for a constant input u (t ) = u 0 .
2. At an initial time t 0 , apply a step change to the plant input, from u 0 to u ∞ (this should
be in the range 10 to 20 % of full scale).
3. Record the plant output until it settles to the new operating point. Assume that you
obtain the curve shown in figure **. This curve is known the process reaction curve.
In this figure m.s.t stands for maximum slope tangent.
4. Compute the parameters model as follows:
y − y0
K= ∞ ; L = t1 − t 0 and τ = t 2 − t1 .
u∞ − u0
Use the figure obtained in part A to calculate the transfer function by the strategy given
above.
By using this transfer function, Simulate the output response (SIMULINK) and
compare the result with the figure obtained in part A.

The model obtained (transfer function) can be used to derive various tuning methods for PID
controllers. Cohen and Coon proposed one of these methods. The suggested parameters are
shown in table 1.

Kp Tr Td
P τ L
1+
KL 3τ
PI τ L 30 τ + 3 L
0.9 + L
KL 12 τ 9τ + 20 L
PID τ 4 L 32 τ + 6 L 4τ L
+ L
K L 3 4τ 13τ + 8 L 11τ + 2 L

The PID controller is given by:

Kp de(t )
u PID = K p e(t ) + e(s ) ds + K p Td
Tr dt
Simulate the model obtained in closed loop with PID deduced from Cohen and
Coon method. Comment your results.

Experiment:
The connection for this experiment is given below Figure 4:
- Set the flap and ventilation pot to div 2.
- The PID deduced from Cohen and Coon method will be implemented.

Different steps:
Switch on the computer:
1-C:\ CBC-8-2\start
2- Ok
3- Set up/ Disturbance Var …/ Channel X / Quiescent level=0 and Disturbance level= set
point(6V)

CEN456- Digital Control Lab 39


Computer Engineering Dept. CCIS- King Saud University

4- Time scale/ Screen Sweep 120,


5- Controller Type / PID (Parallel Configuration),
6- Parameter (set parameter values of Kp, Kd and KI),
5-Operation / Snap shot,
To print the Figure: File / print
Comment your result.

Empirical tuning method


The transfer function of the PID controller is given by:

U (s) KI KD s2 + KP s + KI
. = Kp + + KDs =
E (s) s s

- Kp = proportional gain.
- KI = integral gain.
- KD = derivative gain.
Therefore the PID generates a control action u(t) as a function of the error e(t) given by:
de(t )
u (t ) = K p e(t ) + K D + K I e(τ ) dτ
dt
where Kp , KI, and KD are chosen depending on the process to be controlled.
By trial and error try to chose Kp, KI and Kd to provide the best possible performance for the
temperature process. Note that you have to use the table given in the next page.

The design objectives should be:


1. Good tracking of a reference input,
2. Zero or small steady state error,
3. Fast response,
4. Little oscillation.

Experiment:
The connection for this experiment is given below Figure 4:
- Set the flap and ventilation pot to div 2.

Different steps:
Switch on the computer:
1-C:\ CBC-8-2\start
2- Ok
3- Set up/ Disturbance Var …/ Channel X / Quiescent level=0 and Disturbance level= set
point(6V)
4- Time scale/ Screen Sweep 120,
5- Controller Type / PID (Parallel Configuration),
6- Parameter (set parameter values of Kp, Kd and KI),
5-Operation / Snap shot,
To print the Figure: File / print

CEN456- Digital Control Lab 40


Computer Engineering Dept. CCIS- King Saud University

Y X C B

CASSY
C should be connected to X

Figure 4
Plot and evaluate the response in terms of speed, steady state error, overshoot ect…

Effect of KP,KI,and KD :
A proportional controller (Kp) will have the effect of reducing the rise time and will
reduce ,but never eliminate, the steady-state error. An integral control (Ki) will have the effect
of eliminating the steady-state error, but it may make the transient response worse . A
derivative control (Kd) will have the effect of increasing the stability of the system, reducing
the overshoot, and improving the transient response. Effects of each of controllers Kp, Kd, and
Ki on a closed-loop system are summarized in the table shown below:

CL RESPONSE RISE TIME OVERSHOOT SETTLING TIME S-S ERROR


KP Decrease Increase Small Change Decrease
KI Decrease Increase Increase Eliminate
KD Small Change Decrease Decrease Small Change

Note that these correlations may not be exactly accurate, because Kp, Ki, and Kd are dependent
of each other. In fact, changing one, of these variables can change the effect of the other two.
For this reason, the table should only be used as a reference when you are determining the
values for Ki, Kp and Kd.

SIMULATION: Check the behavior of the temperature model (Transfer function) closed by
the previous PID controller. Comment your results.

CEN456- Digital Control Lab 41


Computer Engineering Dept. CCIS- King Saud University

2- Control of the Water level Process


1- Introduction:
Liquid level processes are very common in the industrial applications such as chemical or
power plants. This experiment will focus on the transient characteristic of the water level
system. Precisely, different operating modes and set up will be explored leading to a better
understanding of the capabilities of the system (analysis and mathematical representation of
the system). Digital controller (Two-position controller and PID) will be introduced to improve
the performance of this system in closed loop.

2- Component and appliances (page56),


Reference variable generator 734 02
Power Amplifier 734 13
Power Supply +/- 15V 726 86
Tank with pump 734 25
Level tank 734 26
Toggle switch
Transparent plastic tubes 8 mm.
Stop- watch
Set of bridging plug.

A-Transient response:
Arrange the experimentation devices according to the connecting diagram given in figure 5:
- The input voltage = 8V, the time scale=120s and pot=6.
- Recording the transient behavior with the following adjustments:
a. The submersible tube (sensor) in the first position:
i. Slide 0 in position 1 &5,
ii. Slide 0 in position 1 &4.
b. The submersible tube in the second position:
i. Slide 4 in position 2 and slide 0 in position 5,
ii. Slide 4 (use 2nd aperture from below, close all others) in position 3 and
slide 0 in position 1 &5.
c. The submersible tube in the first position:
i. Slide 2 in position 5, Slide 0 in position 1,
ii. Slide 1 in position 5, slide 4 (use the 2nd aperture from below and close
all others) in position 3 and slide 0 in position 1.
d. The submersible tube in the second position:
i. Slide 2 in position 5, Slide 0 in position 1,
ii. Slide 1 in position 5, slide 4 (use the 2nd aperture from below and close
all others) in position 3 and slide 0 in position 1.

For each case, follow the steps given below:


Switch on the computer:
1-C:\ CBC-8-2\start
2- Ok
3- Set up/ Disturbance Var …/ Channel X / Quiescent level=0 and Disturbance level= set
point(8V)
4- Time scale/ Screen Sweep 120,

CEN456- Digital Control Lab 42


Computer Engineering Dept. CCIS- King Saud University

5-Operation / Step response.


To print the Figure: File / print

This is the CASSY. X


and C should be connected.
B C X
CCC Y

Figure 5

Evaluation:
- For each case, find the transfer function of the open loop system.
- Discuss the effect of the position of slides and sensor on the transient response of
system.

TANK LEVEL MODEL: Simulation


The figure below shows a simple level system qin [m3min-1] and qout [m3min-1] are the
volumetric flows in and out of the tank. The level in the tank is given by h [m]. We wish to
model the behavior of the tank so that we can predict changes in level due to changes in
flow condition. Therefore, we need to develop the mass balance relationships. Since we are
not considering effects, there is no need to consider an energy balance. The flows are
volumetric floes. So, we need a density term ρ to convert from volume units to mass units.
We also need to km=now the cross-section area (A) of the tank, so that we can determine
the volume holdup in tank, and hence the mass holdup.

CEN456- Digital Control Lab 43


Computer Engineering Dept. CCIS- King Saud University

Given these informations, the mass balance of the tank can be written as:
d (ρ A h )
= ρ Qin − ρ Qout
dt

Since there is no heating effect, density can be assumed constant. Also, since the tank is
cylindrical, it has constant cross-section area. Therefore, the differential equation (*) becomes:
ρ A dh dh
= ρ Qin − ρ Qout or A = Qin − Qout
dt dt
Note that the flow out Qout, is determined by the pressure exerted by the liquid, and it is
given by: Qout = k h .

Therefore, the mass balance should be written as:


dh 1
dt A
(
= Qin − k h . )
Find the area A of the tank and the coefficient k.
Simulate the output response of the nonlinear model.
Compare your result with the figure obtained in part A-a-i.

B- Two-position controller
1- SIMULATION:
For each transfer function given above, use the two-position controller (see par B-1 in the
previous experiment) with hysteresis (0 , ±0.5, and ±2) in closed loop with water level
model.
Plot the output and the control signal.
Comment your results.

2- EXPERIMENT:
For the case A-3-b, connect the Leybold two-position controller to the water level system.

Two-position Process
Controller Amp. Sensor

X C B

CEN456- Digital Control Lab 44


Computer Engineering Dept. CCIS- King Saud University

Cassy Interface.
Plot The response and the control signal for the hysteresis (0 , ±0.5, and ±2).
Discuss the effects on the output and the control signal action. Compare the experimental
and simulation results.

C-PID Design for the Water level Process


1- Introduction
The experiment in part A has dealt with open loop responses. In practice, a desired
performance of any process is usually achieved through closed-loop configuration (Feedback).
Figure 6 and 7 show block diagrams of open loop and closed loop configurations. The
fundamental differences between the two cases need to be understood before any appreciation
of control systems is achieved.

Input Power Tank with Water Level Indicator


Voltage Amplifier Pump Level Sensor

Input Voltage System Level Indicator (output)

Figure 6. Open block diagram.

Reference Error Input Voltage Level Indicator


+ Controller U System
-

Figure 7 Closed loop block diagram..

2- Closed Loop performance:


There are many types of controllers that can be used. In this par of experiment, the most basic
control system will be introduced and studied (PID). The transfer function of PID is given by:
U (s) K K s2 + K P s + KI 1
= K p + I + KDs = D = K p 1+ + TD s .
E (s) s s Ti s
Where Kp, KI and KD are selected in order to obtain good response.

CEN456- Digital Control Lab 45


Computer Engineering Dept. CCIS- King Saud University

3-a Experimentation:
Connecting Diagram:

CASSY - SYSTEM

C Controller Y Process
C Amp. Sensor

B
X B

Figure 8.
In the case 3-b, design a PID controller to maintain the level of the water around 80%. The
objectives to be met are:
- Fast response,
- Small steady state error,
- Little or no oscillation (Note: Oscillation destroy the pump in the long run!).
By trial to changing the effect of KP , KI and KD to provide the “Best” possible
performance for the Water level . Plot the final response and the reference input.

Plot the final response, the control signal and the reference input.

3-b SIMULATION:
- Use the SIMULINK to check the behavior of the Water Process model closed by
previous PID controller.
- Plot the level, the control signal and the reference input.
- Compare the experimental and simulation response.

CEN456- Digital Control Lab 46


Computer Engineering Dept. CCIS- King Saud University

3- Traffic Lights System

Introduction:

The MIC957 Traffic Lights Model is a working mimic diagram of the traffic and
pedestrian control lamp signals at a crossroads with one pedestrian crossing. It is designed to
be controlled by any of a range of microcomputers for the purpose of providing exercises in
the use of computer to monitor and control objects.
In this experiment, three exercises presented start at the simplest possible level, while the third
imposes a requirement for a degree of logical thinking.

System Description:
MIC957 Traffic Lights Modeling, which there is some buttons and set of, colored
lamp(figure 9):
• Three lamps for north –south.
• Three lamps for east –west.
• Two lamps for pedestrian crossing.
• These lamps are controlled by one bit of a single 8 bits output port as in the
Table [1].
• Five pushbuttons that may be passed to simulate the detection of vehicle by any
of four traffic sensors as shown below.

CEN456- Digital Control Lab 47


Computer Engineering Dept. CCIS- King Saud University

Figure 9.

Table [1]:

Bit Value Port A Port B


Requests Control
0 1 East Read
1 2 West Amber South road
2 4 South Green
3 8 North Red
4 16 Pedestrian Amber West Road
5 32 - Green
6 64 - Red
7 128 - Green Pedestrian

Experimentation Instructions:

1-All sequences:

Fill the sub-sequences (address) in the table given below by using the data given in
table 1. Write a C program that alters all these sequences.

Table [2]:

Line South West Pedestrian Time Sub-sequence


0 Red Red Red 0 Pedestrian 0x
1 Red Red Green 6 0x
2 Red Red Red 0 0x
3 Red Amber Red 2 West 0x
4 Red Green Red 6 0x
5 Red Amber Red 3 0x
6 Red Red Red 1 0x
7 Amber Red Red 1 South 0x
8 Green Red Red 6 0x
9 Amber Red Red 3 0x
10 Red Red Red 1 0x

2- Sequences altered by pedestrian

It is required to allow vehicles to travel alternatively along the north south and east west
roads. If however a pedestrian processes the request button by the crossing, the normal
sequence should proceed until the south road lights return to read and the pedestrian crossing
should change to green and back to red before the normal sequence is assumed as shown in
Table [2]. Finally write and test a program, which implements your algorithm.

CEN456- Digital Control Lab 48


Computer Engineering Dept. CCIS- King Saud University

3- Sequence modified by vehicles and pedestrians:

In this exercise all input signals will be used. Let us call them requests. It is required to control
the traffic lights according to the following rules:
1- Every change in the lights must follow one of the sub-sequences 0 to 3, 4 to 7 or 8 to
11 listed in the table 2, subject to control by the requests received as follows.
2- A light, one it is at green, will remain so at least for normal period stated in the table 2.
Thereafter, it will remain green unless or until a request has been received for some
other light.
3- If requests are received for both of the other lights, then they will be served according
to the sequence of table 2.
4- Every request must be stored until it is cancelled. Cancellation takes place then the
corresponding light goes green. Further requests for a light that is already green are
ignored.
5- And West request are treated as equivalent, North and South requests are treated as
equivalent.

Note: (For more details about program structure see Annex- 1)


To initialize the port A as input to the PC and port B as the output:
OUTPORTB (0x0303, 0x99);
The address of the port A is: 0x0300;
The address of the port B is: 0x0301;
Acquisition statements:
- To input data from port A: INPORTB (0x0300);
- To output data XX to port B: OUTPORTB (0x0301, XX);

CEN456- Digital Control Lab 49


Computer Engineering Dept. CCIS- King Saud University

4- PC Temperature Controller

Introduction:

The MIC 955 computer application module is designed for practical exercises in the use of a
microcomputer in:
1- Digital temperature measurement control of electrical power formation of simple
closed control loop.
2- The MIC 955 is one of the Feedback MICA series of modules and interfaces for
computer applications.
3- Interfaces for computer Applications. Modules in the range may be used in conjunction
with a variety of computers for which MIC940 series interfaces are available.

The MIC955 module comprises a panel carrying a heated strip of black anodized aluminum
and a cooling fan. The strip carries two resistors, which serves as a heater, and etched platinum
strip resistor, which serves as a temperature sensor. Associated electronics are mounted on the
printed wiring board at the back.

The heater resistor are supplied with power controlled by the microcomputer’s output port,
buffered by a power amplifier, whose output may be monitored at the heater monitor socket on
the panel.
The cooling fan may be controlled in either of two ways, selected by a three-position
‘programmed – off- manual’. In the programmed condition power to the motor is switched on
or off by another bit (B5) of the computer’s output port, again acting through a buffer
amplifier. In the manual condition a variable resistor whose knob is labeled “Blower speed”
may control the blower speed. The maximum fan speed in this condition is less than the
maximum under program control, this is by design.

The temperature sensor is connected in a DC bridge circuit. Its output is amplified and the
amplifier output is balanced to zero at 0’C, the sensitivity being 20mV/C at the temperature
monitor’s socket on the panel. The analogue signal is connected to analogue-to-digital (ADC)
converter in this module, so that a digital signal is made available to the associated
microcomputer. The ADC operates when instructed to do so by a computer signal via an
output port, it then places an 8 bits number on the input port so that the computer may read the
number, which is a measure of the temperature at the sensor.

Technical Data:
The module uses the following power supplies: +12V at about 1.2 A -12V a few mA.
Black: 0V common
Red: +12V,
Orange: +5V if required,
Blue: -12V.

CEN456- Digital Control Lab 50


Computer Engineering Dept. CCIS- King Saud University

Block – Diagram

A0

Port A A1

Input ADC Amplifier Sensor


0x300 A7
PC B0
Port B B4
Output B5 (Fan)
0x301 B6 (Heater)
B7
1 1
ADC- Trigger
0

Port and bit allocations for communication between the microcomputer and the module are as
follows:

Table 3:
Bit Port A, Input Port B, Output
0 (LSB) ADC output, bit 0 (LSB)
1 ADC output, bit 1
2 ADC output, bit 2
3 ADC output, bit 3
4 ADC output, bit 4
5 ADC output, bit 5 Fan Command (On=1,Off=0)
6 ADC output, bit 6 Heater Command (On=1,Off=0)
7 (MSB) ADC output, bit 7 (MSB) Start ADC command

Note: In order to trigger ADC, bit 7 of port B must be given a negative pulse, which may be
generated by the binary sequence 1 1 1 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1 1 .

Objective:
This experiment is required to cycle the temperature between limits, which are specified by
entries from the keyboard, using the heater to raise the temperature and the fan when the temperature is
to be lowered. The temperature should be displayed.

Exercise 1: Digital Thermometer


The objective is simply to read and display the temperature measured by the temperature
sensor. In order to accomplish this an analogue-to-digital conversion must be triggered and the
data read and displayed on the computer screen.

You develop your own program (C language) that works as follow


The microcomputer trigger B7 to operating the ADC.
The ADC converts the analog data that measure by sensor to digital data
The microcomputer read one byte input throw port A.
Then the microcomputer displays the temperature value.

CEN456- Digital Control Lab 51


Computer Engineering Dept. CCIS- King Saud University

Exercise 2: Limit Cycle


It is required to cycle the temperature between limits, which are specified by entries from
the keyboard, using the heater to raise the temperature and the fan when the temperature is to
be lowered. The temperature should be displayed.

Thus, the data requirements include the two temperature limits, the data handled and the
signals, which control the heater and fan. In detail therefore the data is:
• Input:
High temperature limit to be entered from keyboard low temperature limit to be
entered from keyboard ADC data byte read by the microcomputer' s input port.

• Output:
ADC trigger bit [B7] (most significant bit of MIC955 control byte, Port B), the heater
switch bit [B6] port B .The fan switch bit [B5] port B.
When the temperature is superior to the maximum, the fan turn ON and heater turn OFF
until the temperature decreases to minimum then the heater turn ON and the fan turn off.
If the temperature is between maximum and minimum, then both the fan and the heater are
switched on.

As shown in flow-chart given in figure 10 used to represent the algorithm of program.

Program Algorithm:

CEN456- Digital Control Lab 52


Computer Engineering Dept. CCIS- King Saud University

The flow chart used for program algorithm:

START

Initialize ports

Set Max &Min

Read Temperature

T>Max

Heater OFF
Fan ON
T<Min

Heater OFF Heater OFF


Fan ON Fan OFF

CEN456- Digital Control Lab 53


Computer Engineering Dept. CCIS- King Saud University

Annex –1:

Program structure:

To initialize the port A as input to the PC and port B as the output, use:
OUTPORTB (0x0303, 0x99);
The address of the port A is 0x0300;
The address of the port B is: 0x0301,
Acquisition statements:
- To input data from port A: INPORTB (0x0300).
- To output data XX to port B OUTPORTB (0x0301, XX).

Library:
# include <dos.h>
# include <conio.h>
# include <stdio.h>
# include < bios.h>
main()
{
Data declarations: int x j i, char y, z[10]={……,…..,….,…..,..}
Initializations: j=0 ; i=2,
Outportb (0x0303, 0x99);
Clrscd( );
Printf(“\ …………”);
X=atoi(gets(y));
While ( bioskey(1)==0)
{……



}

}.
To trigger the ADC :
outportb(0x0301,k|0x80);
delay(100);
outportb(0x0301,k&0x7f);
delay(100);
outportb(0x0301,k|0x80);
delay(100);

The instructions that can be used are:


- delay
- printf
- atoi (gets(…..))
- if ( … )…else …(…)
- || , && ( logic operators)
- break
- k++

CEN456- Digital Control Lab 54


Computer Engineering Dept. CCIS- King Saud University

5. Motor Speed Control

Objectives:

1. To investigate the motor characteristic and determine the transfer function of the motor.
2. To implement Two-position and PID controller to improve the steady state
performance.

Apparatus:
1. DC servo system,
2. Personnel computer,
3. Cassy data acquisition system,
4. Printer.

Theoretical background:

Direct-Current (DC) motors are one of the most widely used prime movers in industry
today. Years ago a majority of small servomotors used for control purposes were of the AC
variety. In reality, AC motors are more difficult to control, especially for position control, and
their characteristic are quite nonlinear, which makes the analytical task more difficult. DC
motors, on the other hand, are more expensive, because of the brushes and commutators, and
variable-flux DC motors are suitable only for certain types of control applications.
The DC motor is basically a torque transducer that converts electric energy into mechanical
energy. The torque developed on the motor shaft is directly proportional to the field flux and
the armature current. The relationship is given by:

Tm = K m Φ i a

where Tm is the torque (Nm), Φ is the magnetic flux (Webers), ia is the armature current (A)
and Km is a proportional constant.

In addition to the torque, DC motor generates a back-emf, which is a voltage and it is


proportional to the shaft velocity. It is given by:

eb = K m Φ Ω m

where eb denotes the back-emf (V), and Ωm is the shaft velocity (rad/s) of the motor.

Mathematical model of DC motor:

CEN456- Digital Control Lab 55


Computer Engineering Dept. CCIS- King Saud University

Starting with the control input voltage V(t), the cause and effect equations for the motor
circuit are:

d i a (t ) 1 R 1
= V (t ) − i a (t ) − eb (t )
dt L L L
Tm = K i i a (t )
dθ(t )
eb (t ) = K b = K b Ω(t )
dt
d 2 θ(t ) 1 1 B dθ(t )
2
= Tm (t ) − TL (t ) −
dt J J J dt
where TL represents a load frictional torque.

The transfer function between the motor displacements θ(t) and the input voltage V(t) is:
θ( s ) Ki
=
V ( s ) L J s + (R J + B L ) s 2 + (K b K i + R B ) s
3

and between the speed Ω(t) and the input voltage V(t) :
Ω( s ) Ki
=
V ( s ) L J s + ( R J + B L ) s + (K b K i + R B )
2

This is a second order system.

Note that, if the armature current inductance is neglected (L → 0), the transfer function
becomes:

Ω( s ) Ki Km
= =
V ( s ) R J s + K b K i + R B 1 + Tm s
Ki RJ
where K m = and Tm = .
Kb Ki + R B Kb Ki + R B
This is a first order system.

1 - Transient response of DC motor:

DC Tach
X Motor o
Amp
Cassy C
System
B

CEN456- Digital Control Lab 56


Computer Engineering Dept. CCIS- King Saud University

Fig.2

1-a Experiment:
1- Mount the servo amplifier, power supply and motor on the base board as shown
in figure 2. and 3.
2- Set the input from the data acquisition system as a step of 8 V.
3- Connect the output from the tacho to the input channel (B) of the data
acquisition system.
4- Switch the power on and observe the output.
5- Apply the load and observe the output.
6- In each case, determine the time constant of the motor.
7- Discuss the effect of the load on the transient response.
8- Determine the transfer function of the DC motor (unload case only).

Different steps for Cassy software:


Switch on the computer:
1-C:\CBC-8-2\start
2- Ok
3- Set up/ Disturbance Var…/ Channel X / Quiescent level=0 and Disturbance level = set point
(8V)
4- Time scale / Screen Sweep 120
5-Operation / Step responses.
To print the Figure: File / print.

1-b Simulink:
Check the behavior of the DC motor (transfer function) and compare it with the
response obtained in experiment part.

CEN456- Digital Control Lab 57


Computer Engineering Dept. CCIS- King Saud University

Fig.3

2- Closed loop response of DC motor


In general control system design involves the following three steps:
1- Determine what the system should do and how to do it (design specification).
2- Determine the controller or compensator configuration relative to how it is connected
to the controlled process.
3- Determine the parameter values of the controller to achieve the design goals.
Design specifications: we often use design specifications to describe what the system should
do and how it is done. These specifications are unique to each individual system and often
include specification about relative stability, steady-state accuracy (error), transient response,
and frequency response characteristic. In some applications there may be additional
specifications on sensitivity to parameter variations ( i.e robustness, or disturbance rejection)

CEN456- Digital Control Lab 58


Computer Engineering Dept. CCIS- King Saud University

In this part, two controller configurations are chosen: Two position controller and PID
controller.

2-a Closed-loop with Two-position controller:

X + Two Tach
- Position Amp o
Cassy C Controller
System
B

Fig.4

2-a-1 Experiment:
1- Connect the two positions controller to DC motor,
2- Connect the feedback path from the output (tacho) to the input of the controller.
3- Set the reference to 8V
4- Set the switching hysteresis to h = 0,
5- Plot the response Ω(t). Comment?
6- Deduce the applied control signal V(t)
7- Repeat the experiment with hysteresis h = ±0.5,
8- Repeat the experiment with hysteresis h = ±2.

Different steps for Cassy Software:


Switch on the computer:
1-C:\CBC-8-2\start
2- Ok
3- Set up/ Disturbance Var…/ Channel X / Quiescent level=0 and Disturbance level = set point
(8V)
4- Time scale / Screen Sweep 120
5-Operation / Step responses.
To print the Figure: File / print.

Experiment evaluation:
Discuss the difference between the performance obtained in open loop and in
closed loop with two position controller (for different value of h)
Deduce the effect of the hysteresis on the output and on the control signal.

2-a-2 Simulation:
Check the behavior of the DC motor closed by Two-position controller with different
values of hysterisis (0, ± 0.5 and ±2). Compare the performance and comment the result.

b- PID control of DC motor


One of the forms of controller widely used in industrial process control is called a three-
term, or PID controller. This controller has a transfer function:

CEN456- Digital Control Lab 59


Computer Engineering Dept. CCIS- King Saud University

Ki
G ( s) = K p e(t ) + + KD s
s
The controller provides a proportional term (P), an integral action (I) and a derivative term (D).
The equation for the output in time domain is:
de(t )
u (t ) = K p e(t ) + K I e(τ) dτ + K D
dt
Many industrial processes are controlled using PID controllers. The popularity of PID
controllers can be attributed partly to their good performance in wide range of operating
condition and portly to their functional simplicity, which allows engineers to operate them in a
simple, straightforward manner.

Closed – loop performance:


The objective is to design a PID controller to achieve the following performance:
Fast response,
No steady state error,
No oscillation.

2-b-1 Experiments:
Arrange the experiment according to the block diagram shown in figure 5.
Steps for PID controller:
Switch on the computer,
1-C:\CBC-8-2\start
2- Ok
3- Controller type / PID(Parallel configuration),
4- Set up/ Disturbance Var…/ Channel X / Quiescent level=0 and Disturbance level = set point
(8V)
5- Time scale / screen sweep 10
6- Parameters
7- Operation / snapshot.
8- To print the figure: File / print

By trial and error select the optimal value of Kp, KI and KD that achieve desired performance.
Plot the output, reference signal and the control signal.
Deduce the effect of Kp, KI and KD on the response.
Evaluate the performance in terms of speed, steady state error, overshoot etc…

2-b-2 Simulation:
Check the behavior of the DC motor closed by PID controller with parameters obtained
in the experiment part. Compare the performance and comment the result.

CEN456- Digital Control Lab 60


Computer Engineering Dept. CCIS- King Saud University

Fig.5

CEN456- Digital Control Lab 61


Computer Engineering Dept. CCIS- King Saud University

CEN456- Digital Control Lab 62


Computer Engineering Dept. CCIS- King Saud University

Control of Water Level Process


A- Transient response.

Introduction:

Water level processes are very common in the industrial applications such as
chemical or power plants. This experiment will focus on the transient
characteristic of the water level system. Precisely, setup will be explored leading
to a better understanding of the capabilities of the system (analysis and
mathematical representation of the system).

Since a model is a mathematical relation that describes the behavior of the


process and forecasts the reaction to the system to certain environmental
influence. The dynamic model of the water level process can be described by the
transfer function:
-Ls
G(S) = {K/[1 + s]} e

Refer to page 37 to see how to obtain K, and L.

Components and appliances:

Water controlled system 734262


Reference variable generator 73402
Power Amplifier 73413
Power supply unit 72686
Differential power transducer 73481
Immersion tube 734876
Profi-Cassy
Cassy lab software
WinFact software
PID controller 734061

CEN456- Digital Control Lab 63


Computer Engineering Dept. CCIS- King Saud University

Experiment Instructions:

1. Connect the open loop water level experiment as shown in the following
figure:

2. Connect the water level system with the profi-cassy in order to plot the
input and output signals (channel A: input, channel B: output).
3. Open Cassy-lab software, Start => Programs => Cassy lab.
4. Using Cassy lab software, Record the transient behavior for the
following 2 cases:
1. Case 1:
1. Start with Reference voltage = 5 V until you reach a steady
state.
2. Record the time required to achieve this state, name it T.
2. Case 2:
1- Start with Reference voltage = 5 V.
2- At t T s decrease it to 2 V.
3- At t 2T s increase it to 8 V.

In case 2, what can you conclude? Why?

5. Find the open loop transfer function of the system in case 1.


6. Calculate the time response specifications.
7. Comment all of your result.

Simulation:

CEN456- Digital Control Lab 64


Computer Engineering Dept. CCIS- King Saud University

Using SIMULINK, plot the open loop response of your input and compare it
with the figure obtained from the real experiment.

B- Hardware PID controller.

CEN456- Digital Control Lab 65


Computer Engineering Dept. CCIS- King Saud University

C- Software PID controller.


Introduction:

The experiment in part A has dealt with open loop response. In practice, a desired
performance of any process is usually achieved through closed-loop
configuration (feedback).
Figure 1 and 2 shows the difference between open loop closed-loop
configurations.

Input Voltage Level Indicator


Power Tank with Water Level
amplifier pump Sensor

Input Voltage Level Indicator (output )


System

Figure 1: open-loop block diagram.

Input
Voltage
+ Level Indicator
Reference Error Controller U system
(PID)
-

Figure 2: closed-loop block diagram.


Objective:

This part will introduce another type of controller; which is called PID
(Proportional, Integral and Derivative). This control approach is one of the oldest
and most popular techniques used in the industry, because it is simple and
effective. In this experiment we will study how to use PID controller in the water
level system. Also obtain a better response in term of Rise Time, Overshoot,
Settling Time and Steady-State Error. After that we will see how SIMULINK can
be helped to achieve our requirement.

Closed-Loop Performance:

CEN456- Digital Control Lab 66


Computer Engineering Dept. CCIS- King Saud University

There are many types of controllers that can be used. In this par of experiment,
the most basic control system will be introduced and studied (PID).
The transfer function of the PID controller is given by:
U(s) K K S² + KP S + KI 1
= KP + I + KDS = D = KP 1+ + TDS
E(s) s s Ti s Wh

ere:
KP = proportional gain.
KI = integral gain.
KD = derivative gain.
We select them in order to obtain good response.

How can we get the best response?


The answer to this question is as follows:

The Effect of P, I and D controller:

A proportional controller (KP) will have the effect of reducing the rise time and
will reduced but never eliminate the steady state error. An integral control (KI)
will have the effect of eliminating the steady state error, but it may make the
transient response worse. A derivative control (KD) will have the effect of
increasing the stability of the system, reducing the overshoot, and improving the
transient response.

This table summarizes all the above:

The Effect of Kp, Ki and Kd:

CL response Rise Time Overshoot Settling Time S-S Error


KP Decrease Increase Small change Decrease
KI Decrease Increase Increase Eliminate
KD Small change Decrease Decrease Small change

General tips for designing the PID controller:

When you are designing a PID controller for a given system, follow the steps
shown below to obtain a desired response:

1. Obtain an open-loop response and determine what needs to be improved.


2. Add a proportional control to improve the rise time.

CEN456- Digital Control Lab 67


Computer Engineering Dept. CCIS- King Saud University

3. Add a derivative control to improve the overshoot.


4. Add an integral control to eliminate the steady state error.
5. Adjust each of the KP, KD and KI until you obtain a desired overall
response.
Important Notes:
1. Use the table to decide which KX where X=P, I or D to increase or
decrease.
2. Probably, you don’t need to implement all the three controllers.

Experiment:
You job is to design a PID controller to maintain the level of the water around 5
V (50%).
The objective to be met:
1. Fast response.
2. No steady state error.
3. Little or no oscillation (Note: Oscillation destroys the pump in the long
run).

Change the values of Kp, Ki (Ti), Kd (Td) to provide the best possible
performance for the water level. Plot the final response, the control signal and the
reference input.

You will Design a PID controller in two ways.

1- Hardware PID controller:


1- You should adjust the open loop connection to become a closed loop
system with forward controller as suggested in figure 2. Also, you should
use PID controller shown in figure 3 as well as cassy lab software in order
to plot input reference and output response.

CEN456- Digital Control Lab 68


Computer Engineering Dept. CCIS- King Saud University

Figure 3: PID controller.


2- After adjusting PID values, Record the transient behavior for the following
two cases:
1.: Case 1:
3. Start with Reference voltage = 5 V until you reach a steady
state.
4. Record the time required to achieve this state, name it T.
2.: Case 2:
4- Start with Reference voltage = 5 V.
5- At t T s decrease it to 2 V.
6- At t 2T s increase it to 8 V.

3- In case 2, what can you conclude? Why?


4- Calculate the time response specifications and comment all of your result.

2- Software PID controller using WinFACT:


Your hardware connection should be adjusted so that it will present a closed
loop system with a software PID controller as follows:

1- Be sure that you disconnect the hardware PID controller.


2- Connect the reverence input to channel A.
3- Connect the output to channel B; (the summation as well as the PID controller
are done by Win FACT software. After that it will be available at channel X).

CEN456- Digital Control Lab 69


Computer Engineering Dept. CCIS- King Saud University

4- Connect channel X to water level system.


5- Now open Win FACT from Start => programs=> Win FACT6 => BORIS.
Then build the following block diagram:

Try to use the same value as 1 for PID controller. Compare results obtained from
both 1 and 2.

Simulation:

Using SIMULINK, plot the closed loop response as well as the control signal
with PID controller (using your obtained values from Hardware PID controller)
of your input and compare it with the figure obtained from the real experiment.

CEN456- Digital Control Lab 70

S-ar putea să vă placă și