0% found this document useful (0 votes)
39 views133 pages

Dissertation

Uploaded by

Abeng Yogta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views133 pages

Dissertation

Uploaded by

Abeng Yogta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 133

Microcontroller-based

Data Acquisition and Control


with Applications

DISSERTATION

for the Degree of

DOCTOR OF PHILOSOPHY
(Mechanical Engineering)

Sang-Hoon Lee

January 2009
Microcontroller-based Data Acquisition and Control
with Applications

DISSERTATION

Submitted in Partial Fulfillment

of the REQUIREMENTS for the

Degree of

DOCTOR OF PHILOSOPHY (Mechanical Engineering)

at the

POLYTECHNIC INSTITUTE OF NEW YORK UNIVERSITY

by

Sang-Hoon Lee
January 2009

Approved:

Department Head

Date

Copy No.
Approved by the Guidance Committee:

Major: Systems, Controls, and Robotics

Professor Vikram Kapila


Mechanical Engineering
Committee Chairman

Date

Professor Maurizio Porfiri


Mechanical Engineering

Date

Minor: Mechanical Design

Professor Nikhil Gupta


Mechanical Engineering

Date

Minor: Applied Mathematics

Professor Magued Iskander


Civil Engineering

Date

ii
Microfilm or other copies of this dissertation are obtainable from:

UMI Dissertations Publishing

Bell & Howell Information and Learning

300 North Zeeb Road

P.O. Box 1346

Ann Arbor, Michigan 48106-1346

iii
To God, my wife, my daughter, and my parents
Acknowledgment

There is a famous Korean proverb, “Whom one meets during his life could change him

into who he will be.” It was one of the turning points of my life that I met Professor Vikram

Kapila. It has been a great honor to have him as my academic advisor throughout my Ph.D.

program as well as my Master of Science program. He has opened my eyes in the fields of

controls and mechatronics. I still remember the day when Professor Kapila provided me my

first microcontroller kits to work on. That day was another turning point in my career. With

the knowledge of control and mechatronics that I have been taught by him, I was able to

not only accomplish many of my research goals, but also to elevate my career to a higher

level. I would be remiss not to mention how much dedication, trust, and patience he has

shown towards me. I couldn’t be who I am now without his support. In addition to being

the academic influence, he has been a counselor of my life like an uncle, brother, or rabbi.

I am also grateful that he has continuously provided me with financial assistance during my

academic years at Polytechnic Institute of New York University (NYU-POLY). I also thank

Professor Kapila for helping me secure a visiting faculty position at NYU-POLY. I sincerely

thank you, Professor Vikram Kapila.

My graduate studies would not be possible without the financial assistance from various

sources. First, I thank the National Science Foundation’s Research Experience for Teachers

Program under grant 0227479 for financially supporting much of my doctoral degree program.

This grant provided me a research assistantship to assist Professor Kapila in developing and

conducting the Science and Mechatronics Aided Research for Teachers (SMART) program.

Second, I thank the New York State Department of Education’s Engineers of the Future Pro-

gram under grant C400682 for partially supporting me. This grant supported my research in

part and allowed me to collaborate with Professor Kapila in developing and conducting a Sum-

mer Mechatronics Institute for Teachers (SUMMIT) program. I thank all 67 New York/New

Jersey secondary school teachers who participated in the four-week summer research experi-

ence under the SMART (20032005) and SUMMIT (2007) projects, developing mechatronics

v
projects with me and my colleagues. I learned a lot by interacting with them. Finally, I

thank the Mechanical Engineering (ME) department of NYU-POLY for partially supporting

my graduate studies, in the form of teaching assistantships, at various times during my doctoral

degree.

Most of all, I sincerely thank my loving wife, JiYoung Kim, whose enduring patience is

boundless and support endless. She has given me encouragement and comfort during my

entire doctoral program. She has also been praying for me numerous days and nights. It will

never be possible to express, in words, my deep gratefulness for her support. “I love you,

JiYoung.” I also thank God for giving me a precious daughter, Claire Haerin Lee, who has

given me priceless moments and a joyful life just by her existence itself. My family has been

an essential anchor during my graduate studies. They have provided me nourishment in the

form of moral and ethical guidance and supported me with endless prayers. They have shown

me what love of family is. To them, I say I love you all.

Next, I thank Professors Magued Iskander and Nikhil Gupta for being members of my

Ph.D. dissertation committee. I particularly thank another member of my Ph.D. dissertation

committee, Professor Maurizio Porfiri, for introducing me to a new topic of chaos synchro-

nization which has led to a fruitful collaboration. I gratefully thank ME department chair,

Professor George Vradis, for many kind words of encouragement throughout my studies and

providing me with a great opportunity for a full-time teaching position at NYU-POLY. I also

thank ME department administrator, Ms. Lorraine Bildzukewicz, for her countless support

and care.

On a personal note, I thank Dr. Noel Kriftcher for his warm care like an uncle. Next,

I thank the engineering students around me at NYU-POLY, specifically, Chandresh Dubey,

Yan-Fang (Yvonne) Li, Antonio Mannino, Anshuman Panda, Valentin Siderskiy, Christopher

Wilkins, and Hong Wong for their wholehearted support towards many of my personal and

professional accomplishments. Thank you all.

vi
AN ABSTRACT

MICROCONTROLLER-BASED DATA ACQUISITION AND CONTROL WITH

APPLICATIONS

by

Sang-Hoon Lee

Advisor: Professor Vikram Kapila

Submitted in Partial Fulfillment of the Requirements

for the Degree of Doctor of Philosophy (Mechanical Engineering)

January 2009

In the first part of this dissertation, we consider the development of PC-based data ac-

quisition and control (DAC) tools that use inexpensive microcontrollers (e.g., PIC and BASIC

Stamp 2) and widely used technical computing software MATLAB/Simulink, which provides

a wealth of graphical design tools. Our MATLAB and Simulink-based toolboxes yield inex-

pensive DAC solutions by exploiting the serial communication capability of both MATLAB

and microcontrollers. Our framework is well suited for DAC tasks that require graphical user

interface and/or advanced computational capabilities but do not require stringent hardware

performance. We illustrate the efficacy of our DAC toolboxes by performing position control

of a DC motor system and liquid level control of a coupled two-tank system.

In the second part of this dissertation, we consider two problems pertaining to synchro-

nization of chaotic systems. First, we address the problem of synchronizing a master-slave

chaotic system in the sampled-data setting. Second, we address the problem of synchroniz-

ing a sporadically coupled master-slave chaotic system in the sampled-data setting. For both

problems, an Euler approximation technique is used to produce a sampled-data representation

for a continuous-time chaotic system containing a continuous nonlinear function. Whereas

for the first problem we use a time-invariant full-state feedback control law, for the second

problem we employ an intermittent, pulse-based, periodic, full-state feedback control law. We

vii
use the discrete-time Lyapunov stability theory and the linear matrix inequality framework

to construct the two control laws. Finally, by utilizing the MATLAB/microcontroller-based

DAC techniques developed in the first part of this dissertation, we provide experimental val-

idation of our theoretical results by implementing, on a set of microcontrollers endowed with

RF communication capability, a sampled-data master-slave chaotic system based on Chua’s

circuit.

viii
Contents

Acknowledgment v

Abstract vii

List of Figures xiv

1 Introduction 1

2 Development of a MATLAB-based Graphical User Interface Environment


for PIC Microcontroller Projects 8

2.1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

2.2. Hardware Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

2.2.1. Peripheral Interface Controller . . . . . . . . . . . . . . . . . . . . . . . 10

2.2.2. Personal Computer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

2.2.3. RS232 Driver/Receiver . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

2.2.4. PIC Development Board . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

2.2.5. Light Refraction Test Bed . . . . . . . . . . . . . . . . . . . . . . . . . . 13

2.3. Software Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

2.3.1. PIC Assembly Program . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

2.3.2. MATLAB Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

2.3.3. Simulink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

2.3.4. Dials and Gauges Blockset . . . . . . . . . . . . . . . . . . . . . . . . . 18

2.4. Examples of Serial Communication between PIC and PC . . . . . . . . . . . . 18

2.4.1. Serial Communication from PC to PIC: Servomotor Position Control . . 18

ix
2.4.2. Serial Communication from PIC to PC: Data Acquisition, Processing,
and Plotting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

2.4.3. Bi-directional Serial Communication between PIC and PC . . . . . . . . 22

2.5. Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

3 Development of a MATLAB Data Acquisition and Control Toolbox for PIC


Microcontrollers 26

3.1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

3.2. Hardware Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

3.2.1. PIC Microcontroller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

3.2.2. PIC-PG2C Programmer . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

3.2.3. PIC Development Board . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

3.3. Software Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

3.3.1. Template.mdl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

3.3.2. PICLibrary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

3.4. Integration of Simulink and PIC . . . . . . . . . . . . . . . . . . . . . . . . . . 34

3.5. Example—DC Motor Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

3.6. Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

4 Development of a MATLAB Data Acquisition and Control Toolbox for BA-


SIC Stamp Microcontrollers 39

4.1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

4.2. Components Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

4.2.1. BASIC Stamp 2 Microcontroller . . . . . . . . . . . . . . . . . . . . . . 41

4.2.2. MATLAB/Simulink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

4.3. Software Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

4.3.1. Template.mdl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

4.3.2. BS2Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

x
4.4. Simulink Diagram Details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

4.4.1. TotalCompile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

4.4.2. BS2 and MATLAB Serial Communication . . . . . . . . . . . . . . . . . 49

4.4.3. Data Organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

4.5. Example–DC Motor Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

4.5.1. Experimental Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53

4.6. Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

5 Two-Tank Liquid Level Control using a BASIC Stamp Microcontroller and


a MATLAB-based Data Acquisition and Control Toolbox 56

5.1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56

5.2. Coupled Two-Tank System Model . . . . . . . . . . . . . . . . . . . . . . . . . 57

5.2.1. System Identification Objectives . . . . . . . . . . . . . . . . . . . . . . 59

5.2.2. Control Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59

5.2.3. Linearized Error System Model . . . . . . . . . . . . . . . . . . . . . . . 59

5.3. System Identification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60

5.3.1. Experiment 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60

5.3.2. Experiment 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61

5.3.3. Experiment 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62

5.4. Proportional-Plus-Integral (PI) Liquid Level Control . . . . . . . . . . . . . . . 62

5.5. Experimental Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63

5.5.1. System Identification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64

5.5.2. PI Liquid Level Control . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

5.6. Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68

6 Synchronization of Sampled-Data Chaotic Systems 70

6.1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70

xi
6.2. Euler Approximated Sampled-Data Chaotic System Model . . . . . . . . . . . . 71

6.3. Sampled-Data Chaotic System Synchronization Problem . . . . . . . . . . . . . 72

6.4. Sufficient Condition for Synchronization of Sampled-Data Chaotic System . . . 73

6.5. Linear Matrix Inequality-based Controller Synthesis for Synchronization of Sampled-


Data Chaotic System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74

6.6. Illustrative Synchronization Example using Chua’s System . . . . . . . . . . . . 75

6.6.1. Continuous-time Chua’s System . . . . . . . . . . . . . . . . . . . . . . 75

6.6.2. Euler Approximated Sampled-Data Chua’s System . . . . . . . . . . . . 76

6.6.3. Numerical Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77

6.6.4. Experimental Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78

6.7. Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80

7 Pulse Synchronization of Sampled-Data Chaotic Systems 81

7.1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81

7.2. Pulse Synchronization Problem for Sampled-Data Chaotic System . . . . . . . 82

7.3. Sufficient Conditions for Pulse Synchronization of Sampled-Data Chaotic System 83

7.4. LMI-based Periodic Controller Synthesis for Pulse Synchronization of Sampled-


Data Chaotic System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85

7.5. Illustrative Synchronization Example using Chua’s System . . . . . . . . . . . . 86

7.5.1. Numerical Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87

7.5.2. Experimental Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88

7.6. Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88

8 Conclusion and Recommendation for Future Research 92

Appendix 94

Bibliography 107

xii
List of Tables

2.1 M-function for PC to PIC serial communication . . . . . . . . . . . . . . . . . . 20

2.2 M-function for PIC to PC serial communication . . . . . . . . . . . . . . . . . . 21

2.3 M-function for bi-directional serial communication between PIC and PC . . . . 23

2.4 M-function for calculating the index of light refraction . . . . . . . . . . . . . . 24

4.1 Sensor and actuator block description . . . . . . . . . . . . . . . . . . . . . . . 44

5.1 Settling time and percent overshoot requirements and PI controller gains . . . 68

6.1 Largest Lyapunov exponent with respect to different initial conditions and num-
ber of iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77

6.2 Largest Lyapunov exponent with respect to different error magnitudes and num-
ber of iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77

6.3 Largest Lyapunov exponent with respect to different error directions and number
of iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77

7.1 Largest Lyapunov exponent with respect to different initial conditions and num-
ber of iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87

7.2 Largest Lyapunov exponent with respect to different error magnitudes and num-

ber of iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87

7.3 Largest Lyapunov exponent with respect to different error directions and number
of iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87

xiii
List of Figures

2.1 (a) PIC16F74 (b) Pin diagram of PIC16F74 . . . . . . . . . . . . . . . . . . . . 11

2.2 (a) MAX232 (b) Pin diagram of MAX232 . . . . . . . . . . . . . . . . . . . . . 12

2.3 (a) PC and PIC development board (b) Larger view of the PIC development
board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

2.4 Circuit diagram of the PIC development board . . . . . . . . . . . . . . . . . . 13

2.5 (a) Light refraction experiment test bed (b) Light source mounted on the ser-
vomotor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

2.6 Detailed view of the light sensor traveling along the linear potentiometer . . . . 14

2.7 Simulink block diagram for PC to PIC serial communication . . . . . . . . . . 19

2.8 Simulink block diagram for PIC to PC serial communication . . . . . . . . . . 21

2.9 (a) Unfiltered plot of A2D and (b) Filtered plot of A2D . . . . . . . . . . . . . 22

2.10 Simulink block diagram for bi-directional serial communication between PIC
and PC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

2.11 Simulink block diagram for calculating the index of light refraction . . . . . . . 24

2.12 Angle of refraction vs. light sensor output for incidence angle (a) 40◦ and (b) 20◦ 25

3.1 Hardware environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

3.2 (a) PIC-PG2C programmer and a PIC (b) PIC-PG2C programmer with a PIC

mounted . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

3.3 Template and model properties . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

3.4 A2D block and parameter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

xiv
3.5 PinStateIn block and parameter . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

3.6 PWM block and parameter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

3.7 PinStateOut block and parameter . . . . . . . . . . . . . . . . . . . . . . . . . 33

3.8 IOBlock and parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

3.9 Flow diagram of programming the PIC microcontroller . . . . . . . . . . . . . . 35

3.10 Hardware layer schematic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36

3.11 Simulink block diagram: Exploded view . . . . . . . . . . . . . . . . . . . . . . 37

3.12 DC motor angular position tracking response . . . . . . . . . . . . . . . . . . . 37

4.1 MATLAB data acquisition and control toolbox software interface . . . . . . . . 42

4.2 Graphical description of the BS2Library . . . . . . . . . . . . . . . . . . . . . . 45

4.3 Flow diagram for programming the BS2 microcontroller . . . . . . . . . . . . . 50

4.4 Graphical description of serial communication between BS2 and MATLAB . . 51

4.5 Example for sensor array data organization . . . . . . . . . . . . . . . . . . . . 53

4.6 DC motor position tracking response . . . . . . . . . . . . . . . . . . . . . . . . 55

5.1 Two degree-of-freedom, state-coupled, two-tank system . . . . . . . . . . . . . . 58

5.2 Simulink block diagram of the PI controller for Tanks 1 and 2 . . . . . . . . . . 65

5.3 PI controller for Tanks 1 and 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

5.4 Calibration and system identification Simulink block diagram . . . . . . . . . . 66

5.5 (a) Experiment 2–L1(t) response and (b) Experiment 3–L2(t) response . . . . . 67

5.6 Response of (a) L1 (t) and (b) L2(t) using the PI controller gains of case 1 . . . 68

5.7 Response of (a) L1 (t) and (b) L2(t) using the PI controller gains of case 2 . . . 69

5.8 Response of (a) L1 (t) and (b) L2(t) using the PI controller gains of case 3 . . . 69

6.1 Propeller demo boards and 912 MHz radio frequency transceivers for the sampled-
data master-slave Chua’s circuits . . . . . . . . . . . . . . . . . . . . . . . . . . 79

xv
6.2 Plots of the double scroll attractors of the sampled-data master Chua’s circuit:
(a) x1 vs. x2, (b) x1 vs. x3 , and (c) x2 vs. x3 . . . . . . . . . . . . . . . . . . . 79

6.3 Plots of the errors of the sampled-data master-slave Chua’s circuits: (a) e1 4
= x1 −

x̃1, (b) e2 4 4
= x2 − x̃2 , and (c) e3 = x3 − x̃3 . . . . . . . . . . . . . . . . . . . . . . 80

6.4 Plots of the states of the sampled-data master Chua’s circuit vs. the states of the
sampled-data slave Chua’s circuit showing synchronization of the master-slave
Chua’s circuits: (a) x1 vs. x̃1 , (b) x2 vs. x̃2 , and (c) x3 vs. x̃3 . . . . . . . . . . 80

7.1 Plots of the errors (ei 4


= xi − x̃i , i = 1, 2, 3) of the sampled-data master-slave

Chua’s circuits: (a) p = 1, q = 22, (b) p = 3, q = 50, (c) p = 1, q = 1500, and


(d) p = 3, q = 2000 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89

7.2 Plots of the states of the sampled-data master Chua’s circuit vs. the states of the
sampled-data slave Chua’s circuit (xi vs. x̃i , i = 1, 2, 3) showing synchronization
of the master-slave Chua’s circuits: (a), (b), (c) with p = 1, q = 22 and (d), (e),
(f) with p = 3, q = 50 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90

7.3 Plots of the states of the sampled-data master Chua’s circuit vs. the states of
the sampled-data slave Chua’s circuit (xi vs. x̃i , i = 1, 2, 3) showing lack of
synchronization of the master-slave Chua’s circuits: (a), (b), (c) with p = 1, q =
1500 and (d), (e), (f) with p = 3, q = 2000 . . . . . . . . . . . . . . . . . . . . . 91

xvi
Chapter 1

Introduction

Since ancient times, the innate human desire to understand, analyze, and imitate natural

phenomena has inspired numerous ingenious developments and inventions. In the last quarter-

century, the emergence of personal computers (PCs) has changed our lives drastically. For

example, in an earlier era, visual readouts of temperature were produced using thermometers,

which use the concept of the expansion and contraction of a liquid, such as mercury, in response

to the rise and fall of the temperature. A simple form of temperature data acquisition (DAQ)

may entail logging the temperature of the environment on a paper. However, the process of data

logging can also be computerized by using appropriate sensors that convert physical parameters

of interest into electrical signals which in-turn can be acquired by using computerized DAQ

hardware. Hence, DAQ technology creates a bridge between the data-measuring sensors and

data-storing memory devices. Advanced DAQ hardware can also provide a means for driving

external actuators from a computer, by producing command signals for actuators, which is

often termed data acquisition and control (DAC). DAC systems include both hardware and

software.

The role of DAC hardware is: i) to collect incoming analog input signals and convert the

same to digital signals, which is called analog to digital conversion (A2D), for further processing

and storage and ii) to convert outgoing digital signals to analog output, which is called digital

to analog conversion (D2A), for driving an actuator. Pertinent DAC terminology includes:

number of A2D/D2A channels, resolution of A2D/D2A, number of digital Input/Output (I/O)

channels, and sampling rate. Specifications of commercially available DAC hardware are two

to sixteen digital/analog I/O channels, eight- to twenty-four-bit resolution, and 5 Hz to 1 MHz

sampling rate. DAC systems are also categorized by their interfaces with PCs such as plug-in,

serial communication, USB, and parallel port. Each interface technique has its own benefits,

e.g., USB DAC systems have advantage of higher bandwidth and power supply, and plug-in

1
2

DAC systems yield high acquisition rates since they use the PC bus directly. For example,

Quanser’s [1] Q4 [2] plug-in DAC board is equipped with four A2Ds, four D2As, sixteen digital

I/Os, fourteen-bit input resolution, and twelve-bit output resolution. Yet another plug-in DAC

board from National Instrument [3] is NI PCI-7831R [4], which is configured with eight analog

I/Os, ninety-six digital I/Os, and sixteen-bit input resolution.

DAC hardware without software is of little use. DAC systems require low-level hardware

function calls performed by driver software to interface application software with DAC hard-

ware for proper controls. With appropriate software, DAC systems can acquire data at a

specified sampling rate. The driver and application software are usually supplied by DAC

hardware vendors, and measurement and control software can be developed by using a variety

of text-based programming languages such as BASIC, C, FORTRAN, and Java. By using

such measurement and control software, acquired data from DAC boards can be displayed,

analyzed, and stored on a computer. For example, LabVIEW [5] identifies, configures, and

controls DAC board hardware by a device number, and interfaces inputs from various sources

such as serial and parallel ports. In addition, it provides a user-friendly graphical user inter-

face (GUI) for developing complete instrumentation, data acquisition, analysis, and control

functions. Similarly, MATLAB/Simulink [6] enables processing of the acquired data without

necessitating the use of text-based programming languages, since it provides built-in graphical

tools and libraries for data acquisition, control, and analysis.

The DAC technology is continuously being advanced toward being more accurate, reliable,

effective, efficient, and low-cost. It is envisioned that in future low-cost, small form factor DAC

hardware will become available, allowing DAQ technology to become portable and pervasive

by being embedded in hand-held computers, PDAs, and mobile phones. However, current

DAC systems tend to be quite expensive (and not very portable.) In a recent price comparison

of several MATLAB and Simulink supported PC-based DAC boards of different form factors

(e.g., PCI, ISA, and PCMCIA), we determined that these DAC boards cost from five hundred

to several thousand dollars. Furthermore, academic labs generally do not require the intrinsic

high performance features of these DAC systems (e.g., high sampling rates, high resolution

A2Ds, etc.) to educate students. The expensive DAC systems that have high sampling rates
3

and high resolution are sometimes not necessary for simple tasks. Therefore inexpensive DAC

systems are highly desirable for educational purposes.

In contrast to the PC-based DAC boards, microcontrollers are inexpensive devices (cost-

ing only a few tens of dollars), which are widely used for embedded computing. However, a

majority of microcontrollers require programming using an embedded programming variant of

one or another high-level programming languages (e.g., BASIC, C, Java, etc.). In addition,

many low-cost microcontrollers do not allow floating-point numerical computations that may

be needed to implement advanced feedback control algorithms. Therefore, a marriage of in-

expensive microcontrollers and user-friendly software such as LabVIEW and MATLAB will

enable relatively inexpensive DAC systems to be created.

The first part of this dissertation addresses design and development of a MATLAB and

Simulink-based software platform that enables the use of inexpensive microcontrollers for DAC

tasks. Motivated by the current trend toward user-friendly environment, we exploit Simulink’s

icon-based programming environment to develop a library of microcontroller functions. Such a

software environment facilitates implementation of user-defined algorithms in a block diagram

format. In addition, we exploit built-in serial communication capabilities of MATLAB and

Simulink to communicate with various sensors and actuators connected to the microcontroller.

We then introduce position control of a DC motor system and liquid level control of a coupled,

two-tank system to illustrate several important features of our DAC platform.

The second part of this dissertation addresses problems of synchronization and pulse syn-

chronization of a master-slave chaotic system in the sampled-data setting. Chaos is mostly

described as a deterministic phenomenon that exhibits aperiodic features depending on the

initial conditions [7]. Therefore, two identical chaotic systems never show the same trajec-

tories because even minute differences in their initial conditions cause the difference between

their trajectories to grow quickly. Such behavior drives chaos to be pervasive in the study of

geophysical fluid dynamics such as atmospheric and oceanic flows.

Because of the well-known characteristics of chaotic systems such as extreme sensitivity to

