Development of a wireless sensor unit for tunnel monitoring by Sivaram M.S.L. Cheekiralla Bachelor of Technology, Civil Engineering (2001) Indian Institute of Technology, Bombay Submitted to the Department of Civil and Environmental Engineering in partial fulfillment of the requirements for the degree of Master of Science in Civil and Environmental Engineering at the MASSACHUSETTS INSTITUTE OF TECHNOLOGY February 2004 © Massachusetts Institute of Technology 2004. All rights reserved. A uth o r ......................... ; .. ............................. Department of Civil and Environmental Engineering January 16, 2004 Certified by... ....... . . .~~ . .. . . . . . . . . . . . . . . . . . . . . . . j. . Ruaidhri M. O'Connor Assistant Professor The is Supervisor (I1/1 it Accepted by ...................... ,..... ............ .... ... Heidi M. Aepf Chairman, Department Committee on Graduate Students MASSACHUSETTS INSTITE OF TECHNOLOGY FEB 19 2004 LIBRARIES BARKER 2 Development of a wireless sensor unit for tunnel monitoring by Sivaram M.S.L. Cheekiralla Submitted to the Department of Civil and Environmental Engineering on January 16, 2004, in partial fulfillment of the requirements for the degree of Master of Science in Civil and Environmental Engineering Abstract In this thesis we describe the development of a wireless sensor module for tunnel monitoring. The tunnel in question is a part of the London Underground system. Construction of a new tunnel beneath the existing tunnel is anticipated to cause quantifiable vertical displacement. To ensure safe operation of the tunnel during the construction activity, a real-time monitoring system has been created to measure vertical displacements along the critical zone near Highbury & Islington station. A geomechanical analysis, provided by a third party, is used to establish the allowable maximum displacement. A custom wireless sensor module was developed from off-the-shelf components. This module consists of a sensor device, microcontroller, ADC and RF transmitter. The integration of these components is described in detail. Deployment details and some preliminary results are presented. Thesis Supervisor: Ruaidhri M. O'Connor Title: Assistant Professor 3 4 Acknowledgments First of all, I would like to thank Prof. Rory O'Connor for his support. His words of encouragement during tough times were really motivating. I am grateful to him for being my advisor. James Brooks has been a great person to work with. Most of this work has been done with him. His keen insights for solving problems are really inspiring. I appreciate his patience during the tough times we had during this project. I also thank him for listening to some of my fancy suggestions and actually implementing some of them! I would also like to thank all the members of the CMI team. I am thankful to Prof. Whittle and Dr. Germaine for their constructive criticism and useful suggestions during the course of this project. Special thanks to Prof. Amaratunga and George Kokossalakis for their help and support for my qualifying exams. I am thankful to my friends Hari, Phani, Deepak, Dhanush, Sreekar, Bhanu, Dinesh and Srini for all their support and encouragement. Special thanks to Kunal Kunde and Murthy for all the help over the years. I am thankful to my relatives for providing me a homely environment whenever I felt home-sick. Special thanks to Manasa and Jyotsna. I would like to thank my parents, brother and grandmother for all their love, support and encouragement. I would like to dedicate this thesis to my late friend Hari Narayan Sugavanam. This research was sponsored by the The Cambridge MIT Institute's New Technologies for Condition Assessment and Monitoring of Ageing Infrastructure project. 5 6 Contents 1 Introduction 1.1 M otivation . . . . . . . . . . . . . . . . . . . . . . . . . 15 1.2 Wireless monitoring . . . . . . . . . . . . . . . . . . . . 16 1.2.1 Great Duck Island project . . . . . . . . . . . 18 1.2.2 Wireless Modular Monitoring Systems (WiMMS) 18 1.3 1.4 2 15 LUL tunnel monitoring project . . . . . . . . . . . . .. 21 1.3.1 Other Methods . . . . . . . ........... 23 1.3.2 Proposed Method . . . . . . . . . . . . . . . . . 23 Present work . . . . . . . . . . . . ........... 25 Sensors 27 2.1 Sensors.. ......... 2.2 Accelerometers . . . . . . . . 27 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 2.2.1 Sensing Method . . . . . . . . . . 28 2.2.2 Capacitive accelerometers . . . . 29 2.2.3 Piezoelectric accelerometers . . . 29 2.2.4 Potentiometric accelerometers . . 29 2.3 Strain gages . . . . . . . . . . . . . . . . 30 2.4 Linear Variable Differential Transformer 30 2.5 Sensors used in the tunnel monitoring proj ect 31 2.5.1 Pressure transducers . . . . . . . 31 2.5.2 Ultrasonic transducers 32 2.6 . . . . . . MEMS 36 7 2.6.1 3 3.2 3.3 3.4 41 41 . . . . . . . . . . . . . . . . . . . . . . . . . 43 3.1.1 Clocking scheme 3.1.2 Memory Organization . . . . . . . . . . . . . . . . . . . . . . 44 3.1.3 Pin Description . . . . . . . . . . . . . . . . . . . . . . . . . . 46 Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 Universal Synchronous Asynchronous Receiver Transmitter (US- ART) module . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 3.2.2 Analog to Digital Converter . . . . . . . . . . . . . . . . . . . 48 3.2.3 Master Synchronous Serial Port (MSSP) module . . . . . . . . 49 3.2.4 Timer and interrupt features . . . . . . . . . . . . . . . . . . . 49 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 3.3.1 Programming in assembly language . . . . . . . . . . . . . . . 50 3.3.2 Programming in C . . . . . . . . . . . . . . . . . . . . . . . . 51 Operation of the microcontroller . . . . . . . . . . . . . . . . . . . . . 51 Instruction Set 53 Communications 4.1 4.2 38 A rchitecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.2.1 5 . . . . . . . . . . . . . . . . . . . . . . . . Microcontroller 3.1 4 Fiber optic sensors Wire-based systems . . . . . . . . . . . . . . 53 4.1.1 Synchronous serial communications 53 4.1.2 Asynchronous serial communications 55 4.1.3 Bit-banging . . . . . . . . . . . . . . 58 Wireless Technologies . . . . . . . . . . . . . 59 4.2.1 MICA motes . . . . . . . . . . . . . 61 4.2.2 i-Beans . . . . . . . . . . . . . . . . . 62 4.2.3 Linx Technologies RF ICs . . . . . . 64 67 Integration of components 5.1 Interfacing the ADC . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 5.2 Interfacing the i-Bean . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 8 6 5.3 Interfacing the ultrasonics 5.4 Others . . . . . . . . . . . . . . . . .. 82 5.5 Sensor Board . . . . . . . . . 84 5.6 Protocols . . . . . . . . . . . . . . . . 86 5.7 Protocol for i-Bean . . . . . . . . . . . 87 5.8 Protocol for the Ultrasonic transducer 88 . . . .. . . . . . . . 78 Summary 91 6.1 Sum m ary 6.2 Directions for future research 6.3 ................ 91 . . . . . 93 6.2.1 Wireless technology . . . . . . . 93 6.2.2 Hardware . . . . . . . . . . . . 95 6.2.3 Operating system . . . . . . . . 96 Conclusions . . . . . . . . . . . . . . . 96 A Configuration details for ultrasonic transducer using HE860 97 B Sample microcontroller program in assembly language and in C 99 B.1 Program in assembly language . . . . . . . . . . . . . . . . . . . . . B.2 Program in C ..... ............. ..... .... ... .. C Latest version of the microcontroller code C.1 Code to interface the ultrasonics . . . . . . . . . . . . . . . . . . . . D ASCII version of CMI Communication Protocol 9 99 103 105 121 125 10 List of Figures 1-1 Architecture diagram for the wireless sensor network deployed on the Great D uck Island [53]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 1-2 Figure showing the MICA mote in an enclosure [53]. . . . . . . . . . . . 20 1-3 Figure showing the prototype sensing unit for WiMMS [37]. . . . . . . . . 21 1-4 Figure showing a tunnel boring machine used in the CTRL project [13]. 22 1-5 Planned sensor installation in the tunnel. . . . . . . . . . . . . . . . . . 25 1-6 Figure showing the layout of the wireless sensors to measure pressure . . . 26 2-1 Simplified model of an accelerometer [23]. . . . . . . . . . . . . . . . . . 28 2-2 Figure showing the parts of an LVDT [36]. . . . . . . . . . . . . . . . . . 31 2-3 The MPX2200AP pressure transducer [49]. . . . . . . . . . . . . . . . . 33 2-4 HE860 positioning device and HE 240 transducer head [25]. . . . . . . . . 34 2-5 E-152, ultrasonic transducer from Massa corporation [40]. . . . . . . . . . 35 2-6 Figure showing a MEMS accelerometer [3]. . . . . . . . . . . . . . . . . 37 2-7 Figure showing a fiber optic strain gage [59].. . . . . . . . . . . . . . . . 40 3-1 Block diagram of Harvard and Neumann architectures. 3-2 Pin diagram of PIC16F877 [45]. 4-1 Figure showing the data pulses for sending the character 'U' at a baud rate of 9600........... . . . . . . . . . . 42 . . . . . . . . . . . . . . . . . . . . . . 46 .................................... 60 4-2 a) figure showing the MICA processor board and b) MICA sensor board [12]. 61 4-3 Figure showing i-Beans and the base station. 4-4 . . . . . . . . . . . . . . . Linx RM series a)transmitter [34] b) receiver [33]. 11 . . . . . . . . . . . . 63 64 5-1 Pin diagram of AD7713 [4]. . . . . . . . . . . . . . . . . . . . . . . . . 68 5-2 Interfacing the ADC with the microcontroller. . . . . . . . . . . . . . . . 70 5-3 Timing diagram for writing data to the ADC [4]. . . . . . . . . . . . . . 72 5-4 Timing diagram for reading data from the ADC [4]. . . . . . . . . . . . . 74 5-5 Interfacing the i-Bean with the microcontroller. . . . . . . . . . . . . . . 76 5-6 Timing diagram for the i-Bean provided by Millennial Net, Inc. . . . . . . 77 5-7 Figure showing the interface between microcontroller and the ultrasonic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 5-8 Figure showing the ultrasonic transducers in boxes. . . . . . . . . . . . . 82 5-9 Graph of the calibration experiment. . . . . . . . . . . . . . . . . . . . . 83 5-10 Schematic of the sensor board. . . . . . . . . . . . . . . . . . . . . . . . 85 5-11 Figure showing the sensor board and the wireless sensor unit. . . . . . . . 86 6-1 Figure showing the installed sensors in the tunnel. . . . . . . . . . . . . . 92 6-2 Figure showing the receiving unit and the laptop placed in the access shaft transducers. 6-3 of the tunnel. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 Summary of the wireless sensor operation. . . . . . . . . . . . . . . . . . 94 12 List of Tables 5.1 Table showing the timing constraints provided by Millennial Net, Inc. A. 1 Table showing the Configuration String . 75 . . . . . . . . . . . . . . . . . . 97 A.2 Table showing the bits of the PCB for a Beacon . . . . . . . . . . . . . . 98 A.3 Table showing the bits of the PCB for a Pilot . . . . . . . . . . . . . . . 98 13 . 14 Chapter 1 Introduction 1.1 Motivation Infrastructure 1 monitoring can be defined as the use of sensor technologies to characterize a system's condition, performance or response. Civil infrastructure undergo a lot of changes in their structural and serviceability characteristics over time. Some of the common reasons for these changes are degradation of material properties, adverse loading and climatic conditions, improper maintenance, etc. These changes may be gradual over time or can be sudden due to events like earthquakes. In order to ensure safety to the public; rehabilitation, retrofit and repair of the infrastructure becomes necessary. To establish the need for maintenance, the existing state of the structure needs to be known for applying the techniques mentioned above. Apart from the safety issue, economic factors are also important. "Civil infras- tructure systems are generally the most expensive investments/assets in any country (an estimated $ 20 trillion in the United States) and these systems are deteriorating at an alarming rate" [11]. For example, in the United States itself, nearly 50% of the bridges were built before the 1940's. A survey in 1996 showed that 42% of the bridges are functionally deficient or obsolete and the cost of correcting all of these 'The word infrastructure here refers to Civil infrastructure such as buildings, bridges, tunnels, etc. 15 deficient bridges exceeds 90 billion dollars [41]. The nationwide maintenance cost for civil infrastructure is estimated at 1.4 trillion dollars [24]. These figures show that there is a strong necessity to evaluate the state of the existing infrastructure. The state of the infrastructure can be predicted or estimated by monitoring and other Non Destructive Evaluation (NDE) methods. A review of different methods for structural health monitoring can be found here [14]. Monitoring also helps in understanding the structure's performance and in studying the structural response during hazardous or other events which might affect the performance of the structure. Another scenario for infrastructure monitoring is the concept of I-city. "The concept of I-city, envisages an entire metropolis linked to a web-based monitoring system" [58]. With the availability of cheap computing power and advances in sensor technology, the concept of I-city is much more feasible. Again, the chief task in envisaging such a concept is monitoring. These are just some of the reasons for structural monitoring. The goal of this thesis is to explain the different components of a wireless sensor unit, which can be used for wireless infrastructure monitoring. A specific example of a wireless sensor unit is described in this thesis. This sensor unit is currently being used to monitor the behavior of an aging underground train tunnel system in London, UK. 1.2 Wireless monitoring Wireless infrastructure monitoring makes use of wireless sensor technologies. Wireless sensors use wireless communications as a means to transmit data to and from a base station or for inter-sensor communication. Most (if not all) of the monitoring systems existing in Civil Engineering are wire-based systems. The primary purpose of the wires is for data communications, and may also be used for powering the sensors. Some of the important limitations of wire-based systems are: 1. It can be difficult to instrument an existing structure with a wire-based monitoring system. This is because of the practical difficulties associated with laying out wires in an existing structure. Accessibility for laying out wires, and shield16 ing for the wires are major issues. For outdoor installations, the wires need additional shielding from the harsh weather conditions. 2. Wire-based systems are expensive because of the initial cost associated with laying out the wires and the maintenance costs associated with the system. To install a wire-based system, installing the wires alone be approximately 25% of the total system cost and 75 % of the installation time focussed solely on the installation of system wires [37]. 3. Wire-based systems require additional architectural and engineering design to incorporate wires unobtrusively. Wireless systems, to a great extent, are devoid of the above mentioned problems. Wireless monitoring systems also have the added advantage of being modular. They can be moved to new locations as needed. The availability of low-powered and cheap computing power (microcontrollers, Digital Signal Processing (DSP) chips, etc.), Radio Frequency (RF) Integrated Circuits and the development of new wireless standards has fueled a lot of interest in wireless sensor systems. Wireless sensor technology is listed as one of the promising ten technologies of the future [60]. A wide variety of research areas related to wireless sensors have emanated. These include development of new energy-efficient wireless networking algorithms, real-time distributed sensing and control, routing protocols for sensor networks, etc. On the application side, a lot of research is being done in the use of wireless sensor systems for structural and environment monitoring. In structural monitoring, wireless sensors are used for sensing structural integrity during and after an earthquake [20], developing modular systems for monitoring bridges and buildings [38]. In environmental monitoring, wireless sensors are used for monitoring rare and endangered species of plants [54], wild life habitats [22], vineyards [63], etc. In the next couple of sections, a few of these applications are described. 17 1.2.1 Great Duck Island project The Great Duck Island habitat monitoring project is a testbed for wireless sensor network technologies. The wireless sensors used are a custom version of the MICA motes2 (which are discussed in chapter 4 of this thesis). Great Duck Island lies near Desert Island, Maine. It approximately contains 5000 pairs of petrels '. The goal of this project is to study the petrel usage pattern of nesting burrows and to monitor the environmental changes during the breeding season. One of the primary requirement of the sensor system was that it should be non-invasive [53]. Presently, around 50 weather motes (for monitoring weather) and around 70 burrow motes (to monitor temperature, humidity, etc. of the burrows) are deployed. A specially manufactured weather board was used for this project. This sensor board contains photo-resistor (for light), temperature, barometric pressure, humidity and passive infrared sensors (for occupancy). Figure 1-2 shows the MICA mote with its enclosure. The enclosure is designed for robustness and minimum disruption in the functionality of the mote. Figure 1-1 shows the architecture diagram for the monitoring project. More information about this project and live sensor data can be found at the following site [22]. 1.2.2 Wireless Modular Monitoring Systems (WiMMS) The WiMMS group at Stanford University is concentrating on the development of low-cost modular structure monitoring systems. The focus is also on using a de- centralized approach for monitoring. In a centralized approach, all the sensors report to a base station 4. The base station is the unit which is responsible solely for taking decisions, collecting data, etc. Sensors in this modality usually don't communicate among themselves. In a de-centralized approach, the sensors have some intelligence and they can communicate with other sensors and make autonomous decisions if 2 MICA motes are a compact wireless sensor module developed by University of California, Berkeley and now sold commercially by Crossbow Technology, Inc. 3 A petrel is a kind of seabird. 4 The base station need not be a sensor. It is usually a receiving unit connected to a PC or a laptop. 18 Figure 1-1: Architecture diagram for the wireless sensor network deployed on the Great Duck Island [53]. necessary [37]. The WiMMS group have developed a wireless sensing unit which has a MEMS 5based accelerometer, a wireless modem, a 16-bit Analog to Digital Converter (ADC) and a computational core consisting of a 8-bit microcontroller. Figure 1-3 shows the prototype sensing units. The group also has developed another sensing unit that has the additional computational power of a 32-bit microcontroller. This increased power of the microcontroller allows computation to calculate estimates for damage detection using statistical time-series algorithms. Damage detection is predicted from the frequency response of the structure. The validation of the sensing unit was performed on the Almosa Canyon Bridge [39] 5 Micro Electro-Mechanical Systems. 19 ... .... .... . Figure 1-2: Figure showing the MICA mote in an enclosure [53]. The positive thing about these monitoring applications is that the research community is actively interested in using the latest technology to solve some of the problems in structural and environmental monitoring. Also, these applications serve as good educational tools. Students can learn how complex systems behave in the real world. A good example of such a project is the flagpole project at MIT. A virtual laboratory was developed as a part of this project. The virtual laboratory was created to " enhance the comprehension of concepts in structural dynamics, sensor technology and signal processing using a real-world structural system as a laboratory model" [58]. The complex nature of civil engineering systems makes it difficult to develop monitoring systems which are more practical and useful. Also, the heterogeneous nature of the infrastructure means each application is different from the other. Therefore, 20 Figure 1-3: Figure showing the prototype sensing unit for WiMMS [37]. wireless systems should be designed based on the application rather than designing for a generic application. Thus, for the tunnel monitoring project, a new wireless sensor system had to be developed. Some of the reasons for this design are discussed in the subsequent chapters of this thesis. In the next section, the London Underground Limited tunnel monitoring project is described. 1.3 LUL tunnel monitoring project The core of this thesis describes the design and development of a wireless sensor unit, to be used in a tunnel monitoring application. The wireless sensor unit is intended for deployment in a section of the London underground tunnel system during a disruptive construction activity. The construction activity being the construction of a new tunnel below the existing and operational London underground tunnel. The new tunnel is being bored using a Tunnel Boring Machine (TBM, see figure 1-4). Due to the removal of material to accommodate the TBM movement, some displacement in the existing tunnel is expected. These displacements should not exceed the critical value that forces the tunnel to be shutdown. The goal of this project is to use wireless 21 technology to measure these displacements in real-time. An additional objective is to evaluate the potential of wireless technology for monitoring applications. The new tunnel that is being constructed is a part of the Channel Tunnel Rail Link (CTRL) Project. The CTRL is a high speed line running for 109 km between St. Pancras station in London and the Channel Tunnel. This project is being constructed in two sections named Section I and Section II. Section I was opened and became operational in September 2003, while Section II is expected to be completed by the end of 2006. The new tunnel is a part of the work comprising of construction of twin 7.5 km bored tunnels from Stratford station to King's Cross station [13]. The existing tunnel's diameter is around 12 ft and is a section of the Victoria Line (Northbound). The nearest station to the tunnel section of interest is Highbury & Islington. The new tunnel will be perpendicular to the existing tunnel. See figure 1-5 Figure 1-4: Figure showing a tunnel boring machine used in the CTRL project [13]. 22 1.3.1 Other Methods A recently established method to monitor displacements due to excavation makes use of electrolevels. This method is also used for monitoring the section of the tunnel where the wireless sensor system will be deployed [28]. An electrolevel is a " robust, stable, gravity referenced tilt transducer" [15]. Tilt can be thought of as being synonymous with slope. Electrolevels are used for measuring the distortion and alignment of various parts of a structure [15]. Using electrolevels is one of the ways of to measure displacements vertically in the direction of the tunnel. The tilts are integrated over length to get vertical displacements in the direction of the tunnel. This method has the following disadvantages. " Errors get accumulated over the distance and are also exacerbated through the integration process. " System is not redundant in the sense that if one of the electrolevels fail, all subsequent electrolevels become disconnected from the absolute reference frame. Another potential way of measuring these displacements is to use fiber optics. The research group at the Department of Civil Engineering, The University of Birmingham, UK is studying the use of fiber optic sensors for tunnel monitoring. The goal is to develop a remote system for measuring tunnel settlement, distortion and rotation of tunnels. Their current research is focused on developing a test rig for simulating tunnel movements and measuring them using fiber optic sensors and strain gages [17]. Some of the limitations aforementioned are reduced by the wireless tunnel monitoring scheme proposed below. 1.3.2 Proposed Method The two critical values that need to be measured continuously in this project are the vertical displacements along the length of the tunnel and the transverse deformation at the section where the tunnel is directly undercut by the TBM. This section is the critical section. These displacements are calculated in the following manner. 23 1. Vertical displacements along the length of the tunnel: Measurements of the relative change in the absolute pressure in a fixed hydraulic line are used for calculating these displacements. The hydraulic line is laid out along the length of the section of a tunnel (around 50 m of length) and is connected to a fixed reservoir at a known reference location (in this case, this is the access shaft of the tunnel). The relative (with respect to a fixed point) pressure variation in the tube is then proportional to the vertical displacement. Absolute pressure at a few points along the length of the tunnel is measured using pressure transducers. The absolute pressure is measured with respect to the fixed reservoir. This is depicted in figure 1-6. At these points, the boxes containing the sensor boards are fixed. These points are approximately placed every 5 meters. The sensor farthest from the construction activity is assumed 6 to be the fixed point and is used as a reference for calculating the displacements. After taking the pressure measurements, these data are sent wirelessly over to the base station. Temperature is also measured on the sensor board to correct the pressure transducer measurements for temperature. These adjustments are based on calibration data previously determined in a controlled laboratory setting. 2. Transverse deformation at the critical section: Two ultrasonic transducers facing each other are to be installed in the tunnel for calculating the transverse displacements at the critical section. The transducers measure the time of flight for an acoustic signal between the pair and use this measurement to calculate the distance between them. Any change in the transducer measurements indicate movement of the transducers or deformation at the critical section '. After the distance between the two transducers is calculated, the distance readings are sent wirelessly to the base station. Figure 1-5 shows how the sensors are to be installed in the tunnel. 6 This point is assumed to be fixed. If this point moves, the displacements calculated will be relative to the displacement of this fixed point. 7 This change in transducer measurements could be also due to a change in temperature, pressure relative humidity etc. Calibration for these factors is also necessary. Only preliminary calibration has been performed to date, and additional benchmarking remains necessary for accurate measurement. 24 Critical Section 50 m (monitoring distance) 12 ft Highbury &Islington Nearest Station (Circle Line) loin D) 10 Hydraulic Line & Wireless Sensor Node Ultrasonic Transducer Channel Tunnel Rail Link (CTRL) Figure 1-5: Planned sensor installation in the tunnel. The proposed scheme is considered better than that of the electrolevels for the following reasons: " The system is redundant in the sense if one of the pressure transducers fail, it is still possible to calculate displacements. Although, if the hydraulic line breaks, the system also fails. " It is easier to install this system. * It is relatively cheaper and reusable for other similar applications. 1.4 Present work In this thesis, a detailed discussion of the different components of a wireless sensor unit for infrastructure monitoring and integration of these components to construct the wireless sensor unit are presented. Chapter 2 discusses the various sensors that are commonly used in civil infrastructure monitoring and then talks about the sensors used in this project. 25 Reservoir () Pressure sensor with RF module Hydraulic Line Figure 1-6: Figure showing the layout of the wireless sensors to measure pressure Chapter 3 discusses microcontroller architectures and specifically PIC16F877, which has been used in this project. The architecture, memory details and other relevant features of this microcontroller are explained. Chapter 4 discusses the various forms of communication arising in this project. In particular this chapter addresses synchronous and asynchronous (wire-based communications) communication standards and some relevant wireless technologies that have been tested during the course of this project. Chapter 5 describes how the various components were integrated so as to construct the wireless sensor unit. Chapter 6 summarizes the thesis and states the directions for future research. 26 Chapter 2 Sensors This chapter gives a brief overview of some sensor types used for various monitoring applications. These include the accelerometer, strain gage and Linear Variable Differential Transformer (LVDT). Following this, a brief overview of the sensors used for the tunnel monitoring project is given. In the later sections a brief discussion on MEMS and fiber optic sensors follows. 2.1 Sensors A sensor is a device which measures a physical quantity. Sensors are typically used for measuring the parameters which affect a system's state. Common examples include temperature sensors, pressure sensors, etc. For monitoring applications, sensors provide the data by measuring various physical parameters over time. A transducer is a subset of a sensor; a transducer converts the physical quantity measured into an electrical signal proportional to the value of the measured physical parameter [50]. The electrical output of the transducer (which is an analog signal) can be digitized and can be processed using a microcontroller or a Digital Signal Processing (DSP) chip. To convert an analog signal to a digital signal, an Analog to Digital Converter (ADC) is typically used. In the next couple of sections, a brief description of some of the more commonly used sensors in monitoring applications for Civil Engineering systems is given. These 27 are accelerometers, strain gages and LVDT. 2.2 Accelerometers As the name suggests, accelerometers or acceleration transducers measure acceleration. Measures of acceleration can also be interpreted to detect tilt, vibration and shock [50]. Linear acceleration is measured in m/s 2 , or often expressed in terms of g's, where g is the gravitational constant. The standard value of g is 9.81m/s 2 . There are many types of accelerometers and a few of which are discussed below. 2.2.1 Sensing Method Accelerometers use a "sensing method in which the acceleration acts upon a seismic mass (proof mass) that is restrained by a spring and whose motion is usually damped in a spring-mass system" (figure 2-1). Acceleration is proportional to the distance moved by the proof mass from its reference position [23]. Spring Damper Mass Figure 2-1: Simplified model of an accelerometer [23]. 28 2.2.2 Capacitive accelerometers In this type of accelerometers, the proof mass is a freely suspended electrode, which moves with respect to a fixed electrode or stator plate. When acceleration is applied, the distance between the electrodes change and this changes the capacitance. This change in capacitance measured is proportional to the value of the acceleration [50]. 2.2.3 Piezoelectric accelerometers The basic principle of these accelerometers is piezoelectric transduction. The proof mass is connected to a piezoelectric crystal. The piezoelectric crystal is pre-loaded and this loading changes whenever acceleration is experienced. This changes the electrical output of the piezo-material. This gives a relative measure of the acceleration. Typical piezoelectric materials include quartz crystals, Barium Titanate, etc. Piezoelectric transducers usually have a low output signal and very high output impedance. This requires the use of amplifiers which not only magnify the signal, but also act as impedance converters [50]. 2.2.4 Potentiometric accelerometers These accelerometers can be produced at a relatively low cost, have moderate, but acceptable accuracy and a limited frequency range. The displacement of the springmass system causes a displacement of a potentiometric element '. This change in resistance is measured to get the value of the acceleration. Details about other types of accelerometers can be found at [50] and [23]. In the next section, strain gages are discussed 1 Potentiometric element has a potentiometer and the resistance of this element changes because of the displacement. 29 2.3 Strain gages Strain is defined as "the ratio of dimensional change to the total value of the dimension in which the change occurs" [50]. Since strain is dimensionless (as it is a ratio of two physical quantities having the same units), there is no specific unit for strain. It is usually measured in percent or microstrain. Strain is usually measured using piezoresistive materials. Piezoresistive substances undergo a change in their resistance when a stress is applied. Stress is related to strain by the modulus of elasticity, and is defined as the ratio of stress to strain. The sensitivity of a strain gage is measured by the gage factor which is defined as the ratio of unit change in resistance to the ratio of unit change in length. GageFactor,GF =AR/R = AR/R AL/L C The resistance change of a strain gage is converted into voltage using a Wheatstone bridge [50]. Details about different kinds of strain gages can be found at [50] and [23]. 2.4 Linear Variable Differential Transformer Linear Variable Differential Transformer (LVDT) is used for measuring displacement. The absence of physical contact of the sensing element gives the LVDT a high degree of robustness [35]. The LVDT consists of one primary and two secondary magnetic coils and a magnetic core. In its null position, the magnetic field in the two secondary coils gets canceled. Hence, at its null position, the output of a LVDT is zero volts. When the magnetic core is displaced, there is be an imbalance in the electromagnetic field in the two secondary coils. This imbalance in electromagnetic field causes a differential output voltage that is proportional to the displacement and the direction of displacement. Apart from being a very rugged instrument, an LVDT has a high resolution [36]. Figure 2-2 shows the different parts of an LVDT. In the next section the sensors used in the London underground tunnel project are discussed. 30 COIL WINDING ASSEMBLY MAGNETIC CORE ELECTROMAGNETIC SHIELDING CYLINDRICAL CASE Figure 2-2: Figure showing the parts of an LVDT [36]. 2.5 Sensors used in the tunnel monitoring project The sensors used in the tunnel monitoring project are the pressure transducer and the ultrasonic transducers. Though ultrasonic transducers haven't yet been installed in the tunnel, they are described for completeness. It is anticipated that the ultrasonics will be deployed in future monitoring projects. 2.5.1 Pressure transducers Pressure transducer measurements could be absolute (i.e. with reference to a vacuum or zero pressure) or relative (with respect to atmosphere). Pressure transducers are widely used in pressure control systems, flow measurement systems, vehicle air bag deployment, etc [50]. There are different types of pressure transducers. Com- mon types are piezoelectric pressure transducers, strain-gage pressure transducers, 31 capacitive pressure transducer, etc. Information about different types of pressure transducers can be found here [50]. The pressure transducer used in the project is the MPX2200AP from Motorola Corporation (shown in figure 2-3). This pressure transducer is a silicon piezoresistive sensor. A piezoresistive substance changes its resistance when it is stressed. In a piezoresistive transducer, when there is a change in pressure at the input of the transducer, the stress on the piezoresistive material also changes and hence its resistance. This change in resistance is usually detected as a differential voltage across a bridge circuit. Some of the advantages of using a mono-crystalline semiconductor as the piezoresistive element are: * "High sensitivity > 10 mV/V" [52]. 0 "Good linearity at a constant temperature" and the "ability to track pressure changes without hysteresis" [52]. Some of the disadvantages are large initial offset, strong non-linear dependence on temperature and strong drift with temperature. These can be compensated with proper electronic circuitry. More details can be found here [52]. The MPX2200AP measures absolute pressure (i.e. or zero pressure). with reference to a vacuum It has a good linearity (±0.25 % linearity) and is temperature compensated over the range of 00 C to 85 C. Other details of this transducer could be found here [49]. The differential outputs of the transducer are connected to an ADC. The ADC converts the analog output of the transducer to digital format. The digital output from the ADC is collected by the microcontroller. These details are discussed in Chapter 5. In the next section, the ultrasonic transducers are discussed. 2.5.2 Ultrasonic transducers Ultrasonic waves are those sound waves whose frequency is greater than 20 kHz. Ultrasonic transducers can be classified into two kinds. They are: 32 Figure 2-3: The MPX2200AP pressure transducer [49]. " Magnetostrictive transducers, which are mainly used in ultrasonic cleaning baths (used by watchmakers and in the electronics industry) [57]. " Piezoelectric transducers, they have low power consumption than the magnetostrictive transducers and are used in security devices etc. [57]. There are two important parameters related to ultrasonic transducers. They are beam spread and target angle. Beam spread defines the maximum spreading of the ultrasonic sound beam from the transducer. The target angle measures the maximum amount by which the target can be tilted and still be detected by the ultrasonic transducer [57]. Ultrasonic transducers are used to calculate distances by using the time of flight principle. The precision of ultrasonic transducer system allows it to be used to measure small movements (< 1 mm) [25]. The idea of using ultrasonic transducers is to measure deformations at the critical section. That is, the cross-section of the tunnel below which the tunnel boring machine will pass. This is where the largest vertical 33 displacement and related deformation of the tunnel liner occur. The deformations might be in the order of 2 mm or less [56]. The original idea was to place ultrasonic transducers along the circumference of the tunnel and calculate the distance between any two pair of transducers and observe any changes in these distance measurements over time. The change in distance is an indication of relative deformation at the critical cross-section 2 The transducers that were chosen in order to achieve the goal were the HE240 series of transducers from Hexamite Devices (shown in figure 2-4). In addition to the transducers, a positioning device is needed (for each transducer) which has the necessary electronic and control circuitry for operating the ultrasonic transducers. The positioning device measures the time of flight and calculates the distance from this measurement and sends this measurement over a RS-485 network to a controlling device. The positioning device that was chosen was HE860 (from Hexamite Devices) [25]. Figure 2-4: HE860 positioning device and HE 240 transducer head [25]. One of the main obstacles in using the transducers was the problem of unstable readings. The transducers gave very unstable readings when they were not facing each other and moderately stable readings when they were directly facing each other. The 2 This is not strictly true as temperature and other factors might affect the distance measurements made by the ultrasonic transducers 34 reason for this might be a narrow beam angle of the Hexamite ultrasonic transducer. This problem was partially solved when a transducer head from another company (Massa Corporation, figure 2-5) was used [40]. The probable reason for this could be a wider beam angle of the Massa transducer head than the Hexamite transducer head. Because of the narrow beam angle, it was decided that only two transducers will be used,and these transducers will be installed such that they are facing each other directly (see figure 1-5). Some of the results of the tests that were done using the transducers from these two different companies are discussed in Chapter 5. Figure 2-5: E-152, ultrasonic transducer from Massa corporation [40]. Each ultrasonic transducer is configured either as a pilot or a beacon. One of the pilot nodes (called the master node), initiates a timing distance acquisition signal. The master node transmits a synchronization signal (electrical) and measures the time to receive an ultrasonic wave from the beacons. This measured time gives the distance between the pilot and the beacon nodes [25]. Chapter 5 gives the details of the interface between the microcontroller and the ultrasonic transducer. Details of configuring the ultrasonic transducers using the positioning device are given in Appendix A. In the next two sections, two (relatively) new sensor technologies are briefly discussed. These are Micro Electro-Mechanical Systems (MEMS) and Fiber Optic sen- 35 sors. These new technologies will play an important role in the future monitoring applications. 2.6 MEMS Micro Electro-Mechanical Systems or MEMS "is the integration of mechanical elements, actuators, and electronics on a common silicon substrate through the use of microfabrication technology" [23] . As evident from the name, the size of MEMS devices are on the order of the microns (10-6). Since bulk fabrication techniques from the micro-electronic devices can be applied (lithography, etching, micro-machining, etc. ), mass fabrication of these devices make them potentially cheap and more reliable than their macro-mechanical counterparts. Three of the main application areas of MEMS are: * Biotechnology, applications of MEMS in biotechnology include developing biochips for detecting hazardous chemicals and biological agents and developing microsystems for drug delivery [42]. " Communications, the focus in this area is to develop MEMS-based electronic components that can be used for making low-power and low-cost, high-frequency RF circuits. An important use for this is in making light-weight cellular phones [42]. Other important application is developing micro-mirrors for telecommunications. " Accelerometers, low-cost MEMS accelerometers are being used for crash air-bag systems in automobiles [42]. MEMS (figure 2-6) accelerometers are also being used in wireless sensors. A particular example of this is the MICA mote developed by University of California, Berkeley and Crossbow Corporation. Details of the MICA mote are provided in Chapter 4. MEMS have great potential in monitoring applications providing low-cost and low-power sensors. Unfortunately, there are some challenges in using this technology widely. They are: 36 Figure 2-6: Figure showing a MEMS accelerometer [3]. 1. For manufacturing or prototyping MEMS devices, micro-fabrication technology is required and this fabrication technology is not easily accessible. Building such a fabrication unit is very expensive [42]. 2. Packaging MEMS is more difficult than packaging ICs. One reason is protection against the harsh environments in which MEMS devices may be used. This is because of the harsh environments in which MEMS devices may be used. Also, the packaging has to be customized for different applications. Packaging MEMS devices is one of the major obstacle the MEMS community is facing [42]. 3. Numerical and simulating tools for MEMS are very limited [42]. 4. In order to design a MEMS device, the designer would need an extensive knowledge of fabrication techniques. The process of fabricating even a simple MEMS 37 device requires a lot of effort and research [42]. More details on MEMS can be found here [42]. 2.6.1 Fiber optic sensors This section focuses on fiber optic sensors. Fiber optic sensors have existed for quite some time (past 10 years approximately) and hence is not a new technology. "Fiber optics (optical fibers) are long, thin strands of very pure glass about the diameter of a human hair. They are arranged in bundles called optical cables and used to transmit light signals over long distances" [27]. Fiber optic sensors can be broadly classified as extrinsic and intrinsic sensors. Extrinsic sensors use an optical fiber to convey light to a sensing element and use the same or another optical fiber to convey the processed light to a photo detector. On the other hand, intrinsic sensors are those sensors, which use a sensing mechanism that is a part of the optical fiber [41]. Another classification of fiber optics sensors is to classify them on the property of light that is affected by the sensing mechanism. They are: " Intensiometric sensors: these sensors use the variation of light power transmitted through optical fiber for sensing mechanism [41]. * Interferometric sensors: these sensors use the changes in phase of the light as the sensing mechanism [41]. " Polarimetric sensors: these sensors measure temperature or strain by detecting the changes in polarization eigenmodes of an optical fiber [41]. " Modalmetric sensors: these sensors use the changes in "transverse spatial mode distribution of light" as the sensing mechanism [41] " Spectrometric sensors: these sensors use Raman and Brillouin scattering mechanisms for determining temperature profiles [41]. 38 Details of these mechanisms is beyond the scope of the thesis and more information could be found here [41]. Some of the important applications (related to monitoring) of fiber optic sensors are: 1. For bridge monitoring fiber optic sensors are potentially useful in performing the following tasks [41]. (a) Fiber optic sensors could be used in evaluating the long term performance of new construction materials like Carbon Fiber Reinforced Polymers (CFRP). (b) For studying the wind and seismic response of bridges by integrating Fiber Reinforced Polymer (FRP) strengthening elements with fiber optic sensing technology. This can also be used for studying bridge vibration due to traffic loading and other environmental conditions. 2. Fiber optic sensors can be used to measure other mechanical and thermal information. For example, a fiber optic strain gage is shown in figure 2-7. They can also be used as both the sensor and the data channel which has such uses such as measuring strain and temperature information from any point of its length [41]. (a) They could be used for monitoring the degree of cure and temperature of concrete structures and hence indicate when it is appropriate to posttension or moving the concrete structure [41]. Important considerations that should be kept in mind while using this technology is the integrity of fiber optic sensors such that installation should not affect the light properties adversely. More details on fiber optic sensors can be found here [41] Smart sensors are those sensors which integrate some kind of intelligence from a microcontroller, DSP chip, or an application-specific integrated circuit (ASIC) [18]. The wireless sensor units developed for the tunnel monitoring project are smart sensors as they have integrated microcontrollers. In the next chapter, the brain of the wireless sensor unit, the microcontroller is discussed. 39 Figure 2-7: Figure showing a fiber optic strain gage [59]. 40 Chapter 3 Microcontroller A Microcontroller is a miniature computer. It is an Integrated Chip (IC) that has a Central Processing Unit (CPU), Random Access Memory (RAM), Read Only Memory (ROM) and other components that are also present in a computer. The present chapter describes the PIC 'family of microcontroller in detail. Specifically, the PIC16F877 microcontroller is examined, which is used in this project. The PIC microcontroller is manufactured by Microchip Technology, Inc. In this chapter, the architecture and instruction set for the PIC mid-range devices are described. In the architecture section, the clocking scheme, the memory organization and pin description of PIC16F877 microcontroller are discussed. Specific features of the PIC16F877 microcontroller are described and finally the operation of the microcontroller on the sensor board is described. 3.1 Architecture This section explains the architecture of PIC mid-range microcontrollers 2. The clock- ing scheme, memory organization and pin description of the PIC16F877 microcontroller are described. iPIC stands for Peripheral Interface Controller. PICgis a registered trademark of Microchip Technology, Inc. 2PIC microcontrollers which have 14 bit length instructions are classified as mid-range microcontrollers 41 Many of the present day microcontrollers (including the PIC16F877) have a Harvard Architecture. In Harvard Architecture, the program memory and data memory reside separately in two different blocks of memory. While in a Neumann Architecture, the program and data memory reside in the same block of memory. This is depicted in the figure 3-1, which shows the block diagrams of both the architectures. As seen in the figure below, in a Neumann Architecture a single or a shared bus is used to access data and program memory, as they reside in the same block of the memory. In Harvard Architecture separate/different buses are used for accessing the program and data memory. This allows execution of an instruction using data from the data memory and fetching of the next instruction from the program memory[31] in the same instruction cycle. DATA MEMORY CPU M PROGRAM MEMORY MMR PROGRAM MEMORY CPU DATA MEMORY a) Harvard Architecture b) Neumann Architecture Figure 3-1: Block diagram of Harvard and Neumann architectures. Apart from having a Harvard Architecture, the PIC16F877 has some common features that are found in other RISC (Reduced Instruction Set Computers) microcon- trollers3 [47]. They are discussed below: " Long word instructions, each instruction is 14 bits long for a PIC16F877 microcontroller. " Single word instructions: the microcontroller has a 14 bit program memory bus which can access the program memory. Since the instructions are single word 3 RISC microcontrollers have an instruction set comprising of very few instructions. PIC16F877 microcontroller has only 35 instructions. 42 The instructions, all the locations in the program memory are all valid instructions. This leads to a better utilization of the program memory. This also implies that the microcontroller has to read just a single memory location in the program memory for executing an instruction. 3.1.1 Clocking scheme In this section, the clocking scheme and instruction cycle of the PIC microcontroller are described. A microcontroller needs a clock input to synchronize and execute the instructions in its program memory. The external clock input to the microcontroller is through pins OSC1 and OSC2. The PIC16F877 microcontroller communicates with the external world using the pins. The pin description of the PIC16F877 is given later. The four valid clock modes are4 described below: 1. RC mode. In this mode, an external resistor and a capacitor circuit provides a clock input to the microcontroller on the OSCI pin. The frequency of the clock input is a function of the supply voltage, and the values of the resistor and capacitor. The device data sheet has more details regarding the range of resistors and capacitors that can be used [45]. In this mode, the microcontroller outputs a clock pulse on the OSC2 pin, which can be used for clocking other devices. The frequency of this clock pulse is one-fourth of the frequency of the RC clock signal on the OSC1 pin. 2. LP mode. In this mode, the microcontroller uses an external crystal of low speed (usually less than 2 MHz, for exact values, see [45]). Of all the 4 modes, this mode consumes the least power. 3. XT mode. In this mode, the microcontroller uses an external crystal. Typical clock speeds include 2-4 MHz [45]. 4. HS mode. In this mode, the microcontroller uses an external crystal. The clock 4 All the modes that are discussed here are the external clocking modes. Some microcontrollers have internal oscillators/clocks. The PIC16F877 does not have an internal oscillator. 43 speeds are usually greater than 4MHz. Of all the 4 modes, this mode consumes the highest power. The clock input from the OSCI pin of the microcontroller is formed into four non-overlapping quadrature clock cycles namely Q1, Q2, Q3 and Q4. These four clock cycles together form an instruction cycle for the microcontroller. During an instruction cycle, an instruction is executed and the next instruction is fetched simultaneously. Hence, each instruction of the microcontroller takes a time of 4/F..c seconds, where F,,, is the frequency of the clock input to the microcontroller. Complex instructions like GOTO, which branch the program take more than one instruction cycle to execute [45]. Understanding clocking scheme and the instruction cycle helps in writing better programs to program the microcontroller. 3.1.2 Memory Organization In this section, the memory organization of the PIC16F877 is discussed. The memory of a PIC microcontroller is divided into two main components. They are the program memory and the data memory. The PIC16F877 is an Electrically Erasable Programmable Read Only Memory (EEPROM) device (also known as a flash microcontroller) [45]. Program Memory The program memory of the PIC16F877 microcontroller is an EEPROM. The size of this memory is 8K X14 bits (as each instruction is 14 bits long). This program memory is divided into four equally sized blocks called pages. The two important locations in the program memory are: * Reset vector. This is the address at which the microcontroller looks for instructions whenever there is a device reset or whenever the microcontroller starts. The address of the reset vector is Oh 5. 5 0h is 0 in hexadecimal notation. 44 * Interrupt vector. This is the address to which the program branches whenever there is an enabled interrupt. Interrupts are special events which might have to be serviced depending upon the application. Common examples are timer interrupts, serial port interrupts, etc. In order to service an interrupt, the interrupt enable flag for that particular interrupt and the global interrupt flag should be set. If the aforementioned flags are set, whenever the interrupt occurs, the microcontroller services the interrupt by making the program jump to the interrupt vector. Enabling and disabling of the interrupts is done in the program. Data Memory Data Memory can be divided into three categories. They are: 1. General Purpose Registers. General Purpose Registers (GPR) and the Special Function registers (SFR) form the RAM (Random Access Memory)6 of the microcontroller. The size of this RAM is 368 bytes for PIC16F877 [45]. GPR are used for storing the variables and other temporary values that are used in the program. 2. Special Function Registers. The SFR controls the various core and periph- eral features of the microcontroller. The core features are the features necessary for the microcontroller to operate. These include the STATUS, PCL, etc. The peripheral features include features like the Analog to Digital Converter (ADC), USART (Universal Synchronous Asynchronous Receiver Transmitter), etc. These features are explained later in this chapter. 3. Data EEPROM. The Data EEPROM is an EEPROM. This can be used for storing permanent data or some other valuable information. The microcon- troller uses a protocol for writing and reading data from the data EEPROM 6 Similar to the computer's RAM, the microcontroller's RAM is volatile. After a device reset all the values in the RAM registers are reset to their reset values. 45 so that the existing data is not written over accidentally. PIC16F877's data EEPROM has 256 locations and the size of each location is 1 byte [45]. 3.1.3 Pin Description As stated earlier in this chapter, the microcontroller communicates with the external world using its pins. In this section, the pin layout of PIC16F877 is described. Figure 3-2 shows the pin diagram of PIC16F877. These can broadly be classified as Input/Output (I/O) pins and power pins. Each class is now described. TIONPP/THw 1 RAW/ANO 2 m( RA1/AN1 3 rs-a[ RA24AN2NREF-..( 4 R A3ANNRIF + 6 RAC/TOCKI e[ 6 RAFWAN4/b"7I r--[7 REBM"EAN5 S8 REE1/WRAN6 m[ 9 RE2CIAN7 L 10 VDD -B -[ 11 12 OSC1UCLKIN 13 -[ OSC2/CLKOUrT r---[14 RCT10SO/T1CKI ,m-E [R is RC1ITISVCCP2 "--[ 16 RC2VCCP1 L-[ 17 RC3SCKISCL 18 [ RDCVPSP0 e--[ 19 RD1/PSP1 mC 20 K740 39 J -38 37 ]] '4--b --- 36 ) S- --. 35 j 34 _ r CD CD 33 32 R D R87NPGD RBGJPGC RBS RB4 RB3jPGM~ RB2 RB:1 RB0.1NT VD -3 31B ] 30 29 28 )3-a 27 :]1] 4----- , 26 3 s-a -a 25V]3 24 N/SS 23 RC4/SDIX-RDA RD30PSP3 RD)+PSP2 22 21 3]--. RD7,rPSP7 RDGPSP6 RDWPS RD4VPSP4 RC7/RXQDT RC&TX(CK RMsSDO Figure 3-2: Pin diagram of PIC16F877 [45]. I/O pins I/O ports are the ports by which the microcontroller communicates with external devices for I/O operations. The PIC16F877 has 40 pins, of which 33 are I/O pins. Most of the I/O pins are multiplexed to perform other functions. The 33 I/O pins are divided into 5 ports named A,B,C,D and E. The registers corresponding to these ports 46 are PORTA, PORTB, PORTC, PORTD and PORTE respectively [45]. An I/O pin can be either configured as input or output by setting or clearing7 the corresponding bit in a corresponding register. These registers are referred by the prefix TRIS. (TRISA corresponding to PORTA and so on). TRIS stands for tri-state. As the name suggests, tri-state devices have three states. These are logical 1, logical 0 (when the device is in its output mode) and off state (when the device is in its input mode). For example, to configure PIN6 of PORTB as an input pin, bit 6 of the TRISB register has to be set high or logical 1. Power pins and other pins These pins correspond to the pins which are either connected to the power or ground lines. The other pins apart from the power pins are the pins for the clock input, which are OSCI and OSC2. 3.2 Features In this section, some of the important features of the microcontroller are described. These features are not the complete set of features. Details of other features can be found here [45]. The features that are now described are: 1. Universal Synchronous Asynchronous Receiver Transmitter (USART) module 2. Analog to Digital Converter (ADC) 3. Master Synchronous Serial Port (MSSP) module 4. Timer and interrupt features 7 By set we mean writing a "1" and by clearing we mean writing a "0" at the appropriate memory location. 47 3.2.1 Universal Synchronous Asynchronous Receiver Transmitter (USART) module PIC16F877 has an inbuilt module which can be used for synchronous and asynchronous serial communications. Serial communications are explained in detail in the next chapter. USART module can be used for the commonly used asynchronous serial communication standard, RS-232. This standard is used to connect with a PC or other RS-232 compatible devices. The USART module is also used for synchronous serial communications for talking to devices like Analog to Digital Converters (ADCs) and other microcontrollers. Some of the standards for synchronous serial communication are also described in the next chapter. Serial communication can be done either in hardware by using the USART module or in software by writing the appropriate code which would generate the required data pulses. Using the hardware USART has the advantage of using the interrupt features of the microcontroller. An example of such an interrupt is the interrupt generated when the microcontroller receives a byte of data in the asynchronous mode. The software mode does not have these features, but this mode gives the flexibility of choosing any 2 I/O pins for serial communication. The hardware USART restricts this to pins RC6 and RC7 on the PIC16F877 [45] 3.2.2 Analog to Digital Converter An Analog to Digital Converter (ADC) converts an analog input signal into a digital output. The PIC16F877 has an inbuilt ADC, which has a 10-bit resolution. It has 8 input analog channels. These channels are multiplexed with PORTA and PORTE pins of the microcontroller. The 10-bit resolution is sufficient for many applications (10-bit resolution provides a resolution of 0.1% over the range of the ADC). The input signal to the analog channel is a voltage which is usually in the range of 0 to 5 volts. Other possible ranges and configurations in which the ADC can be used are found in the device data sheet [45]. 48 3.2.3 Master Synchronous Serial Port (MSSP) module This module is used for communicating in synchronous serial communication standards such as Serial Peripheral Interface (SPI) and IIC (12C). Protocols, based on these standards are also commonly used for interfacing devices. These standards are explained in Chapter 4. The use of MSSP module makes the application of these protocols quite easy. 3.2.4 Timer and interrupt features Other important features of the microcontroller are the timers and interrupts. The PIC16F877 has 3 inbuilt timers. These are TimerO, Timeri and Timer2. These timers can be used for measuring the amount of time elapsed between any two events (need not be necessarily related to microcontroller internal events) and other timekeeping functions. Interrupts allow the microcontroller to be notified of important events. These include data reception on the USART receiving pin, completion of an analog to digital conversion, etc. As mentioned earlier, the microcontroller should enable the relevant interrupt flag (for a particular interrupt) and the global interrupt flag so that the microcontroller can be interrupted when the particular interrupt occurs. Using the timer and interrupt features one can measure an interval of time. An example to measure an interval of 5 seconds is provided. For example, if a 4 MHz oscillator is used, each instruction takes a time of 1 microsecond to execute. Using the Timer2 scaled down by a factor of 16 (so that time interval between 2 ticks of Timer2 is 1x16 = 16 microseconds), a reset value of 250 (i.e. timer resets itself to zero after it reaches 250 and starts from 0 again) and a post-scaling factor of 10 (i.e. after every 10 resets, an interrupt is generated), therefore, the time interval between any two Timer2 interrupts is 16 x 250 x 10 = 40 milliseconds. 125 such interrupts make 5 seconds. So a counter is used that keeps track of the number of interrupts that have occurred. The counter can be reset once 5 seconds have elapsed. In this way, one can use the timer and interrupt features to 49 measure 5 seconds. 3.3 Instruction Set The microcontroller needs to be programmed for it to perform any task. The in- structions to the microcontroller are written in hexadecimal format which is not a convenient way (for humans) to code the microcontroller. So one has to use either an assembly language or a high-level language like C or BASIC to write the program. This program is then compiled by a special compiler which compiles it into the hexadecimal format, which the microcontroller understands. A programmer then burns (electrically) this program onto the microcontroller's program memory. The following sub section discuss assembly language programming and programming in C. 3.3.1 Programming in assembly language The assembly language for the PIC microcontroller is known as MPASM 8. It was developed by Microchip Technology, Inc., which manufactures the PIC microcontrollers. The PIC16F877 is a RISC microcontroller and has just 35 instructions [45]. These instructions can be broadly classified as: * Control Operations, which control the program flow and other basic features of the microcontroller. " Byte-oriented instructions, dealing with addition, subtraction or other arithmetic or logical operations on the whole register (as a register is 1 byte long). " Bit-oriented instruction, dealing with setting or clearing of a particular bit in a register. " Literal operations, dealing with the operations which involve constants/literals. Appendix B gives an example of a sample program in assembly language. 8 MPASM @is a registered trademark of Microchip Technology, Inc. 50 3.3.2 Programming in C Programming in C is simpler and easier compared to programming in assembly language. But an understanding of the assembly language is definitely an advantage in programming the microcontroller. There are commercial C compilers for programming the PIC microcontrollers. Some commonly used C compilers are CCS [8], Hi-Tech [26], etc. Programming in C for small programs may not lead to a proper utilization of the program memory [19]. This depends on the compiler and most of the compilers have various optimization levels to achieve a better efficient usage of the program memory. The main advantage of programming in C is the ease of programming. Appendix B also gives an example of a sample program in C programming language. Operation of the microcontroller 3.4 This section discusses an example operation of a microcontroller in a wireless sensor unit. The microcontroller can perform the following functions. 1. Periodically collect data from an external ADC, which is usually connected to a sensor. The microcontroller can also use its in-built ADC to collect data from sensors. 2. Packetize this data. The microcontroller after collecting the above readings/data composes a string which has other relevant information like the ID of the sensor board, the length of payload and checksum bytes in addition to the readings/data. 3. Transfer the message string to a RF transceiver. The microcontroller after packetizing the data sends the data to the RF transceiver, which then communicates the readings to the base station. This chapter described some of the basic features of the PIC16F877 microcontroller. Chapter 5, gives the details of the interface between the PIC16F877 and 51 other external devices. In Chapter 4, communication aspects arising in the development of the wireless sensor unit are described. 52 Chapter 4 Communications This chapter discusses the communications component of the wireless sensor unit. At a broad level, this chapter discusses wire-based and wireless communications and some of the standards and technologies related to these. In wire-based communications, synchronous and asynchronous serial communications are described. In wireless communications, different RF technologies considered for the developing the wireless sensor unit are described. 4.1 Wire-based systems Wire-based systems use a wire or a cable as a medium for transferring the data. For example, the telephone system at MIT. Serial communication, by definition sends data bit by bit. Telephone modem is an example of a device that uses serial communication. Synchronous and Asynchronous serial communications are described now. 4.1.1 Synchronous serial communications In this section, synchronous serial communications at the microcontroller level are discussed. At this level, for the synchronization of devices, one of the devices, provides the clock signal. This clock signal is used for timing the data pulses. The device which provides the clock signal is the master device and the rest of them are slaves. The 53 master device coordinates the communication between other devices and itself. Two important standards for synchronous serial communications, which are used for inter-device communications are Serial Peripheral Interface (SPI) and Inter IC Communication (12C). Some microcontrollers have inbuilt modules which facilitate inter-device communications using these standards. If the microcontroller doesn't have such a module, a simple approach called bit-banging can be used as an alternative form of communication. Bit-banging is a term used for software written to generate data pulses for serial (synchronous as well as asynchronous) communications. Now, SPI and 12C standards are described. SPI SPI standard was specified by Motorola Corporation for inter-device communication. SPI is a data exchange format. Data is exchanged, rather than being transmitted or received. Devices using can only exchange data. A device is either a master or a slave and there is only one master device in a network at a given time. Master device can select the slave device to which it wishes to communicate with. SPI specifies four signals. These are SCLK (clock signal), MISO (input for the master or output for slave). MOSI (output for the master and slave input) and SS (slave select signal for selecting a slave) [30]. The PIC16F877 contains a MSSP (Master Synchronous Serial Port) module which simplifies the process of configuring the devices for SPI communications. There is a good tutorial on using the PIC microcontroller for SPI communications [46]. Many of the external devices like EEPROMS and ADCs have SPI features which enables the PIC microcontroller to communicate with these devices. 12C 12C was specified by Philips Corporation. 12C is a half-duplex communication scheme (devices cannot transmit and receive at the same time). Devices are addressed by their address and before initiating any communication with the slave(s), the master sends 54 the address of the slave to which it desires to communicate. Address is of 7 bit length, and the 8th bit indicates whether the slave should transmit or receive. Recipient slave then sends an acknowledgment bit confirming the receipt of the previous message. The master and slave communicate in this fashion with the receiver device (can be either the master or the slave) acknowledging the message after each byte of transmission. After communicating with the slave, the master issues a stop bit indicating the end of the transmission. Master device, if necessary might initiate the communication scheme again to communicate with a particular slave (or a broadcast) [29]. 12C, because of the acknowledgment bit and the need to send the address of the slave for communication cannot achieve a high data rate. The maximum data rate is on the order of 100 Kbps. On the other hand, SPI, which is a data exchange format has a higher data rate (reaching Mbps). There is a good tutorial on using the PIC microcontroller for 12C [44]. The specifications for 12C can be found here [51]. 4.1.2 Asynchronous serial communications In this section, the commonly used asynchronous communication standards, RS-232 and RS-485 1 are discussed. Asynchronous communication assumes that the devices are not synchronized and don't know in advance when they are going to receive data. RS-232 RS-232 2 is a commonly used standard for serial communication between a PC (the COM port is used) and another device (ex:modem). There are different ways of communicating using RS-232 standard. The simplest way is to use a 8-bit transmission, with no parity bit and a single stop bit and start bit. This simple scheme doesn't use any handshaking schemes. RS-232 uses three lines for communication. are TX (transmission), RX (receiving) and GND (ground reference). These While trans- mitting a logical 1 (also called MARK), the voltage on the transmitting line can be 1 2 RS stands for Recommended Standard. The present version of this standard is known as EIA232 (Electronic Industries Association). 55 anywhere between -5 to -15 Volts 3, and while receiving the voltage on the receiving line should be between -3 to -15 Volts. Similarly when transmitting a logical 0 (also called SPACE), the voltage on the transmitting line can be anywhere between 5 to 15 Volts and while receiving, the voltage on the receiving line can be anywhere between 3 to 15 Volts. The difference in voltages while transmitting and receiving is to compensate transmission losses. Typically, RS-232 is used when the transmitting distances are not greater than 100 ft. For transmission distances greater than 100 ft, RS-485 is preferred [21]. RS-232, being an asynchronous communication protocol doesn't use any clock line (for synchronization) for communication. The beginning and end of a byte are indicated by the stop and start bits. The stop bit is a logical 1 (MARK) and the start bit is a logical 0 (SPACE). RS-232 is a full-duplex communication scheme allowing simultaneous reception and transmission. This is possible because of the two separate and independent lines for transmission and reception. Between any 2 bytes of transmission/reception, the transmitting and receiving lines use continuous stop bits and wait for a start bit of the next byte . Therefore, in the idle state, the receiving and transmitting lines are in the MARK state. Baud rate is equal to the bits transmitted per second. For transmitting a byte, 8 + 2 (one for start and one for stop) = 10 bits are transmitted. So in theory, 10 bits are transmitted for conveying 8 bits of information. Transmission and reception using RS-232 is described now (using the simple scheme aforementioned). Before transmitting, the transmission line is in the idle state (MARK or logical 1). The start bit is transmitted first (which is a logical 0 or SPACE). The duration of this bit is equal to 1/(baud rate) seconds. After the start bit the individual data bits are transmitted with the LSB (Least Significant Bit) being transmitted first and the MSB (Most Significant Bit) being transmitted last. The duration of each subsequent bit is also 1/(baud rate) seconds. After the MSB is transmitted, the stop bit is transmitted and the line is held in that state until the start bit of the next byte/character has to be transmitted. See figure 4-1, which shows 3 These voltages are with respect to the ground line. 56 how the character 'U' ' is transmitted at 9600 baud (the voltage levels correspond to non RS-232 voltage levels which, need to be converted to RS-232 levels using a RS-232 driver). The receiving line receives the start bit first which pulls the receiving line from a MARK (idle state) to a SPACE (start bit). When the line goes to SPACE, the receiver waits for a time equal to half the bit width (bit width is 1/baud rate) and proceeds further only if the line is still in the SPACE state. ' After this the line is sampled after every bit width of time until all the 8 bits of information are retrieved [61]. The line again goes to the idle state waiting for the next byte. Some of the limitations of RS-232 are stated below. 1. RS-232 is a peer-to-peer communication scheme. It cannot be used in a network mode. 2. Range of RS-232 is limited. Typical range is less than 100 ft. The advantages of RS-232 are its full duplex communication capabilities and its simplicity. Since the voltage outputs from the PIC microcontroller are usually 0 V (for logical 0) and 5 V 6 (for logical 1), these voltages need to be converted to RS-232 compatible voltages. This is achieved by using a RS-232 driver, which converts the output voltage from the microcontroller to RS-232 compatible voltage. Details of some commonly used drivers can be found here [5]. RS-485 RS-485 ' uses a balanced differential line driver for communication. RS-485 is primar- ily meant for creating a network of devices where all the devices use a shared medium to communicate. The shared medium is a twisted pair of cables and a ground line. A logical 0 or 1 depends upon the voltage difference between the two cables of the twisted pair of cables. These cables are labeled as A and B and both of them carry 4 ASCII value of 'U' is 85, which in binary is 01010101. 1f the line is not in the SPACE state, the receiver assumes the transition to be noise. 6assuming the supply voltage to be 5 V. 7 Also known as EIA/TIA-485 (Telecommunications Industry Association). 5 57 the same signal. The voltage difference between these 2 lines, Vb dictates the logic. If Vab is between -0.2 V to -6 V, the logic state is MARK or logical 1 and if Vab is between 0.2 to 6 V, the logic state is SPACE or logical 0. These ranges allow for attenuation and transmission losses in the cables 8. The mean voltage in the cables is called the common mode voltage, Vm, and this voltage should lie between -7 to 12 Volts [6]. The cable labeled A is also known as non-inverting (+) input and the cable labeled as B is known as inverting (-) input. Devices which are RS-485 compatible usually have control lines, which control when the device can receive or transmit. Since, RS-485 uses a shared medium, only one device can transmit at a time. RS-485 compatible devices have control lines which enable them to transmit or to receive. Some of the advantages of RS-485 are: 1. Networking is possible with RS-485. 2. Up to 32 devices can be connected in a single network. 3. Transmission distances up to 4000 ft can be achieved. Once again, the voltage output from the PIC microcontroller is either 0V or 5V. These need to be converted to RS-485 compatible voltages. This is achieved by using a RS-485 driver. One such example of RS-485 driver is ADM1485 from Analog Devices Inc. Details of this device can be found here [2]. Now the bit-banging approach is described, which can be used for both synchronous and asynchronous serial communications. 4.1.3 Bit-banging Bit-banging is the term for software written (instead of using the hardware capabilities to produce data pulses) for producing data pulses. The data pulse durations should be exact or nearly exact durations that are obtained by using hardware USART module. For synchronous serial communications, two lines are used, one for the clock signal and the other for the data. 8 RS-485 uses twisted pair of cables for communication. Using a twisted pair reduces a lot of electromagnetic interference [6]. 58 Fundamentally, serial communication is transfer of information using data pulses. In asynchronous communications, the bit-width is governed by the baud rate, while in synchronous communications bit-width is directly dependent on the width of clock pulses (the width of clock pulses depends on the specific requirements of the devices). Most of the present-day microcontrollers have modules for generating the data pulses (of appropriate width). Bit-banging is a very crude (but efficient) way of mimicking the data pulses. Bit-banging is best explained by an example. Consider again transmitting the ASCII character 'U' at a baud rate of 9600. The waveform appears in the following fashion (see figure 4-1) at the microcontroller if the in-built module is used. The same data pulses can be generated using appropriate microcontroller instructions (i.e. bit-banging). For example, if an oscillator of 11.0592 MHz is used, length of each instruction cycle is 0.362 microseconds approximately. Figure 4-1 gives the bit-width or duration of a bit is 0.104 milliseconds. To generate a duration of this interval, the microcontroller has to output a line high or low for 288 (0.104 ms/0.362 us) instruction cycles. In this way a single bit is mimicked. Similarly the other bits are mimicked to transfer information. This is a very crude way of doing things but this approach is useful for microcontrollers which don't have an in-built USART module. Also, if C language is used for programming the microcontroller the compiler generates the appropriate code for bit-banging (in asynchronous mode only). For synchronous mode, the clock line is also used. For interfacing the external ADC with the PIC16F877 (for developing the sensor unit), the bit-banging approach is used. 4.2 Wireless Technologies In this section some of the relevant wireless technologies that were considered for this project are discussed. RF based systems do not require a line of sight for transferring data (some of them like GPS receivers need a line of sight for communication). One of the major technologies in using RF systems is the Bluetooth Standard. The Bluetooth standard 59 stop idle state stp 5V 0V 0 0 0 start 0.1042 ms bit Figure 4-1: Figure showing the data pulses for sending the character 'U' at a baud rate of 9600. has been primarily developed for wireless communications between devices in a personal area network. Bluetooth compatible devices operate in the 2.4 GHz frequency band and have a working range of 10 m. Bluetooth compatible devices have an attractive feature of operating at a low power, but the short range of these devices is a major limitation [7]. Other RF systems that can be used for monitoring applications are usually devices which work in the frequency ranges that fall in the Industrial, Scientific and Medical (ISM) band of the RF spectrum or other license free bands 9. In the following sections, the various technologies (RF) considered for developing the wireless sensor units for the project are described. They are: 1. MICA motes from Crossbow Technology, Inc. 2. i-Bean from Millennial Net,Inc. 3. Linx Technology RF ICs These are discussed in detail in the following sub-sections. 9 Primary license free bands in US are 900-928 MHz and 2.39-2.5 G Hz bands. Since the final deployment would be in UK, we used devices which have a frequency of 433 MHz [16]. 60 4.2.1 MICA motes At the time, this project started (September 2002) MICA motes (see figure 4-2) were the primary choice for the RF technology. The mote technology has been developed by University of California, Berkeley and the motes are commercially manufactured by Crossbow Technology, Inc. The MICA motes come with a processing board, which has the microprocessor, the wireless transceiver and a sensor board which can be connected to this processing board with a 51 pin connector. The particular sensor board which was used for testing the MICA motes had a dual-axis MEMS accelerometer, magnetometer, photo diode, thermistor, microphone and a sounder. MICA motes use TinyOS as the operating system for the microprocessor [12]. " TinyOS is a component-based runtime environment designed to provide support for deeply embedded systems which require concurrency intensive operations while constrained by minimal hardware resources" [62]. Prof.David Culler's research group at University of California, Berkeley is primarily concentrating on developing and improving TinyOS. More details of TinyOS can be found at this place [62]. a) b) Figure 4-2: a) figure showing the MICA processor board and b) MICA sensor board [12]. The utility of the MICA motes for monitoring applications was done as a part of a class project at MIT. The primary goal of the class project was to use the 61 MICA motes for monitoring a MIT building (building 48), which was experiencing noticeable (human noticeable) vibration due to the adjacent construction work. Some of the important observations that were made from the project are: 1. The MICA mote uses the inbuilt ADC (Analog to Digital Converter) of the microcontroller for performing analog to digital conversions. This inbuilt A/D converter has a 10 bit resolution [9]. This resolution is insufficient for the tunnel monitoring application. 2. Some of the features of the MICA motes are not accessible for modification . This greatly reduces the flexibility of the MICA motes [9]. 3. With the generation of MICA mote that were used in the class project, it is not possible to use a generic sensor board. One is forced to use the sensors like photo, temperature sensors, accelerometer, magnetometer, etc [9]. These sensors are not required (except for the temperature sensor) for the tunnel monitoring project. The MICA motes are being used for extensive research in developing wireless sensor networking algorithms and other research activities [22]. Different monitoring applications require different sensors and hence a greater flexibility is required for using application specific sensors, which the MICA motes lacked. This was the major limitation in using the MICA motes for the tunnel monitoring project. 4.2.2 i-Beans i-Bean (see figure 4-3) is a wireless transceiver with analog and digital inputs and a microcontroller to control its operation. i-Beans have the capability of forming self configuring networks and they are optimized for power consumption [48]. For the present project, Millennial Net Inc. has custom manufactured i-Beans with a serial interface. Any generic sensor/device which can output the data in serial format can ioThe MICA motes are pre-manufactured and it is not an easy task to modify the existing circuitry 62 use this interface to transfer data to the i-Bean and utilize the existing i-Beans' self configuring networking feature to develop a wireless sensor networking system. Some of the important features that were absent in these devices are: 1. With the serial interface, the i-Beans are just transmitters and the i-Bean base station, a receiver. 2. The original payload requested was 40 bytes, but the actual payload capability is 20 bytes. Figure 4-3: Figure showing i-Beans and the base station. Other important limitations with the i-Beans are: 1. The serial interface was sensitive to the oscillator's frequency. The data received at the base station was incorrect at a clock speed of 2 MHz. 63 2. The i-Bean base station does not work on all PCs. 3. The i-Bean uses a proprietary protocol for transmitting the data over the radio. This forces to use the manufacturer's software. This places some limitations in developing the software for storing the data in a database. These limitations and the strict time line meant an alternative technology had to be used for building the wireless sensor unit. The subsequent RF transmitter that was chosen is the Linx RF IC (RM series), manufactured by Linx Technologies, Inc. [32]. 4.2.3 Linx Technologies RF ICs Linx Technologies manufactures RF ICs which can be easily interfaced with a microcontroller. These ICs are simple transmitters and receivers with no special features (which i-Bean and MICA motes have, ex: self configuring network capability). The specific series that is currently used is the RM series (see figure 4-4). The details for the transmitter and receiver can be found at [33], [34] respectively. 0.?9 in. 0,83 in, POB level Oin spacing: D1 in 1.20 In. X In, a) Figure 4-4: b) Linx RM series a)transmitter [34] b) receiver [33]. Some of the limitations of this technology are discussed below. 1. It has been found that the transmitter has to transmit 3 times so that the receiver can receive properly. 64 2. There will be a loss of data due to collisions, when two or more sensors transmit at the same time. 3. These devices are not really power efficient. Typical power consumption is greater than 50 mW. From the discussion on wireless technologies, one finds that there is no perfect technology which can be easily used for any monitoring application. The i-Bean seems to be a promising technology with the serial interface. One would hope that the latest version of i-Beans will have a well developed and tested serial interface which gives the i-Beans some kind of flexibility, so that they can be used in different applications. In this chapter, the various aspects of communications in developing the wireless sensor unit were discussed. In the next chapter the details of the integration of various components to form the wireless sensor unit are described. 65 66 Chapter 5 Integration of components The present chapter first discusses the integration of the components that form the wireless sensor unit. Following this, the protocols for composing the messages are discussed. 5.1 Interfacing the ADC In this section, the details of the interface between the microcontroller and the external ADC are discussed. The reason for using an external ADC is to acquire sufficient resolution in the pressure measurements. In order to have a resolution of 1 mm displacement at a pressure of 20 m (10 m atmospheric pressure plus 10 m water head) that corresponds to a resolution of 1 in 20,000. This requires an ADC that has a minimum resolution of logj0000 bits or 15 bits. The on-board ADC of the microcontroller has a resolution of 10 bits which is in-sufficient for acquiring the desired resolution. Hence an external ADC is used. The external ADC used in this project is the AD7713 model from Analog Devices, Inc. The resolution of the AD7713 is 24 bits. The microcontroller talks to the ADC using synchronous serial communication protocols. Synchronous serial communications have been discussed in the previous chapter. A brief review of synchronous serial communications is below. Synchronous Communications (at the microcontroller level) requires a clock to 67 time the data pulses. Serial communication, by definition sends data bit by bit. The device which provides the clock signal for timing the data pulses is the master device. The master device coordinates all the communication between the master device and all other devices, which are called slave devices. In the present case, the microcontroller is the master device and the ADC is the slave device. The microcontroller has to be interfaced with other components (like the RF transmitter) other than the ADC. Hence, it should have control over all the communication between the ADC and itself (rather than the ADC controlling). Therefore, the microcontroller is in the master mode and the ADC is in the slave mode. Some ADC readings are lost when the ADC is in the slave mode. This is because the microcontroller collects data from the ADC at a different rate (0.2 Hz) from the conversion rate (0.5 Hz)of the ADC. But this loss does not affect the monitoring requirements in any drastic way as the readings from the ADC are only required to be collected once in every 5 seconds. SCLK [ 24 DGND 0 MCLK IN 2 23 SYNC _ MODE 6 DVOD 22 SDATA 21 ORDY MCLK OUT 3 AOT 4 AD7713 20 RFS TOP VEW 19 VS AGNO AINI(+) f (Not to Scale) AIN1(-)8 17 AIN3 9 16 RTD2 AIN2(+) AIN2(-) 10 15 REF IN(+) STANDBY 1 AVD12 AVD 14 REF IN(-) 13 R~ RTD1 Figure 5-1: Pin diagram of AD7713 [4]. Figure 5-1 shows the pin configuration of the ADC. Some of the important pins and their functions are explained below. The description for others can be found at 68 [4]. * SCLK, this pin carries the clock signal for timing the data pulses. If the ADC is in slave mode, the microcontroller provides this clock signal (as in the present case), else the ADC provides the clock signal. * MCLK IN & MCLK OUT, these pins are used for providing the clock/oscillator input to the ADC. This clock is needed for the ADC to function and is completely different from the clock signal the SCLK pin carries. The frequency of this clock can be from 400 kHz to 2 MHz. Presently a 2 MHz crystal is used. * AIN2(+) & AIN2(-), these pins are the differential input pins to the ADC. The pressure transducer that is used has a differential output and hence the differential input pins are used on the ADC. * SDATA, a bidirectional communication pin on which all the data to/from the ADC is transmitted/received. * DRDY, this pin goes low whenever the ADC has finished a conversion and the data is ready to be collected. This is a hardware indicator for the microcontroller to collect data. * RFS and TFS, Receive Frame Synchronization and Transmit Frame Synchronization pins. RFS is made low when the microcontroller receives data. TFS is made low when the microcontroller transmits data to the ADC. " REF IN(+) & REF IN(-), these pins are the reference voltage pins. For the present case, these values are 2.5V and OV. . Ao, this pin controls which register (data or control) of the ADC is accessed. If this pin is low, the control register is accessed, else (i.e. this pin is high) the data register is accessed. Figure 5-2 shows the various connections between the microcontroller and the ADC. The ADC on power reset is in its default mode. In the default mode, the ADC 69 outputs only 2 bytes of the digital output (instead of 3 bytes). Therefore, the ADC needs to be configured so that it can output 24 bits or 3 bytes. This is done by writing a 24 bit code to the ADC's control register. This 24 bit code defines how the ADC should operate. One important consideration when writing to the control register is that all the 24 bits should be written completely when writing to the control register. Else, the control register fails to load the code in the control register. This causes the ADC to operate in the default mode or the mode in which the ADC was previously operating. The 24-bit code contains single bit flags and integer values [4]. B7 B6 SCLK A2 DGnd nvai' o2 SDAT DRD M4z SYNC A Mo A5 EQ RFS TFq El E2 A N3 S |AITN](+) -AINI(-) AIN2(+) AIN2(-) o 5V AD 10K 7713 Ref In( 5AV AV PFC 16F877 10K PRESSURE TRANSDUCE1 - 5V Figure 5-2: Interfacing the ADC with the microcontroller. Some of the features which the control register controls are described below and the particular settings that are used in this project are also explained. 70 " calibration mode, the ADC can operate in any of these four calibration modes. They are normal mode (i.e. no calibration mode and this is the default state), system-calibration, self-calibration and active background calibration mode. In the active background calibration mode, the ADC operates in a continuous calibration mode. This mode compensates for the re-calibration of the device when there is a change in the ambient temperature. In this mode, only one input channel of the ADC is used and the other channels are shorted (zeroed) for the background calibration. For details of other modes, see [4]. " Programmable Gain Amplification (PGA). This is used for amplifying the differential input from the pressure transducer. Presently, a value of 64 is used. This implies that both the input signals from the transducer are amplified by a factor of 64 before the conversion takes place. * Channel, selecting which channel on the ADC to use. Presently, channel 2 is used for converting the pressure transducer readings. There are three channels on the ADC of which 2 are differential input channels and the third one is a single input channel [4]. * Word length, to select if the digital output from the ADC should be 2 or 3 bytes. ADC is configured to output 3 bytes. " Bipolar or unipolar output selection. If bipolar output is selected, data is output in offset binary. Presently, bipolar output is used. After selecting the desired configuration settings (i.e. the 24 bit code), the microcontroller transmits this code to the ADC. Then the ADC loads this code into the control register. The steps to write the code are as follows. 1. Initially TFS, RFS and 2. AO AO pins are made high. pin is pulled low. Bringing Ao register instead of the data register. 71 pin low designates access to the control 3. TFS pin is pulled low to indicate the ADC that the microcontroller is transmitting. 4. The 24 bit configuration code is sent, starting with the most significant bit (MSB). 5. TFS and A0 pins are pulled back high. Step 3 of the above procedure is implemented using a bit-banging approach, which is described now. The microcontroller has two pins allocated for sending data to the ADC, SDATA (for data) and SCLK (for the clock signal). See figure 5-2. Both these pins are configured as outputs and initially they are low. Once the microcontroller is ready to send the data, it does the following: SCLK I1 SEDATA (1 M5 Figure 5-3: Timing diagram for writing data to the ADC [4]. 1. Modulate the SDATA pin high or low (1 or 0) '. The state of SDATA is held high/low until it is changed explicitly. 2. After a delay of 1 cycle, the SCLK line is made high and is held high for 2 cycles. 'These values are when the microcontroller is using a 4 MHz clock and the ADC is using a 2 MHz clock. 1 cycle is 1 microsecond. 72 3. SCLK line is then made low and after 1 cycle, step 1 is repeated. This operation is repeated until all the 24 code bits are transmitted. Figure 5-3 shows the timing pulses (SCLK), settings of A0, TFS,DRDY and a sequence of data bits on the SDATA line in the write mode. The constraints on the different timings (shown as labels on the figure) can be found here [4]. Now the steps for receiving data from the ADC are explained. 1. The ADC pulls the DRDY pin low whenever the conversion data is ready to be taken. The microcontroller keeps polling to see if it is low. If the data in the control register of the ADC has to be accessed 2, the microcontroller need not wait for this pin to go low. It can access the ADC's control register even if the DRDY pin is high. 2. Once the DRDY pin goes low, then the RFS pin is made low. However,if the ADC's control register has to be accessed, the microcontroller need not wait for the DRDY to go low, it can directly make RFS pin low. 3. Microcontroller starts receiving the data with the MSB coming first. Since, the microcontroller is in the master mode it has to provide the clock signal so that the ADC can send the data. 4. After the data has been received, the RFS pin and if necessary the AO are pulled high. Again a bit-banging procedure is used to read the data from the ADC. This is explained in more detailed terms to elucidate the operation. Once again, the SDATA and SCLK lines are used. See figure 5-2. SDATA is made an input pin as the microcontroller has to read data synchronously from the ADC. 1. Once the RFS pin is made low, the microcontroller waits for 2 cycles and then reads the SDATA line. 2 This might be done to examine the contents of the control register and see if the settings are satisfactory. 73 2. The SCLK pin is made high and is held high for 2 cycles. 3. The SCLK pin is made low and the step 1 is repeated. This operation is repeated until all the bits have been received. Figure 5-4 shows the timing pulses (SCLK), settings of Ao, RFS and a sequence of data bits on the SDATA line in the read mode (from the data register). The constraints on the different timings (shown as labels on the figure) can be found here [4]. t~~ -- t 1 5T SA Figure 5-4: Timing diagram for reading data from the ADC [4]. 5.2 Interfacing the i-Bean The previous chapter discussed some of the various RF technologies including the iBean. This section focuses on the details of the interface between the microcontroller and the i-Bean. This task is described as it formed a prototype communication interface for the project. As mentioned in the previous chapter, the i-Beans were specially configured for the project with a serial interface by the manufacturer (Millennial Net 74 Inc. ). There are three lines/pins through which the microcontroller interacts with the i-Bean. They are: 1. RTS (Ready To Send), the microcontroller pulls this line low whenever it wants to transmit data to the i-Bean. This is a signal to the i-Bean that the microcontroller is ready to send data. 2. CTS (Clear To Send), this line signals (line goes low) an indication from the i-Bean to the microcontroller that it is ready to receive data from the microcontroller. This happens after the microcontroller makes the RTS line low. 3. DATA or RX, When the CTS goes low, the microcontroller knows that the i-Bean is waiting to get data from it. The microcontroller sends data (in serial format L9600 baud) using this line. Figure 5-5 shows the connections from the microcontroller to the i-Bean. The i-Bean operates at 3V and hence a special voltage regulator (LP2950) was used. This converts the 9V supply (power supply to the sensor module) to a 3V output, which powers the i-Bean. For the same reason, a voltage bridge is used, which converts the 5V output from the PIC microcontroller to meet the i-Bean requirements. These voltage bridges appear on the RTS and DATA/RX lines. Fig 5-6 shows the timing diagram for the different pins. The constraints on the timings that are shown in figure 5-6 and are also listed in table 5.1. Parameter ti t2 t3 Description CTS response time CTS timeout CTS release after end of message or 20 bytes received Minimum 1 0 0 Maximum Unit 40 millisecond 20 millisecond 20 millisecond Table 5.1: Table showing the timing constraints provided by Millennial Net, Inc. The code to interface the i-Bean with the microcontroller is explained now. 75 PIC 16F877 CTS RTS C5 D3 GND -' 1 7-W RX V cc (3V) LP2950-3.C 9V I + 22 uF Figure 5-5: Interfacing the i-Bean with the microcontroller. 1. The microcontroller collects the digital pressure transducer readings from the external ADC and the thermistor and board voltage readings from the in-built ADC of the microcontroller. The data is formed into a message string which is passed to the i-Bean. When the microcontroller is ready to send the message string, it pulls the RTS line low. The message composition and the protocol used for composing the message are discussed in a later section of this chapter. 2. After the microcontroller pulls the RTS line low, it keeps polling for the CTS line to see if it is low. The time interval for the CTS line to go low (after RFS becomes low) is between 1 to 40 ms. The microcontroller keeps polling the CTS line for 40 ms. Now two situations arise. They are: 76 RTS ti CTS t2 t3 DATA DATA Figure 5-6: Timing diagram for the i-Bean provided by Millennial Net, Inc. (a) CTS line goes low in the 40 ms time. sends the data to the i-Bean. In this case, the microcontroller The data is sent at a baud rate of 9600 and as suggested by the manufacturers, two additional stop bits are used. This is approximately 200 us at 9600 baud. As mentioned in the previous chapter, the maximum payload is 20 bytes. (b) In the second case, the CTS line doesn't go low in the 40 ms time. this case, the microcontroller pulls the RTS line high. In This data is lost because the i-Bean could not receive the data from the microcontroller. The microcontroller just proceeds with collecting data again, composing the message string and try sending data again to the i-Bean. The above procedure is used for sending data to the i-Bean. Once the data is sent to the i-Bean, this data is relayed by the i-Bean to the base station. The base station has a receiver which receives messages from i-Beans and is connected to a PC serial port. The PC runs the software provided by the manufacturers of the i-Bean. This software displays the incoming data at the base station and stores this data in a text 77 file. The software run on the base station had to be modified so that it is possible to check for the integrity of the messages. The i-Beans are not being used in the project because of operational issues arose around the stability of RF communications. Given the strict time line of the project, alternative technologies were considered. Subsequently, the RF transmitter manufactured by Linx Technologies was chosen. The technical details of Linx transmitter were discussed in Chapter 4. The Linx RF IC is not integrated with a formal operating system to manage networking and other hardware issues. This factor forced to resort to raw transmission of data with out collision detection. In future versions, for the better management of networking issues, a system with an operating system would be constructed. This operating system can be a variant of the TinyOS or some similar operating system. 5.3 Interfacing the ultrasonics In this section, details of the interface between the microcontroller and the ultrasonic transducers are discussed. In order to interface the ultrasonics, some changes had to be made to the sensor board. Ultrasonic transducers were discussed in Chapter 2. As mentioned, the positioning devices consist of the basic circuitry for the ultrasonic to operate and calculate the distance. The ultrasonic receiver is a Hexamite HE240 series receiver [25] and the transmitter head, a transceiver (E-152) from Massa Corporation [40]. The ultrasonic transducers have to be configured before they can output data. The PIC microcontroller sends the configuration details over the RS-485 network 3. Therefore,the configuration details have to be known in advance to program the microcontroller. An alternative way is to configure the ultrasonic transducers dynamically. This possibly can be done in two ways. 1. By using a RF transceiver on the sensor board, it is possible for the sensor unit to listen for any messages from the base station. In such case, it is possible to 3 This network consists of the two ultrasonic transducers and the sensor unit. All these devices use a shared medium of wires to communicate. 78 send the configuration data and instructions for the microcontroller to configure the ultrasonics. 2. Using a serial interface to the sensor board and programming the microcontroller so that it can listen for any incoming data. In order to do this, the microcontroller has to listen periodically or an interrupt can be generated whenever it receives data. In order to use the interrupt feature, the microcontroller should use hardware USART module for receiving data. Since the ultrasonic transducers also use the hardware USART, one should disconnect the ultrasonics before giving instructions to the microcontroller to configure the ultrasonic transducers. Listening periodically is not a very efficient way, as it is difficult to get the microcontroller's attention. Another limitation is that this has to be done in the field/tunnel. For this project, the microcontroller is programmed so that it can configure the ultrasonic transducer system comprising a single transmitter and a single receiver. This was the proposed configuration of the ultrasonic transducers. Since, the hexamite positioning devices come with pre-assigned addresses, the configuration data has to be programmed correctly in the microcontroller. The configuration data that the microcontroller sends to the ultrasonic transducer system is shown below. #W 84 OD 01 01 00 00 93\r#S 1C OD 01 00 00 00 2A\r\r 4 Configuration data is explained in Appendix A. As mentioned, the ultrasonic transducers use a shared medium (twisted pair of cables connecting them) to communicate with each other and the microcontroller. They use the RS-485 standard for communication, which was been explained in the previous chapter. The microcontroller outputs data in serial format, which is converted to RS-485 compatible differential outputs using a standard RS-485 driver. ADM1485 was used for this purpose [2]. The microcontroller needs two pins to communicate on the RS-485 network and two other pins to enable its reception and transmission on the RS-485 network. 4 \r is carriage return, since microcontroller is programmed in C. 79 Figure 5-7 shows the various connections between the microcontroller, ADM1485 and the ultrasonic transducers. ADM 1485 00 C7 5 V I RS-485 Network C6 Twisted pair of cables D3 D2 Figure 5-7: Figure showing the interface between microcontroller and the ultrasonic transducers. Before sending the configuration data to the ultrasonics, the microcontroller should enable the transmission line (by pulling the data transmission enable line high) and disabling the reception line (by pulling the data reception enable line high). If the data reception enable line is not disabled, the microcontroller would hear an echo of the data it sends. However, this can be used as a test to check if the data sent by the microcontroller is right or wrong. The microcontroller before transmitting the configuration data, captures the attention of the ultrasonic transducers by sending a control code, a carriage return followed by the escape character. When the microcontroller sends these characters, the ultrasonic transducers wait to hear the configuration data from the controlling device. In this case, it happens to 80 be the microcontroller. The microcontroller then sends the configuration data to the ultrasonic transducers. Following this, the microcontroller disables its transmission to the ultrasonic transducer network5 and enables its reception. The ultrasonics send data every 0.25 seconds 6. Specifically, the format of the data collected from the ultrasonics appears in this fashion. -1234 -1233 There is a new line character at the end of each line of data. The microcontroller is programmed in such a a way that it only considers characters between "-" and the new line character. As the data is in a string format, it needs to be converted to a long ' before it can be stored. After converting the data from string format into long format, the microcontroller collects the next reading and after 20 readings have been collected, the microcontroller averages those 20 readings, composes the message string and sends it to the RF transmitter. Figure 5-8 shows the sensors that were intended to be used in the tunnel. A simple experiment was done to determine the resolution of the ultrasonic transducers. The two transducer boxes (shown in figure 5-8) were placed facing each other on two tables. They were separated by a distance of around 12 ft (the same size as the tunnel diameter). One of the transducers (the Hexamite device) was moved towards the other transducer by a distance of 10 cm in 10 equal steps. At each step, the distance measurements were made, and the average of 200 such measurements was taken as a representative value. The transducer was moved backwards in 10 equal steps to its starting position. During these movements, the transducers were still facing each other. This process of moving one of the transducers forwards and 5 Only one device can transmit in a RS-485 network. Disabling the microcontroller's transmission avoids any accidental data transmission from the microcontroller. 6 This rate is fixed. 7 For the CCS compiler, long is a 16 bit integer [19]. 81 =7 7- MORM Figure 5-8: Figure showing the ultrasonic transducers in boxes. backwards was repeated once, and at each step the average of 200 readings was taken. All these values were plotted as shown in figure 5-9. From the graph, one can see that the response of the ultrasonic transducers is linear, which is satisfactory. But the, standard deviation (or the resolution) of the 200 readings taken at each step was typically around 2 mm (not shown in the graph). As mentioned in Chapter 1, the deformations are expected to be in the order of 2 mm. By a simple rule of thumb, to measure 2 mm deformations, the least resolution required is 0.2 mm. Clearly, the ultrasonic transducers will not be able to achieve the task of measuring 2 mm deformation. Hence they haven't been deployed in the tunnel. 5.4 Others Some other minor, but important details of the sensor board are discussed in this section. They are listed below. 1. The microcontroller has two pins which are connected to the ADM233LJN (RS232 driver). It is possible to use a female end of a serial port connector and use it for debugging purposes or talking to the microcontroller. 2. There is a thermistor on the sensor board which is in series with a 10 K ohm 82 0 88 ~ fowad-21 I * 1;a:. ~4 4~~ a . back iart:. 2 f8A0 . d-2 b. - kThr 800 1 distanc. f tom reof pd nt Inmm Figure 5-9: Graph of the calibration experiment. resistor. The thermistor's resistance changes with temperature changes and this can be used for measuring the temperature at the sensor board. The node which joins these two components is connected to an ADC channel of the microcontroller. 3. There are two 1 M ohm resistors which are directly connected to the power supply of the board. These two resistors form a voltage divider and the voltage drop across one of the resistor is an input to an ADC channel of the microcontroller. This voltage gives an indication of the power supply to the board. 4. Finally, there are two voltage regulators on the board for supplying 5 V (power for most of the components) and 3 V (for the i-Bean). 83 5.5 Sensor Board Figure 5-10 shows the schematic of the sensor board. The sensor board was de- signed after testing the interface of the ADC with the microcontroller, considering the requirements from the Millennial Net Inc. (for i-Beans) and the future intention of interfacing the ultrasonics with the same board. The software that was used for generating the required circuit schematic, and the necessary files for manufacturing the PCB (Printed Circuit Board) is Protel DXP [1]. Some changes have been made from the original design. They are: 1. The original sensor boards had 2 MHz ceramic oscillators and it was found that some of the boards were not working properly. The ceramic oscillators were found to be the cause of the malfunction. Hence the oscillators were changed to 2 MHz crystals and then consistent operation was possible. 2. When testing the i-Beans on the sensor board, it was found that the i-Beans were also not working properly. As mentioned in the previous chapter, 4 MHz oscillators had to be used to fix this problem. Hence, the 2 MHz crystals ' were subsequently replaced with 4 MHz crystals. 3. In the original schematic, the ADM1485's enable pins were wrongly connected to the power line. This had to be changed for interfacing the ultrasonics. A small bread board is used, which houses the ADM1485 and for other connections. Also, the thermistor and the pressure transducer were removed from the board to access some more pins of the microcontroller, so that the ADM1485 can be interfaced to the microcontroller. This was done for interfacing the ultrasonic transducers only. All changes were performed manually and should be amended on the original design for any future work. 4. Two additional wires were soldered at the back of the board so that the hardware USART lines of the microcontroller can be used for interfacing the ultrasonics. The reason for using the hardware USART lines is that the microcontroller is 8 The 2 MHz crystals were replaced only for the microcontroller and not for the external ADC. 84 k 4~ AE 14: [C ] -T- AL E E ] D- - C bd[ r I E 30-E 3 16 ---4- L2 E: ]L3 2] E : E ] I FCI /f 1 X2200A cJJz L LD rnsd uc er-- 0 I ---- - - LP2950-!IJ3 q uF fI I~ ~tter'y Figure 5-10: Schematic of the sensor board. 85 um W Figure 5-11: Figure showing the sensor board and the wireless sensor unit. more efficient in receiving data from the ultrasonics. Even with the last two modifications, the sensor board could not be used to interface the ultrasonics because of a defective power supply to the sensor board. Hence, two printed prototyping boards were required to interface the ultrasonics with the microcontroller. This is shown in figure 5-8 Apart from these changes it was found that one of the board also had defective voltage regulators. The sensor boards are enclosed in a metallic box, so that they can be used in the tunnel (see figure 5-11). In the next section the protocols for composing the messages are discussed. 5.6 Protocols This section briefly describes the protocols for composing the message strings, that are transmitted to the base station by the RF transmitter. The base station software in turn checks the validity of the data and incorporates it into the database if the data is valid. This protocol was written by James Brooks, but some minor changes and suggestions were made by the author and described further in this section. Appendix C lists the details of the latest version of the protocol. In the next couple of sections, 86 the protocol that is used for sending data when the i-Bean is used as the transmitter and the protocol for the ultrasonics when a Linx transmitter is used. 5.7 Protocol for i-Bean This section explains the protocol that is used for sending data from the i-Bean to the base station. Some of the changes that have been made to the base station software (provided by Millennial Net Inc.) are also mentioned. The software changes had to be made so that the data could be checked for its integrity at the base station. The message format is as follows. 1. The first two bytes of the message are the start bytes. These are 123 and 43 in decimal. All messages require these start bytes. 2. The next two bytes are for the length of the message. The LSB (Least Significant Byte) is followed by the MSB (Most Significant Byte). 3. The next two bytes are for the sensor id. Again, the LSB is followed by the MSB. 4. The next two bytes are for the reading number. The reading number starts from 1 and continues until 65536 and starts from 0 again. The reading number helps determine some readings are missing. This is indicated if there is a skip in the reading number instead of being consecutive. 5. The next three bytes are for the pressure transducer reading. The LSB comes first and the MSB last 6. The next two bytes are from the channel 0 of the in-built ADC of the microcontroller. MSB follows LSB. This gives the thermistor reading 7. The next two bytes are from the channel 1 of the in-built ADC of the microcontroller. MSB follows LSB. This gives the supply voltage to the board. 87 8. The next two bytes are the checksum bytes. The check sum bytes are the sum of all the bytes starting from the start bytes to the bytes before the checksum bytes. An example of a (correct) message string is below (in decimal format). 43 , 17, 0, 123, 1, 0, 10, 0, 100, 230, 11, 55, 3, 189, 8,22, 3 Since the i-Bean uses proprietary protocols for transmitting data,one has to use the code provided by i-Bean manufacturers at the base station for interpreting the data. This code had to be modified so that this could also check the integrity of the data that the base station received using the above mentioned protocol. The modified code at the base station first checks if the start bytes are right and see if the message length bytes indicate the true message length and finally the code checks if the checksum bytes are right. If either the start bytes are wrong or if the checksum bytes are wrong, the code would mention so. 5.8 Protocol for the Ultrasonic transducer In this section, the protocol for transmitting the ultrasonic data from the sensor unit to the base station is discussed. This protocol is a part of the complete protocol described in Appendix B. The protocol is described below. 1. The first three characters of the message string are CMI followed by the character "," 2. The next two characters of the message string are UR followed by the character ",". UR for Ultrasonic report. 3. The next character is the sensor id followed by the character " 4. The next two characters mentions the transmitter and the receiver followed by the character ", 5. The next four characters indicate the output from the ultrasonics in decimal followed by an asterisk. 88 6. Finally, the last two characters are the LSB (in hexadecimal) of the checksum. The checksum is the sum of all the ASCII values of the characters from the starting character to the character (including ",") before the asterisk. An example of a correct message string is shown below. CMI,UR,Q,SU,1234*F3 In this chapter, the details of the interfacing of various components have been discussed. These components form the sensor unit of the wireless sensor network. The data protocols and some relevant details of the sensor board also have been discussed. The next chapter summarizes the thesis and states the directions for future research. 89 90 Chapter 6 Summary 6.1 Summary The goal of the London Underground monitoring project is to develop a real-time system to measure displacements and deformations. This thesis discusses the various components of the wireless sensor unit that was developed.. In particular, the discussion is focused more on the hardware details, where the different electronic components are interfaced with the microcontroller. The wireless sensors were installed in the tunnel on the 17th October, 2003. Presently, the sensors are collecting data and reporting to a base station receiver in the access shaft of the tunnel. The receiver collects the data and transmits the data to a laptop. The program running on the laptop checks for the integrity of the data using the protocol described in Appendix B. These data are then stored in a text file and a wireless modem periodically sends them to an MIT server. Figure 6-1 shows a sensor installed in the tunnel. The figure also shows the location of the various wireless sensors installed in the tunnel. Figure 6-2 shows the receiving unit and the laptop in the access shaft of the tunnel. Figure 6-3 summarizes the whole operation of the wireless sensors in the tunnel. There are still areas for improvement in the project and are addressed in the next section. Even though data is being collected, a lot of processing has to be done to remove noise from the readings. The processing also accounts for data that was lost 91 1H Figure 6-1: Figure showing the installed sensors in the tunnel. perhaps due to faulty communication or extreme interference due to the passing of a train or to correct for various environmental effects. These effects might be because of the temperature variation in the tunnel or again transient effects such as a change in the pressure, when a train passes through the tunnel. The present processing scheme employed averages the readings over 5 minute intervals. For intervals that do not have any readings (because of lost readings), a linearly interpolated value is used between the previous and next intervals which have a reading. After this, a low pass filter is used to remove the sensor noise. The filtered values are also stored in the database and are used to calculate displacements. This installation highlighted some of the important issues in designing a wireless sensor system. However, because of the limited time-frame of the project, many other considerations remain unsolved. For example, on-chip processing for energy conservation, appropriate communication protocols for collision detection, etc. 92 Figure 6-2: Figure showing the receiving unit and the laptop placed in the access shaft of the tunnel. 6.2 Directions for future research In this section, some of the improvements that can be made to the existing system are discussed. This discussion focuses on the wireless technology and the hardware that is being currently used and how they might be enhanced. 6.2.1 Wireless technology The RF IC that was used for this project is the Linx RM series ICs. These are simple devices with no ability to apply a communications protocol. This fact is obvious, especially if these ICs are compared with the MICA motes or the i-Beans. The network topology of the wireless sensors installed in the tunnel is similar to a limited hub and spoke topology. Since inter-sensor communication and contention resolution are not possible, there will be often collisions when two or more transmitters try to transmit at the same time and this causes loss of data. This might not be such a critical issue if only few sensors 1 are used and data is not extremely valuable. Such a system is inherently unscalable. Additionally integrity and continuity is critical such 'In the present project, 16 of them are being used. 93 Int.mrir, lr ful n Acces Expectedtettlentnt lorf L L ExAtting s Are reWitstrnW * rervo itAchted I turnnel wall ied n ht New CTRL tun-e1 6rn dinjo C~ItL 0,06TunnO Oosring Michine Figure 6-3: Summary of the wireless sensor operation. an architecture is wholly inadequate. Another limitation of the Linx ICs used is the lack of bi-direction communication capabilities. This limitation further impacts the scalability and loss of data factors mentioned. Bidirectional communication capability would also provide the option of sending data in hops, i.e. we could send data through intermediate sensor nodes. Bidirectional capability also increases redundancy in the routes through which data is routed in the system. This capability makes the system more sophisticated and provides an ideal platform to study the performance of different ad-hoc networking and multi-hop routing protocols. In order to achieve bidirectional capability, some of the possible options are: . Bluetooth devices, which are low-cost, low-power devices and have bidirectional 94 capabilities. The limitation of these devices is the communication range (around 10 m) of these devices. " Other RF ICs which have bidirectional communication capability. These include RF ICs from RFM [55] and Chipcon [10]. This then increases the functionality that the microcontroller has to provide for proper handling of bidirectional communications. In addition they have a microcontroller integrated on chip, which allows specific customization of communication protocols suitable for each specific monitoring task. " Future versions of the MICA motes or the i-Bean might be useful for a similar kind of application. The MICA motes do have bidirection communication capability, while the present version of i-Bean (i.e. the version that was tested for this project) do not have this capability. 6.2.2 Hardware The microcontroller that was used in this project is a PIC16F877. The typical power consumption of this microcontroller is 0.6 mA 03V and a 4 MHz. There are newer microcontrollers from Microchip Technology, Inc. such as the nanowatt range that have lower power consumption than this microcontroller. A list of such microcontrollers can be found here [43]. Lower power microcontrollers are important for making the wireless sensor unit autonomous, with minimum human intervention. Lower power increase the life of the sensing unit, compared to the present one, and also allows more devices to be interfaced with the microcontroller, again compared to the present one. Another important component to consider is a DSP chip. This would allow efficient local processing of the data. With local processing of data, it is possible to minimize the number of messages sent to the base station. This in turn saves a lot of power as RF communications are power expensive. 95 6.2.3 Operating system Another important area for future work is to use a low-level operating system on the microcontroller. This provides the microcontroller with multi-tasking and schedul- ing features. One such example is TinyOS [621. For future applications, a TinyOS compatible microcontroller may be used or a basic operating system (like TinyOS) may be developed for the microcontroller(s) that is(are) used. This allows a lot of flexibility in developing the applications. 6.3 Conclusions This thesis described the development of a wireless sensor module for tunnel monitoring. A real-time monitoring system was developed and deployed to measure vertical displacements along the critical zone near Hihbury & Islington station. Real-time measurements were not possible as the data had to be processed before the displacements could be calculated. To conclude, there is a lot of exciting opportunity to develop more sophisticated sensor devices in the future and to enhance the society through distributed monitoring of infrastructure. 96 Appendix A Configuration details for ultrasonic transducer using HE860 The composition of the configuration string for configuring the ultrasonic transducers using HE860(as the positioning device) is shown in table A.1. Byte 1 2 3 4 5 Parameter Program Control Byte(PCB) Termination Byte(TB) Number of Beacons Byte(NBB) Beacon Designation Byte(BDB) Noise Suppression Byte(NSB) Table A.1: Table showing the Configuration String A beacon is a device which can tarnsmit ultrasonic waves and a pilot is a device which can receive ultrasonic waves. The PCB(for a beacon) settings are shown in A.2. For the configuration described in Chapter 5 (i.e. one beacon and one pilot connected over serial network), Bits 2 and 7 should be set (making it 84 in hexadecimal) for the beacon. The terminal byte is ODh (in hexadecimal) for the beacon. NBB = 01h, BDB = 01h and NSB = 00h for the beacon. For the PCB of the pilot (table A.3),Bit 2 (though it is unnecessary) , Bit 3 and 97 Bits Bit 0 Bit 1 Bit 2 Bit 3 Bit 4 Bit 5 Bit 6 Bit 7 Bit Function(Beacon) Synchronization using ultrasound Synchronization override Beacon is linked on a serial network Ignored Ignored Ignored Ignored Should be set for a Beacon Table A.2: Table showing the bits of the PCB for a Beacon Bit 4 are set, which makes it ICh. TB = ODh, NBB = 01h, BDB =00h and NSB = 00h for the pilot. The configuration bytes for the beacon(s) should be sent before sending the configuration bytes for the pilot. Bits Bit Bit Bit Bit Bit Bit 0 1 2 3 4 5 Bit Function(Pilot) Synchronization using ultrasound Reserved Reserved Pilot acquires data continuously Device is the master (initiator) on the network Ignored Bit 6 Ignored Bit 7 Should be cleared for a Pilot Table A.3: Table showing the bits of the PCB for a Pilot 98 Appendix B Sample microcontroller program in assembly language and in C B.1 Program in assembly language A simple program which counts in binary from 0 to 255 and starts again from 0. list p=16f877 include "pl6f 877. inc" ; Start at the reset vector ;(this is where the chip boots from by ;default) org Ox000 goto start start ; the SFRs we want to use are in bank 1 so we set the STATUS bits 99 ; to make bank 1 active (i.e. set context) ; SFRs TRISA,B,C,D,E correspond to the respective I/O ports/pins ; on chip ; Each bank defines an offset address applied/prepended to the ; value of the mnemonic used to refe to a register ; e.g. if banki is at some address say 1000, and TRISA has a ; reference value/token of 77, then the absolute address of ; TRISA is 1000 + 77 = 1077 (check spec for actual address values bsf STATUS,RPO ; set bcf STATUS,RP1 ; clear bit RP1 in STATUS bit RPO in STATUS ; we want to assign the prescalar multiplier for timer TMRO ; by through the SFR OPTIONREG bits. - place required settings in W and mov to OPTIONREG - here we use prescalar of 1:256 for TMRO, use internal clock cycle movlw b'00000111' movwf OPTIONREG ; load Os into working reg w ; clear all TRISs bits (0) i.e. these ports are entirely O/P ; We are setting ALL of the I/0 pins as O/P to ensure we know ; their designation movlw H'00' movwf TRISA movwf TRISB movwf TRISC 100 movwf TRISD movwf TRISE ; need to move to bank 0 to access PORTA,B,C,D,E ; since we know bit RP1 is 0, we only need to change (clear) ; RPO to specify bank 0 bcf STATUS, RPO ; bank 0 ; now setup value in portB to be zero, i.e. we are ; clearing all bits (0). Simplest way is to clear register ; in one instruction using _clrf_. We could clear each bit ; individually but it is unecessary. clrf PORTB ; now loop through binary values by incrementing PORTB by 1 (i.e. b'00000001') each loop increment corresponds to 256 timer ticks, each timer tick is 256 usec, so each update of the vlaue in PORTB takes 256^2 usec ~= 0.06 sec. We'll see this barely as the frequency is 16 Hz the logic of the loop is to poll the INTCON reg to see if the TOIF bit is set using the instruction btfss (bit test file skip-if-set) if not set it continues to instruction "goto $ - 1" which tells it to go to the previous line (i.e. $ means current line, $ - 1, 101 means the previous line). so it keeps testing INTCON,TOIF until TOIF is set when it determines TOIF bit is set this indicates overflow of the timer and tells program to "skip" the next instruction. So the program reaches the "bcf INTCON,TOIF" instruction which clears the TOIF bit and at the same time since TIMERO has overflowed it effectively wraps around to restart at 0, so we are back at the same initial starting conditions for the loop i.e. TIMERO is 0 and the TOIF bit is clear (0). count incf PORTB,1 btfss goto INTCON, TOIF $ -1 bcf INTCON, TOIF goto end count ; et fini 102 B.2 Program in C Similar program in C, but uses interrupts instead of polling. #include <16F877.h> // header file for address definitions #fuses XTNOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP #use delay (clock=4000000) // int value = 0; // clock speed 4MHz 8 bit int, global variable #INTTIMERO // Interrupt service routine void isr 0 { value ++; // increment value outputb(value); // and show the new ''value'' portb on } main() { settris-a(OxOO); // make all the ports output settris.b(OxOO); settris-c(OxOO); settris-d(OxOO); settris-e(OxOO); output-b(value);// output 0 on portb enableinterrupts(GLOBAL); // enables interruptst //at the global level enableinterrupts(INTTIMERO)// enables TimerO 103 // interrupt settimerO(O) ; sets the timer to zero; do }while(true); //infinite loop so that interrupts are // always generated } 104 Appendix C Latest version of the microcontroller code The present verison of the microcontroller code and the code to interface the ultrasonics is listed below. //Code for CMI LUL pressure module microcontroller //Version 5 31July2003 //ADC Reset after negative or low values //4MHz clock //sending thru Linx at 9600 baud //config comm always thru RS232, 2400 baud //delays function of sensorid #include <16F877.h> #device *=16 ADC=10 #fuses XT,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP #include <stdlib.h> #use delay(clock=4000000) #define SYNC PINB6 #define ADRINP PINB7 #define SCLK PINA2 #define SDATA PINA5 #define DRDY PINEO #define RFS PIN_El #define TFS PINE2 #define RADIOPWR PINC5 105 #define RCVPIN PIN_B1 #define MAXMSGLEN 32 #define NUMFIELDS 5 #separate void init_7713_adc(); void listenmodeo; void sendserial-messageo; int data[31 ={ObOOOOOOOO, Ob0000000, unsigned int presstmr = 0; unsigned int temp-tmr = 0; char gstr[421; int chk-ptr; int field-ptr[NUMFIELDS]; char sum, sensorid; int gi,gj; int data-to-port=1; unsigned int press-freq = 5; unsigned int temp-freq = 30; #INTTIMER2 void istr2() { static int mscount = 25; static short lastval=1; if (input(RCVPIN) != lastval) { listenmode(; if(last-val==0) lastval=1; else lastval=0; } mscount--; if(mscount==0) { presstmr++; temp-tmr++; mscount = 25; } } void add_checksum(char *str) 106 Ob000000}; { gi = 0; sum = Ox00; while( str[gil != OxCO) { sum += strEgil; gi++; } str[gil = sprintf(str + gi + 1, "XX", sum); str[gi+31 = OxOO; } void chop-checksum(char *str) gi = 0; while(str[gil OxOO) { if (strEgil == { str[gi] = OxOO; return; } gi++; } } void send radiomessage() #use rs232(baud=9600, xmit=PINC4, rcv=PINB1) if (data-to-port==1) { sendserialmessageo; chop-checksum(gstr); } addchecksum(gstr); output-high(RADIOPWR); for(gi=0; gi<20; gi++) putc(Ox00); putc(OxOD); 107 putc(OxOA); printf (gstr); putc(OxOD); putc(OxOA); printf(gstr); putc(OxOD); putc(OxOA); printf (gstr); putc(OxOD); putc(OxOA); delay-ms(10); outputjlow(RADIOPWR); } void sendserial-message() #use rs232(baud=2400, xmit=PINBO, rcv=PINB1) addchecksum(gstr); printf(gstr); putc(OxOD); putc(OxOA); } void send-ack(char *msg-type, int result) sprintf(gstr, "CMI,AR,%c,%s,%d", sensorid, msg-type, result); sendserialmessageo; } void sendversion() { sprintf(gstr, "CMI,VR,%c,P,Ver 5,31JulO3",sensorjid); sendserialmessageO; } void sendid() { sprintf(gstr, "CMI,IR,%c",sensorjid); 108 sendserial-messageo; } void setid(char id) writeeeprom(Ox02, id); sensorid = read-eeprom(Ox02); sendidO; } void sendschedule() { sprintf(gstr, "CMI,SR,Xc,/u,%u", sensor id, pressjfreq, temp-freq); sendserialmessageO; } void setschedule(char *pres, char *tp) { int pi, ti; char temp[51 ,type [31; sprintf (type, "SS"); if ((presEO] < '0') 11 (presEO > '9')) { sendack(type,2); return; } if ((tp[0] < '0') 11 (tp[0] > '9')) { sendack(type,2); return; } for (gi=0; gi<5; gi++) { tempEgi] = pres[gi]; if (pres[gil==',') { temp[gi]=0x00; break; } } pi = atoi(temp); 109 if ((pi<3) 11 (pi>250)) { send-ack(type,2); return; } for (gi=0; gi<5; gi++) { temp[gil = tp[gil; if (tp[gil=='*') { temp[gi]=OxOO; break; } } ti = atoi(temp); if ((ti<3) 11 (ti>250)) { send-ack(type,2); return; } writeeeprom(Ox04, pi); writeeeprom(Ox05, ti); pressjfreq = readeeprom(0x04); temp-freq = read-eeprom(Ox05); if ((press-freq != pi) 11 (temp-freq != ti)) { send-ack(type, 3); return; } sendack(type,O); sendscheduleo; } void senddataout() sprintf(gstr,"CMI,DR,%c,%d", sensorid, datato-port); send-serialmessageO; } void setdataout(char setting) char temp[31; sprintf(temp,"DS"); 110 if (setting == '0') writeeeprom(Ox03, 'n'); else if (setting == '1') writeeeprom(Ox03, 'y'); else sendack(temp,2); datatoport = 1; if (read-eeprom(0x03) == 'n') data-to-port = 0; senddata-out(; } #separate void sendmisc() char stri[321; strcpy(strl,gstr); strl[311 = Ox00; sprintf(gstr, "CMI,MR,%c,%s", sensorid, stri); sendserial-messageO; chop-checksum(gstr); sendradiomessageO; } short my-get-char(char *the-byte, long timeout) { static long i; for (i=0; i<timeout; i++) if (kbhit()) *the-byte = getcho; return 1; } delay-us(10); } return 0; } short my-get-message(char *string, int length, long timeout) 111 static int byte-count; bytecount = 0; while (byte-count < length) { if (my-get-char((string + byte-count), timeout) == 0) string[byte-count] = Ox00; if (byte-count==0) return 0; else return 1; } byte-count++; } return 1; } short checkmessage(char *msg) chk-ptr = 0; for (gi=0; gi<NUMFIELDS; gi++) field-ptr[gil = 0; for (gi=0; gi<MAXMSGLEN; gi++) { if (msg[gi] == '*') chk-ptr break; = gi; } } if (chk-ptr == 0) return 0; gj=100; for (gi=0; gi<MAXMSGLEN - 2; gi++) { if ((msg[gil=='C') && (msg[gi+1]=='M') && (msg[gi+21=='I')) gj = 0; field-ptr[0] = gi; 112 break; } } if (gj == 100) return 0; sum = Ox00; for (gi=field-ptr[0]; gi<chk.ptr; gi++) sum = sum + msg[gil; sprintf(gstr, "X", sum); if ((gstr[0] != msg[chk-ptr + 11) 11 (gstr[1] != msg[chk-ptr + 21)) return 0; for (gi=field-ptr[01; gi<chkptr; gi++) if (msg[gi]==',') { gj++; if (gj >= NUMFIELDS) return 0; field-ptr[gjl = gi+1; } } return 1; } void listen-mode() static char rcvmsg[MAXMSGLEN]; sprintf(gstr,"?"); sendserialmessageO; rcv-msg[0] = OxOO; rcv-msg[MAXMSGLEN-1] = OxOO; if (my-get-message(rcv-msg, MAXMSGLEN, 65000) == 1) { if (check-message(rcv-msg)==0) continue; 113 if (field-ptr[1] == 0) continue; if ((rcv-msg[field-ptr[11] && (rcv-msg[field-ptr[1] == 'V') + 11 == 'Q')) { if ((rcvmsg[field-ptr[211 == sensor-id) 11 (rcv-msg[field-ptr[2]1 == '#')) { sendversion(); } } else if ((rcv-msg[field-ptr[1]] == 'I') && (rcv-msg[field-ptr[1] + 1] == 'Q')) send-ido; else if ((rcv-msg[field.ptr[1]] == 'I') && (rcv-msg[field-ptr[1 + 11 == 'S')) set-id(rcv-msg[field-ptr[211); else if ((rcv-msg[field-ptr[1]] == 'S') && (rcv-msg[field-ptr[1] + 11 == 'Q')) { if ((rcv-msg[field-ptr[2]1 == sensor-id) 11 (rcv-msg[field-ptr[2]1 == '#')) { sendscheduleo; } } else if ((rcv-msg[field-ptr[1]] == 'S') && (rcv-msg[field-ptr[1] + 11 == IS')) { if ((rcv-msg[field-ptr[2]1 == sensor-id) 11 (rcv-msg[field-ptr[211 == 1#1)) { setschedule(&rcv-msg[field-ptr[311, &rcvmsg[field-ptr[411); } } else if ((rcvmsg[field-ptr[1]] == 'D') && (rcv-msg[field.ptr[1] + 11 == 'Q')) { if ((rcv-msg[field-ptr[2]1 == sensor-id) 11 (rcv-msg[field-ptr[2]1 == '#)) 114 { senddataout(); } } else if ((rcv.msg[field-ptr[1] == 'D') (rcv-msg[field-ptr[1 == 'S')) + 11 && { if ((rcv-msg[field-ptr[2]1 == sensor-id) 11 (rcv-msg[field-ptr[2]1 == { setdataout(rcv-msg[field-ptr[3]1); } } else { sprintf(gstr,"Not know <<s>>",rcvmsg); sendserialimessageO; } } else { sendserial-messageo; } delay-ms(50); } void write_7713_adc() { int x[31 = {OblO100001, OblOO00111, OblO111001}; // LSB MSB //mode = act. background calib. //PGA gain = 64 //channel AIN2 //// //24 bit word //RTD off //burn-out off //bi-polar //filter so 2Hz output-low(ADRINP); delay-cycles(1); 115 output low(TFS); for (gi=0; gi<24; gi++) { output-bit(SDATA, shiftleft(x,sizeof(x),0)); delay-cycles(1); outputhigh(SCLK); delay-cycles(2); outputlow(SCLK); delay-cycles(1); } output-low(SDATA); delay-cycles(1); output._high(TFS); delay-cycles(1); output-high(ADRINP); } #separate void read_7713_adc() { gj =0; while (true) if (input (DRDY)==0) { outputlow(RFS); for(gi=0; gi<24; gi++) { delay-cycles(2); shiftleft(data,3,input(SDATA)); outputhigh(SCLK); delay-cycles(2); outputjlow(SCLK); } output-high(RFS); break; } delay-ms(100); if (gj>100) { 116 sprintf(gstr,"7713ResetADC"); send-misco; init_7713_adco; gj=0; } } } void read_7713_adcreg() { outputjlow(ADRINP); output_low(RFS); for(gi=O; gi<24; gi++) { delay-cycles(2); shift_left(data,3,input(SDATA)); output-high(SCLK); delay-cycles(2); outputilow(SCLK); } output-high(ADRINP); output-high(RFS); } void report-reg() { int bit; char inbin[251; for(bit=0; bit<24; bit++) { if(shift§left(data,3,0)==1) inbin[bit] = '1'; else inbinEbit] = '0'; } in-bin[24] = Ox00; sprintf(gstr,"ADC: %s", in-bin); sendmisco; } 117 #separate void send-press-msg() { float step = 0.5000; float value = 0.0000; //int offsetbinary = true; for (gi=0; gi<24; gi++) { if (shiftjleft(data,3,0)==1) value += step; step = step/2.000; } value -= 0.5000; sprintf(gstr,"CMI,PR,%c,%01.9f", sensorid, value); sendradiomessageO; if (value < 0.01) { sprintf(gstr,"SPMResetADC"); sendmisco; init_7713_adco; //reset ADC } } long onboardadc(int num) { long reading; setadcchannel(num); delay-ms(100); reading = read-adco; return reading; } #separate void send-temp-msg() { long reading; float ftemp, fvolt; reading = onboardadc(0); 118 fvolt = (reading/1023.00)*10.00; reading = onboard-adc(1); ftemp = (reading/1023.00); sprintf(gstr, "CMI,TR,Xc,1.lf,%01.3f", sensorid, fvolt, ftemp); sendradiomessageO; } #separate void init_7713_adc() settris-a(ObOO001011); output-high(RFS); delay-ms(1); output-high(TFS); delay.ms(1); output-high(ADRJINP); delay-ms(1); output-low(SYNC); delay-ms(1000); output-high(SYNC); delay-ms(1); write_7713_adc0; settris-a(ObOO101011); delay-ms(1); read_7713_adcreg(); report-rego; } main() { int badreads=O; char seq-char; settris-a(ObOO001011); settris-b(ObOO001100); settris-c(ObOO010000); settrisAd(OxOO); settris-e(ObOO000001); setup-adc(adc-clock-div_32); 119 setup-adc-ports(RAORA1_ANALOGRA3_REF); output-low(RADIOPWR); sensorid = read-eeprom(Ox02); if (read-eeprom(0x03) == 'n') datato-port = 0; pressjfreq = read.eeprom(Ox04); temp-freq = read-eeprom(Ox05); if ((press-freq > 250) 11 (pressjfreq < 3)) pressjfreq = 5; if ((temp-freq > 250) 11 (temp-freq < 3)) tempjfreq = 30; if ((sensorid >= 'A') && (sensorid <= 'Z')) { for (seq-char = 'A'; seq-char < sensorid; seq-char++) delay-ms(222); } sprintf(gstr,"Hello"); sendmisco; init_7713_adcO; enableinterrupts(INTTIMER2); enable-interrupts(GLOBAL); setup-timer_2(T2_DIVBY_16, 250, 10); settimer2(0); while(true) { read_7713_adc(); if(data[0]==0x00 && data[1]==OxOO && data [21 ==0x00) badreads++; else if (data[01==0xFF && data[1]==OxFF && data[21==0xFF) badreads++; 120 else badreads=O; if (badreads>2) { sprintf(gstr,"MainResetADC."); send-misco; init_7713_adcO; badreads=O; } while (press-tmr < pressjfreq) delay-ms(10); if ((sensorid >= 'A') && (sensorid <= 'Z')) { for (seq-char = 'A'; seq-char < sensorjid; seq-char++) delay-ms(73); } sendpress-msgo; //pressure press-tmr = 0; //reset timer if (temp-tmr >= tempjfreq) //time to send temperature { send-temp-msgo; temp-tmr = 0; } } } C.1 Code to interface the ultrasonics #include <16F877.h> #device *=16 ADC=10 #fuses XT,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP #use delay (clock=4000000) #include<stdlib.h> #define DE PIND2 // TP9 driver enable pin for transmitting, I/ high while transmitting #define RE PIND3 II TP8 receive enable pin for receiving, 121 #define #define #define #define #define // low while receiving TX485 PINC6 RX485 PINC7 TXRF PINC4 RXRF PIN_B1 RADIOPWR PINC5 char v; void config() { int i; int data[7]; output-high(DE); // delay-cycles(1); b6 is driver enable for transmitting #use rs232(baud=19200, xmit=TX485, rcv=RX485) putc(OxOD); putc(Ox1B); printf("#W840D0101000093\r# S1COD010000002A\r\r"); putc('-'); output-low(DE); output-low(RE); } main() { int data[7]; char chars[301; int i, j,k,l,m, sum; int32 value; long values[201; write-eeprom(2,'U'); output-high(RE); output_low(DE); config(); do 122 { #use rs232(baud=19200, xmit=TX485, rcv=RX485) gets(data); if(data[0] = { values [kl= atol(data); value += values[k]; k ++; } if(k==20) { value = value/20; sprintf(chars,"CMI,UR,U,SW,%lu",value); for(l=0; 1<30; 1++) { if (chars [1 !=0x00) sum += chars[1]; else break; } #use rs232(baud=9600, xmit=TXRF, output-high(RADIPWR); delay.cycles(1); printf("CMI,UR,U,SW,Xlu*XX\r\n", printf("CMI,UR,U,SW,Xlu*%X\r\n", printf("CMI,UR,U,SW,Xlu*%X\r\n", delay-ms(10); outputjlow(RADIOPWR); k =0; value =0; sum =0; } } while(true); } 123 rcv=RXRF) value,sum); value,sum); value,sum); 124 Appendix D ASCII version of CMI Communication Protocol This is the actual draft of the protocol used for composing the messages. This has been written by James Brooks, who also worked on this project. This is a protocol for communication between field sensors and the controlling base station. It is not as data-efficient as a binary protocol, but it is easier to parse and debug as the messages can be read by users. New messages can be added at any time within this framework. The specifics outlined here pertain to Version 4 of the microcontroller code currently loaded on the pressure sensors' microcontrollers. For the current installation, the radio link is through a Linx-brand transmitter at 9600 baud. Data messages (Pressure and Temperature Reports) and Miscellaneous Reports are sent out over the radio link to the base station. The microcontroller boards also have the option to communicate directly to a computer through a serial port at 2400 baud. (Faster baud rates were found problematic with some computers.) The computer can configure the microcontroller over this link. Messages to query or to set settings on the microcontroller come from the controlling computer over this link. Messages reporting the status of various settings pass from the microcontroller to the controlling computer over this link. Optionally, the data messages containing the readings the sensor is taking also come over this link. 125 A software utility written for this project can be used to send messages to the microcontroller. Any application (such as HyperTerminal) set to 2400 baud can listen to the microcontroller output. Sending messages is more difficult as the microcontroller is not always listening to the serial port. Our application sends out the byte OxFF continuously until it hears a response. When the microcontroller hears the bytes coming in on the serial port, it sends back the character '?' meaning it is ready to listen. The application on the computer side then sends the message to the microcontroller. Data Fields: The different fields of the messages will be separated by commas for easy parsing. Start bytes: Every message will start with three bytes, the letters "CMI" these indicate that a message is starting. These letters will never appear elsewhere in any message. Message Type: The next field after the start bytes will be the message type. This will be a two letter code identifying what the message is about. The types fall into three categories: Queries, Reports, and Settings, the codes for these messages end in 'Q', 'R', and 'S' respectively. ID: Each sensor has a unique ID. This is one character, stored in non-volatile memory on the microcontroller. Most messages contain the ID of either the sensor reporting in, or of the sensor that the message is intended for. This unique ID is in some cases duplicated by the fact that some wireless systems have a feature that the source of messages is tagged. However, having our own identities frees us to use any method for transmitting the messages, even a simple wired connection. The character '#' as the ID in a message means that this message is intended for all sensors who hear it. Checksum: Every message ends with a checksum. The purpose of the checksum is to identify when the bytes of a message have been corrupted. The receiver of the message should check that the checksum is correct and discard the message if it is not. The checksum is two characters long and appears after an asterisk appended to the message. To calculate the checksum, start with a byte set to zero. Starting at the first character of the message (the 'C' of "CMI") and ending before the asterisk, 126 add the binary value of each byte into the sum. The resulting one-byte value can be represented by a two-digit hexadecimal number. These two digits serve as the checksum. Messages Identity Query(IQ): This is sent by the base to a certain sensor to ask what that sensor's ID is. The sensor should answer with Identity Response. Fields: Start, Type Example: CMI,IQ*9F Meaning: "What is your name?" Identity Report (IR): The sensor uses this to report what its ID is. For the moment the identity is one-byte long, but future applications can use longer IDs. Fields: Start, Type, ID Example: CMI,IR,B*OE Meaning: "I am Sensor B" Identity Set (IS): This is sent by the base to a sensor to set its ID. It is anticipated that it will only ever need to be set once for each sensor. It is important that only this sensor is listening when this message is sent out, otherwise multiple sensors will have the same ID. The sensor replies with the Acknowledgement Report to say if the ID switch was successful. Fields: Start, Type, ID Example: CMI,IS,B*OF Meaning: "You will be called B from now on." Version Query (VQ): The base uses this to find out from the sensor what version of firmware is running on the sensor's microcontroller. It is answered with Version Report. Fields: Start, Type, ID Example: CMI,VQ,E*1D Meaning: "Sensor E,what is your firmware version?" 127 Version Response (VR): The sensor responds to a Version Query with this message containing its firmware. Fields: Start, Type, ID, Type of Sensor (P=pressure, U=ultrasonic, more as needed), Version, Date Example: CMI,VR,E,P,Ver2,17JunO3*69 Meaning: "I am Sensor E, a Pressure sensor, running version 2 of the firmware, from June 17th." Pressure Report (PR): The pressure sensor sends this one out automatically based on the schedule it's been programmed with. Fields: Start, Type, ID, Pressure Reading Example: CMI,PR,E,0.12654336*40 Meaning: "Sensor E reporting a pressure of 0.12654336." Temperature Report (TR): The pressure sensor also sends out (with less frequency) this message containing the supply voltage to its board and the thermistor reading. The conversion of thermistor reading to temperature will take place at the base. Fields: Start, Type, ID, Supply Voltage, Thermistor Voltage Example: CMI,TR,E,8.6,0.878*15 Meaning: "Sensor E reporting a supply voltage of 8.6 volts, and a thermistor reading of 0.878." Schedule Query (SQ): This is to ask the microcontroller the frequency of its automatically outputted messages. Fields: Start, Type, ID Example: CMI,SQ,G*1C Meaning: "Sensor G, how are your messages scheduled?" Schedule Report (SR): The microcontroller on a pressure module uses this message to report how its automatic reporting schedule is set. It sends it in response to a SQ message and also after it sets itself in response to an SS message. Frequencies are in seconds. Fields: Start, Type, ID, Pressure Frequency, Temperature Frequency Example: CMI,SR,G,5,30*OD 128 Meaning: "This is Sensor G. I send pressure measurements every 5 seconds and temperature readings every 30 seconds." Schedule Set (SS): This is to schedule the frequency of the automatically outputted messages on a pressure sensor. The values are in seconds. Acceptable values are from 3 seconds to 250 seconds. The temperature messages cannot be more frequent than the pressure messages. Fields: Start, Type, ID, Pressure Frequency, Temp. Frequency Example: CMI,SS,G,10,40*3B Meaning: "Sensor G, you are to report pressure every 10 seconds, temperature every 40 seconds." Data Messages Query (DQ): This is to ask the microcontroller whether the data messages (PR and TR) are sent only to the radio, or also to the serial connection. A user attached with a serial cable can view the data messages if they are on, but if the module is going to be wireless for a long period, with no one listening through a serial cable, it is wasteful to send the messages out both ways. A value of 1 means the data messages also go to the serial port; a value of zero means the data messages do not go to the serial port. Default is 1. Fields: Start, Type, ID Example: CMI,DQ,C*09 Meaning: "Sensor C, do you send data messages to the serial port?" Data Messages Report (DR): The microcontroller on a pressure module uses this message to report whether or not it is outputting data messages (PR and TR) on the serial port as well as the radio port. A value of 1 means the messages go out on both, a value of 0 means they go only out the radio port. Fields: Start, Type, ID, Value Example: CMI,DR,C,1*67 Meaning: "This is Sensor C. I send my data messages out both the radio port and the serial port." 129 Data Messages Set (DS): This is to set whether or not the data messages (PR and TR) are sent out over the serial port as well as the radio port. The only acceptable value is 0 (messages only over radio port) or 1 (messages over both radio and serial ports). Fields: Start, Type, ID, Value Example: CMI,DS,C,0*67 Meaning: "Sensor C, stop sending data reports over the serial port." Miscellaneous Report (MR): Whenever the sensor has anything else to relate to the outside world, it can use this message. What action the base takes is undefined at the moment, but this should be useful for debugging. Fields: Start, Type, ID, Message Example: CMI,MR,B,Resetting ADC in MainO*C8 Meaning: "This is sensor B and I felt the need to tell you that." Acknowledgement Report (AR): Certain messages sent by the base are answered by this message to communicate whether the action was taken or not. Fields: Start, Type, ID, Type of Message Being Acknowledged, Error Code Error Codes: 0 =Incoming message accepted and action undertaken successfully 1 = Checksum of incoming message was wrong 2 = Message accepted, but contained unacceptable values 3 = Message accepted, but action not taken Others to be added as necessary Example: CMI,AR,G,SS,0*39 Meaning: "Sensor G accepts the Schedule Setting message just sent to it." Ultrasonic Distance Report (UR): The microcontroller running the Hexamite ultrasonic distancing system reports measured distances back to the base using this message. It specifies the ID of the microcontroller reporting in as well as the identities of the two transducers acting as endpoints for the measurement. The identity of the ultrasonic transmitter comes first and the identity of the ultrasonic receiver comes last. The distance reported is in the same units as output by the Hexamite system; one unit is approximately 0.7mm. The distance reading is in decimal form 130 as opposed to the hexadecimal output by the Hexamite. Fields: Start, Type, ID, Path of measurement (Unit "S" to unit "U"), Distance Example: CMI,UR,Q,SU,1234*F3 Meaning: "Sensor Q reports that the distance measured from transceiver S to transceiver U is 1234 units." 131 132 Bibliography [1] Altium Limited, http://www.protel. com/productoverview. htm. Overview of Protel DXP. [2] Analaog Devices, Inc., http: //www. analog. com/productSelection/pdf / ADM1485_a.pdf. ADM1485 datasheet, Jun 2000. [3] Analog Devices, Inc., http://www.analog.com/AnalogRoot/sitePage/ mainSectionHome/0,2130,level%4%253D%25252D1%25261evel1% 253D212%25261evel2%253D213%2526level3%253DX25252D1,0%0.html. iMEMS@Accelerometers. [4] Analog Devices, Inc., http://www.analog. com/UploadedFiles/DataSheets/ 778541587AD7713_ c .pdf. AD7713 Datasheet, Nov 1997. [5] Analog Devices, Inc., http: //www.analog. com/UploadedFiles/Data-Sheets/ 213876976ADM223_230L_241Lb.pdf. RS-232 Drivers, Jun 2001. [6] B & B Electronics Limited. RS-422 and RS-485 Application Note, Oct 1997. [7] Bluetooth SIG, Inc., http: //www. bluetooth. com. Official Bluetooth website. [8] CCS, Inc., http: //www. ccsinf o. com/picc. shtml. Homepage of CCS, Inc. [9] Sivaram Cheekiralla, Hariharan Lakshmanan, Ying-Jui Chen, Charuleka Varadharajan, and Vijay Singh Choudhary. Wireless sensor based infrastructure monitoring. Class project report, Dec 2002. 133 [10] Chipcon AS, http: //www. chipcon. com/index. cf m?katid=2. Chipcon prod- ucts list. [11] Ken P. Chong, Nicholas J. Carino, and Glenn Washer. Health monitoring of civil infrastructures. In Health Monitoring and Management of Civil Infrastructure Systems, Bellingham, Washington, USA, March 2001. SPIE. [12] Crossbow Technologies, Inc., http://www.xbow. com/Products/Product.pdf files/Wireless-pdf/MICA.pdf. Mica datasheet, Apr 2003. [13] Official web-site of channel tunnel rail link. World Wide Web, http: //www. ctrl.co.uk. [14] Scott W. Doebling, Charles R. Farrar, Michael B. Prime, and Daniel W. Shevitz. Damage Identification and Health Monitoring of Structural and Mechanical Systems from Changes in Their Vibration Charaecteristics: A Literature Review. Technical report, Los Almos National Laboratory, http: //www. lanl. gov/projects/ncsd/pubslitreview.pdf, 1996. [15] Electrolevel applications in civil engineering. World Wide Web, http: //www. tilt-measurement. com/appnotes/htmlfiles/an5.html. [16] Federal Communications Commission, http: //www. f cc. gov/Bureaus/OPP/ working-papers/oppwp38chart .pdf. U.S. Spectrum Allocation, 300-3000 MHz, November 2002. [17] Optical fibre sensors for remote tunnel displacement monitoring. World Wide Web, http: //www.bham. ac.uk/CivEng/resproj/metje1/index.htm. [18] Randy Frank. Understanding smart sensors. Artech House, Boston, 1996. [19] Nigel Gardner. An Introduction to Programming the Microchip PIC in CCS C. Bluebird Electronics, 2002. [20] Steven D. Glaser. Sensing Structural Integrity. http: //www. ce. berkeley. edu/ ~glaser/CUREe.pdf. 134 [21] Peter W. Gofton. Mastering serial communications. Sybex, London, 1986. [22] Habitat monitoring on great duck island. World Wide Web, http://www. greatduckisland.net/. [23] David C. Greene. Sensor technology and application to a real-time monitoring system. Master of engineering. thesis, Department of Civil and Environmental Engineering, Massachusettts Institute of Technology, 2001. [24] Miriam Heller. An Integrated View of NSF and Infrastructure Systems Re- search. Technical report, National Science Foundation, http: //www. f iatech. org/Presentations/FiatechCapProjMH.ppt, November 2002. [25] Hexamite ultrasonic devices. World Wide Web, http: //www. hexamite. com. [26] Hi-Tech Software, http: //www. htsof t. com. Homepage of Hi-Tech Software. [27] How Fiber Optics Work. World Wide Web, \hhtp: //electronics. howstuffworks.com/fiber-optici.htm. [28] ITM Limited., http: //www. itm- ltd. com/pCTRL220. htm. Instrumentationfor Channel Tunnel Rail Link COntract 220. [29] David Kalinsky and Roee Kalinsky. Article on I2C. http: //www. embedded. com/story/0EG20010718S0073, Aug 2001. [30] David Kalinsky and Roee Kalinsky. Article on SPI. http: //www. embedded. com/story/0EG20020124S0116, Feb 2002. [31] Sid Katzen. The Quintessential PIC microcontroller. Springer, New York, USA, 1st edition, 2001. [32] Linx Technologies Corporation, http: //www. linxtechnologies. com/ldocs/ main. html. Linx Technologies: RF Transmitters Receivers Transceivers Connectors. 135 [33] Linx Technologies, Inc., http://www.linxtechnologies.com/ldocs/pdfs/ rxmanual.pdf. Linx RM series receiver data guide, Nov 2001. [34] Linx Technologies, Inc., http://www.linxtechnologies. com/ldocs/pdf s/ txmmanual.pdf. Linx RM series transmitterdata guide, Nov 2001. [35] LVDT Principles of Operation. World Wide Web, http: //www. rdpelectrosense.com/displacement/lvdt/lvdt-principles.htm. [36] LVDT Principle of Operation. World Wide Web, http://www.lvdtcollins. com/lvdt/lvdt . htm. [37] Jerome P. Lynch. Decentralizationof Wireless Monitoring and Control technologies for Smart Civil Structures. PhD thesis, Stanford University, August 2002. [38] Jerome P. Lynch, Kincho H. Law, Anne S. Kiremidjian, Thomas W. Kenny, and Ed Carryer. monitoring. The design of a wireless sensing unit for structural health In Proceedings of the 3rd International Workshop on Structural Health Monitoring, September 2001. [39] Jerome P. Lynch, Arvind Sundararajan, Kincho H. Law, Anne S. Kiremidjian, Ed Carryer, Hoon Sohn, and Chuck Farrar. Field validation of a wireless structural monitoring system on the almosa canyon bridge. In SPIE 10th Annual InternationalSymposium on Smart Structures and Materials, San Diego, califor- nia, USA, March 2003. [40] Massa e-152 model specifications. World Wide Web, http: //www.massa. com/ datasheets/e152.html. [41] Raymond M. Measures. StructuralMonitoring with Fiber Optic Technology. Aca- demic Press, San Diego, California, USA, 2001. [42] Mems technology. World Wide Web, http: //www. memsnet . org/mems. 136 [43] Microchip Technology, Inc., http: //asp. microchip. com/www/ParamChart. aspx?branchID=103&mid=&gdir=101%0. Microchip nano Watt technology mi- crocontrollers. [44] Microchip Technology, Inc., http: //www. microchip. com/download/lit/ suppdoc/toots/i2c .pdf. I2C tutoral for PIC microcontrollers,Sep 2002. [45] Microchip Technology, Inc., http://www.microchip.com/download/lit/ pline/picmicro/f amilies/16f87x/30%292c. PIC16F877data sheet, Nov 2002. [46] Microchip Technology, Inc., http: //www. microchip. com/download/lit/ suppdoc/toots/spi. pdf. SPI tutoral for PIC microcontrollers, Sep 2002. [47] Microchip Technology, Inc., http: //www. microchip. com/download/lit/ suppdoc/refernce/midrange/33023a.%pdf. Mid-range MCU Family Reference Manual, Feb 2003. [48] Millennial Net, Inc., http://www.rmillennial.net/pdf/MNBrochure.pdf. i- Bean brochure, Apr 2003. [49] Motorola, Inc., http://e-www.motorola.com/f iles/sensors/doc/data_ sheet/MPX2200.pdf. MPX2200 Data Sheet, May 2002. [50] Harry N. Norton. Handbook of Transducers. Prentice Hall, Englewood Cliffs,NJ, 1989. [51] Phillips Semiconductors, http://www.semiconductors.philips.com/ acrobat/literature/9398/39340011. %pdf. 12C specification, Jan 2000. [52] Demystifying piezoresistive pressure sensors. World Wide Web, http: //www. maxim--ic .com/appnotes. cfm/appnote number/871/ln/en. [53] Joseph Polastre. Design and Implementation of Wireless Sensor Networks for Habitat Monitoring. Master's thesis, University of California, Berkeley, May 2003. 137 [54] A remote ecological micro-sensor network. World Wide Web, http: //www. botany.hawaii.edu/pods/overview.htm. [55] RF Monolithics, Inc., http: //www. rf m. com/products/spec. htm. RFM products list. [56] H. Samuel, R.J. Mair, C.Y. Lu, I.L.J. Chudeleigh, T.I. Addenbrooke, and P.Readings. The effects of boring a new tunnel under an existing masonry tunnel. In Geotechnical aspects of underground construction in soft ground: proceedings of the InternationalSymposium on Geotechnical Aspects of Underground Construction in Soft Ground, July 1999. [57] Ian R. Sinclair. Sensors and Transducers. Newnes, Boston, 2001. [58] R. Sudarshan. A Web-Based Virtual Laboratory for Real-Time Monitoring of Physical Infrastructure. Master's thesis, Department of Civil and Environmental Engineering, Massachusetts Institute of Technology, June 2002. [59] Systems Planning and Analysis, Inc., http: //www. spa. com/smtdf ot .htm. SPA:Fiber Optic Transducers. [60] Technology Review. 10 Emerging Technologies That Will Change the World, February 2003. [61] Steve Thackery. Article on RS-232. http: //www. piclist. com/techref /io/ serial/rs232. htm. [62] Tinyos website. World Wide Web, http: //today. cs. berkeley. edu/tos/. [63] New computing frontiers - the wireless vineyard. World Wide Web, http: // www. intel. com/labs/f eatures/rsOlO3l.htm. 138