initial conditions, deterministic sequences, and aperiodic behaviors, synchronization of chaotic

oscillators is widely used in such application as cryptographic and secure communication sys-
4

tems [8–13]. For example, Pecora and Carroll of the U.S. Naval Research Laboratory realized

that synchronization of chaotic signals might be useful for encrypting private electronic commu-

nications [14]. The basic principle behind these systems is to use chaos to mask a transmitted

signal, and chaos synchronization to securely recover it in reception, which is often known as

chaotic masking. The other ways of encrypting signals by using chaos are chaos shift keying

and chaos modulation [15, 16]. The basic idea behind the use of chaos-based encryption is

to provide protection of data from unauthorized usage since an encrypted message cannot be

decrypted, modified, or replaced by unauthorized personnel.

Most experimental and theoretical research on master-slave synchronization focuses on

continuous-time systems [17–26]. Many communication applications such as cellular phones,

radios, and Internet communication are exposed to unwanted noise. Moreover, in secure com-

munications applications, noise corruption in analog signal transmission can lead to severe

drawbacks of synchronization schemes [27, 28]. Therefore, sampled-data systems have been

studied in [10, 29, 30] to improve the robustness of secure communications based on chaotic

synchronization. This sampled-data setting also leads to a reduction in the amount of infor-

mation exchange between a coupled master-slave chaotic system and results in the efficiency

of bandwidth usage.

Nevertheless, synchronization of chaotic oscillators at every sampling instant sometimes

may not be realistic because of excessive power load and additional time delay, etc. In a

sampled-data setting, therefore, study of master-slave synchronization of chaotic oscillators

that are only sporadically coupled seems particularly more realistic for communication systems

[31–34]. This synchronization scheme is referred to as pulse synchronization [19, 22], wherein

the feedback gain periodically changes over time.

In the second part of this dissertation, we consider two problems pertaining to synchro-

nization of chaotic systems. First, we address the problem of synchronizing a master-slave

chaotic system in the sampled-data setting. Second, we address the problem of synchroniz-

ing a sporadically coupled master-slave chaotic system in the sampled-data setting. For both

problems, an Euler approximation technique is used to produce a sampled-data representation

for a continuous-time chaotic system containing a continuous nonlinear function. Whereas


5

for the first problem we use a time-invariant full-state feedback control law, for the second

problem we employ an intermittent, pulse-based, periodic, full-state feedback control law. We

use the discrete-time Lyapunov stability theory and the linear matrix inequality framework to

construct the two control laws. Finally, by utilizing the MATLAB/microcontroller-based DAC

techniques developed in the first part of this dissertation, we provide experimental validation

of our theoretical results by implementing, on a set of microcontrollers endowed with RF com-

munication capability, a sampled-data master-slave chaotic system based on Chua’s circuit.

Specially, using serial communication capabilities of the microcontroller and MATLAB, the

synchronization of the sampled-data chaotic systems is graphically represented on MATLAB.

This dissertation is organized as follows.

Chapter 2 addresses MATLAB-based GUI development using Peripheral Interface Con-

trollers (PICs) that are inexpensive microcontroller units with built-in serial communication

functionality. Similarly, MATLAB, a widely used technical computing software, allows serial

communication with external devices. In addition, MATLAB provides graphical design tools

such as Simulink and Dials and Gauges Blockset. In Chapter 2, we exploit the serial commu-

nication capability of PIC microcontrollers and the MATLAB software along with graphical

design tools of MATLAB to create a MATLAB-based GUI environment for PIC microcon-

troller projects. Three examples are included to illustrate that the integration of low-cost

PIC microcontrollers with the MATLAB-based GUI environment allows data acquisition, data

processing, data visualization, and control.

Chapter 3 addresses development of a PC-based DAC tool that uses a PIC microcontroller,

MATLAB, and Simulink. Specifically, a library of PIC microcontroller functions for Simulink

is created. Moreover, the PIC microcontroller and MATLAB are merged, by exploiting their

serial communication capability, to produce an inexpensive DAC platform. Finally, the efficacy

of this DAC platform is illustrated by performing angular position control of a DC motor.

Chapter 4 addresses development of a MATLAB and Simulink-based software platform

that enables the use of an inexpensive BS2 microcontroller for DAC tasks. The framework is

well suited for DAC tasks that require GUI and/or advanced computational capabilities but do

not require stringent hardware performance. We illustrate the efficacy of our DAC technique
6

by performing position control of a DC motor using a BS2 microcontroller and our MATLAB

DAC toolbox.

Chapter 5 addresses a liquid level control design problem of a coupled, two-tank system by

using the MATLAB-based DAC platform developed in Chapter 4. The classical proportional-

plus-integral (PI) controller is employed for the liquid level control of the coupled, two-tank

system. To effectively utilize this control methodology, the system parameters, e.g., tank

dimensions and pump characteristics, must be known exactly. However, this may not be feasible

since system parameters may change due to the effects of scaling in tanks and orifices, aging

of pump, and wear. Thus, to determine the system parameters, we conduct an experimental

system identification study which uses the inherent nonlinear dynamics of the two tank system.

Chapter 6 addresses the problem of synchronizing a master-slave chaotic system in the

sampled-data setting. We begin by using an Euler approximation technique to discretize a

continuous-time chaotic system containing a continuous nonlinear function. Next, we formulate

the problem of global asymptotic synchronization of the sampled-data master-slave chaotic

system as equivalent to the states of a corresponding error system asymptotically converging

to zero for arbitrary initial conditions. Moreover, using the discrete-time Lyapunov stability

theory and the linear matrix inequality (LMI) framework, we construct a state feedback control

law which yields global asymptotic synchronization of the sampled-data master-slave chaotic

system. Finally, we provide an experimental validation of our results by implementing, on a set

of microcontrollers endowed with RF communication capability, a sampled-data master-slave

chaotic system based on Chua’s circuit.

Chapter 7 addresses the problem of pulse synchronization of a master-slave chaotic system

in the sampled-data setting. We begin by developing a pulse-based intermittent control system

for chaos synchronization. Similar to Chapter 6, the discrete-time Lyapunov stability theory

and the LMI framework are used to construct a state feedback periodic pulse control law for

synchronization of the sampled-data master-slave chaotic system. Finally, we provide an ex-

perimental validation of our results by implementing, on a set of microcontrollers endowed with

RF communication capability, a sampled-data master-slave chaotic system based on Chua’s

circuit.
7

Finally, Chapter 8 provides some concluding remarks and recommendations for future

research.
Chapter 2

Development of a MATLAB-based Graphical User


Interface Environment for PIC Microcontroller
Projects

2.1. Introduction

Peripheral Interface Controllers (PICs), developed and marketed by Microchip Technol-

ogy, Inc. [35], are inexpensive microcontroller units that include a central processing unit and

peripherals such as memory, timers, and input/output (I/O) functions on an integrated cir-

cuit (IC). There are more than 100 varieties of PIC microcontrollers available, each providing

functionality for different types of applications [36], making PICs one of the most popular

microcontrollers for educational, hobby, and industrial applications. Similar to other micro-

controllers, PICs are usually not designed to interface with human beings; instead they are

directly embedded into automated products/processes. Thus, graphical user interface (GUI)

capabilities, which have become a mainstay of many personal computer (PC) applications, are

nonexistent for PICs.

Endowing PIC-based projects with GUI tools can speed the development process in data

driven applications such as feedback control, smart sensors, etc. Microchip Technology’s emu-

lator and debugger products (e.g., MPLAB IDE, MPLAB-ICE) are very helpful in debugging

PIC source code and emulating user-written programs. However, these tools do not provide

data co-processing and advanced data visualization capabilities.

Fortunately, PIC microcontrollers include serial communication functionality to facilitate

data communication with external devices such as analog to digital converters (A2Ds), 1-wire

sensors, etc. Similarly, MATLAB, a commercially available interactive mathematical program-

ming software, also provides serial data communication functionality on PCs. In addition,

Simulink, MATLAB’s interactive icon-based programming environment, enables users to sim-

ulate and analyze dynamic system models. Finally, the Dials and Gauges Blockset of Simulink

8
9

allows users to embed control objects (e.g., sliders, knobs) and display objects (e.g., graphs,

gauges) in Simulink models to develop an interactive GUI environment. In this Chapter, we

exploit the serial communication functionality of MATLAB to enable a PC to communicate

with PIC microcontrollers to transmit control commands and receive sensory data. In addi-

tion, we utilize MATLAB, Simulink, and Dials and Gauges Blockset to develop an interactive

GUI environment for PIC projects, allowing enhanced data processing and visualization.

The rest of the Chapter is organized as follows. In Section 2.2, we describe the hardware

environment including the PIC microcontroller and a light refraction test bed. In Section 2.3,

we describe the software environment used in this Chapter. In Section 2.4, we illustrate the

effectiveness of our MATLAB-based GUI environment to interact with PIC microcontroller by

using three examples: i) export user commands from a Simulink GUI to an actuator interfaced

to the PIC; ii) import signals from a sensor interfaced to the PIC into a Simulink GUI; and iii)

use Simulink GUI to export user commands to the PIC and import sensory data from the PIC

to control a device and monitor its status. Finally, Section 2.5, we provide some concluding

remarks.

2.2. Hardware Environment

The hardware environment for this Chapter consists of a PIC microcontroller, a PC, a

RS232 driver/receiver, and a DB-9 serial cable. The PIC microcontroller is interfaced with

external devices such as sensors (e.g., photoresistors) and actuators (e.g., servomotors). In

addition, the PIC microcontroller performs embedded computing. The PC is used to write

user specified embedded programs to be executed by the PIC microcontroller. Furthermore,

the PC hosts an interactive GUI for the user to manipulate control variables and visualize

sensory data. The PIC microcontroller and the PC communicate using a serial interface. A

PIC development board (see section 2.2.4) and a light refraction experiment test bed (see

section 2.2.5) are used to illustrate our PIC-based data acquisition and control approach.
10

2.2.1. Peripheral Interface Controller

PIC microcontrollers are small, low-cost controllers that include a processor and a variety

of peripherals. PICs are significantly easier to use vis-à-vis embedded microprocessors. As an

example, users can assign desired functionality (e.g., A2D, universal synchronous/asynchronous

receiver and transmitter (USART)) to I/O pins of PICs. PICs can be operated at various clock

speeds (32 kHz to 20 MHz). PIC’s memory architecture separates its data memory from its

program memory with the program memory available as One-Time Programmable (OTP),

Erasable Programmable Read-Only Memory (EPROM), or FLASH. PICs are programmed in

the PIC assembly language using a 35 single-word instruction set. See [37, 38] for more details

on hardware and software features of PIC microcontrollers.

The user specified embedded PIC program is written on the PC and downloaded from the

PC to the PIC microcontroller using the DB-9 serial cable connection between the PC and

a PIC Development Programmer on which the PIC microcontroller is installed. Commonly

available PIC Development Programmers include PICSTART Plus [39] from Microchip, Inc.,

and PIC-PG2B, a handy, low-cost programmer [40] from Olimex Ltd., among others. In this

Chapter, we use the PICSTART Plus programmer that requires MPLAB Integrated Devel-

opment Environment, a free software available on the Microchip website, for programming

PICs.

We employ a PIC16F74, a 40-pin CMOS FLASH-based, 8-bit, mid-range (14-bit instruction

word length) microcontroller (see Figure 2.1). PIC16F74 has 4K (14-bit words) of FLASH

program memory and 192 bytes of data memory. Furthermore, it has 33 digital I/O pins

organized in 5 groups of I/O ports that can be assigned as 8-bit A2D, Capture/Compare/PWM

(CCP), the 3-wire Serial Peripheral Interface (SPI), the 2-wire Inter-Integrated Circuit (I2C)

bus, USART ports, etc. We use an external 20 MHz high-speed crystal oscillator to supply

operating clock cycles. The PIC16F74 can be powered using a wide range of voltage sources,

e.g., 2 volt direct current (VDC) to 5.5VDC, and each of its I/O pin can sink or source up to

25mA of current. It is ideal not only for laboratory data acquisition (the application considered

in this Chapter), but also for automotive, industrial, and consumer applications.
11

(a) (b)

Figure 2.1: (a) PIC16F74 (b) Pin diagram of PIC16F74

2.2.2. Personal Computer

In this Chapter, an IBM-compatible Pentium 3 PC running Microsoft Windows NT 4.0

operating system is used. As previously mentioned, the PC is used to write, debug, and

download embedded PIC programs. One of the serial ports on the PC is reserved for serial

communication with the PIC microcontroller. MPLAB, MATLAB (version 6.1), Simulink,

and Dials and Gauges Blockset are installed on the PC. Control variables are manipulated via

the PC by interacting with control panels embedded in the Simulink program. In addition,

all experimental data is collected and displayed on the PC in display panels embedded in the

Simulink program.

2.2.3. RS232 Driver/Receiver

MAX232 (see Figure 2.2) is a 2-channel, RS232 driver and receiver manufactured by Maxim

Integrated Products, Inc. It requires a 5VDC power supply and converts voltage levels between

PC-based logic and PIC microcontroller-based logic. Specifically, whereas the voltage levels

of logic high and logic low for the PC correspond to -12VDC and 12VDC, respectively, like

many other microcontrollers the logic high and low for the PICs correspond to 5VDC and

0VDC, respectively. The MAX232 is used with five 1µF capacitors to adjust the voltage level

differences between the PC-based logic and the PIC-based logic. See [41] for more details of

the MAX232 hardware features.


12

(a) (b)

Figure 2.2: (a) MAX232 (b) Pin diagram of MAX232

2.2.4. PIC Development Board

The PIC development board (see Figure 2.3) consists of a sensor (photoresistor), a 3-

pin header for a servomotor connection, a 20MHz crystal oscillator, a MAX232 with five

1µF capacitors, a PIC16F74 microcontroller, a breadboard, and two DB-9 connectors. The

photoresistor sensor provides light intensity measurement and is interfaced to a pin allocated

as an 8-bit A2D in port A of the PIC16F74 microcontroller. The circuit diagram of Figure 2.4

illustrates how various sensors and actuators of the light refraction experiment test bed (see

section 2.2.5) are interfaced to the PIC microcontroller. The PIC transmits/receives sensory

data to/from the PC via the MAX232. A reset button is connected to the Master Clear

(MCLR) pin of the microcontroller.


Reset button
Pentium class PC

DB-9 serial cable


PIC

DB-9 connector to Photoresistor


light refraction test bed
3-pin
servomotor
connector
MAX232
(a) (b)

Figure 2.3: (a) PC and PIC development board (b) Larger view of the PIC development
board
13

5V 5V

10 kΩ
1 40 H-Bridge
Reset button
10 kΩ H-Bridge
1kΩ 39
5V
2 Laser
Linear 38
potentiometer 3 34 Servomotor 1μF 1μF
Photoresistor
Limit switches 4 5V
1 16 2
5V 32 1μF
0.1μF 3 6
1μF
11 31 4
0.1μF 1μF
12 5
15pF 26 12 13 RS232 output
RX
13 14 RS232 input
25 11
TX
14 15
15pF 20MHz
MAX232
PIC16F74

Figure 2.4: Circuit diagram of the PIC development board

2.2.5. Light Refraction Test Bed

The light refraction test bed (see Figure 2.5) is a mechatronics-aided physics experiment

developed under a National Science Foundation (NSF) sponsored Science and Mechatronics

Aided Research for Teachers (SMART) program [42] at Polytechnic Institute of New York

University. This experiment is designed to demonstrate the law of light refraction. It consists

of a light source, a light sensor, a linear potentiometer, two limit switches, a servomotor, a

DC motor, a liquid reservoir, and necessary circuitry. A liquid reservoir on the top of the

test bed can store various liquid media whose index of refraction needs to be determined. For

simplicity, in this Chapter, we use water from a water fountain as the test liquid.

Servomotor Light source


Reservoir
H-Bridge

Light sensor

Linear
DC motor Limit switches potentiometer

(a) (b)

Figure 2.5: (a) Light refraction experiment test bed (b) Light source mounted on the servo-
motor
14

On one side of the tank, as shown in Figure 2.5 (b), a laser pointer, used as the light

source, is mounted on the arm of the servomotor that sets the angular position of the light

source to the incidence angle specified by the user. On the other side of the tank, a general

Cadmium Sulfide (CdS) photoresistor, used as the light sensor, is mounted on the wiper of the

linear potentiometer. It monitors the refracted light coming out from the liquid reservoir (see

Figure 2.6). A DC motor drives the light sensor along the linear potentiometer by turning

a motor shaft connected to a brass screw rod thereby transforming rotary motion into linear

motion. Limit switches at each end of the linear potentiometer indicate sensor travel limit.

The photoresistor and the linear potentiometer output analog voltage signals between 0VDC

and 5VDC.

Figure 2.6: Detailed view of the light sensor traveling along the linear potentiometer

2.3. Software Environment

Software environment for this Chapter consists of the PIC assembly language, MATLAB,

Simulink, and Dials and Gauges Blockset. The PIC assembly language is a primitive pro-

gramming language consisting of a 35 single-word instruction set. MATLAB is an interactive

technical computing software. Simulink is MATLAB’s model-based, system-level, visual pro-

gramming environment that is widely used to simulate and analyze dynamic system models

using icon-based tools. Finally, the Dials and Gauges Blockset of Simulink provides an ability

to embed visual, realistic-looking, virtual instrumentation in Simulink models. In this Chap-

ter, these software tools are judiciously synthesized to produce an effective, interactive GUI

environment. In the sequel, we summarize key instructions of the PIC assembly language and
15

MATLAB that enable serial communication between PIC microcontroller and MATLAB GUI

running on the PC.

2.3.1. PIC Assembly Program

As indicated above, the PIC assembly language consists of a 35 single-word instruction set

(see datasheets [43] for details). The PIC data memory is partitioned into several banks (e.g.,

5 banks for PIC16F74) that contain the general-purpose registers and the special-function reg-

isters. The special-function registers are used to set up special operations (e.g., A2D, USART,

and PWM) and to watch the status of the special operations (e.g., the availability of transmis-

sion or reception of the USART). Below, we review key PIC instructions and special function

registers used for serial communication functionality.

1) Key PIC Instructions

BCF: Bit clear f

Syntax: [label] BCF f, b

BCF literally means that the bth bit in the register ‘f’ is cleared. BCF sets the bth bit in the

register ‘f’ to zero, logic low.

BSF: Bit set f

Syntax: [label] BSF f, b

BSF instruction does the opposite of BCF, i.e., it sets the bth bit in the register ‘f’ to one,

logic high.

MOVLW: Move literal to w

Syntax: [label] MOVLW k

The literal ‘k’ is loaded into the working register. The literal ‘k’ can be expressed in terms of

an 8-bit binary, decimal, or hexadecimal number. For example, b’00101111’ in 8-bit binary is

equivalent to 0x2F in hexadecimal. Note that the prefixes b, 0x, and d declare the data type

to be binary, hexadecimal, and decimal, respectively.

MOVWF: Move w to f

Syntax: [label] MOVWF f


16

MOVWF transfers data from the working register to the specified register ‘f.’ Since the lit-

eral ‘k’ cannot be directly assigned into the specified register ‘f,’ the literal ‘k’ is first assigned

to the working register (e.g., MOVLW k) and then moved into the register ‘f’ (e.g., MOVWF f).

BTFSS: Bit test f, skip if set

Syntax: [label] BTFSS f, b

BTFSS checks the bth bit in the specified register ‘f,’ and executes the next instruction if this

bit is zero. Alternatively, if the bit is one, the next instruction is skipped, and the following

instruction is executed.

2) Special Function Registers Used for Serial Communication Functionality

MOVLW d’value’

MOVWF SPBRG

The special function register ‘SPBRG’ contains the user-specified baud rate for serial com-

munication. In particular, the command MOVLW d’129’ places 129 in the working register.

Next, the command MOVWF SPBRG moves the content of the working register to the special

function register ‘SPBRG.’ The placement of ‘value’ 129 in the ‘SPBRG’ register sets the baud

rate to 9,600.

MOVLW b’clock source select bit, 9-bit transmit enable bit, transmit enable bit, USART mode

select bit, unimplemented, high baud rate select bit, transmit shift register status bit, 9th bit of

transmit data’

MOVWF TXSTA

The special function register ‘TXSTA’ contains information for the data-transmit status and

control in an 8-bit binary expression. In particular, the use of commands MOVLW b’00100100’

and MOVWF TXSTA, sets up the ‘TXSTA’ register to enable 8-bit, high speed asynchronous

serial data transmission.

MOVLW b’serial port enable bit, 9-bit receive enable bit, single receive enable bit, continuous

receive enable bit, unimplemented, framing error bit, overrun error bit, 9th bit of received data’

MOVWF RCSTA

The special function register ‘RCSTA’ contains information for the data-receive status and
17

control in an 8-bit binary expression. In particular, the use of commands MOVLW b’10010000’

and MOVWF RCSTA, sets up the ‘RCSTA’ register to enable 8-bit, continuous asynchronous

serial data reception.

2.3.2. MATLAB Program

MATLAB is a commercially available, widely used, interactive, technical computing soft-

ware. MATLAB’s versions 6.1 and higher provide serial communication functionality. To

serially communicate with an external device from MATLAB, the following steps need to be

performed. First, create a serial port object to identify the specific serial port of the PC

connected to the external device. In addition, specify how this serial port is to be configured

(i.e., baud rate, number of data bits, etc.). Second, connect the serial port object created

above to the external device. Third, send command signals to the external device and re-

ceive data from the external device. Fourth, disconnect serial communication connection from

the external device and close the serial port object. Finally, release control of the serial port.

We list the key MATLAB instructions used for serial communication. See [6] for further details.

serial (the PC serial port, the baud rate, the number of data bits)

This command is used to create a new serial port object. In addition, it configures the serial

port properties. In this Chapter, we used the COM2 serial port of the PC with 9,600 baud rate.

fopen (object)

This command opens the serial port object just created and connects the PC to the external

device for actual serial communication.

fread/fwrite (object, size, precision)

The fread command enables the PC to read binary data from the external device. Alternatively,

the fwrite command enables the PC to send control data in binary format to the external device.

fclose (object)

This command closes the serial port object, thereby disconnecting serial communication be-

tween MATLAB and the external device.


18

freeserial (port)

Once MATLAB establishes a data link with the serial port, it assumes complete control of

the serial port. The freeserial command is used, after closing the port object using the fclose

command, to force MATLAB to relinquish control of the serial port. The command takes on

one argument, the port that was used for data communication. This command is executed

from the MATLAB command line after the termination of experiment.

2.3.3. Simulink

Simulink is MATLAB’s interactive, icon-based programming environment [44]. It enables

users to build block diagrams to simulate and analyze dynamic system models. Designers can

effortlessly transfer paper designs of dynamic systems into Simulink block diagrams. Simulink

block diagrams can be modified as easily as paper models of dynamic systems. In addition,

Simulink allows for detailed monitoring of dynamic system outputs at any point in the block

diagram using various tools (e.g., Scope, Display, etc.). Finally, data processing tasks such as

signal scaling, filtering, etc., can be easily performed in Simulink.

2.3.4. Dials and Gauges Blockset

The Dials and Gauges Blockset [45] provides enriched views of graphical, 3-D instruments

called virtual instruments. It has various templates that can be customized to create realistic

virtual instruments for electrical, aerospace, automotive, medical, and process control systems.

The virtual instruments created using the Dials and Gauges Blockset dynamically interact with

MATLAB and Simulink, thus providing an interactive interface for users to enter command

inputs and visualize sensory outputs.

2.4. Examples of Serial Communication between PIC and PC

2.4.1. Serial Communication from PC to PIC: Servomotor Position Control

This example illustrates one-directional serial communication from the PC to the PIC

microcontroller. In particular, it demonstrates that the user commands from a Simulink block

diagram can be exported to an actuator interfaced to the PIC microcontroller. The example
19

focuses on servomotor position control.

The Simulink block diagram for this example is shown in Figure 2.7. It consists of a dial,

from the Dials and Gauges Blockset, denoted as the servo angle knob. The user interacts with

the dial to enter servomotor position control command. The dial has a range from 0 to 90

degrees with one-degree resolution. The value of the angle commanded by the user is shown

in the middle of the knob.

Figure 2.7: Simulink block diagram for PC to PIC serial communication

The MATLAB m-function block next to the knob contains a MATLAB m-file (see Table

2.1) to perform serial communication from the PC to the PIC. The user specified servomotor

position control command is transmitted to the PIC via a serial cable connection between the

PC and the PIC. When the PIC receives the command angle, it assigns the angle to a variable

in the PIC code. Next, the PIC utilizes the command angle to compute, generate, and apply

pulse trains for servomotor position control.

In this example, we used a 6VDC standard servomotor that is interfaced to the 3-pin

servomotor connection header on the PIC development board (see Figure 2.3). The PIC

assembly code corresponding to this example is available in Appendix A.1.


20

Table 2.1: M-function for PC to PIC serial communication

%MATLAB function serial out.m for serial communication from PC to PIC


function serial out(angle) %serial out function defined
ser obj=serial(‘COM2’,‘baudrate’,9600); %create and configure a serial port object
fopen(ser obj); %connect the serial port object to the device
ServoCommand=round(angle+107.3); %input for servomotor where 107.3 refers to offset
fwrite(ser obj,[ServoCommand],‘async’); %send user command, i.e., dial input, to the PIC
pause(1);
fclose(ser obj); %disconnect the serial port object from the device

2.4.2. Serial Communication from PIC to PC: Data Acquisition, Processing, and
Plotting

This example illustrates one-directional serial communication from the PIC microcontroller

to the PC. In particular, it demonstrates that a Simulink block diagram can be designed to

acquire measurement from a sensor that is interfaced to the PIC. The example focuses on

acquiring measurements from a photoresistor that senses light intensity.

Referring to Figure 2.4, a light sensor is constructed by connecting a 10 KΩ resistor and a

photoresistor in a voltage divider circuit. The output of the light sensor varies depending on

the light intensity incident upon the photoresistor; here the light sensor output refers to the

voltage at the junction of the 10KΩ resistor and the photoresistor. This output is connected

to I/O pin 2 of the PIC16F74. The I/O pin 2 is configured as an A2D in the PIC assembly

code. Each time, the PIC assembly code tasks the PIC to measure the light sensor output, the

PIC16F74 converts the analog voltage signal at the voltage divider output into a corresponding

8-bit digital value. Thus, when the photoresistor is placed in dark condition, the 8-bit A2D

returns a value close to 255. Alternatively, when the photoresistor is exposed to bright light,

the A2D returns a value close to 0.

The Simulink block diagram for this example is shown in Figure 2.8, where a MATLAB

m- function (see Table 2.2) is used to acquire the digitized output of the sensor using serial

communication. The Simulink block diagram of Figure 2.8 also processes and plots the sensory

data. In particular, the top scope in Figure 2.8 plots the light intensity measurement (in terms
21

of digitized output of the voltage divider circuit) versus time, where the measurements are

filtered using a low-pass filter. The middle scope plots the unfiltered light intensity measure-

ment. Finally, the bottom scope plots the light intensity measurement in terms of voltages by

processing the 8-bit digital value of the voltage divider circuit through a gain factor.

Scopes

Figure 2.8: Simulink block diagram for PIC to PC serial communication

Table 2.2: M-function for PIC to PC serial communication

%MATLAB function serial in.m for serial communication from PIC to PC


function v=serial in(dmyin) %serial in function defined
ser obj=serial(‘COM2’,‘baudrate’,9600);%create and configure a serial port object
ser obj.ReadAsyncMode = ‘manual’; %specify an asynchronous read operation
fopen(ser obj); %connect the serial port object to the device
LightSensOut=fread(ser obj,1,‘uint8’); %read the light sensor output
fclose(ser obj); %disconnect the serial port object from the device
v=LightSensOut; %8-bit representation of the light sensor output

An experiment was conducted in which the light intensity was abruptly altered at several

time instances. The response plots acquired and processed using the Simulink block diagram

of Figure 2.8 are shown in Figure 2.9. The filtered output response in Figure 2.9(b) is much

smoother than the unfiltered response in Figure 2.9(a). Thus, Figure 2.9 demonstrates the

efficacy of signal co-processing using MATLAB and Simulink for PIC-based projects. The PIC
22

assembly code corresponding to this example is available in Appendix A.2.

Light sensor O/P (8-bit)

Light sensor O/P (8-bit)


Time (Sec) Time (Sec)

(a) (b)

Figure 2.9: (a) Unfiltered plot of A2D and (b) Filtered plot of A2D

2.4.3. Bi-directional Serial Communication between PIC and PC

In this example, the light refraction test bed is used to demonstrate the advantage of ex-

ploiting bi-directional serial communication between PIC and MATLAB-based GUI executing

on the PC. A Simulink-based interactive GUI for the light refraction test bed is shown in

Figure 2.10. The user interacts with the dial object to command the angle of incidence of

light source. The MATLAB m-function block next to the knob contains a MATLAB m-file

(see Table 2.3) that transmits the user command input to the PIC serially. The PIC stores

the user input in a variable and uses it to compute, generate, and apply pulse trains to control

servomotor position. This positions the light source, mounted on the servomotor arm, at the

commanded angle of incidence. Next, the PIC turns on the light source and performs the fol-

lowing tasks: drive the light sensor along the linear potentiometer by turning the DC motor,

measure the position of the light sensor along the linear potentiometer and the corresponding

output of the light sensor, and transmit the position and light sensor measurements to the

PC. The MATLAB m-function block shown in Figure 2.10 enables receipt of the position and

light sensor measurements from the PIC serially. Simulink blocks following the m-file function

block are used for various data processing tasks, e.g., conversion of position measurement to

the refraction angle and computation of index of light refraction. Finally, a generic numeric
23

LED display, from the Dials and Gauges Blockset, is used to indicate the calculated value of

index of light refraction for the experimental liquid.

Figure 2.10: Simulink block diagram for bi-directional serial communication between PIC
and PC

Table 2.3: M-function for bi-directional serial communication between PIC and PC

%MATLAB function serial inout.m for bi-directional serial communication bet. PIC & PC
function V=serial inout(angle) %serial inout function defined
ser obj=serial(‘COM2’,‘baudrate’,9600);%create and configure a serial port object
ser obj.ReadAsyncMode = ‘manual’; %specify an asynchronous read operation
fopen(ser obj); %connect the serial port object to the device
ServoCommand =round(angle+107.3); %input for the servomotor with offset of 107.3
fwrite(ser obj,[ServoCommand],‘async’); %send user command, i.e., dial input, to the PIC
LightSensOut =fread(ser obj,1,‘uint8’); %read the light sensor output from the PIC
Position=fread(ser obj,1,‘uint8’)+9; %read the linear pot. output from the PIC
fclose(ser obj); %disconnect the serial port object from the device
V=[LightSensOut;Position]; %output in matrix form

Figure 2.11 shows the block diagram of index of light refraction subsystem of Figure 2.10.

The block diagram of Figure 2.11 is used to generate a plot of angle of refraction versus the

light sensor output. Figure 2.12 shows the plots of angle of refraction versus the light sensor

output for two commanded values of incidence angle, namely, 40◦ and 20◦. Note that for each

incidence angle, the index of refraction is computed from the angle of refraction corresponding
24

to the smallest output returned by the light sensor. Thus, the block diagram of Figure 2.11

is also used to calculate the index of light refraction. The MATLAB m-function (see Table

2.4) in this subsystem monitors and captures the angle data corresponding to the smallest

measurement returned by the light sensor. Note that the light sensor output is smallest when

the intensity of refracted light focused on the light sensor is highest. Next, the angle data is

used to compute the index of light refraction. The PIC assembly code corresponding to this

example is available in Appendix A.3.

XY Graph block

Figure 2.11: Simulink block diagram for calculating the index of light refraction

Table 2.4: M-function for calculating the index of light refraction

%MATLAB function PickMin.m for capturing the angle of refraction when max.
%Light is on the light sensor.
function y=PickMin(minangle,minLSO,LSO,angle) %PickMin function defined
if LSO <= minLSO %loop for updating the minangle
minangle=angle; %update minangle wrt minLSO
end
y=minangle; %angle at the most light intensity

2.5. Conclusion

In this Chapter, we developed and presented MATLAB-based GUIs for PIC microcon-

troller projects by exploiting Simulink, Dials and Gauges Blockset, and serial communication

capabilities of MATLAB and PIC. Three examples were presented to illustrate the produc-
25

(a) (b)

Figure 2.12: Angle of refraction vs. light sensor output for incidence angle (a) 40◦ and (b)
20◦

tivity enhancement potential of the MATLAB-based GUI environment when developing PIC

microcontroller projects. The GUIs designed using framework of this Chapter allow the user

to: i) vary control commands; ii) acquire sensory data; iii) perform on-line data processing;

and iv) visualize data using realistic looking virtual instruments. Note that the framework

of this Chapter allows the use of microcontroller as a low-cost, stand-alone data acquisition

and control board (DACB). Whereas PC-based DACBs typically cost several hundred to over

thousand dollars, a PIC microcontroller costs only a few dollars. Thus, the use of PIC micro-

controllers with the proposed MATLAB-based GUI environment provides a low-cost DACB

solution that can be particularly beneficial to educators.


Chapter 3

Development of a MATLAB Data Acquisition and


Control Toolbox for PIC Microcontrollers

3.1. Introduction

Data acquisition and control boards (DACBs) are essential for interfacing sensors/actuators

with decision making devices such as a personal computer (PC). Thus, DACBs are used in

monitoring/instrumentation applications involving machinery, process, environment, etc., and

in automatic control applications. Even though a variety of DACBs have become widely

available in the last 15 years, the systems that target the educational sector and provide support

for icon-based programming environments, such as LabVIEW [5] and Simulink [44], tend to

be quite expensive. Moreover, instructional labs generally may not require the intrinsic high-

performance features of many of the commercially available DACBs (e.g., high sampling rates,

high resolution analog to digital converters (A2Ds), etc.) for the typical electro-mechanical

laboratory experiments. This Chapter proposes a microcontroller-based data acquisition and

control (DAC) system that is particularly suitable for educators interested in developing lab

experiments that do not require high-cost, high-performance data acquisition hardware and

yet can benefit from the icon-based programming environment of Simulink.

Several recent papers [46–48] have focused on interfacing low-cost microcontrollers (such

as BASIC Stamp 2 (BS2) and Peripheral Interface Controller (PIC)) with icon-based pro-

gramming environments such as LabVIEW and Simulink. For example, in Chapter 2, we

concentrated primarily on endowing a PIC microcontroller with graphical user interface (GUI)

capability by exploiting the GUI tools of MATLAB/Simulink. However, the methodology of

Chapter 2 requires manually programming the microcontroller for all sensing, control compu-

tation, and actuation tasks and for serial communication with the GUI running on the PC. To

program a PIC microcontroller using PIC assembly programming language requires knowledge

and experience with the syntax of the PIC programming languages and is often tedious.

26
27

This Chapter proposes a PIC microcontroller-based low-cost DAC system that exploits

MATLAB and Simulink as the key software components for implementing DAC algorithms

using a block-diagram format. Specifically, this Chapter exploits a newly developed library of

PIC functions for Simulink and the serial communication capability of both the PIC micro-

controller and MATLAB to produce a seamless integration between them. The framework of

this Chapter completely obviates the need to manually program the PIC microcontroller by

creating a library of PIC microcontroller functions for Simulink. Specifically, the DAC tool-

box of this Chapter facilitates: i) automatic generation of proper PIC assembly codes for a

variety of sensors and actuators; ii) automatic programming of the PIC microcontroller; and

iii) data communication between the PIC microcontroller and MATLAB. In an instructional

laboratory, this approach allows instructors and students to focus on hardware-in-the-loop im-

plementation, experimental validation, and industry-style rapid control prototyping. Finally,

this Chapter is in the spirit of Chapter 4, which provides a MATLAB DAC toolbox for the BS2

microcontrollers. However, whereas the BS2 microcontroller costs over $45 and includes only

digital input/output (I/O) functionality, thus requiring external A2Ds to interface with ana-

log sensors, the PIC16F74 microcontroller, used in this Chapter, costs under $5 and includes

built-in A2D functionality.

The rest of the Chapter is organized as follows. In Section 3.2, we describe the PIC mi-

crocontroller and the related development hardware. In Section 3.3, we describe the software

environment used in this Chapter. In Section 3.4, we give details concerning the software

integration of Simulink with the PIC microcontroller. In Section 3.5, we illustrate the func-

tionality and capability of the DAC hardware and software of this Chapter by performing

position control of a DC motor. Finally, In Section 3.6, we provide some concluding remarks.

3.2. Hardware Environment

The main components of the DAC hardware of this Chapter are a PIC microcontroller,

a PIC-PG2C programmer, and a PIC development board. A DB-9 serial cable is used to

interface the programmer/development board to a PC which hosts the MATLAB DAC toolbox.

Specifically, the DB-9 cable allows i) programming the PIC microcontroller from the PC and
28

ii) data communication between the PIC and the PC. In this Chapter, an IBM-compatible

Pentium 4 PC running Microsoft Windows XP operating system is used. See Figure 3.1 for a

pictorial representation of the aforementioned hardware environment.

PC

PIC development board

PIC microcontroller

DB-9 serial cable

PIC-PG2C programmer

Figure 3.1: Hardware environment

3.2.1. PIC Microcontroller

The DAC platform of this Chapter uses a PIC16F74 [43] microcontroller. In this Chapter,

five of the six I/O pins of port A and three I/O pins of port E are reserved for eight 8-bit

A2Ds, eight I/O pins of port B are reserved for eight digital inputs, two of the eight I/O pins of

port C are reserved for two PWM outputs, and eight I/O pins of port D are reserved for eight

digital outputs. Finally, an external 20 MHz high-speed crystal oscillator is used to supply

operating clock cycles to the PIC. See Ref. [37, 38] for more details on hardware and software

features of PIC microcontrollers.

3.2.2. PIC-PG2C Programmer

The user specified PIC program, which is created on a PC, is downloaded from the PC to

a PIC microcontroller by serial communication. Serial communication between the PC and

the PIC microcontroller is enabled by using a DB-9 serial connection between the PC and

a PIC development programmer that hosts the PIC microcontroller. Two widely used PIC

development programmers are Microchip’s PICSTART Plus and Olimex’s PIC-PG2C [49]. In

this Chapter, the handy and low-cost PIC-PG2C programmer (see Figure 3.2) is used. In

contrast to other PIC programmers, the PIC-PG2C programmer receives power from the PC’s

serial port thus obviating the need for any additional power supply. Finally, the PIC-PG2C
29

programmer requires IC-Prog [50], a freely available software, to download PIC HEX code to

the PIC microcontroller. Note that the PIC HEX code is obtained from the PIC assembly

code by using the MPASM assembler [51], also available for free.

(a) (b)

Figure 3.2: (a) PIC-PG2C programmer and a PIC (b) PIC-PG2C programmer with a PIC
mounted

3.2.3. PIC Development Board

The PIC development board of this Chapter is a modified version from the board discussed

in Chapter 2. It consists of: i) a PIC16F74 microcontroller; ii) a 20MHz crystal oscillator

to supply operating clock cycles to the PIC microcontroller; iii) the RS232 driver/receiver

circuitry for serial data communication with the PC; iv) a DB-9 connector; and v) a bread-

board area for custom circuits and easy connectivity between the PIC microcontroller and

sensors/actuators. As discussed in Chapter 2, the Maxim’s MAX232 IC [41] with five 1µF ca-

pacitors serves as the RS232 driver/receiver for voltage-level transformation between PC-based

and the PIC-based logic.

3.3. Software Environment

The software environment for this Chapter consists of MATLAB version 6.5, Simulink

version 5.0, the PIC assembly language, a newly developed Simulink library for the PIC micro-

controller, MPASM, and IC-Prog. The MATLAB toolbox for the PIC microcontroller consists

of a Simulink library of PIC microcontroller functions such that based on the user selected con-

figuration of individual I/O pins of the PIC microcontroller, Simulink automatically produces

and downloads the proper PIC assembly code to the microcontroller. Moreover, the MATLAB
30

toolbox also allows data communication between the PIC microcontroller and MATLAB. Thus,

the MATLAB toolbox for the PIC microcontroller completely obviates the need to manually

program the PIC microcontroller. Note that the MATLAB toolbox automatically executes

the assembler program MPASM and the download program IC-Prog, both of which usually

require command line execution. See Refs. [51, 52] for details on programming the PIC mi-

crocontroller in command line via serial communication. The MATLAB toolbox for the PIC

microcontrollers has two main components: i) a Simulink model file named Template.mdl and

ii) a block library named PICLibrary.

3.3.1. Template.mdl

The Template.mdl model file (see Figure 3.3) is a predesigned Simulink model file which

must be used to design Simulink block diagrams for interaction with the PIC microcontroller.

A function named TotalCompile has been embedded within the callback parameters of the

Template.mdl so that the TotalCompile function executes at the beginning of each Simulink

block diagram cycle, before the block diagram actually runs. Details of various tasks performed

by the TotalCompile function are provided in a later subsection. Finally, note that renaming

the Template.mdl file still preserves the callback property embedded in the file, whereas opening

a new Simulink model file does not.

Template.mdl model properties are modified to call


the TotalCompile function at the beginning of
each Simulink block diagram cycle

Figure 3.3: Template and model properties


31

3.3.2. PICLibrary

The PICLibrary is a custom library of Simulink blocks (in the form of s-functions) that in-

terface with sensors and actuators connected to the PIC microcontroller. The following blocks

are currently included in the PICLibrary: A2D, PinStateIn, PWM, and PinStateOut. More-

over, the library includes a block labeled IOBlock that is required in all user-designed Simulink

diagrams to enable serial communication between the PIC microcontroller and MATLAB.

Hardware settings and parameter requirements of each block are detailed below.

1) A2D block (see Figure 3.4) configures the analog to digital conversion module of the PIC

microcontroller. Note that five of the six I/O pins of port A and three I/O pins of port E of

the PIC16F74 microcontroller can be configured as eight 8-bit A2Ds. Thus, analog sensors can

be directly interfaced to any of the eight A2D pins and the corresponding pin number can be

passed as the parameter required by the A2D block.

Figure 3.4: A2D block and parameter

2) PinStateIn block (see Figure 3.5) configures the I/O pins of port B of the PIC16F74 mi-

crocontroller to serve as digital inputs. Specifically, each of the eight pins of port B can serve

as a digital input by passing the corresponding pin number as a parameter to the PinStateIn

block.

3) PWM block (see Figure 3.6) configures PWM modules of the PIC microcontroller. Specifi-

cally, two of the eight I/O pins of port C of the PIC16F74 microcontroller can be configured

as PWM outputs. Since the PIC16F74 microcontroller does not include a digital to analog

converter, in this Chapter, we use the PWM outputs to produce the required analog voltage
32

output by varying the duty cycle of the PWM signal. Thus, two analog actuators can be

interfaced to the two I/O pins of port C that produce PWM outputs and the corresponding

pin numbers are passed as the parameter required by the PWM block.

Figure 3.5: PinStateIn block and parameter

Figure 3.6: PWM block and parameter

4) PinStateOut block (see Figure 3.7) configures the I/O pins of port D of the PIC16F74

microcontroller to serve as digital outputs. Specifically, each of the eight pins of port D can

serve as a digital output by passing the corresponding pin number as a parameter to the

PinStateOut block.

5) IOBlock is necessary for every Simulink block diagram that requires interaction with the

PIC microcontroller. It performs the following tasks: i) initiate serial communication be-

tween MATLAB and the PIC microcontroller when the Simulink block diagram is initially

executed; ii) transmit and receive data between MATLAB and the PIC microcontroller while

the Simulink block diagram is running; and iii) terminate serial communication between MAT-
33

LAB and the PIC microcontroller when the Simulink block diagram is stopped. The callback

function properties of the IOBlock include start serial and stop serial functions that initiate

and terminate serial communication, respectively. In the Simulink block diagram, the IOBlock

is programmed to have the first priority for execution. This ensures that all sensor and ac-

tuator data in MATLAB are first received and sent, respectively, which then is used by the

corresponding sensor and actuator blocks in the Simulink block diagram.

Figure 3.7: PinStateOut block and parameter

Figure 3.8: IOBlock and parameters

Several Simulink blocks, such as an integrator block, require the knowledge of sampling

period for their proper use in a given Simulink block diagram. In this Chapter, the IOBlock is

used to determine, experimentally, the sampling period of the Simulink block diagram. Here,

sampling period is defined as the time required to execute one entire cycle of the Simulink

block. The IOBlock determines the sampling period by averaging the time taken to run a

user-specified number of cycles of the Simulink block diagram. An averaged sampling period
34

is not expected to provide the exact sampling period for each Simulink block cycle and its use

is not recommended when hard real-time constraints are to be enforced.

3.4. Integration of Simulink and PIC

When blocks from the PICLibrary are used in the Template.mdl model file, a sequence

of operations specified by the TotalCompile function are performed before the Simulink block

diagram begins to run. The main role of the TotalCompile function is to program the PIC

microcontroller and to facilitate serial communication between MATLAB and the PIC mi-

crocontroller. As seen in Figure 3.3, the TotalCompile function is set as a “Simulation start

function” of “Callbacks” option in the “Model properties” of Template.mdl.

The TotalCompile function performs the following sequence of tasks. First, global variables

are declared and used to share data with Simulink blocks of PICLibrary. Second, sensor and

actuator blocks used in the Simulink diagram are matched with the corresponding Simulink

blocks in the PICLibrary. Furthermore, each block is categorized as a sensor or an actuator and

its name is stored in an array of sensor/actuator structures with the specified block properties.

The sensor/actuator array information is also used when data is serially communicated. Third,

using the sensor/actuator block information gathered in the previous step, a PIC assembly

code is generated. This step is facilitated by the fact that for each sensor/actuator block in the

PICLibrary the corresponding PIC assembly code has already been created and saved as an m-

file. Fourth, a portion of the IOBlock MATLAB code is generated to allow serial communication

between MATLAB and the PIC microcontroller. This MATLAB code sends and receives the

same amount of data that the PIC microcontroller receives and sends, respectively. Fifth, the

PIC microcontroller is programmed in two steps: i) using the MPASM assembler the PIC

assembly code, generated in step 3 above, is converted to the corresponding PIC HEX code

and ii) using the IC-Prog the PIC HEX code is downloaded to a PIC microcontroller installed

on a PIC-PG2C programmer. Figure 3.9 shows a flow diagram of the three steps involved in

programming the PIC microcontroller.

After the TotalCompile function completes its sequence of tasks, the Simulink block diagram

begins to execute when the user confirms that the PIC microcontroller has been removed from
35

PIC assembly code is PIC assembly code is converted PIC HEX code is downloaded
generated by TotalCompile to PIC HEX code by MPASM by IC-Prog via the serial port

Figure 3.9: Flow diagram of programming the PIC microcontroller

the PIC-PG2C programmer and properly installed onto the PIC development board. At this

stage, serial communication between the PIC microcontroller and MATLAB also begins. If

Simulink is stopped and needs to be run again, without any changes to the configuration of

the PIC microcontroller I/O pins, then the PIC microcontroller need not be reprogrammed.

Once the Simulink block diagram begins to execute, the PIC and PC exchange sensory

feedback and actuator commands via serial data communication. Specifically, special function

8-bit PIC registers are used for the serial communication of sensor/actuator data [43, 47]. The

IOBlock receives/transmits data from/to the PIC and stores the data in sensor/actuator global

variables.

3.5. Example—DC Motor Control

To illustrate the functionality and capability of the DAC hardware and software of this

Chapter, position control of a DC motor is performed. Specifically, a DC motor test-bed is

interfaced with a PIC-based DAC board and a control algorithm is implemented using Simulink

and the MATLAB toolbox for the PIC microcontroller. The DC motor test-bed, shown in

Figure 3.10, consists of an armature controlled DC motor, instrumented with a continuous

rotation potentiometer, and a power module.

The potentiometer output is used to obtain the necessary feedback signals and to provide

a real-time display of the angular position of the motor. To control the angular position of the

DC motor, the PIC microcontroller applies a controlled voltage signal produced by a control

algorithm running on Simulink.


36

Digitized sensor data


from PIC
Analog sensor data

Analog control output


Control output
from Simulink

DC motor and power module PIC development board Simulink block diagram

Figure 3.10: Hardware layer schematic

In this Chapter, a proportional-integral-derivative (PID) controller [53] is used for the

angular position control of the DC motor. The functionality of various Simulink blocks used in

Figure 3.10 (see Figure 3.11 for an exploded view) is as follows. The A2D Pot block serves as

an A2D block to convert the analog output of the potentiometer into an 8-bit digital data. The

PID Controller block encapsulates the standard PID control algorithm. The inputs to the PID

Controller block are: i) the desired angular position of the DC motor and ii) the potentiometer

signal (the digitized output of A2D Pot block). The output of the PID Controller block is a

controlled voltage signal to be applied to the motor. In Figure 3.11, the PID Controller block

output is processed by the PWM Motor block which serves as a PWM block. Note that

the power amplifier module of the DC motor shown in Figure 3.10 requires a ±5 volt direct

current (VDC) to drive the DC motor. Accordingly, the PID control algorithm outputs a

±5VDC control signal. However, the PIC microcontroller can output only 0—5 VDC using

the PWM output. Thus, the ±5VDC output of the PID controller is appropriately transformed

to command the PWM Motor block with a 0—5 VDC command signal. Finally, by processing

the PWM output from the PIC microcontroller using a simple operational amplifier based

circuitry, the 0—5 VDC PWM output is converted into a ±5VDC signal for input to the

power amplifier module.

An analytical model of the DC motor under PID control, yielding a third-order closed-loop

transfer function [53], is used to determine numerical values of the PID controller gains. Specif-

ically, by requiring the closed-loop transfer function to have: i) a pair of complex-conjugate

poles with a damping ratio and natural frequency of 0.69 and 1.93, respectively, and ii) a third

real pole at -80, the PID control gains are computed to be KP=1.43, KI=1.97, and KD =0.5.
37

Figure 3.11: Simulink block diagram: Exploded view

This analog PID controller is implemented using Simulink’s ODE4 (Runge-Kutta) algorithm

with a sampling period of 0.13 second. For the computed gains, the experimental response

exhibits an average 2 percent settling time of 5.9sec and a percentage overshoot of 18.25%. For

comparison, the theoretical values for the 2 percent settling time and the percentage overshoot

are 3sec and 14%, respectively. Figure 3.12 shows a sample experimental response of the DC

motor angular position under PID control implemented using the framework of this Chapter.

Figure 3.12: DC motor angular position tracking response


38

3.6. Conclusion

This Chapter provided an overview of a low-cost DAC toolbox that consists of the newly

developed Simulink library for PIC microcontrollers. Serial communication capabilities of

the PIC microcontroller and MATLAB allowed programming of the PIC microcontroller from

MATLAB and exchange of sensory data and actuation signals between the PIC microcontroller

and MATLAB. The capabilities of this low-cost DAC system were illustrated through a DC

motor angular position control experiment.


Chapter 4

Development of a MATLAB Data Acquisition and


Control Toolbox for BASIC Stamp Microcontrollers

4.1. Introduction

Data acquisition and control boards, also known as DAC boards, are used in virtually

every field of engineering to establish communication between sensors/actuators and decision

making devices, e.g., a personal computer (PC). In academia these boards are used from entry

level laboratory experiments for physics and chemistry to upper level laboratory experiments

in automatic controls and signal processing.

A variety of PC-based DAC boards are available from vendors such as Quanser [1], Na-

tional Instruments [3], and Advantech [54]. Furthermore, DAC solutions from several of these

vendors support icon-based programming environments (e.g., LabVIEW [5] and Simulink [44])

for implementing measurement and control algorithms. The existing PC-based DAC boards

supporting Simulink’s icon-based programming environment require several additional soft-

ware technologies. Specifically, in order to incorporate functionality of a particular MATLAB-

supported DAC board, the user needs MATLAB’s Real-Time Workshop (RTW) toolbox and

a C compiler. In addition, the user must provide a real-time environment (e.g., Real-Time

Windows Target for MATLAB-based DAC solutions, Real-Time Extension for Quanser-based

DAC solutions, etc.) for real-time execution of the designed algorithm. However, in some

cases, the user may not require real-time execution of the algorithm (e.g., environmental mon-

itoring). Thus, similar to PC-based DAC hardware solutions, the software requirements for

the existing PC-based DAC solutions may be excessive.

In Chapter 3, we presented a MATLAB and Simulink-based software platform that enables

the use of an inexpensive PIC microcontroller for DAC tasks. In this Chapter, we develop

a low-cost PC-based DAC board using Parallax Inc.’s BASIC Stamp 2 (BS2) microcontroller

[55]. Furthermore, we provide a library of BS2 functions for Simulink. Next, we exploit

39
40

Simulink’s icon-based programming environment to implement user-defined algorithms in a

block diagram format. In addition, we build upon the foundation of [48] to exploit Simulink

and MATLAB’s built-in serial communication capabilities to communicate with various sensors

and actuators connected to a BS2 microcontroller. The BS2 microcontroller was selected to

illustrate our DAC toolbox since MATLAB/Simulink device library for BS2 can be easily

developed and implemented by exploiting BS2’s BASIC style instructions that are simpler

vis-à-vis instruction sets of other microcontrollers. Moreover, our BS2 device library requires

only minor modification for use of new types of sensors and actuators with our MATLAB DAC

toolbox.

The framework of this Chapter is significant for several reasons. First, by extending the

capabilities of Simulink to low-cost microcontrollers, our method overcomes two limitations

common to most microcontrollers, viz., the lack of advanced icon-based software interface for

efficient development of control algorithms and the lack of a graphical user interface (GUI) to

allow intuitive interaction. Second, our DAC platform is very economical since it requires the

use of only an off-the-shelf BS2 microcontroller (under $50) and obviates the need for overhead

software such as RTW required for most PC-based DAC systems, thus further lowering the

cost of acquiring such a system. This affords an opportunity to students to conduct industry-

style rapid control prototyping and hardware in the loop experiments. Third, the ability to

interface and program microcontrollers using the intuitive graphical programming environment

of Simulink provides the flexibility and versatility of equipping a wide array of undergraduate-

level laboratories (physics, measurement systems, feedback control, and mechatronics) at an

economical cost using our DAC platform. Fourth, our microcontroller-based DAC system is

inherently portable due to its small size and low power requirement, extending its benefits

to students who can acquire their personal DAC system for capstone design projects and for

experimental research.

The rest of the Chapter is organized as follows. In Section 4.2, we describe the components

for the MATLAB-based BS2 DAC system. In Section 4.3, we describe two main components

of the software interface for the DAC system. In Section 4.4, we describe the sequence of tasks

running on the DAC system. In Section 4.5, we illustrate the functionality and capability of
41

the DAC hardware and software of this Chapter by performing position control of a DC motor.

Finally, In Section 4.6, we provide some concluding remarks.

4.2. Components Overview

Our MATLAB-based BS2 DAC system is composed of two main components, hardware

and software. The hardware required for this DAC system is the BS2 microcontroller and user

selectable sensors and actuators. The software required for this system is MATLAB with serial

communication capability and Simulink.

4.2.1. BASIC Stamp 2 Microcontroller

The BS2 is a popular microcontroller used both in hobby and industrial projects. The BS2

has 16 general-purpose digital input/output (I/O) pins. Throughout the rest of this Chapter,

we will refer to these digital I/O pins as pins. The high state on a BS2 pin refers to a 5

volt direct current (VDC) and a low state on a BS2 pin refers to a 0VDC (ground potential).

See [55] for further details on the BS2 microcontroller hardware.

Additional hardware used in this Chapter is the Board of Education (BOE) development

board. The BOE provides: i) built-in circuitry for programming the BS2 microcontroller and

serial data communication; ii) an interface for a power supply; iii) user accessibility of the BS2

pins; and iv) a breadboard area for custom circuits. In this Chapter, the BOE is used as an

interface allowing for easy connectivity to sensors and actuators.

4.2.2. MATLAB/Simulink

MATLAB/Simulink is the primary software environment for our BS2 DAC toolbox. The

Simulink toolbox contains many libraries whose elements can be embedded in Simulink block

diagrams. Simulink also provides user-defined blocks, in the form of s-function blocks, which

can be modified to perform user-defined tasks. Furthermore, every Simulink block allows for a

set of “callback functions,” which execute upon specific events when running a Simulink block

diagram. See [56] for further details on callback functions.


42

4.3. Software Interface

Referring to Figure 4.1 the software interface of our DAC system consists of two main

components: i) a Simulink model file named Template.mdl and ii) a block library named

BS2Library. Template.mdl is the file where the user designs the Simulink block diagram for

interaction with the BS2. BS2Library is the library of additional blocks that communicate

data with sensors and actuators connected to the BS2 microcontroller.

Simulink block diagram

Template.mdl
Empty block diagram with predefined model
parameters

BS2Library contains block for


various sensors and actuators

Callback model parameter:


Simulation Start Function

Template model properties is modified to call the


function “TotalCompile” at the beginning of each
Simulink block diagram cycle

Figure 4.1: MATLAB data acquisition and control toolbox software interface
43

4.3.1. Template.mdl

The Template.mdl model file is an empty Simulink block diagram, where the user designs

the Simulink block diagram for interaction with the BS2. The key property of Template.mdl

is the inclusion of a function within the callback parameters of this Simulink model file, where

this function is to be executed before the start of the block diagram. Furthermore, renaming

this file still preserves this property, whereas opening a new Simulink model file does not.

When starting the Simulink block diagram, the callback function called TotalCompile is

executed first. This function performs several important tasks and enables the communication

between MATLAB and the BS2 microcontroller. Details of this function are provided in a

subsequent section.

4.3.2. BS2Library

The BS2Library is a custom library for Simulink, which provides blocks (in the form of

s-functions) that interface with sensors and actuators connected to the BS2. See Table 4.1

for a complete listing of sensor and actuator blocks currently available. Furthermore, this

library contains a block labeled IOBlock that enables serial communication between the BS2

microcontroller and MATLAB and computes the sampling period of a block diagram. This

block is required in all user-designed Simulink block diagrams that will incorporate sensors and

actuators connected with the BS2 microcontroller. Figure 4.2 provides a graphical description

of the BS2Library.

1) Sensors and Actuators: Sensor and actuator blocks provided in the BS2Library are used to

communicate with sensors and actuators connected with the BS2 microcontroller. Each sensor

or actuator block contains block parameters that need to be set for appropriate hardware

configuration. The following describes hardware settings and parameter requirements of each

block.

i) RCtime block: This block measures the time taken by a specific pin on the BS2 to change

its state. It is used to obtain measurements from a variable resistance/capacitance sensor. The

variable resistance/capacitance sensor is required to be connected in a series resistor-capacitor


44

Table 4.1: Sensor and actuator block description

Name Description
PinStateIn Sensor block giving the state of a BS2 pin,
which is either high (5VDC) = 1 or low (0VDC) = 0
RCtime Sensor block that measures the time it takes for a pin
to change its state from high (5VDC) to low (0VDC), or vice versa
AtoD LTC1296 Sensor block that provides voltage on a specified channel
from an LTC1296 analog to digital converter (A2D)
PinStateOut Actuator block which changes the state of a BS2 pin
to high (5VDC) = 1 or low (0VDC) = 0
ServoMotor Actuator block that turns a servo motor to a desired position
DtoA MAX537 Actuator block that outputs a specified voltage
to a MAX537 digital to analog converter (D2A)

circuit with a constant capacitor/resistor, i.e., if the sensor is a variable resistor, a constant

capacitor is required, and vice versa. See [57] for further details on how to construct an RC

circuit. The RCtime block requires two parameters. The first parameter is the BS2 pin on

which the BS2 monitors the state of the resistor-capacitor circuit. The second parameter is

the initial state of the resistor-capacitor circuit.

ii) AtoD LTC1296 block: This block can receive voltage data from an LTC1296 A2D IC.

The LTC1296 A2D IC, manufactured by Linear Technology Inc., is a 12-bit A2D (11-bit plus

an additional sign bit) that has 8 single input channels, which can be used as 4 differential

inputs, and requires a ±5VDC power supply. Furthermore, this IC is controlled by the BS2 via

the serial peripheral interface (SPI). The AtoD LTC1296 block requires five parameters. The

first parameter is the BS2 pin on which sensor data (in the form of a voltage signal) from the

LTC1296 IC is sent to the BS2. The second parameter is a specific channel on the LTC1296

IC that contains the sensor data. The third parameter is the BS2 pin from which the BS2

sends the “clock” signal to the LTC1296 IC. The fourth parameter is the “chip select” pin

and corresponds to the BS2 pin that enables operation of the LTC1296 IC. Finally, the fifth

parameter is the BS2 pin from which the configuration information for the LTC1296 IC is sent.

See [58] for further details on the LTC1296 IC.

iii) ServoMotor block: This block controls standard servo motors connected to a BS2 mi-
45

BS2Library
Serial Communication
Sensors
Actuators

IOBlock Sensor and Actuator Blocks


Enables serial Block parameters are needed to
communication between generate BS2 Code
Matlab and Bs2
Displays averaged sampling
period
Sensors Actuators

IOBlock Properties

Sample actuator block properties


st
IOBlock has 1 priority

Initiates serial Sensor or actuator has 2nd priority


communication

Sample actuator block parameters

Terminates serial
communication

Figure 4.2: Graphical description of the BS2Library


46

crocontroller, one of which is the Parallax servo motor manufactured by Futaba Corp. The

ServoMotor block requires one parameter, the BS2 pin which transmits a pulse-width mod-

ulated signal that controls the servo motor. See [59] for further details on how to operate a

servo motor from the BS2.

iv) DtoA MAX537 block: This block sends voltage data supplied by the Simulink block

diagram to the MAX537 D2A IC. The MAX537 D2A IC, manufactured by Dallas Semiconduc-

tor Inc., is a 12-bit D2A (11-bit plus an additional sign bit) that has 4 single output channels,

which can be used as 2 differential outputs, and requires a ±5VDC power supply. The MAX537

IC requires four parameters. The first parameter is the BS2 pin from which actuator data (in

the form of voltage output) is to be sent to the MAX537 IC. The second parameter is a specific

output channel on the MAX537 IC. The third parameter is the BS2 pin from which the BS2

sends the “clock” signal to the MAX537 IC. Finally, the fourth parameter is the “chip select”

pin. See [60] for further details on the MAX537 IC.

Finally, sensor and actuator blocks are responsible for writing to or reading from global

variables, which are to be sent or received from the BS2, respectively. Details of these opera-

tions are provided in a subsequent section.

2) IOBlock: The main purpose of this block is: to i) initiate serial communication between

the BS2 microcontroller and MATLAB; ii) send and receive data between BS2 and MATLAB;

and iii) terminate this serial communication link.

The initiation and termination of serial communication is performed by two functions,

OpenSerialPortScript and CloseSerialPortScript, which are executed at the Start and Stop

state of the Simulink block diagram, respectively. For a set of sensors and actuators to be

used in a Simulink block diagram, the IOBlock performs serial communication with the BS2

such that the order of data received from sensors and sent to actuators is determined by the

TotalCompile function. Details of serial data communication are provided in a subsequent

section.

The IOBlock is programmed to be the first block executed in the Simulink block diagram.

This ensures that all sensor and actuator data in MATLAB is first received and sent, respec-
47

tively, which then is used by the appropriate sensor and actuator blocks in the Simulink block

diagram.

4.4. Simulink Diagram Details

This section describes in detail the sequence of tasks that are performed before running a

Simulink block diagram. In particular, we outline the set of tasks that the function, Total-

Compile, performs. Finally, in this section we describe the serial data communication between

MATLAB and BS2.

4.4.1. TotalCompile

TotalCompile is composed of a sequence of sequential tasks.

1) Using Global Variables: Global variables are used in order to share data with any sensor or

actuator block from the BS2Library.

2) Storing Sensors and Actuators Blocks: After defining global variables the TotalCompile

function reads the Simulink model file as a text file. In this process the function looks for

all the blocks (by name) that are present in the Simulink block diagram that match with the

ones stored in the BS2Library. It should be noted that for this task to be performed correctly,

the Simulink model file must be saved before starting the Simulink block diagram. Unsaved

Simulink model files may not include the most recent changes to the sensor or actuator block

parameters. Furthermore, if a user adds or removes sensor or actuator blocks to or from the

block diagram, this unsaved Simulink model file may not reflect these recent changes.

When a matching block is found, it is then categorized as a sensor or an actuator. The type

of block is then used in conjunction with the specified block parameters to be stored in a data

structure depending on its category, e.g., a sensor or an actuator structure. Thus, for multiple

sensor blocks in a Simulink block diagram, an array of sensor structures is allocated. Similarly,

an array of actuator structures is allocated. The sensor array stores all sensor blocks present

in the Simulink block diagram, and an actuator array stores all actuator blocks present in this

diagram. If there are no sensor or actuator blocks present in the diagram a “null” object is
48

stored indicating an empty array.

The order in which sensor blocks are stored in the array is the same as the order in which

the sensor blocks are listed in the text file of the Simulink model file. The actuator array is

organized in a similar manner.

Since in a Simulink block diagram it is possible to have multiple blocks with the same

name, two parameters are used to determine each block uniquely. The first parameter is a pin

of the sensor/actuator connected to the BS2. However, certain sensors or actuators devices

may have multiple channels, in which case, a second parameter is used to store the channel

information. The sensor or actuator array information is later used to organize data sent via

serial communication.

3) Generating MATLAB and PBASIC Code: The sensor and actuator arrays are used to gen-

erate MATLAB and PBASIC code. The PBASIC code, which is used to program the BS2, is

generated first. We note that within the BS2Library block, every sensor or actuator block has

an associated PBASIC code. Thus, for a given sensor or actuator structure, a corresponding

PBASIC code can be provided. Finally, the PBASIC code is organized as follows: i) BS2

waits for MATLAB to send the actuator data; ii) this actuator data drives the actuators; iii)

data is gathered from the sensors; and iv) sensor data is sent to the Simulink block diagram.

Next, a section of the IOBlock’s MATLAB code is generated to facilitate serial communication

between MATLAB and BS2. In particular, this MATLAB code sends and receives the same

amount of data that the BS2 receives and sends, respectively.

4) Programming the BS2: Referring to Figure 4.3, programming the BS2 involves: i) the tok-

enization of the PBASIC code and ii) the sending of this tokenized code to the BS2 via serial

communication. The tokenization process involves sending the PBASIC code to a C++ exe-

cutable program. This program performs tokenization of the PBASIC code using a tokenizer

library provided by Parallax Inc. and stores the result in a text file. The tokenized code is

organized as a set of data packets to be sent to the BS2. See [61] for details on how to tokenize

PBASIC code. Next, a Java program transmits the tokenized PBASIC code packet by packet

to the BS2 using serial communication. See [61] for details on how to program the BS2 via
49

serial communication. After attempting to program the BS2, a Boolean is set to true or false

depending on the success or failure of programming the BS2, respectively.

5) Starting a Simulink Block Diagram: If the BS2 was successfully programmed, then the

Simulink block diagram will start, otherwise the block diagram will stop and produce an error

message on the MATLAB command window.

4.4.2. BS2 and MATLAB Serial Communication

Referring to Figure 4.4, BS2 and MATLAB communicate with each other using the serial

communication port. Both BS2 and MATLAB have built-in functions that provide serial

communication capabilities. It is important to note that all sensor data is sent from MATLAB

as one packet and all actuator data is received by MATLAB as one packet through serial

communication. Sensor data in the sensor packet can be retrieved by the corresponding sensor

blocks in the Simulink block diagram, whereas data from the actuator blocks are packaged into

a single packet for transmission to the BS2.

The use of packets for data communication between MATLAB and BS2 is efficient compared

with the transmission of individual, disjoint sensor or actuator data. In transmitting packets

for data communication, the amount of information needed to be sent via serial communication

is reduced, i.e., in one sensor or actuator packet, the necessary data for serial communication is

one start and stop bit, whereas for individual, disjoint sensor or actuator data, multiple start

and stop bits are necessary for serial communication.

The IOBlock receives the sensor packet and stores the data in a sensor global variable. The

sensor packet received from the BS2 is first converted to the appropriate sensor data, i.e., a

numerical value dependent on the sensor type, and is then stored in the sensor global variable.

The IOBlock transmits data from the actuator global variable to the BS2 for execution. In

constructing the actuator global variable, each actuator block converts the numerical value

of their actuator data into a set of bytes. Next, the sets of bytes for all actuator blocks

are packaged into a packet and saved into the actuator global variable. See Figure 4.4 for a

graphical description of this packet. Lastly, data communication between BS2 and MATLAB

will continue until the Simulink block diagram is stopped.


50

Tokenization of PBASIC

PBASIC Code is generated


by TotalCompile

C++ program reads the PBASIC code as a text file and


tokenizes this code using the BS2 tokenizer library

Tokenizer provides tokenized PBASIC code in the form of


serial communication packets

Java program accepts the tokenized PBASIC code and


programs the BS2 via the serial port

Java program attempts to program the BS2 and sets a true/false


Boolean depending on the success or failure of programming
the BS2

If the Boolean is true MATLAB starts the Simulink block


diagram, else the Simulink block diagram is stopped

Figure 4.3: Flow diagram for programming the BS2 microcontroller


51

BS2 and MATLAB Serial Communication

MATLAB
Gets data from actuator blocks and sends to Bs2
Receives sensor data from BS2

Serial Port
Bidirectional data communication is established
DB-9 serial cable
1 byte
Start

Tach1 Start PC
2 Bytes of
Tachometer Data Tach2 M1 2 Bytes of
DC Motor
Pot1 M2 Data
2 Bytes of
Potentiometer Data Stop
Pot2
Stop
BS2 installed on BOE

BS2
Outputs actuator data to the actuator
Collects data from sensors and transmits information to MATLAB

DAC ADC

DC Motor Potentiometer Tachometer

Laptop
BS2 installed on

DB-9 serial cable

Power supply DC Motor test-bed

Figure 4.4: Graphical description of serial communication between BS2 and MATLAB
52

4.4.3. Data Organization

Both sensor and actuator data transmitted through serial communication is organized in a

specific order. As seen in Figure 4.5, the order in which data is stored for a sensor packet is the

same as how the sensor structures are ordered in the sensor array. Furthermore, the actuator

packet is ordered in a similar manner.

Each BS2Library block has access to both sensor and actuator arrays and sensor and

actuator global variables. Each sensor or actuator used in the Simulink block diagram is

uniquely determined based on a pin number that the sensor or actuator uses for connection

with the BS2 and the device channel (if device controls multiple channels). Depending on the

pin number and device channel, each sensor or actuator block can search for its position in its

corresponding sensor or actuator array. See Figure 4.5 for an example of a sensor block with its

corresponding position in the sensor array. Once the position of a sensor block is determined,

the appropriate sensor data can be retrieved from the sensor global variable. Also, an actuator

block can store actuator data to the actuator global variable in a similar manner.

4.5. Example–DC Motor Control

For illustrative purposes, in this example, we explore the DC motor control experiment

discussed in Chapter 3 using the BS2 microcontroller and our MATLAB DAC toolbox shown

in Figure 4.4. The potentiometer outputs a ±5VDC signal corresponding to the absolute

angular position of the motor. The tachometer outputs a ±5VDC signal corresponding to

the angular velocity of the motor. The BS2 supplies a controlled voltage signal to control

the DC motor angular position. The DC motor sends and receives analog signals from the

microcontroller using an LTC1296 A2D and a MAX537 D2A, respectively. A MAX764 DC-DC

inverter, manufactured by Dallas Semiconductor Inc. [62] and powered by the BOE’s +5VDC

power supply, is used to obtain a ±5VDC power supply for the LTC1296 and MAX537.

In this experiment, we used MATLAB version 6.5, which has a built-in serial communication

library, in addition to Simulink version 5.0. This experiment utilizes the classical proportional-

integral-derivative (PID) controller to control the position of the DC motor. Referring to Figure
53

Figure 4.5: Example for sensor array data organization

4.4, two A2D blocks are used to import sensor data to the PID controller, i.e., the block labeled

AtoD LTC Pot sends DC motor potentiometer data and the block labeled AtoD LTC Tach

sends DC motor tachometer data to the PID controller. The output from these sensor blocks

is then connected to appropriate calibration gain blocks. Furthermore, a D2A block labeled as

DtoA MAX Motor is used to transmit the PID controller output to the DC motor.

4.5.1. Experimental Results

A classical PID controller is implemented in Simulink to control a DC motor using the BS2

library. Specifically, an analog PID controller is designed and implemented using Simulink’s

Euler approximation integration algorithm [56] (with a sampling period of 0.13sec). For il-

lustrative purposes, two sets of performance specifications are used to design corresponding

PID control gains that are used to obtain experimental response of the motor for 0◦ and 90◦

angular position commands for the motor arm.


54

The PID control gains used in this experiment are computed using the analytical model

of the DC motor under the PID feedback control. It can be shown that a third-order transfer

function with one real pole, a pair of complex-conjugate poles, and a finite zero captures

the closed-loop transfer function of the DC motor with the PID controller (see, Section 5.4

of [53] for a similar transfer function). Next, by specifying the desired damping ratio and

natural frequency of complex-conjugate closed-loop poles and the location of the real pole as

0.69, 1.16, and -47.8479, respectively, the PID control gains are computed to be KP = 1.28,

KI = 1.06, and KD = 0.21. Following [53], for these control gains it can be shown that

the closed-loop response theoretically exhibits a 2 percent settling time of 5sec and a percent

overshoot of 25%. Referring to Figure 4.6, which shows experimental time history of the DC

motor arm angular position, these control gains were used from 0 to 58sec. As evidenced from

Figure 4.6, the experimental response exhibits an average experimental 2 percent settling time

of 9.89sec and a percent overshoot of 29.36%. Next, by specifying the desired damping ratio

and natural frequency of complex-conjugate closed-loop poles and the location of real pole

as 0.69, 0.58, and -24, respectively, the PID control gains are computed to be KP = 0.32,

KI = 0.13, and KD = −0.19. For these control gains it can be shown that the closed-loop

response theoretically exhibits a 2 percent settling time of 10sec and a percent overshoot of

25%. Referring to Figure 4.6, these control gains were used from 58 to 105sec. As evidenced

from Figure 4.6, the experimental response exhibits an average experimental 2 percent settling

time of 11.03sec and a percent overshoot of 31%.

4.6. Conclusion

In this Chapter, we developed an inexpensive DAC system by exploiting the serial commu-

nication capabilities of MATLAB and the BS2 microcontroller. Using the advanced features

of Simulink, our software environment allows for the generation of PBASIC code for a variety

of sensors and actuators, programming of the BS2 microcontroller, and data communication

between BS2 and MATLAB. Furthermore, a DC motor control experiment was conducted to

show the salient features of our DAC toolbox. Specifically, a PID controller was implemented

in a Simulink block diagram to control the DC motor arm position.


55

135 Actual DC Motor Position


Desired DC Motor Position
120

105

90
DC Motor Position (degrees)

75

60

45

30

15

−15
PID Control gains are switched

−30

−45
0 10 20 30 40 50 60 70 80 90 100
Time (seconds)

Figure 4.6: DC motor position tracking response


Chapter 5

Two-Tank Liquid Level Control using a BASIC


Stamp Microcontroller and a MATLAB-based Data
Acquisition and Control Toolbox

5.1. Introduction

A variety of PC-based data acquisition and control (DAC) boards are currently available

in the market. These DAC boards can be broadly classified in two categories: i) high-end

DAC boards, which provide a wide range of advanced hardware capabilities along with a

sophisticated software environment; and ii) low-end DAC boards, which are primarily used for

data acquisition of a few selective signals while using proprietary software.

With the emergence of MATLAB [6] as a widely used scientific computing tool in industry

and academia, many users seek a DAC platform that can interface with and exploit advanced

computing capabilities of MATLAB to perform hardware-in-the-loop experiments. Moreover,

within the last decade, new developments in automated code generation programs have allowed

users to utilize interactive icon-based control system simulation tools such as Simulink [44] for

real-time control. In particular, using the Simulink block library and Real-Time Workshop

(RTW) along with Simulink block libraries for vendor-specific DAC boards, one can generate

C code from Simulink-based feedback control diagrams for real-time controller implementation

on PC-based DAC boards. The ability to rapidly and efficiently design and implement complex

control algorithms using an icon-based programming environment enables control designers to

enhance productivity.

In Chapter 4, we developed a low-cost DAC platform which allows Parallax Inc.’s BASIC

Stamp 2 (BS2) microcontroller [55] to be programmed by MATLAB and Simulink. In this

Chapter, we illustrate several important features of the DAC platform developed in Chapter

4 by performing liquid level control of a coupled, two-tank system. Liquid level control is

ubiquitous in industrial applications, e.g., food processing, effluent treatment, power gener-

56
57

ation plants, pharmaceutical industries, water purification systems, and industrial chemical

processing. Thus, the study of liquid level control encompasses many engineering disciplines,

e.g., electrical, chemical, civil, and mechanical.

In this Chapter, we employ the classical proportional-plus-integral (PI) controller for liquid

level control of a coupled, two-tank system [63]. To effectively utilize this control methodology,

the system parameters, e.g., tank dimensions and pump characteristics, must be known exactly.

However, this may not be feasible since system parameters may change due to the effects

of scaling in tanks and orifices, aging of pump, and wear. Thus, to determine the system

parameters, we conduct an experimental system identification study which uses the inherent

nonlinear dynamics of the two-tank system.

The rest of the Chapter is organized as follows. In Section 5.2, we describe the coupled,

two-tank system model and formulate system identification and control design objectives. In

Section 5.3, we outline a method to perform system identification. In Section 5.4, we design

a PI controller. In Section 5.5, we perform experimental validation of the results of earlier

sections. In Section 5.6, we draw some concluding remarks.

5.2. Coupled Two-Tank System Model

Figure 5.1 shows a two degree-of-freedom, state-coupled, two-tank system. This system

consists of two tanks with orifices and liquid level sensors at the bottom of each tank, a pump,

and a liquid basin. The two tanks have the same diameters and can be fitted with differing

diameter outflow orifices. In this experimental setup, the pump provides the infeed to Tank 1

and the outflow of Tank 1 becomes the infeed to Tank 2. The outflow of Tank 2 is emptied

into the liquid basin. The following conditions, with regard to the system dynamic model, are

used to describe the levels of liquid in Tanks 1 and 2:

i) the liquid levels in Tanks 1 and 2, denoted as L1(t) and L2(t), respectively, are measured

using two pressure sensors;

ii) L1(t) is always greater than 0cm and less than 30cm;

iii) L2(t) is always greater than 0cm;

iv) the desired liquid level in Tank 2 is greater than 0cm and less than 20cm for t > 0 ; and
58

v) the voltage applied at the input terminals of the pump, denoted by Vp(t), is between 0 and

22 volt direct current (VDC).

The nonlinear mathematical model describing the liquid levels of Tanks 1 and 2 is given

by [63]
q
L̇1 (t) = −A L1 (t) + BVp (t), (5.1)
q q
L̇2 (t) = C L1 (t) − D L2(t), (5.2)

a1 √ Kp 4 a1
√ 4 a2

where A 4
= A1 2g, B 4
= A1 , C = A2 2g, and D = A2 2g, ai is the cross-sectional area of the

outflow orifice at the bottom of the Tank i, Ai is the cross-sectional area of the Tank i, Kp is

the pump constant, g is the gravitational acceleration, and i =1, 2.

Figure 5.1: Two degree-of-freedom, state-coupled, two-tank system


59

5.2.1. System Identification Objectives

In this Chapter, we assume that the system parameters A, B, C, and D or equivalently

ai , Ai , Kp , and g, for i =1, 2, are not known exactly. As previously discussed, the uncertainty

about system parameters may arise due to corrosive buildup in the liquid level system or the

deterioration of the pump motor. Thus, a control design based on the idealized values of the

system parameters may lead to performance deterioration for the closed-loop system. In a

subsequent section, we outline a series of experiments, which exploit the nonlinear dynamics

of (5.1) and (5.2), to numerically estimate the system parameters A, B, C, and D.

5.2.2. Control Objectives

Given a desired, constant, liquid level for Tank 2, denoted as L2d, design a control input

Vp(t) such that lim L2 (t) = L2d . This objective is to be achieved with the assumption that
t→∞
L1 (t) and L2 (t) can be measured. Furthermore, the control design is to utilize estimates of the

system parameters.

To quantify this control objective, we define the liquid level tracking error for Tanks 1 and

2, i.e., l1 (t) and l2(t), as follows:

l1(t) = L1 (t) − L1d , (5.3)

l2(t) = L2 (t) − L2d , (5.4)

where L1d is some desired, constant liquid level for Tank 1, which using (5.2) is characterized
a2 2
as L1d 4
= ( a1 ) L2d .

5.2.3. Linearized Error System Model

To facilitate the design of a controller to achieve the aforementioned control objectives, we

begin by describing the linearized error system model (see reference [63] for details)

l̇1(t) = α1 l1(t) + β1u(t), (5.5)

l˙2(t) = α2l2 (t) + β2l1 (t), (5.6)

4
where u(t) = Vp(t) − Vpd and Vpd is the desired pump voltage, which using (5.1) is characterized

2gL1d
as Vpd 4
= a1 Kp . Furthermore, the parameters α1 , β1 , α2 , and β2 in (5.5) and (5.6) are defined
60

as, respectively,

A D C
α1 4
= − √ , β1 4 4
= B, α2 = − √ , and β2 4
=√ . (5.7)
4L1d 4L2d 4L1d

Next, we develop the transfer function models for the linearized error system of (5.5) and (5.6)

by taking the Laplace transform of (5.5) and (5.6) and rearranging terms to yield

l1(s) β1
= , (5.8)
u(s) s − α1
l2(s) β2
= , (5.9)
l1(s) s − α2
4 L[l (t)], l (s) 4 L[l (t)], and u(s) 4 L[u(t)] with L denoting the Laplace operator
where l1(s) = 1 2 = 2 =

[64].

5.3. System Identification

In this section, we outline an experimental method to determine the parameters of the

coupled two-tank system given in (5.1) and (5.2). Specifically, motivated by the nonlinear

dynamics of (5.1) and (5.2), we outline a set of experiments that yield the system parameters
A C
A, B, C, and D. In experiment 1, we first obtain numerical values for the ratios B and D. In

experiment 2, we obtain the numerical value for the parameter A, which using the numerical
A
value of B obtained in experiment 1 yields B. In experiment 3, we obtain the numerical value

for the parameter D using the same procedure as in experiment 2, which using the numerical
C
value of D obtained in experiment 1 yields C.

5.3.1. Experiment 1

A C
In this experiment, we obtain expressions that relate the ratios B and D to steady state

conditions of the pump and the liquid levels of Tanks 1 and 2. Specifically, we begin by noting

that if a fixed voltage is applied to the pump, then the liquid levels of Tanks 1 and 2 will reach

steady state after a sufficient amount of time. This characteristic can be proven by directly

solving the differential equations (5.1) and (5.2) given that Vp(t) is constant. Next, the solution

of (5.1) and (5.2) under steady state conditions, i.e., with L̇1 (t) = 0 and L̇2 (t) = 0 yields

A Vpss
=√ , (5.10)
B L1ss
61
s
C L2ss
= , (5.11)
D L1ss
respectively, where L1ss, L2ss, Vpss are the steady state liquid levels of Tanks 1 and 2, and the

steady state pump voltage, respectively. From (5.10) and (5.11), by applying a fixed voltage

Vpss to the pump and directly measuring the liquid levels of Tanks 1 and 2 after a sufficient
A C
amount of time, i.e., L1ss and L2ss , we can determine numerical values of B and D.

5.3.2. Experiment 2

In this experiment, we fill Tank 1 with a fixed amount of liquid and record the time history

of the liquid level in Tank 1 as it is discharged. Using this time history, we can determine

a relationship between the system parameter and the liquid level in Tank 1 at a given time

instant. To do so, we solve the differential equation (5.1) with Vp(t) = 0 and obtain
q q 1
L1 (t) = L1(t0 ) − A(t − t0 ), (5.12)
2

where t0 is the initial time and L1 (t0) is the initial liquid level in Tank 1. Note that equation

(5.12) is only valid when the right hand side of (5.12) is nonnegative, i.e., prior to full discharge

of Tank 1 since once Tank 1 is fully discharged the right hand side of (5.12) becomes negative.

To determine when the liquid in Tank 1 is fully discharged, we set L1(t) = 0 in (5.12) and

solve for the corresponding time, resulting in


p
∗ 2 L1 (t0 )
t = + t0 , (5.13)
A

where t∗ is the time of full discharge of Tank 1. Using (5.13), the analytic expression for the

liquid level in Tank 1 is given by


 √
 p 2 L1 (t0 )

 ( L1 (t0 ) − 12 A(t − t0 ))2 t< + t0
A
L1 (t) = √ (5.14)


 2 L1 (t0 )
0 t≥ A + t0

2 L1 (t0 )
Thus, if we choose a time instant t̄ with t̄ < A + t0 , or equivalently when the liquid level

in Tank 1 is still discharging, then (5.12) can be rewritten to yield the parameter A as follows
p p
L1 (t0 ) − L1(t̄)
A=2 . (5.15)
(t̄ − t0 )
62

Next, substituting (5.15) into (5.10), we can determine the parameter B as follows
 p p √
L1(t0 ) − L1(t̄) L1ss
B= 2 . (5.16)
(t̄ − t0 ) Vpss

Note that the determination of the numerical value for B in (5.16) requires the use of the

experimental data obtained from experiments 1 and 2, i.e., the steady state values L1ss, Vpss

from experiment 1 and t̄, t0 , L1 (t̄), L1 (t0 ) from experiment 2.

5.3.3. Experiment 3

In this experiment, we fill Tank 2 with a fixed amount of liquid and then obtain the time

history of the liquid level in Tank 2 as it is discharging. Using this time history, we can obtain

a relationship between the system parameter D and the liquid level in Tank 2 at a given time

instant. Similar to experiment 2, using the solution of (5.2), we obtain a relationship between

the system parameter D and the liquid level in Tank 2 as follows


p q
L2(t0 ) − L2 (t̂)
D=2 , (5.17)
(t̂ − t0 )

where t̂ is a time instant before Tank 2 is fully discharged. Now, substituting (5.17) into (5.11),

we can determine the parameter as follows


q s
 p
L2 (t0 ) − L2 (t̂)  L2ss
C= 2 . (5.18)
(t̂ − t0 ) L1ss

Note that the determination of the numerical value for C in (5.18) requires the use of the

experimental data obtained from experiments 1 and 3, i.e., the steady state values L1ss , L2ss

from experiment 1 and t̂, t0 , L2 (t̂), L2 (t0 ) from experiment 3.

5.4. Proportional-Plus-Integral (PI) Liquid Level Control

In this section, we outline a PI liquid level control design that is based on the linearized

model of (5.8) and (5.9). As described previously, the liquid level control problem consists

of controlling the liquid level of Tank 2 to a desired, constant liquid level L2d . From (5.9),

to control the liquid level in Tank 2, we must use the liquid level of Tank 1, i.e., l1 (t) as a

pseudo control input. This necessitates control of liquid level of Tank 1 to a desired liquid level
63

L1d, which serves as a command signal for the Tank 1 controller u(t), or equivalently Vp (t).

Referring to Figures 5.2 and 5.3, we design PI controllers for Tank i, i =1, 2, as follows

KIi
Ci (s) = KPi + , (5.19)
s

where KPi is the proportional gain and KIi is the integral gain. To aid in determining the

controller gains KPi and KIi, the desired closed-loop responses for Tank i are specified in

terms of a settling time Tsi and percent overshoot oi performance criterion. It then follows

from reference [64] that the settling time and percent overshoot criterion can be related with

the closed loop damping ratio ξi and natural frequency ωni for Tank i, as follows

bi
ξi = q , (5.20)
2
bi + π 2

4
ωni = , (5.21)
Tsiξi
oi
where bi = log( 100 ). Thus, using (5.20) and (5.21), the controller gains KPi and KIi that

achieve the desired closed-loop responses for Tank i are obtained as follows [63]

1
KPi = (2ξiωni + αi ), (5.22)
βi
2
ωni
KIi = , (5.23)
βi
where αi and βi given in (5.7) depend on the parameters A, B, C, and D, which are obtained

via system identification.

5.5. Experimental Validation

In this section, we explore the experimental system identification and liquid level control

of a two-tank system using the BS2 microcontroller and the BS2 DAC toolbox developed in

Chapter 4. The two-tank, liquid level system is a commercial laboratory equipment developed

and marketed by Quanser Consulting Inc. [65]. The PC-based BS2 DAC platform developed in

Chapter 4 allows MATLAB and Simulink to seamlessly interact with the BS2 microcontroller.

In particular, this DAC platform provides a library of Simulink functions, which allows for di-

rect interaction between user-defined Simulink block diagrams and sensors/actuators connected

to the BS2 microcontroller.


64

The PC-based BS2 DAC platform is composed of two main components, hardware and

software. The hardware required for this platform is the BS2 microcontroller, and user se-

lectable sensors and actuators. The software required for this platform is the MATLAB-based

DAC toolbox.

The BS2 DAC toolbox supports several different types of input and output signals. How-

ever, in this Chapter, only analog input and output signals between ±5VDC are considered.

To convert an analog input signal to a digital format for use on a PC, we utilize the 12-bit

LTC1296 A2D IC. Analogously, to convert an actuation signal, whose representation is in a

digital format, to an analog output signal, we utilize the 12-bit MAX537 D2A IC. Both ICs

are natively supported in the BS2 DAC toolbox. See Chapter 4 for more details of the BS2

DAC toolbox features.

The BS2 DAC toolbox allows users to implement control designs and to develop DAC

panels within Simulink block diagrams. This toolbox provides a Simulink custom library

(BS2Library), which contains blocks that interface with sensors and actuators connected to

the BS2. In this Chapter, we use only the IOBlock, AtoD LTC1296, and DtoA MAX537. The

descriptions of these blocks are provided in Chapter 4.

As described earlier, the liquid levels of Tanks 1 and 2 are measured using pressure sensors,

where the output signal of the sensor is a voltage in the range of 0 to 5VDC corresponding

to the liquid levels in Tanks 1 and 2. A calibration gain for the pressure sensors is then

determined, i.e., the gain that converts the sensor output voltage to centimeters of liquid is
20
computed as 4.2 ( Vcm
olt ) . The pressure sensor analog signals are supplied to the LTC1296 A2D

and are utilized in the Simulink block diagram, as shown in Figures 5.2 and 5.4. Using the

MAX537 D2A, the BS2 supplies a controlled voltage signal to the pump, which controls the

liquid levels of Tanks 1 and 2.

5.5.1. System Identification

In performing experiment 1, as outlined earlier, we applied a constant 7VDC signal to

the pump Vpss , which produced a steady state liquid level in Tanks 1 of L1ss = 10.75cm and

a steady state liquid level in Tank 2 of L2ss = 11.40cm. Next, we performed experiment 2
65

Figure 5.2: Simulink block diagram of the PI controller for Tanks 1 and 2

Figure 5.3: PI controller for Tanks 1 and 2


66

Figure 5.4: Calibration and system identification Simulink block diagram

outlined earlier by filling Tank 1 with 16.46cm of water, i.e., L1(t0 ) = 16.46cm, and obtained

the liquid level of Tank 1 as it was discharged. Figure 5.5(a) shows the liquid level time

history of Tank 1. From Figure 5.5(a), the initial time of discharge t0 is 11.5sec and the time

of full discharge t∗ is 26sec. To compute the system parameter A, we chose t̄ = 16sec, which

corresponds to a liquid level in Tank 1 of L1 (t̄) = 10cm. Using (5.15) and (5.16), A and B are

computed numerically to be 0.3978 and 0.1863, respectively.

Next, we performed experiment 3 outlined earlier, by filling Tank 2 with 15.80cm of water,

i.e., L2 (t0 ) = 15.80cm, and obtained the liquid level of Tank 2 as it was discharged. Figure

5.5(b) shows the liquid level time history of Tank 2. From Figure 5.5(b), the initial time
67

of discharge t0 is 59.5sec and the time of full discharge t∗ is 76sec. To compute the system

parameter D, we chose t̂ = 66sec, which corresponds to a liquid level in Tank 2 of L2 (t̄) =

7.8cm. Using (5.17) and (5.18), C and D are computed numerically to be 0.4056 and 0.3938,

respectively.

Next, we used the liquid level time histories given in Figure 5.5 to obtain numerous time

instances t̄ and t̂, corresponding to many estimates of the system parameters A, B, C, and D.

We then averaged, individually, the estimates of A, B, C, and D and obtained the following:

A = 0.4382, B = 0.2052, C = 0.4486, D = 0.4356. For comparison, manufacturer specifications

of the Tanks 1 and 2 cross-sectional areas and orifices areas produce the nominal system

parameters A = 0.5128, B = 0.2991, C = 0.5128, and D = 0.5128.

(a) (b)

Figure 5.5: (a) Experiment 2–L1(t) response and (b) Experiment 3–L2(t) response

5.5.2. PI Liquid Level Control

Next, we implement the PI control architecture discussed earlier to control the liquid level

of Tank 2. Referring to Figure 5.2, two A2D blocks labeled Tank 1 Liquid Level and Tank 2

Liquid Level, are used to import the signals L1 (t) and L2 (t). These sensor signals are then

used for the PI controller of Tanks 1 and 2, wherein the control signal Vp(t) is sent to a D2A

block labeled Pump Voltage for output to the pump.

In this experiment, we specify the desired liquid level of Tank 2 to be L2d = 12cm. Next,
68

we design the control gains KPi, KIi, i = 1, 2 using (5.22) and (5.23) given a set of settling

time and overshoot performance criterion. The resulting control gains are shown in Table 5.1.

Table 5.1: Settling time and percent overshoot requirements and PI controller gains

Ts1 o1 Ts2 o2 KP1 KI1 KP2 KI2


Case 1 20 sec 1.5 % 30 sec 1.5 % 1.6315 0.3039 3.0559 0.3288
Case 2 35 sec 1.5 % 50 sec 1.5 % 0.7963 0.0785 1.4565 0.1184
Case 3 60 sec 1.5 % 70 sec 3.5 % 0.3322 0.0267 0.7710 0.0641

Figures 5.6–5.8 show the time history of L1 (t) and L2 (t) using the control gains given in

Cases 1–3 given in Table 5.1. Note that the controller design for the system is obtained by

linearizing the nonlinear model near the predetermined steady state level of Tank 2. Therefore,

the response is not guaranteed to satisfy the imposed constraints.

(a) (b)

Figure 5.6: Response of (a) L1 (t) and (b) L2(t) using the PI controller gains of case 1

5.6. Conclusion

In this Chapter, we utilized the MATLAB and Simulink-based DAC platform developed in

Chapter 4 to control a two degree-of-freedom, state-coupled, two-tank system. We outlined a

comprehensive method to perform system identification, and provided a design of a set-point

tracking controller to control the liquid level of the two-tank system. In addition, we exper-

imentally validated the system identification method by using the BS2 DAC toolbox, which
69

(a) (b)

Figure 5.7: Response of (a) L1 (t) and (b) L2(t) using the PI controller gains of case 2

(a) (b)

Figure 5.8: Response of (a) L1 (t) and (b) L2(t) using the PI controller gains of case 3

produced estimates of the two-tank system parameters. Finally, we experimentally obtained

the response of the set-point tracking controller, which showed good tracking performance

using several sets of performance criterion. This Chapter illustrates that the integration of a

low-cost BS2 microcontroller and the MATLAB and Simulink based DAC toolbox can be used

for data acquisition, experimental system identification, and advanced feedback control.
Chapter 6

Synchronization of Sampled-Data Chaotic Systems

6.1. Introduction

Synchronization of chaotic oscillators has incurred great interest in recent years, see for ex-

ample the excellent reviews [66–68]. Synchronization phenomena have been observed in many

biological systems, including animal groups [69], fireflies [70], animal gaits [71], heart stimula-

tion [72], and neural activity [73]. Synchronization techniques are applied in many engineering

and science fields, including secure communications [8–11], meteorology [74], chemistry [74],

nonlinear optics [75], multi-vehicle robotics [76], and epidemics [33].

Synchronization schemes for two identical chaotic oscillators can be classified into bidi-

rectional [77–79] and unidirectional [17, 21, 23, 24, 26] depending on the coupling between the

oscillators [80]. Synchronization of unidirectionally coupled oscillators is generally referred to

as master-slave synchronization. In this case, one system acts as a “master” by driving the

other system that consequently behaves as a “slave.”

Most experimental and theoretical research on master-slave synchronization focuses on

continuous-time systems, see for example [17, 21, 23, 24,26]. Nevertheless, in many engineering

applications noise corruption in analog signal transmission can lead to severe drawbacks of

synchronization schemes [27, 28]. Sampled-data systems have been studied in [10, 29, 30] to

improve robustness of secure communications based on chaotic synchronization. Synchroniza-

tion of sampled-data systems can also be useful in designing robust and effective cooperative

control algorithms for robotic teams.

In this Chapter, we establish sufficient conditions for global synchronization of a sampled-

data master-slave chaotic system. We consider the case of linear state feedback, and we

determine sufficient conditions on the feedback gain matrix for global synchronization. We

transform the global synchronization problem into a global asymptotic stability problem, by

describing the system dynamics in terms of an error sequence. We use the discrete-time

70
71

Lyapunov stability theory and the linear matrix inequality (LMI) framework to analyze global

asymptotic synchronization of the sampled-data master-slave chaotic system. In order to

illustrate the proposed approach, we specialize our results to the synchronization of Chua’s

circuits. Theoretical results are validated through experiments conducted on sampled-data

implementations of Chua’s oscillators. Each oscillator is developed using a microcontroller and

linear state feedback is realized through RF communication.

The rest of the Chapter is organized as follows. In Section 6.2, we present a sampled-data

representation of a continuous-time chaotic system using the Euler approximation technique.

In Section 6.3, we transform the global synchronization problem into a global asymptotic

stability problem. In Section 6.4, we provide a sufficient condition for global synchronization.

In Section 6.5, we apply the LMI framework to construct a feedback gain matrix. In Section

6.6, we describe the microcontroller-based setup, and we present experimental results. In

Section 6.7, we provide conclusion.

6.2. Euler Approximated Sampled-Data Chaotic System Model

In this section, we develop a sampled-data representation of a chaotic system using the Euler

approximation technique. Specifically, a continuous-time chaotic system model containing a

continuous nonlinear function is discretized using Euler’s method to obtain a corresponding

sampled-data model of the chaotic system. To begin, consider the following continuous-time

chaotic system

ẋ(t) = Ac x(t) + gc (x(t)), (6.1)

where x(t) ∈ Rn is the continuous-time state vector, Ac ∈ Rn×n is a constant state matrix of the

continuous-time system, and gc (x) : Rn → Rn is a continuous vector nonlinear function. Before

proceeding, we assume that the nonlinear function, gc (·) satisfies the following condition [21]

˜ = Mc (ξ − ξ),
gc (ξ) − gc(ξ) ˜ (6.2)

where ξ, ξ̃ ∈ Rn and Mc ∈ Rn×n is a bounded matrix with its components dependent on ξ and
˜ Next, using the Euler approximation method [81], the continuous-time chaotic system (6.1)
ξ.
72

can be discretized to yield the following sampled data representation

x(k + 1) = Ad x(k) + gd(x(k)), (6.3)

where Ad 4 4
= hAc + I, gd = hgc , h is the step size of the Euler approximation method, and I is

the n × n identity matrix.

Now using the unidirectional coupling technique, we characterize a chaotic slave system for

(6.3) as follows

x̃(k + 1) = Ad x̃(k) + gd(x̃(k)) + K(x(k) − x̃(k)), (6.4)

where K ∈ Rn×n is a feedback gain matrix that is to be designed to synchronize the slave

system (6.4) to the master system (6.3).

6.3. Sampled-Data Chaotic System Synchronization Problem

In order to characterize the sampled-data chaotic system synchronization problem, we

define the error between the states of the master and slave systems, (6.3) and (6.4), respectively,

as follows
4
e(k) = x(k) − x̃(k). (6.5)

The dynamics of the error state e(k) is readily obtained from the master system dynamics

(6.3) and the slave system dynamics (6.4) and is given by

e(k + 1) = Ãe(k) + gd(x(k)) − gd (x̃(k)), (6.6)

where à 4
= Ad − K.

Remark 6.1. Recall the definition gd 4


= hgc and that gc satisfies (6.2), then it follows that

gd(·) satisfies the following condition

˜ = Md (ξ − ξ),
gd(ξ) − gd(ξ) ˜ (6.7)

where Md 4 ˜
= hMc is a bounded matrix with its components dependent on ξ and ξ.

Finally, the problem of synchronizing the dynamics of sampled-data slave system (6.4) to

the dynamics of sampled-data master system (6.3) necessitates that the states of the error
73

system dynamics given in (6.6) asymptotically converge to zero for any initial condition, i.e.,

lim e(k) = 0. (6.8)


k→∞

6.4. Sufficient Condition for Synchronization of Sampled-Data Chaotic Sys-


tem

In this section, using a quadratic Lyapunov function and Lyapunov stability analysis, we

provide a sufficient condition for the synchronization of the sampled-data master-slave chaotic

system. Before proceeding, we restrict matrix Md to the form shown as


q
X
Md = γi M̂i , i = 1, . . . , q, (6.9)
i=1

where γi is a bounded scalar with its components dependent on ξ and ξ˜ and M̂i is a constant

structure matrix that captures the structure of Md. Moreover, let δi , i = 1, . . . , q, be given

scalars such that

γi γj ≤ δi δj , i = 1, . . . , q, (6.10)

for ξ, ξ̃ ∈ Rn .

Theorem 6.1. Let K ∈ Rn×n be given and suppose there exists an n × n positive definite

matrix P such that


q X
X q
T
2Ã P Ã + 2 δi δj M̂iT P M̂j − P < 0. (6.11)
i=1 j=1
In this case
4
V (e(k)) = eT (k)P e(k), (6.12)

is a Lyapunov function that guarantees that the error system dynamics (6.6) satisfy (6.8), thus

yielding global asymptotic synchronization of the sampled-data master-slave chaotic system.

Proof. To show that the error state dynamics (6.6) are globally asymptotically convergent,

we begin by computing the Lyapunov difference as follows

∆V (e(k)) = eT (k + 1)P e(k + 1) − eT (k)P e(k), (6.13)

which along the error dynamics (6.6) yields

∆V (e(k)) = eT (k)ÃT P Ãe(k) − eT (k)P e(k) + [gd(x(k)) − gd(x̃(k))]T P Ãe(k)

+eT (k)ÃT P [gd(x(k)) − gd (x̃(k))] + [gd(x(k)) − gd(x̃(k))]T P [gd (x(k)) − gd (x̃(k))]. (6.14)
74

Next, using (6.7), and collecting terms, ∆V (e(k)) can be compactly written as

∆V (e(k))=eT (k)(ÃT P Ã + MdT P Ã + ÃT P Md + MdT P Md − P )e(k). (6.15)

Since V (e(k)) of (6.12) is a positive definite candidate Lyapunov function, global asymptotic

stability for the error system dynamics (6.6) is ensured by requiring that ∆V (e(k)) in (6.15)

is negative definite, i.e.,

ÃT P Ã + MdT P Ã + ÃT P Md + MdT P Md − P < 0. (6.16)

We now provide a sufficient condition for (6.16) to hold. First, using (Ã − Md )T P (Ã − Md ) ≥ 0

to bound the second and third terms of the left hand side of (6.16), we obtain

ÃT P Ã + MdT P Ã + ÃT P Md + MdT P Md − P ≤ 2ÃT P Ã + 2MdT P Md − P. (6.17)

Next, using (6.9) and (6.10), the right hand side of (6.17) can be further bounded as follows
q X
X q
2ÃT P Ã + 2MdT P Md − P ≤ 2ÃT P Ã + 2 δi δj M̂iT P M̂j − P. (6.18)
i=1 j=1

It now follows that (6.11) provides a sufficient condition for (6.16), which in turn provides a

sufficient condition for the global asymptotic stability for the error system dynamics (6.6).

6.5. Linear Matrix Inequality-based Controller Synthesis for Synchroniza-


tion of Sampled-Data Chaotic System

In this section, we transform the sufficient condition (6.11) into an LMI condition which

yields the controller gain matrix K of (6.4) to facilitate the global asymptotic synchronization

of the sampled-data master-slave chaotic system.

Theorem 6.2. Suppose there exist a positive definite matrix P ∈ Rn×n and a matrix

G ∈ Rn×n satisfying
 q
q X 
X
1
 − δi δj M̂iT P M̂j + 2P ATd P −G T

 i=1 j=1  > 0. (6.19)
P Ad − G P
In addition, let K ∈ Rn×n be given by

K = P −1 G. (6.20)
75

Then P and K satisfy (6.11), yielding the global asymptotic stability for the error system

dynamics (6.6).

Proof. We begin by rewriting (6.11) as follows


q X
X q
1
− δi δj M̂iT P M̂j + P − (Ad − K)T P P −1 P (Ad − K) > 0. (6.21)
i=1 j=1
2

Now, using G = P K from (6.20), (6.21) becomes


q X
X q
1
− δi δj M̂iT P M̂j + P − (ATd P − GT )P −1 (P Ad − G) > 0. (6.22)
i=1 j=1
2

Finally, by an application of the Schur Complement [82], it follows that (6.22) is equivalent

to (6.19). Thus, it follows that the existence of a positive definite matrix P ∈ Rn×n and a

matrix G ∈ Rn×n satisfying (6.19) and of K ∈ Rn×n satisfying (6.20) is equivalent to the

existence of a positive definite matrix P ∈ Rn×n and K ∈ Rn×n satisfying (6.11). This proves

that the existence of a positive definite matrix P ∈ Rn×n and a matrix G ∈ Rn×n satisfying

(6.19) and of K ∈ Rn×n satisfying (6.20) yields the global asymptotic stability for the error

system dynamics (6.6).

6.6. Illustrative Synchronization Example using Chua’s System

In this section, we illustrate the result of Section 6.5 by designing and implementing a

feedback control gain K for the chaotic slave system dynamics (6.4). We do so by considering

the sampled-data implementation of a master-slave Chua’s circuit pair.

6.6.1. Continuous-time Chua’s System

The continuous-time Chua’s system is characterized by (6.1) with n = 3,


 
−α α 0
 
Ac =  1 −1 1  , (6.23)
0 −β 0
 
−αf (x1 )
 
gc(x) =  0 , (6.24)
0
76

where α, β are given positive scalars, x1 denotes the first component of vector x, f (·) is a

piecewise linear function characterized as

1
f (x1) = bx1 + (a − b)(|x1 + 1| − |x1 − 1|), (6.25)
2

and a and b are given negative constants. Referring to [21], the nonlinear function f (·) can be

expressed as

f (ξ1) − f (ξ˜1 ) = γ1(ξ1 − ξ˜1 ), (6.26)

where γ1 is dependent on ξ1 and ξ̃1, and is bounded by constants a and b as follows a ≤ γ1 ≤

b < 0.

6.6.2. Euler Approximated Sampled-Data Chua’s System

Euler approximated sampled-data representations of the master and slave Chua’s circuits

are given by (6.3) and (6.4), respectively, with


 
−hα + 1 hα 0
 
Ad =  h −h + 1 h  , (6.27)
0 −hβ 1
 
−hαf (x1 )
 
gd(x) =  0 . (6.28)
0

Note that for gd given in (6.28), Md of (6.7) is given by Md = γ1 M̂1 where


 
−hα 0 0
 
M̂1 =  0 0 0 . (6.29)
0 0 0

Next, select the step size for the Euler discretization technique as h = 0.02. Then, the

sampled-data system (6.3) with Ad and gd(x) given by (6.27) and (6.28), respectively, can be

shown to be chaotic by showing that its largest Lyapunov exponent is positive [83]. Following

the procedure of [83], which eliminates the dependence of Lyapunov exponent computation

on initial condition (Table 6.1), error magnitude (Table 6.2), error direction (Table 6.3), and

number of iteration, the largest Lyapunov exponent is determined to be ≈ 0.4.


77

Table 6.1: Largest Lyapunov exponent with respect to different initial conditions and number
of iteration

Iteration Case 1 Case 2 Case 3 Case 4 Case 5 Case 6


10 0.4242 0.4846 0.4705 0.2398 0.4810 0.5222
100 0.4718 0.4833 0.4739 0.4101 0.4701 0.5025
1000 0.4664 0.4793 0.4822 0.4776 0.4789 0.4822

Table 6.2: Largest Lyapunov exponent with respect to different error magnitudes and number
of iteration

Iteration Case 1 Case 2 Case 3 Case 4 Case 5


10 0.4987 0.4105 0.3970 0.3964 0.3964
100 0.4486 0.4181 0.4107 0.4112 0.4112
1000 0.4451 0.4708 0.4727 0.4708 0.4708

Table 6.3: Largest Lyapunov exponent with respect to different error directions and number
of iteration

Iteration Case 1 Case 2 Case 3 Case 4 Case 5 Case 6


10 0.3602 0.3730 0.3573 0.3602 0.3730 0.3573
100 0.5033 0.5047 0.5030 0.5033 0.5047 0.5030
1000 0.4660 0.4662 0.4660 0.4660 0.4662 0.4660

6.6.3. Numerical Parameters

The following numerical values for the various system parameters are adopted from [21]:

α = 9.78, β = 14.97, a = −1.31, and b = −0.75. Finally, to simplify the experimental demon-

stration of the synchronization of the sampled-data master-slave chaotic system, we restrict P

and G in LMI (6.19) to be diagonal, which in turn yields a diagonal gain matrix K in (6.20).

Using this procedure, for the given problem data, the following gain matrix K can be obtained

K = diag(0.804, 0.980, 1.000). (6.30)


78

6.6.4. Experimental Setup

For an experimental validation of the results of this Chapter, the following sequence of

operations are performed.

First, the sampled-data representation of the master Chua’s system (i.e., (6.3) with Ad

and gd given by (6.27) and (6.28), respectively) is implemented on a microcontroller (MC1).

Moreover, at each sampling instant k = 0, 1, . . ., the corresponding state x(k) is transmitted

by MC1, using an RF transceiver, to a second microcontroller (MC2).

Second, the sampled-data representation of the slave Chua’s system (i.e., (6.4) with Ad,

gd, and K given by (6.27), (6.28), and (6.30), respectively) is implemented on MC2. Note that

as stated above, MC2 receives, using an RF transceiver, the state x(k) of the master Chua’s

system and uses it as indicated in (6.4). Finally, for post-processing, at each sampling instant

k = 0, 1, . . ., MC2 communicates master and slave states x(k) and x̃(k), respectively, using

serial communication, to MATLAB running on a Personal Computer (PC). Specifically, using

the serial communication capabilities of the Propeller microcontroller and MATLAB (see, e.g.,

Chapter 2—Chapter 5 for serial interfacing of various microcontrollers and MATLAB), x(k)

and x̃(k) are imported into MATLAB for a graphical representation of the synchronization of

the sampled-data chaotic systems.

In this Chapter, for MC1 and MC2, we used Parallax’s [84] Propeller demo boards [85] that

are based on a 32-bit processor. The Propeller demo board consists of a P8X32A-Q44 Propeller

microcontroller chip, an EEPROM, and eight digital I/O pins. The P8X32A-Q44 Propeller

chip has eight 32-bit processors, thus allowing multi-processing. The Propeller chip can be

programmed using a low-level assembly programming language or a high-level programming

language Spin, used in this Chapter. Finally, the Propeller chip is operated with a voltage level

of 3.3 volt direct current (VDC) and can communicate with a PC serially via a USB connec-

tion. For RF communication from MC1 to MC2, we used two 912MHz RF transceivers [86],

which have both transmitter and receiver functionalities on the module. The RF transceivers

communicate eight bits of data at 9600 baud rate. Note that at each sampling instant k, MC1

executing the sampled-data representation of the master Chua’s circuit needs to transmit the
79

corresponding three-D state vector x(k). Since, MC1 is based on a 32-bit processor, each

component of x(k) is encoded using 32 bits. Thus, for the purposes of RF transmission, MC1

divides each component of x(k) into four sets of eight-bit data. Analogously, as MC2 receives

four sets of eight-bit data, it combines them to produce the original 32-bit representation of

the state data transmitted by MC1.

Figure 6.1 shows the pair of Propeller demoboards (MC1 and MC2), with RF transceivers

installed on-board, that are used to experimentally illustrate the synchronization of sampled-

data master-slave Chua’s system. Figure 6.2 shows the chaotic behavior produced by (6.3)

running on MC1 and plotting on MATLAB. Finally, Figures 6.3 and 6.4 show that the master-

slave system (i.e., (6.3) and (6.4)) is globally asymptotically synchronized.

Figure 6.1: Propeller demo boards and 912 MHz radio frequency transceivers for the sampled-
data master-slave Chua’s circuits

1.5 8 8

6 6
1

4 4

0.5
2 2
x2

x3

x3

0 0 0

−2 −2
−0.5

−4 −4

−1
−6 −6

−1.5 −8 −8
−5 −4 −3 −2 −1 0 1 2 3 4 5 −5 −4 −3 −2 −1 0 1 2 3 4 5 −1.5 −1 −0.5 0 0.5 1 1.5
x1 x1 x2

(a) (b) (c)

Figure 6.2: Plots of the double scroll attractors of the sampled-data master Chua’s circuit:
(a) x1 vs. x2 , (b) x1 vs. x3, and (c) x2 vs. x3
80

10 10 10

8 8 8

6 6 6

4 4 4

e1 2 2 2

e2

e3
0 0 0

−2 −2 −2

−4 −4 −4

−6 −6 −6

−8 −8 −8

−10 −10 −10


0 10 20 30 40 50 60 70 80 90 100 0 10 20 30 40 50 60 70 80 90 100 0 10 20 30 40 50 60 70 80 90 100
k k k

(a) (b) (c)

Figure 6.3: Plots of the errors of the sampled-data master-slave Chua’s circuits: (a) e1 4
= x1 −
x̃1 , (b) e2 4 x
= 2 − x̃ 2 , and (c) e 4 x − x̃
3= 3 3

5 1.5 8

4
6
1
3
4
2
0.5
2
1
x˜1

x˜2

x˜3
0 0 0

−1
−2
−0.5
−2
−4
−3
−1
−6
−4

−5 −1.5 −8
−5 −4 −3 −2 −1 0 1 2 3 4 5 −1.5 −1 −0.5 0 0.5 1 1.5 −8 −6 −4 −2 0 2 4 6 8
x1 x2 x3

(a) (b) (c)

Figure 6.4: Plots of the states of the sampled-data master Chua’s circuit vs. the states of the
sampled-data slave Chua’s circuit showing synchronization of the master-slave Chua’s circuits:
(a) x1 vs. x̃1 , (b) x2 vs. x̃2, and (c) x3 vs. x̃3

6.7. Conclusion

In this Chapter, using the Euler approximation method, we obtained a sampled-data rep-

resentation of a continuous-time chaotic system. Using the discrete-time Lyapunov stability

theory, we developed a sufficient condition for the synchronization of a sampled-data master-

slave chaotic system. In addition, using the LMI framework, we constructed a state feedback

control law for the synchronization of the coupled chaotic system. By implementing a sampled-

data master-slave chaotic system based on Chua’s system on a pair of microcontrollers, we

experimentally validated the results of this Chapter.


Chapter 7

Pulse Synchronization of Sampled-Data Chaotic


Systems

7.1. Introduction

Secure communication systems based on synchronization of chaotic oscillators have been

recently investigated, see for example [8–13]. The general idea behind these systems is to

use chaos to mask a transmitted signal, and chaos synchronization to securely recover it in

reception. In this case, the chaotic oscillator at the transmitter acts as a “master” by driving

the chaotic oscillator at the receiver, that consequently behaves as a “slave.”

In addition to synchronization of chaotic systems in a sampled-data setting studied in

Chapter 6, in this Chapter, we study master-slave synchronization of chaotic oscillators that

are only sporadically coupled. This scenario seems particularly realistic for communication

systems. We consider the case of linear state feedback and we assume that the feedback

periodically changes over time. Following the work of [19] for analog systems, we refer to this

synchronization scheme as pulse synchronization [19, 22]. We establish sufficient conditions for

pulse synchronization using Lyapunov stability theory and the linear matrix inequality (LMI)

framework. Specifically, we show that chaotic synchronization is possible even if the oscillators

are only intermittently coupled, that is, even if most of the time they are uncoupled. The

Chua’s circuits experiment setup discussed in Chapter 6 is also used to specialize our results

of this Chapter.

The type of intermittent coupling considered in this Chapter has been analyzed in the

framework of consensus theory for continuous-time systems [31, 32], and peer-to-peer synchro-

nization of analog complex networks [33,34]. We note that, in consensus theory, the individual

systems’ dynamics is linear while in the present case the coupled systems are strongly nonlin-

ear. We further observe, that results in [33,34] are only for local synchronization since they are

based on linearized dynamics. In this Chapter, the inherent nonlinear nature of the coupled

81
82

systems is retained and the problem is cast into a sampled-data setting.

The rest of the Chapter is organized as follows. In Section 7.2, we formulate a global

pulse synchronization problem. In Section 7.3, we provide sufficient conditions for global pulse

synchronization. In Section 7.4, we apply the LMI framework to construct periodic feedback

gain matrices that yield global pulse synchronization. In Section 7.5, we provide experimental

validation of our results using a microcontroller-based implementation of master-slave Chua’s

circuits. In Section 7.6, we provide conclusions.

7.2. Pulse Synchronization Problem for Sampled-Data Chaotic System

In order to characterize the pulse synchronization problem for the sampled-data master-

slave chaotic system, we use the sampled-data representation of the system developed in Chap-

ter 6, which is as follows

x(k + 1) = Ad x(k) + gd(x(k)), (7.1)

x̃(k + 1) = Ad x̃(k) + gd(x̃(k)) + K(k)(x(k) − x̃(k)), (7.2)

where Ad 4 4
= hAc + I, gd = hgc , h is the step size of the Euler approximation method, and I is

the n × n identity matrix, K : Z → Rn×n , with Z denoting the set of nonnegative integers, is a

feedback gain matrix that is to be designed to synchronize the slave system (7.2) to the master

system (7.1).

Then the dynamics of the error state e(k) (see (6.5)) is readily obtained from the master

system dynamics (7.1) and the slave system dynamics (7.2) and is given by the following

nonlinear nonautonomous system

e(k + 1) = (Ad + Md − K(k))e(k), (7.3)

where (6.7) has been used.

For pulse synchronization of the sampled-data master-slave chaotic system, we consider the

case where K(k) is a periodic gain such that

K(mN + i) = K(i), i = 0, 1, . . ., p − 1, (7.4)

K(mN + i) = K(i) = 0n×n , i = p, p + 1, . . ., p + q − 1, (7.5)


83

where N 4
= p + q is the number of samples in a complete cycle, m ∈ Z, and p, q ∈ Z+ , with

Z+ denoting the set of positive integers. That is, over a period N , the periodic control gain

K(k) is non-zero for the first p samples and zero for the next q samples. In this case, the error

system (7.3) yields

e(k + 1) = A(k)e(k), (7.6)

where

A(k) = Ad + Md − Kk , k = mN, . . . , mN + p − 1, (7.7)

= A d + Md , k = mN + p, . . . , mN + p + q − 1, (7.8)

and Kk = K(k) is used for notational convenience.

Finally, the problem of pulse synchronizing the dynamics of sampled-data slave system

(7.2) to the dynamics of sampled-date master system (7.1) necessitates that the states of the

error system dynamics given in (7.6) asymptotically converge to zero for any initial condition,

i.e.,

lim e(k) = 0. (7.9)


k→∞

7.3. Sufficient Conditions for Pulse Synchronization of Sampled-Data Chaotic


System

In this section, using quadratic Lyapunov functions and Lyapunov stability analysis, we

provide sufficient conditions for pulse synchronization of the sampled-data master-slave chaotic

system. For notational convenience, let Pn denote n × n positive definite matrices.

Theorem 7.1. Let p matrices Kk : Z → Rn×n , k = 0, . . . , p − 1, be given and suppose there

exist N matrices Pk ∈ Pn such that


X̀ X̀
2ÃTk Pk+1 Ãk + 2 δi δj M̂iT Pk+1 M̂j − Pk < 0, k = 0, . . ., p − 1, (7.10)
i=1 j=1

X̀ X̀
2ATd Pk+1 Ad + 2 δi δj M̂iT Pk+1 M̂j − Pk < 0, k = p, . . ., p + q − 1, (7.11)
i=1 j=1

where Ãk 4
= Ad − Kk . In this case

4
V (e(k), k) = eT (k)Pk e(k), (7.12)
84

is a periodic quadratic Lyapunov function, with Pk+N = Pk , k ∈ Z, that guarantees that the

system dynamics (7.6) satisfy (7.9), thus yielding global asymptotic synchronization of the

sampled-data master-slave chaotic system.

Proof. To show that the error system dynamics (7.6) are globally asymptotically convergent,

we begin by computing the Lyapunov difference as follows

∆V (e(k), k) = eT (k + 1)Pk+1 e(k + 1) − eT (k)Pk e(k), (7.13)

which along the error dynamics (7.6) yields

∆V (e(k), k) = eT (k)(AT (k)Pk+1 A(k) − Pk )e(k). (7.14)

Since V (e(k), k) of (7.12) is a positive definite candidate Lyapunov function, global asymptotic

stability for the error system dynamics (7.6) is ensured by requiring that ∆V (e(k), k) in (7.14)

is negative definite, i.e.,

AT (k)Pk+1 A(k) − Pk < 0, k = 0, . . . , p + q − 1. (7.15)

Using (7.7) and (7.8) in (7.15) produces

(Ãk + Md )T Pk+1 (Ãk + Md ) − Pk < 0, k = 0, . . . , p − 1, (7.16)

(Ad + Md )T Pk+1 (Ad + Md ) − Pk < 0, k = p, . . . , p + q − 1.

We now provide sufficient conditions for (7.16) and (7.17) to hold. First, for k = 0, . . . , p − 1,

using (Ãk − Md)T Pk+1 (Ãk − Md ) ≥ 0, we obtain

ÃTk Pk+1 Ãk + MdT Pk+1 Ãk + ÃTk Pk+1 Md + MdT Pk+1 Md − Pk

≤ 2ÃTk Pk+1 Ãk + 2MdT Pk+1 Md − Pk . (7.17)

Similarly, for k = p, . . . , p + q − 1, using (Ad − Md)T Pk+1 (Ad − Md ) ≥ 0, we obtain

ATd Pk+1 Ad + MdT Pk+1 Ad + ATd Pk+1 Md + MdT Pk+1 Md − Pk

≤ 2ATd Pk+1 Ad + 2MdT Pk+1 Md − Pk . (7.18)


85

Next, using (6.9) and (6.10), the right hand sides of (7.17) and (7.18) can be further bounded

as follows
X̀ X̀
2ÃTk Pk+1 Ãk + 2MdT Pk+1 Md − Pk ≤ 2ÃTk Pk+1 Ãk + 2 δi δj M̂iT Pk+1 M̂j − Pk , (7.19)
i=1 j=1

X̀ X̀
2ATd Pk+1 Ad + 2MdT Pk+1 Md − Pk ≤ 2ATd Pk+1 Ad + 2 δi δj M̂iT Pk+1 M̂j − Pk . (7.20)
i=1 j=1

It now follows that (7.10) and (7.11) provide sufficient conditions for (7.16) and (7.17), respec-

tively, which in turn provide a sufficient condition for the global asymptotic stability for the

error system dynamics (7.6).

Remark 7.1. Note that by selecting a periodic Lyapunov function, we are able to guaran-

tee that the Lyapunov difference is decreasing even when the master-slave chaotic system is

decoupled.

7.4. LMI-based Periodic Controller Synthesis for Pulse Synchronization of


Sampled-Data Chaotic System

In this section, we transform the sufficient condition (7.10) into an LMI condition which

when solved along with the LMI condition (7.11) yields the periodic controller gain matrices Kk

of (7.7) to facilitate the global asymptotic pulse synchronization of the sampled-data master-

slave chaotic system.

Theorem 7.2. Suppose there exist N matrices Pk ∈ Pn and p matrices Gk ∈ Rn×n satisfying
 
X̀X̀
1
−
 δi δj M̂iT Pk+1 M̂j + 2 Pk ATd Pk+1 − GTk 

 i=1 j=1  > 0,
Pk+1 Ad − Gk Pk+1
k = 0, . . . , p − 1, (7.21)

and (7.11). In addition, for k = 0, . . . , p − 1, let Kk : Z → Rn×n be given by

−1
Kk = Pk+1 Gk . (7.22)

Then Pk and Kk satisfy (7.10) and (7.11), yielding the global asymptotic stability for the error

system dynamics (7.6).


86

Proof. We begin by rewriting (7.10) as follows

X̀ X̀ 1
− δi δj M̂iT Pk+1 M̂j + Pk − (Ad − Kk )T Pk+1 Pk+1
−1
Pk+1 (Ad − Kk ) > 0. (7.23)
i=1 j=1
2

Now, using Gk = Pk+1 Kk from (7.22), (7.23) becomes

X̀ X̀ 1 −1
− δi δj M̂iT Pk+1 M̂j + Pk − (ATd Pk+1 − GTk )Pk+1 (Pk+1 Ad − Gk ) > 0. (7.24)
i=1 j=1
2

Finally, by an application of the Schur Complement [82], it follows that (7.24) is equivalent to

(7.21). Thus, it follows that the existence of N matrices Pk ∈ Pn and p matrices Gk ∈ Rn×n

satisfying (7.21) and (7.11) and of p matrices Kk : Z → Rn×n satisfying (7.22) is equivalent

to the existence of N matrices Pk ∈ Pn and p matrices Kk : Z → Rn×n satisfying (7.10) and

(7.11). This proves that the existence of N matrices Pk ∈ Pn and p matrices Gk ∈ Rn×n

satisfying (7.21) and (7.11) and of p matrices Kk : Z → Rn×n satisfying (7.22) yields the global

asymptotic stability for the error system dynamics (7.6).

Remark 7.2. Suppose for a given problem (7.21) and (7.11) are feasible with p = p∗ and

q = q ∗ , respectively. Then the corresponding matrices Kk , k = 0, . . . , p∗ − 1, obtained from

(7.22) render the error system dynamics (7.6) globally asymptotically stable for all q ≤ q ∗ .

7.5. Illustrative Synchronization Example using Chua’s System

In this section, we illustrate the result of Section 7.4 by designing and implementing a

periodic feedback control gain Kk for the chaotic slave system dynamics (7.2). We use the

Euler approximated sampled-data Chua’s system (6.27) and (6.28) discussed in Chapter 6.

In this Chapter, we select the step size for the Euler discretization technique as h = 0.005.

Then, the sampled-data system (7.1) with Ad and gd (x) given by (6.27) and (6.28), respectively,

can be shown to be chaotic by showing that its largest Lyapunov exponent is positive (≈ 0.4)

[83]. Table 7.1—Table 7.3 show the independence of Lyapunov exponent computation on initial

condition, error magnitude, error direction, and number of iteration.


87

Table 7.1: Largest Lyapunov exponent with respect to different initial conditions and number
of iteration

Iteration Case 1 Case 2 Case 3 Case 4 Case 5 Case 6


10 0.3974 0.4450 0.3865 0.3547 0.4236 0.3865
100 0.4101 0.3959 0.3836 0.3865 0.3995 0.3836
1000 0.3996 0.4005 0.3928 0.3951 0.3999 0.3928

Table 7.2: Largest Lyapunov exponent with respect to different error magnitudes and number
of iteration

Iteration Case 1 Case 2 Case 3 Case 4 Case 5


10 0.4257 0.2921 0.2786 0.2786 0.2786
100 0.4794 0.4392 0.4290 0.4288 0.4288
1000 0.4270 0.4293 0.4256 0.4255 0.4255

Table 7.3: Largest Lyapunov exponent with respect to different error directions and number
of iteration

Iteration Case 1 Case 2 Case 3 Case 4 Case 5 Case 6


10 0.3975 0.4011 0.3963 0.3975 0.4011 0.3963
100 0.4101 0.4105 0.4099 0.4101 0.4105 0.4099
1000 0.3997 0.3997 0.3997 0.3996 0.3997 0.3996

7.5.1. Numerical Parameters

The following numerical values for the various system parameters are adopted from [21]:

α = 9.78, β = 14.97, a = −1.31, and b = −0.75. Finally, to simplify the experimental demon-

stration of pulse synchronization for the sampled-data master-slave chaotic system, we restrict

Pk and Gk in (7.21) and (7.11) to be diagonal, which in turn yields diagonal gain matrices

Kk in (7.22). Using this procedure, for the given problem data with p = 1, LMIs (7.21) and

(7.11) were determined to be feasible up to q = 22 and the following control gain matrix was

obtained

K1 = diag(0.9511, 0.9950, 1.000). (7.25)


88

Similarly, for the given problem data with p = 3, LMIs (7.21) and (7.11) were determined to

be feasible up to q = 50 and the following control gain matrices were obtained

K1 = diag(0.9509, 0.9948, 0.9998),

K2 = diag(0.9304, 1.0020, 0.9779),

K3 = diag(0.9723, 0.9875, 1.0227). (7.26)

7.5.2. Experimental Results

For an experimental validation of the results of this Chaper, the same experimental setup

discussed in Chapter 6 is used. Figures 7.1(a), 7.1(b), and 7.2 show that control gains (7.25)

and (7.26) yield pulse synchronization of the master-slave system (i.e., (7.1) running on MC1

and (7.2) running on MC2) for p = 1, q = 22 and p = 3, q = 50, respectively. Moreover,

Figures 7.1(c), 7.1(d), and 7.3 show that the master-slave system lacks synchronization for

p = 1, q = 1500 and p = 3, q = 2000, with control gains (7.25) and (7.26), respectively.

7.6. Conclusion

In this Chaper, we developed sufficient conditions for pulse synchronization of a sampled-

data master-slave chaotic system using the discrete-time Lyapunov stability theory. In addi-

tion, using the LMI framework, we constructed a periodic state feedback control law for pulse

synchronization of the coupled chaotic system. We validated our results by performing pulse

synchronization of a pair of Chua’s circuits implemented on a pair of microcontrollers.


89

0.5 0.5
e1

e1
0 0
−0.5 −0.5

0 50 100 150 200 0 50 100 150 200

0.2 0.2
e2

e2
0 0

−0.2 −0.2
0 50 100 150 200 0 50 100 150 200

1 1
e3

e3
0 0

−1 −1
0 50 100 150 200 0 50 100 150 200
k k
(a) (b)

0.5 0.5
0
e1

e1

0
−0.5 −0.5

0 1000 2000 3000 4000 5000 6000 7000 0 1000 2000 3000 4000 5000 6000 7000

0.2
0.2
e2

e2

0 0

−0.2
−0.2
0 1000 2000 3000 4000 5000 6000 7000 0 1000 2000 3000 4000 5000 6000 7000

1
1
e3

e3

0 0
−1
−1
0 1000 2000 3000 4000 5000 6000 7000 0 1000 2000 3000 4000 5000 6000 7000
k k
(c) (d)

Figure 7.1: Plots of the errors (ei 4


= xi − x̃i , i = 1, 2, 3) of the sampled-data master-slave Chua’s
circuits: (a) p = 1, q = 22, (b) p = 3, q = 50, (c) p = 1, q = 1500, and (d) p = 3, q = 2000
90

5 8

1
4

x∼

x∼
x∼

3
1

0 0 0

−4
−1

−5 −8
−5 0 5 −1 0 1 −5 0 5
x1 x2 x3

(a) (b) (c)


5 8

1
4
x∼

x∼
x∼

3
1

0 0 0

−4
−1

−5 −8
−5 0 5 −1 0 1 −5 0 5
x1 x2 x3

(d) (e) (f)

Figure 7.2: Plots of the states of the sampled-data master Chua’s circuit vs. the states of
the sampled-data slave Chua’s circuit (xi vs. x̃i , i = 1, 2, 3) showing synchronization of the
master-slave Chua’s circuits: (a), (b), (c) with p = 1, q = 22 and (d), (e), (f) with p = 3, q = 50
91

5 8

1
4

x∼

x∼
x∼

3
1

0 0 0

−4
−1

−5 −8
−5 0 5 −1 0 1 −5 0 5
x x x
1 2 3

(a) (b) (c)


5 8

1
4
x∼

x∼
x∼

3
1

0 0 0

−4
−1

−5 −8
−5 0 5 −1 0 1 −5 0 5
x x x
1 2 3

(d) (e) (f)

Figure 7.3: Plots of the states of the sampled-data master Chua’s circuit vs. the states of
the sampled-data slave Chua’s circuit (xi vs. x̃i , i = 1, 2, 3) showing lack of synchronization
of the master-slave Chua’s circuits: (a), (b), (c) with p = 1, q = 1500 and (d), (e), (f) with
p = 3, q = 2000
Chapter 8

Conclusion and Recommendation for Future


Research

This dissertation has concentrated on two disparate topics: i) design and development of

a user-friendly icon-based data acquisition and control (DAC) software that enables the use

of low-cost microcontrollers as DAC hardware and ii) synchronization of master-slave chaotic

systems. Throughout this dissertation, the design and efficacy of our proposed methodologies

were verified via experimental validation studies. MATLAB-based DAC tools exploited Pe-

ripheral Interface Controller (PIC) and BASIC Stamp 2 (BS2) microcontrollers. On the other

hand, synchronization of a master-slave chaotic system utilized a Propeller microcontroller.

In the first part of this dissertation (Chapters 2—5), we developed MATLAB-based DAC

tools that provide graphical user interfaces (GUIs) to interact with inexpensive microcontrollers

such as PIC and BS2. We exploited the serial communication functionality of MATLAB to

enable a PC to communicate with the microcontrollers to transmit control commands and

receive sensory data. Moreover, we utilized MATLAB, Simulink, and Dials and Gauges Block-

set to develop interactive GUI environments for the microcontrollers, allowing enhanced data

processing and visualization. Next, we developed a DAC toolbox wherein users can simply

use predefined libraries (user-defined algorithms in block diagram formats) of microcontroller

function within Simulink’s icon-based programming environment. Our software environment

was designed for allowing in particular: i) the generation of proper microcontroller codes for a

variety of sensors and actuators; ii) programming of the microcontroller; and iii) data commu-

nication between the microcontroller and MATLAB. The effectiveness of our MATLAB-based

GUI environment to interact with microcontrollers was illustrated by showing several impor-

tant features of the DAC platform by performing liquid level control of a coupled, two-tank

system and position control of a DC motor system. The classical PI and PID controllers were

92
93

designed for liquid-level control and position control, respectively.

The results of Chapters 2—5 can be extended in several ways. In regards to the communi-

cation method of the DAC toolbox, our current approach uses the RS232 serial communication

protocol. However, many newer computing platforms (desktops and laptops) do not provide the

serial ports. Instead, the RS232 protocol has been replaced by the USB communication proto-

col. Although the RS232 serial communication protocol still can be used by using serial/USB

adapters for the computing platforms which do not have serial ports, further exploration of

USB-based DAC tool design can provide additional speed for data acquisition.

In the second part of this dissertation (Chapters 6 and 7), synchronization of a master-slave

chaotic system in the sampled-data setting was studied by using the Euler approximation tech-

nique to discretize a continuous-time chaotic system containing a continuous nonlinear func-

tion. In addition, pulse synchronization of a master-slave chaotic system in the sampled-data

setting was investigated by developing a pulse-based intermittent control system for chaos

synchronization. Moreover, we used a discrete-time Lyapunov stability theory and a linear

matrix inequality framework to construct a time-invariant full-state feedback control law for

the synchronization problem of a chaotic master-slave system and an intermittent, pulse-based,

periodic, full-state feedback control law for the sporadically coupled synchronization problem

of a chaotic master-slave system. Finally, we validated our theoretical results on an experi-

mental setup consisting of a set of propeller microcontrollers endowed with RF communication

capability and a sampled-data master-slave chaotic system based on Chua’s circuit.

The results of Chapters 6 and 7 can be extended in several ways. In regards to the discretiza-

tion technique, instead of using the Euler approximation technique, higher order discretization

technique such as the Runge-Kutta method can be used to discretize the continuous-time

chaotic systems. In regards to the applications of the results, the synchronization of the

sampled-data chaotic system can be expanded to various applications such as the cooperative

control algorithm for the teams of robots to achieve tasks assigned by synchronizing motions.
Appendix A.1

PIC Assembly Code for Serial Communication from PC to PIC

;This code is used to control angular position of a servomotor

;1. Receive user command from PC

;2. Generate pulse train to drive servomotor to a desired angle

LIST p=16f74

INCLUDE “p16f74.inc”

CONFIG CP OFF & WDT OFF & HS OSC & PWRTE ON ;configure PIC16F74

counter EQU 20h ;file address of counter var

iteration EQU 21h ;file address of iteration var

tempval EQU 22h ;file address of tempval var

ORG 0 ;origin address is 0

CLRF STATUS ;clear status register

GOTO BootStart ;go to BootStart

BootStart

BANKSEL PORTA ;select bank 0

CLRF PORTB ;clear portB

CLRF PORTC ;clear portC

BANKSEL TRISA ;select bank 1

MOVLW b’00000000’

MOVWF TRISB ;set PORTB as all outputs

MOVLW b’10000000’

MOVWF TRISC ;set RC7 as input


TimerInitialization

BSF STATUS, RP0 ;select bank 1

MOVLW b’00000001’

MOVWF OPTION REG ;set prescaler of TMR0 to 1:4

BCF STATUS, RP0 ;select bank 0

MOVLW b’10000100’

MOVWF INTCON ;enable all unmasked interrupts and TMR0 register overflow

CLRF TMR0 ;clear timer

BaudRateSettingsforUSART

BSF STATUS, RP0 ;select bank 1

MOVLW d’129’

MOVWF SPBRG ;set baudrate 9600 for 20MHz crystal

MOVLW b’00100100’

MOVWF TXSTA ;8-bit asyn. high-speed transmission

BANKSEL RCSTA ;select bank 0

MOVLW b’10010000’

MOVWF RCSTA ;8-bit asyn. continuous reception

MOVF RCREG, W

MOVF RCREG, W

MOVF RCREG, W ;flush reception buffer 3 times

MainProgram

BCF STATUS, RP0 ;select bank 0

Check BTFSS PIR1, RCIF ;check if data is received

GOTO Check

MOVF RCREG, W ;move received data to W

MOVWF tempval ;save data from W into tempval

MOVLW 0x64

MOVWF iteration ;save iteration value for pulse train


BeginServo

MOVF tempval, 0 ;move tempval to W

MOVWF counter ;save data from W into counter

LoopHigh

CLRF TMR0 ;clear timer

BSF PORTB, 1 ;set RB1 to high

MOVLW 0x05

InnerLoopHigh

SUBWF TMR0, 0 ;set and countdown timer

BTFSS STATUS, 2 ;check if timer is zero

GOTO InnerLoopHigh ;go to InnerLoopHigh again

BCF STATUS, 2 ;reset zero bit of status

DECFSZ counter ;countdown counter and check if zero

GOTO LoopHigh ;go to LoopHigh

BCF PORTB, 1 ;set RB1 to low

MOVLW 0xfa

MOVWF counter ;set the value of counter for low

LoopLow

CLRF TMR0 ;clear timer

BCF STATUS, 2 ;reset zero bit of status

MOVLW 0x15

InnerLoopLow

SUBWF TMR0, 0 ;set and countdown timer

BTFSS STATUS, 2 ;check if timer is zero

GOTO InnerLoopLow ;go to InnerLoopLow again

BCF STATUS, 2 ;reset zero bit of status

DECFSZ counter ;countdown counter and check if zero

GOTO LoopLow ;go to LoopLow


BCF STATUS, 2 ;reset zero bit of status

DECFSZ iteration ;countdown iteration, check if zero

GOTO BeginServo ;go to BeginServo

GOTO MainProgram ;go to MainProgram to repeat

END ;end line of the code


Appendix A.2

PIC Assembly Code for Serial Communication from PIC to PC

;This code is used to collect the light sensor output ;1. Measure the voltage output from pho-

toresistor

;2. Send the digitized output to PC using USART

LIST p=16f74

INCLUDE “p16f74.inc”

CONFIG CP OFF & WDT OFF & HS OSC & PWRTE ON ;configure PIC16F74

ORG 0 ;origin address is 0

CLRF STATUS ;clear status register

GOTO BootStart ;go to BootStart

BootStart

BANKSEL PORTA ;select bank 0

CLRF PORTA ;clear portA

CLRF PORTC ;clear portC

BANKSEL TRISA ;select bank 1

MOVLW b’00000001’

MOVWF TRISA ;set RA0 as input

MOVLW b’10000000’

MOVWF TRISC ;set RC7 as input

ADCInitialization

BCF STATUS, RP0 ;select bank 0

MOVLW b’10000001’
MOVWF ADCON0 ;enable ADC and select CH0

BSF STATUS, RP0 ;select bank 1

MOVLW b’00000100’

MOVWF ADCON1 ;set RA0, 1, and 3 to A/D ports

TimerInitialization

BSF STATUS, RP0 ;select bank 1

MOVLW b’00000001’

MOVWF OPTION REG ;set prescaler of TMR0 to 1:4

BCF STATUS, RP0 ;select bank 0

MOVLW b’10000100’

MOVWF INTCON ;enable all unmasked interrupts and TMR0 register overflow

CLRF TMR0 ;clear timer

BaudRateSettingsforUSART

BSF STATUS, RP0 ;select bank 1

MOVLW d’129’

MOVWF SPBRG ;set baudrate 9600 for 20MHz crystal

MOVLW b’00100100’

MOVWF TXSTA ;8-bit asyn. high-speed transmission

BANKSEL RCSTA ;select bank 0

MOVLW b’10010000’

MOVWF RCSTA ;8-bit asyn. continuous reception

StartADCandUSART

CALL ADCLight ;call ADCLight subroutine

CALL Send ;call Send subroutine

GOTO StartADCandUSART ;go StartADCandUSART

;SUBROUTINE

ADCLight

BSF ADCON0,GO ;start A/D conversion


Wait

BTFSC ADCON0,GO ;check if A/D conversion is done

GOTO Wait

MOVF ADRES,W ;move ADC data to W

RETURN

Send

BSF STATUS, RP0 ;select bank 1

BTFSS TXSTA, 1 ;check if transmission is available

GOTO Send

BCF STATUS, RP0 ;select bank 0

MOVWF TXREG ;move data to TXREG register

RETURN

END ;end line of the code


Appendix A.3

PIC Assembly Code for Bi-directional Serial Communication

;This code is used to run the light refraction test bed

;1. Generate pulse train to drive servomotor to a desired angle

;2. Turn on the Laser mounted on the arm of the servomotor

;3. Turn on the DC motor

;4. Measure the light intensity and linear position

;5. Convert sensor data into 8-bit A/D and send them to PC

;6. Stop DC motor if the limit switch at the end is pressed

;7. Relocate light sensor to the initial position

LIST p=16f74

INCLUDE “p16f74.inc”

CONFIG CP OFF & WDT OFF & HS OSC & PWRTE ON ;configure PIC16F74

counter EQU 20h ;file address of counter var

iteration EQU 21h ;file address of iteration var

tempval EQU 22h ;file address of tempval var

iter EQU 23h ;file address of iter var

iter1 EQU 24h ;file address of iter1 var

iter2 EQU 25h ;file address of iter2 var

iter3 EQU 26h ;file address of iter3 var

ORG 0 ;origin address is 0

CLRF STATUS ;clear status register

GOTO BootStart ;go to BootStart


BootStart

BANKSEL PORTA ;select bank 0

CLRF PORTA ;clear portA

CLRF PORTB ;clear portB

CLRF PORTC ;clear portC

BANKSEL TRISA ;select bank 1

MOVLW b’00000111’

MOVWF TRISA ;set RA0, 1, and 2 as inputs

MOVLW b’00000000’

MOVWF TRISB ;set PORTB as all outputs

MOVLW b’10000000’

MOVWF TRISC ;set RC7 as input

ADCInitialization

BCF STATUS, RP0 ;select bank 0

MOVLW b’10000001’

MOVWF ADCON0 ;enable ADC and select CH0

BSF STATUS, RP0 ;select bank 1

MOVLW b’00000100’

MOVWF ADCON1 ;set RA0, 1, and 3 to A/D ports

TimerInitialization

BSF STATUS, RP0 ;select bank 1

MOVLW b’00000001’

MOVWF OPTION REG ;set prescaler of TMR0 to 1:4

BCF STATUS, RP0 ;select bank 0

MOVLW b’10000100’

MOVWF INTCON ;enable all unmasked interrupts and TMR0 register overflow

CLRF TMR0 ;clear timer

BaudRateSettingsforUSART
BSF STATUS, RP0 ;select bank 1

MOVLW d’129’

MOVWF SPBRG ;set baudrate 9600 for 20MHz crystal

MOVLW b’00100100’

MOVWF TXSTA ;8-bit asyn. high-speed transmission

BANKSEL RCSTA ;select bank 0

MOVLW b’10010000’

MOVWF RCSTA ;8-bit asyn. continuous reception

MOVF RCREG, W

MOVF RCREG, W

MOVF RCREG, W ;flush reception buffer 3 times

MainProgram

CALL ReceiveAngle ;call ReceiveAngle subroutine

MOVLW 0x64

MOVWF iteration ;save iteration value for pulse train

BeginServo

MOVF tempval, 0 ;move tempval to W

MOVWF counter ;assign user input into counter

LoopHigh

CLRF TMR0 ;clear timer

BSF PORTB, 1 ;set RB1 to high

MOVLW 0x05

InnerLoopHigh

SUBWF TMR0, 0 ;set and countdown timer

BTFSS STATUS, 2 ;check if timer is zero

GOTO InnerLoopHigh ;go to InnerLoopHigh again

BCF STATUS, 2 ;reset zero bit of status

DECFSZ counter ;countdown counter and check if zero


GOTO LoopHigh ;go to LoopHigh

BCF PORTB, 1 ;set RB1 to low

MOVLW 0xfa

MOVWF counter ;set the value of counter for low

LoopLow

CLRF TMR0 ;clear timer

BCF STATUS, 2 ;reset zero bit of status

MOVLW 0x15

InnerLoopLow

SUBWF TMR0, 0 ;set and countdown timer

BTFSS STATUS, 2 ;check if timer is zero

GOTO InnerLoopLow ;go to InnerLoopLow again

BCF STATUS, 2 ;reset zero bit of status

DECFSZ counter ;countdown counter and check if zero

GOTO LoopLow ;go to LoopLow

BCF STATUS, 2 ;reset zero bit of status

DECFSZ iteration ;countdown iteration, check if zero

GOTO BeginServo ;go to BeginServo

TurnLaser

BSF PORTB, 5 ;turn on the laser

TurnMotor

BSF PORTB, 7 ;turn on the DC motor

CALL DelayDCMotor ;call DelayDCMotor subroutine

StartADCandUSART

CALL ADCLight ;call ADCLight subroutine

CALL Send ;call Send subroutine

CALL DelayUSART ;call DelayUSART subroutine

CALL ADCPosition ;call ADCPosition subroutine


CALL Send ;call Send subroutine

CALL DelayUSART ;call DelayUSART subroutine

BTFSS PORTA, 2 ;check if the light sensor is at the end

GOTO StartADCandUSART ;go StartADCandUSART

ReverseDCMotor

BCF PORTB, 5

BCF PORTB, 7 ;stop the DC motor

CALL DelayDCMotor2 ;call DelayDCMotor2 subroutine

BSF PORTB, 6 ;reverse the direction of the DC motor

CALL DelayDCMotor2 ;call DelayDCMotor2 subroutine

CheckInitialPosition

BTFSS PORTA, 2 ;check if the sensor back to the origin

GOTO CheckInitialPosition

Finish

BCF PORTB, 6 ;turn off the laser

GOTO Finish ;finish the program

;SUBROUTINE

ReceiveAngle

BCF STATUS, RP0

BCF STATUS, RP1 ;select bank 0

BTFSS PIR1, RCIF ;check if data is received

GOTO ReceiveAngle

MOVF RCREG, W ;move received data to W

MOVWF tempval ;save data from W into tempval

RETURN

Send

BSF STATUS, RP0 ;select bank 1

BTFSS TXSTA, 1 ; check if transmission is available


GOTO Send

BCF STATUS, RP0 ;select bank 0

MOVWF TXREG ; move data to TXREG register

RETURN

ADCLight

BCF STATUS, RP0 ;select bank 0

MOVLW b’10000001’

MOVWF ADCON0 ;enable ADC and select CH0

CALL Pause ;call Pause subroutine

BSF ADCON0, GO ;start A/D conversion

GOTO Wait ;go to Wait

ADCPosition

BCF STATUS,RP0 ;select bank 0

MOVLW b’10001001’

MOVWF ADCON0 ;enable ADC and select CH1

CALL Pause ;call Pause subroutine

BSF ADCON0, GO ;start A/D conversion

Wait

BTFSC ADCON0, GO ;check if A/D conversion is done

GOTO Wait

MOVF ADRES, W ;move ADC data to W

RETURN

Pause ;short delay

MOVLW 08h

MOVWF iter

Loop1 DECFSZ iter

GOTO Loop1

RETURN
DelayUSART ;delay for USART

MOVLW 0x0a

MOVWF iter1

GOTO Delay

DelayDCMotor ;delay for limit switch in the beginnig

MOVLW 0x1a

MOVWF iter1

GOTO Delay

DelayDCMotor2 ;delay for limit switch at the end

MOVLW 0x3f

MOVWF iter1

GOTO Delay

Delay

Loop2 MOVLW 0xff

MOVWF iter2

Loop3 MOVLW 0xff

MOVWF iter3

Loop4 DECFSZ iter3

GOTO Loop4

DECFSZ iter2

GOTO Loop3

DECFSZ iter1

GOTO Loop2

RETURN

END ;end line of the code


Bibliography

[1] Online: http://www.quanser.com/choice.asp, website of Quanser Consulting Inc.

[2] Online: http://www.quanser.com/english/html/solutions/fs q4.html, website of Quan-

ser Consulting Inc., (access link for Q4).

[3] Online: http://www.ni.com/, website of National Instruments Corp.

[4] Online: http://sine.ni.com/nips/cds/view/p/lang/en/nid/13861, website of National In-

struments Corp., (access link for NI PCI-7831R).

[5] Online: http://www.ni.com/labview/, website of National Instruments Corp., developer

and distributor of LabVIEW.

[6] Online: http://www.mathworks.com/products/matlab/?BB=1, website of MathWorks

Inc., developer and distributor of MATLAB.

[7] S. H. Strogatz, Nonlinear Dynamics and Chaos, Westview Press, Cambridge, MA, 2000.

[8] K. M. Cuomo, V. A. Oppenheim, and S.H. Strogatz, “Synchronization of Lorentz-based

Chaotic Circuits with Application to Communications,” IEEE Transactions on Circuits

and Systems II, vol. 40, pp. 626–633, 1993.

[9] M. Feki, “An Adaptive Chaos Synchronization Scheme Applied to Secure Communica-

tion,” Chaos, Solitons and Fractals, vol. 18, pp. 141–148, 2003.

[10] M. Feki, B. Robert, G. Gelle, and M. Colas, “Secure Digital Communication using

Discrete-Time Chaos Synchronization,” Chaos, Solitons and Fractals, vol. 18, pp. 881–

890, 2003.

[11] S. Hayes, C. Grebogi, and E. Ott, “Communicating with Chaos,” Physical Review Letters,

vol. 70, pp. 3031–3034, 1993.


[12] B. Jovic, C. P. Unsworth, G. S. Sandhu, and S. M. Berber, “A Robust Sequence Synchro-

nization Unit for Multi-User DS-CDMA Chaos-based Communication Systems,” Signal

Processing, vol. 87, pp.1692–1708, 2007.

[13] A. N. Miliou, I. P. Antoniades, S. G. Stavrinides, and A. N. Anagnostopulos, “Secure

Communication by Chaotic Synchronization: Robustness under Noisy Conditions,” Non-

linear Analysys: Real World Applications, vol. 8, pp. 1003–1012, 2007.

[14] L. M. Pecora, T. L. Carroll G. A. Johnson, D. J. Mar, and J. F. Heagy, “Fundamentals

of Synchronization in Chaotic Systems, Concepts, and Applications,” American Institute

of Physics, vol. 7, no. 4, pp. 520–543, 1997.

[15] H. Dedieu, M. P. Kennedy, and M. Hasler, “Chaos Shift Keying: Modulation and De-

modulation of a Chaotic Carrier using Self-Synchronizing Chua’s Circuits,” IEEE Trans-

actions on Circuits and Systems II, vol. 40, no. 4, pp. 634–642, 1993.

[16] S. Tang, H. F. Chen, S. K. Hwang, and J. M. Liu, “Message Encoding and Decoding

through Chaos Modulation in Chaotic Optical Communications,” IEEE Transactions on

Circuits and Systems I, vol. 49, pp. 163–169, 2002.

[17] T. L. Carroll and L. M. Pecora, “Synchronizing Chaotic Circuits,” IEEE Transaction on

Circuits and Systems, vol. 38, pp. 453–456, 1991.

[18] H.-H. Chen, “Global Synchronization of Chaotic Systems via Linear Balanced Feedback

Control,” Chaos, Solitons and Fractals, vol. 186, pp. 923–931, 2007.

[19] L. Fortuna, M. Frasca, and A. Rizzo, “Experimental Pulse Synchronization of Two

Chaotic Circuits,” Chaos, Solitons and Fractals, vol. 17, pp. 335–361, 2003.

[20] G. Grassi and S. Mascolo, “Nonlinear Observer Design to Synchronize Hyperchaotic Sys-

tems via a Scalar Signal,” IEEE Transactions on Circuits and Systems - I: Fundamental

Theory and Applications, vol. 44, pp. 1011–1014, 1997.


[21] G. P. Jiang, W. K. S. Tang, and G. Chen, “A Simple Global Synchronization Criterion

for Coupled Chaotic System,” Chaos, Solitons and Fractals, vol. 15, pp. 925–935, 2003.

[22] R. Kilic, “Experimental Study on Impuslive Synchronization between Two Modified

Chua’s Circuits,” Nonlinear Analysis: Real World Applications, vol. 7, pp. 1298–1303,

2006.

[23] A. I. Lerescu, N. Contandache, S. Oancea, and I. Grosu, “Collection of Master-Slave

Synchronized Chaotic Systems,” Chaos, Solitons and Fractals, vol. 22, pp. 599–604,

2004.

[24] J. H. Park, “Chaos Synchronization of a Chaotic System via Nonlinear Control,” Chaos,

Solitons and Fractals, vol. 25, pp. 579–584, 2005.

[25] L. M. Pecora and T. L. Carroll, “Synchronization in Chaotic System,” Physical Review

Letters, vol. 64, pp. 821–824, 1990.

[26] J. Sun and Y. Zhang, “Some Simple Global Synchronization Criterions for Coupled

Time-Varying Chaotic Systems,” Chaos, Solitons and Fractals, vol. 19, pp. 93-98, 2004.

[27] U. Kocarev and L. Parlitz, “General Approach for Chaotic Synchronization with Ap-

plications to Communication,” Physical Review Letters, vol. 74, no. 25, pp. 5028-5031,

1995.

[28] B. Andrievsky, “Adaptive Synchronization Methods for Signal Transmission on Chaotic

Carrier,” Mathematics and Computers in Simulation, vol. 58, pp. 285–293, 2002.

[29] T.-L. Liao and N.-S. Huang, “Dead-Beat Chaos Synchronization and its Applications to

Image Communications,” IEICE Transactions on Fundamentals, vol. E82-A, no. 8, pp.

1669-1673, 1999.

[30] U. Parlitz and S. Ergezinger, “Robust Communication Based on Chaotic Spreading Se-

quences,” Physics Letters A, vol. 188, pp. 146–150, 1994.


[31] Y. Hatano and M. Mesbahi, “Agreement over Random Networks,” IEEE Transactions

on Automatic Control, vol. 50, no. 11, pp. 1867–1872, 2005.

[32] M. Porfiri and D. J. Stilwell, “Consensus Seeking over Random Weighted Directed

Graphs,” IEEE Transactions on Automatic Control, vol. 52, no. 9, pp. 1767–1773, 2007.

[33] M. Porfiri, D. J. Stilwell, E. M. Bollt, and J. D. Skufca, “Random Talk: Random Walk

and Synchronizability in a Moving Neighborhood Network,” Physica D, vol. 224, pp.

102–113, 2006.

[34] D. J. Stilwell, E. M. Bollt, and D. G. Roberson, “Sufficient Conditions for Fast Switch-

ing Synchronization in Time Varying Network Topologies,” SIAM Journal on Applied

Dynamical Systems, vol. 5, pp. 140–156, 2006.

[35] Online: http://www.microchip.com/1010/index.htm, website of Microchip Technology,

Inc.

[36] Online: http://www.microchip.com/1010/suppdoc/appnote/index.htm, website of Mi-

crochip Technology, Inc., (access link for application notes, code examples, and tem-

plates).

[37] D. W. Smith, PIC in Practice, Newnes, Oxford, U.K., 2003.

[38] M. Predko, Programming and Customizing Picmicro r Microcontrollers, McGraw-Hill,

New York, NY, 2002.

[39] Online: http://www.microchip.com/1010/pline/tools/picmicro/program/picstart/index

.htm, website of Microchip Technology, Inc., (access link for PICSTART Plus Develop-

ment Programmer).

[40] Online: http://www.olimex.com/dev/, website of Olimex Ltd., (access link for PIC-

PG2B Development Programmer).

[41] Online: http://pdfserv.maxim-ic.com/en/ds/MAX220-MAX249.pdf, website of Maxim

Integrated Products, (access link for MAX232 datasheet).


[42] Online: http://mechatronics.poly.edu/smart/, website of Polytechnics NSF funded Re-

search Experience for Teachers project.

[43] Online: http://www.microchip.com/download/lit/pline/picmicro/families/16f7x/30325

b.pdf, website of Microchip Technology, Inc., (access link for PIC16F74 device datasheet).

[44] Online: http://www.mathworks.com/products/simulink/, website of MathWorks Inc.,

developer and distributor of Simulink.

[45] Online: http://www.mathworks.com/products/dialsgauges/, website of The Math

Works, Inc., developer and distributor of Dials and Gauges Blockset (access link for

Dials and Gauges Blockset product information).

[46] C. J. Radcliffe, “The BASIC Stamp II and LabVIEW, ”http://www.parallax.com/dl/

sw/labviewbs2.pdf.

[47] S.-H. Lee, Y.-F. Li, and V. Kapila, “Development of a Matlab-Based Graphical User

Interface for PIC Microcontroller Projects,” Proceedings of the American Society of En-

gineering Education Conference, Salt Lake City, UT, Session 2220, 2004.

[48] Y.-F. Li, S. Harari, H. Wong, and V. Kapila, “Matlab-based Graphical User Interface

Development for BASIC Stamp 2 Microcontroller Projects,” Proceedings of the American

Control Conference, Boston, MA, pp. 3233–3238, 2004.

[49] Online: http://www.olimex.com/dev/pic-pg2.html, website of Olimex Ltd., (access link

for PIC-PG2C Serial Port Programmer).

[50] Online: http://www.ic-prog.com/, website of IC-Prog software.

[51] Online: http://ww1.microchip.com/downloads/en/DeviceDoc/33014J.pdf, website of

MPLAB Integrated Development Environment for the PIC microcontroller programming

(access link for the MPASM assembler user’s guide for PIC microcontrollers).

[52] Online: http://www.ic-prog.com/cmdline.txt, website of IC-Prog software (access link

for the command line programming for PIC microcontrollers).


[53] R. C. Dorf and R. H. Bishop, Modern Control Systems. Addison Wesley, Menlo Park,

CA, 2005.

[54] Online: http://www.advantech.com/, website of Advantech Co.

[55] Online: http://www.parallax.com/Default.aspx?tabid=295, website of Parallax Inc., de-

veloper and distributor of the BASIC Stamp 2 (BS2-IC) microcontroller (access link for

BASIC Stamp product information).

[56] Online: http://www.mathworks.com/access/helpdesk/help/pdf doc/simulink/sl using.

pdf, website of MathWorks Inc., developer and distributor of Simulink (access link for

documentation on Simulink callback functions).

[57] Online: http://www.parallax.com/dl/docs/cols/nv/vol1/col/nv15.pdf, website of Paral-

lax Inc., developer and distributor of the BASIC Stamp 2 microcontroller (access link

for documentation on the RCtime instruction for the BASIC Stamp 2 microcontroller).

[58] Online: http://www.linear.com/pc/downloadDocument.do?navId=H0,C1,C1155,C1001

,C1158,P1484,D3526, website of Linear Technology Corp., developer and distributor of

the LTC1296 A2D (access link for product information).

[59] Online: http://www.parallax.com/dl/docs/prod/motors/stdservo.pdf, website of Paral-

lax Inc., of the BASIC Stamp 2 microcontroller (access link for servo motor product

information).

[60] Online: http://pdfserv.maxim-ic.com/en/ds/MAX536-MAX537.pdf, website of Dallas

Semiconductor Inc., developer and distributor of the MAX537 D2A (access link for prod-

uct information).

[61] Online: http://www.parallax.com/html pages/downloads/tokenizer/tokenizer.asp, web-

site of Parallax Inc., developer and distributor of the PBASIC tokenizer library (access

link for the Parallax tokenizer library and the tokenizer documentation).
[62] Online: http://pdfserv.maxim-ic.com/en/ds/MAX764-MAX766.pdf, website of Dallas

Semiconductor Inc., developer and distributor of the MAX764 DC-DC inverter (access

link for product information).

[63] H. Pan, H. Wong, V. Kapila, and M. S. deQueiroz, “Experimental Validation of a Non-

linear Backstepping Liquid Level Controller for a State Coupled Two Tank System,”

Journal of Control Engineering Practice, Vol. 13, pp. 2740, 2005.

[64] R. N. Bateson, Introduction to Control System Technology, Prentice-Hall, Upper Saddle

River, NJ, 1999.

[65] Online: http://www.quanser.com/english/downloads/products/Specialty/CoupledTan-

ks PIS 031708.pdf, website of Quanser Consulting Inc., developer and distributor of the

coupled water tanks test-bed (access link for product information).

[66] S. Boccaletti, J. Kurths, G. Osipov, D. L. Valladares, and C. S. Zhou, “The Synchro-

nization of Chaotic Systems,” Physics Reports, vol. 366, pp. 1–101, 2002.

[67] G. Chen and X. Yu (Eds.), Chaos Control Theory and Applications, Lecture Notes in

Control and Information Sciences, vol. 292, Springer, Berlin, 2003.

[68] J. M. Gonzalez-Miranda, Synchronization and Control of Chaos, Imperial College Press,

London, 2004.

[69] S. Camazine, W. Ristine, and M. E. Didion, Self-Organization in Biological Systems,

Princeton University Press, 2003.

[70] J. Buck and E. Buck, “Synchronous Fireflies,” Scientific American, vol. 234, p. 74, 1976.

[71] J. J. Collins and I. Stewart, “Coupled Nonlinear Oscillators and the Symmetries of

Animal Gaits,” Science, vol. 3, pp. 349–392, 1993.

[72] J. Honerkamp, “The Heart as a System of Coupled Nonlinear Oscillators,” Journal of

Mathematical Biology, vol. 19, pp. 69–88, 1983.


[73] T. I. Netoff and S. J. Schiff, “Decreased Neuronal Synchronization during Experimental

Seizures,” Journal of Neuroscience, vol. 22, pp. 7297–7307, 2002.

[74] Y. Kuramoto, Chemical Oscillations, Waves and Turbulence, Springer, Berlin, 1984.

[75] J. Ohtsubop, “Feedback Induced Instability and Chaos in Semiconductor Lasers and

Their Applications,” Optical Review, vol. 6, no. 1, pp. 1–15, 1999.

[76] J. A. Fax and R. M. Murray, “Information Flow and Cooperative Control of Vehicle

Formations,” IEEE Transactions on Automatic Control, vol. 49, no. 9, pp. 1465–1476,

September 2004.

[77] Z. Ge and Y. Chen, “Synchronization of Mutual Coupled Chaotic Systems via Partial

Stability Theory,” Chaos, Solitons and Fractals, 2007.

[78] S. Tsay, C. Huang, D. Qiu, and W. Chen, “Implementation of Bidirectional Chaotic Com-

munication Systems Based on Lorenz Circuits,” Chaos, Solitons and Fractals, vol. 20,

no. 3, p. 56779, 2004.

[79] Y. Yu and S. Zhang, “The Synchronization of Linearly Bidirectional Coupled Chaotic

Systems,” Chaos, Solitions and Fractals, vol. 22, p. 189197, 2004.

[80] M. Haeri and B. Khademian, “Comparisons between Different Synchronization Methods

of Identical Chaotic Systems,” Chaos, Solitons and Fractals, vol. 29, pp. 1002–1022, 2006.

[81] M. Arcak and D. Nesic, “A Framework for Nonlinear Sampled-Data Observer Design via

Approximate Discrete-Time Models and Emulation,” Automatica, vol. 40, no. 11, pp.

1931–1938, 2004.

[82] S. Boyd, L. El-Ghaoui, E. Feron, and V. Balakrishnan, Linear Matrix Inequalities in

System and Control Theory, Philadelphia, PA, 1994.

[83] H. Peitgen, H. Jurgens, and D. Saupe, Chaos and Fractals, Springer-Verlag, New York,

NY, 1992.
[84] Online: http://www.parallax.com/, website of Parallax, Inc.

[85] Online: http://www.parallax.com/detail.asp?product id=32100, website of Parallax,

Inc., (access link for Propeller Demo Board).

[86] Online: http://www.parallax.com/detail.asp?product id=27985, website of Parallax,

Inc., (access link for 912 MHz RF Transceiver).

You might also like