An Abstract of

Development of an Implantable Data Acquisition System

Prachi Santosh Sonalkar

Submitted in partial fulfillment of the requirements for

The Master of Science in Bioengineering

The University of Toledo

August 2005

Implantable medical devices offer several fascinating possibilities for improving human health. Coupled with advancements in the miniaturization of electronic systems, the array of implantable medical devices will continue to

expand. Furthermore, if instrumentation based implants are interfaced to a

communication sub-system, the potential exists for wireless

software updates and real-time data acquisition from integrated sensors which

could relay patient health information or implant mechanical conditions to an

external system.

This thesis focuses on development of such a platform. The current

system incorporates a Radio Frequency (RF) telemetry system integrated to an

embedded microcontroller with multi-channel data acquisition capabilities. This

system employs a XE1201A (Xemics Inc, Switzerland) transceiver chipset

providing a bi-directional 405 MHz RF communications link. This transceiver is

integrated to an ultra-low power MSP430F149 (Texas Instruments, Dallas TX)

i microcontroller with 12-bit analog to digital capabilities. In addition, a similar external system is interfaced to a PC for complete control and real-time data acquisition is developed, a custom developed script language is implemented to input required commands for collection of desired data from a particular sensor.

The software code and protocol to establish bi-directional communication was developed in ANSI C which is implemented on the microcontroller and the PC interface was developed using LabVIEW (National Instruments, Austin TX). In addition, all ASICs are available in die form to allow for ultra-miniaturization. The system was evaluated in a spinal disc implant equipped with strain and temperature sensors. Future work will involve manufacturing the entire system in an ultra-compact package through the use of flip-chip technology.

ii

ACKNOWLEDGEMENTS

I would like to acknowledge the partial support by the Ohio Department of

Development and the AO Research Foundation for this project. I would like to especially thank my advisor Dr. Brent Cameron for his constant assistance,

encouragement, and excellent guidance throughout my graduate education.

Furthermore, I also wish to thank my thesis committee members, Dr. Fournier

and Dr. Molitor for their valuable advice on this thesis. In addition, I would like to

thank my colleagues Mr. Fadel Mahfouz, Mr. Kirankumar Samudrala, Mr. Mihir

Tambe, Ms. Sunita Gopalakrishnan, Ms. Swetha Krishnan, Mr. William (Bill)

Levicky, and Mrs. Yanfang Li for their great help in this study and research and

suggestions on this thesis. I would like to thank my parents, my in-laws, my

brother and all my friends who are always there for support and encouragement

and last but definitely not the least I would like to thank my husband Santosh for always being there for me.

iii TABLE OF CONTENTS

1 INTRODUCTION...... 1 1.1 MOTIVATION ...... 2 1.2 OVERVIEW OF THE IMPLANTABLE DATA ACQUISITION SYSTEM...... 3 1.3 ROLE OF RF TELEMETRY ...... 5 1.3.1 Radio Communication...... 6 1.3.2 Demodulation and Detection...... 7 1.3.3 Coding and Error Detection ...... 8 1.3.3.1 Manchester Encoding...... 8 1.3.3.2 Parity Check...... 9 1.4 FCC STANDARDS FOR MEDICAL IMPLANTS...... 10 1.4.1 MICS Band...... 10 1.4.2 WMTS Band...... 12 2 THEORY...... 13 2.1 DATA ACQUISITION SYSTEM...... 13 2.2 MSP430 MICROCONTROLLER...... 15 2.2.1 Features...... 15 2.2.2 Pin Designations...... 16 2.2.3 Functional Block Diagram...... 17 2.2.3.1 Oscillator/Clock Subsystem ...... 18 2.2.3.2 Flash Memory (JTAG)...... 19 2.2.3.3 ADC12 Module...... 19 2.2.4 Electrical Characteristics over Operating Temperature Range...... 20 2.3 DIGITAL RF WIRELESS UHF TRANSCEIVER XE1201A ...... 21 2.3.1 Features...... 22 2.3.2 Pin designations...... 23 2.3.3 Functional Block Diagram...... 24 2.3.4 External Components Design ...... 25 2.3.4.1 SAW Resonator Circuit ...... 25 2.3.4.2 LNA Tank Circuit...... 26 2.3.4.3 Up Converter Tank Circuit...... 27 2.3.4.4 LO Tank Circuit ...... 27 2.3.5 Electrical Characteristics...... 28 2.4 MAXIM SILICON OSCILLATOR...... 29 2.5 EXTERNAL BATTERY RECHARGING SYSTEM ...... 31 2.6 INTEGRATION WITH BIOCHEMICAL AND PHYSIOLOGICAL SENSORS ...... 31 2.6.1 Challenges for Real Time Monitoring...... 31 2.7 POWER REQUIREMENT CONSIDERATIONS ...... 32 2.7.1 Monitoring Implant Conditions ...... 33 2.8 SENSOR FABRICATION ...... 34 2.9 USE OF INBUILT ADC12 AND MULTIPLEXER ...... 35 2.10 INTEGRATED TEMPERATURE SENSOR...... 36 2.11 FLIP-CHIP TECHNOLOGY ...... 37

iv

3 MATERIALS AND METHODS...... 39 3.1 MICROCONTROLLER AND TRANSCEIVER INTERFACE...... 41 3.2 EVALUATING TRANSCEIVER PERFORMANCE IN A BODY PHANTOM ...... 42 3.3 DEVELOPMENT: PORTABILITY AND TOOLS...... 42 3.3.1 Tool for Driver Development...... 43 3.3.2 Chip Initialization...... 44 3.3.3 Bit Banging and UART Concepts...... 45 3.3.4 Software Interface for Accessing Hardware from a PC ...... 46 3.3.5 Code Generation...... 46 3.3.6 Implant Side Program Logic:...... 47 3.3.7 User-end Program Logic:...... 49 3.3.8 Device Driver Portability...... 52 3.4 SCHEMATIC...... 52 4 RESULTS AND DISCUSSION ...... 57 4.1 XE1201A CONTROL REGISTERS INITIALIZATION: ...... 57 4.2 ERROR RATE IN DATA COMMUNICATION AND EFFICIENCY ...... 59 4.3 SENSOR VOLTAGE RANGE AND SENSITIVITY...... 62 4.3.1 Analog Sensors...... 62 4.3.2 Temperature Sensor...... 64 4.4 LABVIEW FRONT-END AND SCRIPT LANGUAGE DEVELOPMENT...... 65 4.5 BODY PHANTOM EXPERIMENT RESULTS...... 68 5 CONCLUSIONS AND FUTURE WORK ...... 70 6 REFERENCES ...... 73 7 APPENDIX...... 76 7.1 HEADER FILE XE1201DRIVER.H CODE ...... 76 7.2 HEADER FILE GLOBALS.H CODE...... 83 7.3 XE1201A - MSP430F149 INTERFACE RECEIVER CODE...... 84 7.4 XE1201A - MSP430F149 INTERFACE TRANSMITTER CODE...... 94 7.5 ANALOG TO DIGITAL CONVERSION MODULE CODE ...... 112 7.6 TEMPERATURE SENSOR DATA COMMUNICATION CODE...... 114 7.7 LABVIEW PROGRAM LOGIC/DIAGRAM ...... 129

v LIST OF FIGURES

Figure 1: Overview of the implantable system...... 3 Figure 2: Chips used for communication a) Xemics XE1201A b) MSP430F149...... 5 Figure 3: System architecture for the implantable data acquisition system...... 14 Figure 4: Pin designations for the MSP430 microcontroller ...... 16 Figure 5: Functional block diagram for MSP430 microcontroller...... 17 Figure 6: Timing diagram for the three wire bus...... 23 Figure 7: Pin designations for the XE1201A transceiver ...... 23 Figure 8: Functional block diagram for XE1201A transceiver ...... 24 Figure 9: Saw resonator external circuit...... 26 Figure 10: LNA tank circuit ...... 27 Figure 11: Up-converter tank circuit ...... 27 Figure 12: LO tank circuit ...... 28 Figure 13: Pin connections for MAX7375...... 30 Figure 14: Temperature sensor interface ...... 36 Figure 15: Two way communication between implant and external controller ...... 39 Figure 16: Uplink communication block diagram...... 40 Figure 17: Downlink communication block diagram ...... 40 Figure 18: Schematic of microcontroller and transceiver interface...... 41 Figure 19: Flow-chart for uplink communication...... 49 Figure 20: Flow-chart for downlink communication ...... 51 Figure 21: Schematic diagram of combined microcontroller and transceiver circuit ...... 54 Figure 22: (a) 2 Layered (b) 4 Layered combined circuit boards...... 56 Figure 23: Waveform showing XE1201A register setup...... 59 Figure 24: Communication waveform demonstrating synchronized communication at a data rate of 4800Hz...... 60 Figure 25: Communication protocol...... 60 Figure 26: Communication waveform representing delay in the communication...... 62 Figure 27: Analog to digital conversion output...... 63 Figure 28: Data acquisition system monitoring console ...... 66

LIST OF TABLES

Table 1: Pin designation for the MSP430 microcontroller…………………………………. 17 Table 2: Electrical characteristics of MSP430 microcontroller………………………….. 20 Table 3: Pin designation for the XE1201A transceiver……………………………………. 24 Table 4: Electrical characteristics of XE1201A transceiver……………………………….. 32 Table 5: Truth table for XE1201A registers settings……………………………………….. 45 Table 6: Device driver functions and their purpose………………………………………… 47 Table 7: Temperature sensor output for various temperatures…………………………… 64

vi

1 Introduction

Implantable electronic devices are a new generation line of products

emerging in the biomedical industry. They have a fast growing market and a

promising future. The first generation of the devices was implanted with a surface

electrode; the next generation was partially implanted in the body with leads

coming out of the skin. The major drawback of these devices was the discomfort

and especially the risk of infection. Hence the next step was development of a

fully implantable device. The first and probably the most successful device to

date is the pacemaker. An implantable defibrillator was the next most successful

device. The implantable electrical neuromodulation devices, neuroprosthesis as

well as implantable drug delivery systems are a few other examples [1-3].

Implantable medical devices present endless possibilities for improving

human health. With the advancement and miniaturization of bio-instrumentation it

is likely that the array of implantable medical devices will continue to expand in

the years to come. These devices can be of further use if they can communicate

with an external monitoring system to download health data, the mechanical

conditions of the implant, change the device settings depending upon the need and introduce new procedures as per the doctors requirements. Hence it will answer the major concerns of the designing engineer; as well as the doctor using the device, by being more reliable, more accurate and convenient to use.

1 This thesis aims to develop a comprehensive model for data transmission

through the human body. The study focuses on development of a Radio

Frequency (RF) Telemetry system that will enable control of the (implant) device

externally. It will also enable controlling the device settings and collect and record

data [4-6].

1.1 Motivation

The measurement of the performance of new medical devices; provides a

better understanding of the interaction of these devices with biological systems.

In the specific area of orthopedic research, there is need for continuous real-time

monitoring of patients with fracture fixation plates and intra medullar rods to

determine the healing rate. To address these needs, a set of instrumentation

specific devices to support the measurement and telemetry of biomedical data

needs to be developed. The instrumentation should be capable of collecting data

from the implanted device and communicating it with the outside controlling

source. In order to have a complete communication system, the instrumentation chipset needs to have two sets of transceivers and . This will enable the instrumentation device to communicate bidirectionally. Hence an integrated circuit chipset that provides the above discussed functionality to the implant was needed. Henceforth in this thesis, the instrumentation devices will be addressed as “integrated circuit (IC) chipsets”. The ICs generate and control the transmission/reception of the communication signals. Although the integrated circuit chipset is targeted for applications such as a spinal disc implant, one can foresee the adaptation of the basic telemetry functions to the measurement of

2 other physiological data. The system was developed to incorporate basic

functionality for signal acquisition, data storage, and telemetric communication in

order to maximize the potential of using the devices in such applications. The design of this general-purpose chipset is then constrained by the functionality, size, and power consumption limitations inherent in the design of implantable devices but could be easily modified to match custom needs of the requirement.

1.2 Overview of the Implantable Data Acquisition System

A complete biotelemetry system may be divided into four subsystems, as

shown in Figure 1:

User

Power Controller ADC TO SENSORS

Antenna or Communication Coupling

Figure 1: Overview of the implantable system

In our approach, each of the four functional blocks represents a specific

circuitry providing the required functionality. The power sub-system will be an

inductive power coupling circuitry in parallel with a battery providing a means to

charge the implant. The controller block is the main processing unit that controls

the data communication through the implant. The Analog to Digital converter

(ADC) will be the part that collects data from physiological sensors and provides the data to the controller in the implant side. The dotted User block will be the substitute for the ADC for the external interface in form of a software program.

3 The circuitry used for each block and the interface between them will be

discussed in detail in the third chapter. The fourth block is the communication

block that focuses on transmitting and receiving the controller directed signals to

and from the implant.

Selection of the circuitry or chipsets for the above mentioned

functionalities is based on various factors. Two main constraints affecting the

design of the biomedical implant are size and power. The size of the device

should be small enough to comfortably fit on the surface of a fixation plate with

minimum obstruction to any vital tissues. The power consumption of the device

should be minimal to extend the operational lifetime for battery powered

applications. To minimize the size and power consumption of the devices, we are

implementing the design as custom integrated circuits. Power consumption is

minimized by using low power devices and slow clock speeds. In addition, power

consumption is reduced by selectively controlling power to certain subsystems

such as the analog-to-digital converter when not in use. In this thesis, we focus

on the implementation of a general-purpose controller. This integrated circuit primarily controls acquisition of physiological data and implements a simple communication protocol for relaying the data over a telemetry link.

The system consists of an implantable multi-channel data acquisition system that incorporates a bidirectional RF communications link using a pair of microcontrollers, a pair of transceivers and a number of physiological sensors.

The transceiver used is XE1201A (Xemics Inc, Switzerland) seen in Figure 2(a) , which is a low power transceiver operating at 433 MHz capable of operating in

4 the 405 MHz frequency range which meets the FCC regulations for medical

implants [7]. The microcontroller being used is MSP430F149 (Texas Instruments,

Dallas TX) illustrated in Figure 2(b), which is also an ultra-low power device well

suited for in-vivo implants.

a) b)

Figure 2: Chips used for communication a) Xemics XE1201A b) MSP430F149

1.3 Role of RF Telemetry

Telemetry is the term for using wireless radio communication for sending

automatic indications or manually read values from different measuring

instrument or devices. The usage of this technique is becoming more and more

common and new usage areas are evolving. Today’s system, in pacemaker for

example, uses a low speed, very low distance inductive communication system,

that is limited to data rates of a few kilobits per second at a decimeter range [6].

To improve the current techniques and generate new applications a low power and high speed RF transceiver with long distance communication ability needs to be developed. An integrated RF-link offers much higher data rates and communication distances up to a few meters.

5 If high data rates are available together with applications like these, then

there is a possibility to easily download the data statistics from a patient. Other

usage areas could be for example body-implanted sensors, which can

communicate with each other over a wireless RF transceiver solution. The

development within radio communication using digital transmission leads towards

safer built systems with fewer errors in the transmission. When using digital

transmission the possibilities to control the data flow increases and if desired can

include correction of the transmitted data. This decreases the total amount of

errors in the communication [8, 9].

1.3.1 Radio Communication

The transmission of digital signals is increasing around the world at a

rapid rate and the number of users at different frequencies is quickly increasing.

The source signals in radio communication are often referred to as base band signals. From electromagnetic theory, it can be construed for efficient radiation of electrical energy from an antenna; the signal must be at least in the order of the magnitude of a wavelength in the size given by Equation 1.

c = f * λ (1)

Where c is the velocity of light, f is the signal frequency and λ is the wavelength.

For sending a base band wireless signal, the radiation energy is often frequency-

translated to a higher frequency range, this translation is called

modulation and it ensures efficient transmission. Digital modulation provides

more information capacity, compatibility with digital data services, higher data

6 security and many more benefits towards analog modulation. With analog

transmission,

interference in the channel is difficult to be removed as the receiver is unable to

distinguish between wanted signal and noise. The advantages of digital transmission can be used for pure analog signals. At the transmitter end there is an A/D conversion and then a digital modulation on the RF carrier; at the receiver end after reconstruction of the digital signal a D/A conversion aids in reproduction of the original analog signal. For transmitting a signal over the air, there are three

main steps. First a pure carrier is generated at the transmitter. The next step is

the modulation stage. In the modulation process the base band signal constitutes

the modulating signal and the carrier signal which is a higher frequency signal

(sinusoidal signal). The third and the final step is transmission of this modulated

signal in air with the help of an antenna. This modulation type is also sometimes

called carrier wave (CW) modulation. Few basic digital modulation techniques

are Amplitude-shift keying (ASK), Frequency-shift keying (FSK) and Phase-shift

keying (PSK) [8-15].

1.3.2 Demodulation and Detection

The demodulator or the detector is the circuit, in which the recreation of

the original modulating frequency (the information) from the carrier frequency is

done. The output of an ideal detector must be an exact reproduction of the modulation existing on the carrier wave. Failure to accurately recover this intelligence will result in distortion and degradation of the demodulated signal and

perhaps some information will be lost. Carrier modulation allows the transmission

7 of modulating frequencies without the use of transmission wire as mentioned before. However, for the communication process to be completed or to be useful, the information or data must be recovered in its original form at the receiving site.

Each type of modulation is different and requires different techniques to recover

(demodulate) the information. To detect and recover an OOK (On/Off Keyed) signal, a method of detecting the presence or absence of RF oscillation is necessary. Demodulators that detect the presence of RF oscillations and convert them into a recognizable form have a simple architecture and are therefore useful in low power constructions [9, 16-20].

1.3.3 Coding and Error Detection

When using wireless radio communication there are several different

types of error detection techniques. In this subsection some of these techniques

will be described briefly. For radio communications over wireless media,

Manchester encoding is very often used as error detection.

1.3.3.1 Manchester Encoding

Manchester encoding is a type of error detection that is often used by

different RF devices. It is a coding that represents an original bit by another set of

bits. If the original data is a Logic 0, the Manchester code is 0 to 1 (upward

transition at bit center) and if the original data is a Logic 1, the Manchester code

is 1 to 0 (downward transition at bit center). In Manchester coding there are two bits of Manchester encoded data for each bit of original data. The penalty for

doing this is that Manchester encoded data consumes double bandwidth. The

8 coding can be seen as a synchronous clock encoding technique used to encode

the clock and data of a synchronous bit stream. The encoding may also be

alternatively viewed as a phase encoding where each bit is encoded by a positive

90 degree phase transition, or a negative 90 degree phase transition. The

Manchester code is therefore sometimes also known as a bi-phase code. In

general, when transmitting serial data to a radio receiver, a DC component of

zero must be maintained (over a finite time). This is so the demodulator in the

receiver can properly interpret the received data as 1's and 0's. Manchester

encoding allows doing this, because either 01 or 10 always represent each bit.

Given that a 0 encodes 10 and a 1 encodes 01, it follows that 00 and 11 are

illegal sequences or codes during the data information. These codes are

sometimes used to error check the data. It is possible to have the 8-bit not

Manchester encoded “illegal code” 11110000, which is an unlikely occurrence.

This “illegal code” has the property of having a DC component of zero and has

one, 1 to 0 transition. This code can therefore be used as a unique start

sequence identifying the boundaries of a Manchester encoded bit stream or data

frame [16, 21-23].

1.3.3.2 Parity Check

Parity check is one of the simplest techniques of error detection. Parity check always means either even or odd parity, where even parity means that the total number of 1’s must be even and vice versa for odd parity. The parity bit is added in a data packet as an extra bit and this technique is usually used in small

data packets. In reality the calculation is done with XOR of all bits in the packet.

9 Parity check is good for single bit errors and if odd numbers of bits are changed

during the data transfer. If even numbers of bits are changed in the packet it is

undetectable [16, 21-23].

1.4 FCC Standards for Medical Implants

In the United States, the Federal Communications Commission (FCC) has set aside two main frequency bands for medical data transmissions, viz MICS and WMTS. In 1999, FCC set aside the Medical Implant Communications

Service (MICS) frequency band. The MICS band, located in the frequency range of 402–405 MHz, is reserved specifically for wireless data communications between implanted medical devices and external equipment. Wireless Medical

Telemetry Services (WMTS) enables monitoring equipment to remotely and unobtrusively observe several patients at one time. Such telemetry systems transmit real-time physiologic data, so it is critical to ensure that data are not lost

or delayed. More and more radios for non-medical applications are operating in

the ISM bands, increasing the likelihood of signal loss and interference. FCC,

therefore, has set aside frequency bands specifically for WMTS also. More

discussion about these bands is provided in the following sub-sections.

1.4.1 MICS Band

MICS is an ultra-low power, unlicensed, mobile radio service for

transmitting data in support of diagnostic or therapeutic functions associated with

implanted medical devices. From a regulatory viewpoint, the establishment of the

MICS band began in the mid-1990s when Medtronic petitioned the FCC to

10 allocate spectrum dedicated to medical-implant use. After gaining wider industry support, the 402–405 MHz MICS band was recommended for allocation by ITU-

R Recommendation SA1346 in 1998. FCC established the band in 1999, and similar standards followed in Europe [37].

The allocation of this band supports the use of longer- range (typically 2 m), high-speed wireless links. The MICS band overcomes the limitations of dated inductive systems and facilitates the development of next-generation medical devices supporting improved patient healthcare. This is especially important, as escalating medical costs drive the growth of remote health monitoring. Because of the signal propagation characteristics in the human body, compatibility with the incumbent users of the band (meteorological aids such as weather balloons), and its international availability, the 402–405 MHz band is well suited for such remote monitoring. The MICS standard allows for a maximum transmitted power (in air) of 25 mW. The external programmer may easily radiate at this power level; however, this is not the case for an implant due to large antenna losses, body losses, and limitations in available implant transmit power. Good power amplifier design is important for maximizing the available implant transmit power.

Nevertheless, battery performance and current limitations in the implant are the ultimate limiting factors.

11 1.4.2 WMTS Band

The Wireless Medical Telemetry System (WMTS) band was created by

the Federal Communications Commission (FCC) under regulatory control, so hospital telemetry systems could be free from interference created by digital

television transmissions, and interference from other in-band RF sources [24].

The Wireless Medical Telemetry Service (WMTS) sets aside the frequencies of:

608 to 614 MHz, 1395 to 1400 MHz, and 1429 to 1432 MHz for primary or co-

primary use by eligible wireless medical telemetry users. Eligible WMTS users

are limited to authorize a health care provider, which includes licensed

physicians, healthcare facilities, and certain trained and supervised technicians.

The healthcare facilities eligible for the WMTS are defined as those that offer services for use beyond 24 hours, including hospitals and other medical providers. WMTS standards are specifically for medical communications for a longer range of about 32km-80km [27]. A key feature of the new WMTS is the provision for establishment of a Frequency Coordinator to maintain a database of user and equipment information to facilitate sharing of the spectrum and to help prevent interference among users of the WMTS. The FCC order also provides a definition for wireless medical telemetry, which is consistent with recommendations made in April 1999 by the American Hospital Association

(AHA) Task Group on Wireless Medical Telemetry. The FCC defines wireless medical telemetry as: "the measurement and recording of physiological parameters and other patient-related information via radiated bi- or unidirectional electromagnetic signals" [28].

12

2 Theory

2.1 Data Acquisition System

Based on the earlier discussion, a bidirectional data acquisition system was developed. The system architecture is illustrated in Figure 3.The system consists of a XE1201A transceiver chipset providing a bi-directional 405 MHz RF communications link. The transceiver is used to perform the modulation and demodulation of signals in the data communication system. This transceiver

XE1201A is integrated to the MSP430F149 microcontroller with 12-bit analog to digital (ADC) capabilities. Both the devices were selected on the basis of various

considerations such as minimum operational power requirements, data

sensitivity, compatibility between these devices based on electrical

characteristics, etc. These considerations will be discussed in details in the

sections 2.2 and 2.3. The data acquisition system can be widely divided into two

sections, viz, the implant section and an user friendly external system that helps communicate and interpret the input commands to obtain required data. The external system consists of a 433 MHz antenna, a RF transceiver chip and the microcontroller, that has a wireless interface to a PC for complete control and real-time data acquisition through a custom developed script language. A similar system is implemented in the implant with an addition of five strain sensors and a temperature sensor to measure physiological properties. The five physiological sensors will be placed at vital peripheral locations of the implant in order to

13 monitor the implant functioning. A temperature sensor will be placed along with the implant to keep a check on the temperature of implant surroundings.

T1= Temperature gauge S1-5 Oscilloscope T1 S1 Microcontroller S2 Microcontroller RF Chip set S3 MSP 430 Labview MSP 430 XE 1201 A S4 RF link Front-end Spinal S5 405 MHz IA Disc IA RF Chip set Implant XE 1201 A Serial Port Battery Interface Power Supply

Interface Application Protocol

Preamble Data Stop Bits Bit

Figure 3: System architecture for the implantable data acquisition system

A script language that implements easy to remember and user friendly commands have been developed. The script language enables the user to send across requests for required data and analyze the received implant data on the screen. A final consideration in this system development is to condense the entire circuitry to the smallest size possible. To achieve this, analysis of requirement of each and every component and reduction of component size in the circuitry was considered.

14 2.2 MSP430 Microcontroller

2.2.1 Features

The Texas Instruments manufactured MSP430 microcontroller requires a low range power supply between 1.8 – 3.6V. It is categorized as an ultra low power consumption device as it requires 280 µA at 1MHz and 2.2V in an operational mode and in a stand by mode just 1.6 µA. When in an off mode the micro controller consumes 0.1 µA for RAM retention. The microcontroller has 5 power saving modes, and it takes less than 6 µsec to go from wake up in stand by mode to fully functional state. The microcontroller has 16 bit Reduced

Instructions Set Computer (RISC) architecture and has a 125 nano second instruction cycle time. It also has a 12 bit A/D converter with internal reference, sample and hold and auto scan feature. The microcontroller has two 16 bit timers namely A and B. Timer A has three capture or compare registers and

Timer B has seven captures and compare with shadow registers. It has an on- chip comparator to compare various voltage inputs and is capable of handling serial onboard programming, with no need for external programming voltage. It has a serial communication interface (USART) which can function as asynchronous UART or synchronous SPI interface. The microcontroller has a

60KB + 256B Flash Memory and 2KB RAM. It is available in 64-Pin Quad Flat

Pack (QFP) and in die form with an area as small as 2.5mm by 2.5mm.

Typical applications include sensor systems that capture analog signals, convert them to digital values, and process and transmit the data to a host system. The timers make the configurations ideal for industrial control

15 applications such as ripple counters, digital motor control, EE-meters, hand-held meters, etc. The MSP430 also has an on chip ADC that can be used to sample analog data. The ADC12 module supports fast, 12-bit analog-to-digital conversions. The module implements a 12-bit sampler, reference generator and a 16 word conversion-and-control buffer. The conversion-and-control buffer allows up to 16 independent ADC samples to be converted and stored without any CPU intervention.

2.2.2 Pin Designations

Figure 4: Pin designations for the MSP430 microcontroller

As mentioned earlier the MSP430 is a 16-bit, 64 pin microcontroller shown in Figure 4. For the purpose of programming 8 I/O pins were allocated for various functions as illustrated in Table 1. Pins 2-6 and 59-61, which are the ADC input pins were used for sampling sensor output. Serial port RS-232C communication

16 was done through pins 12-13. Apart from this, pins 8-9 were used to connect to an external watch crystal and pin number 1 and pin number 63 were used for power supply and ground respectively. The pin numbers significant for the data transmission and reception are also listed in Table 1.

Table 1: Pin designation for the MSP430 microcontroller. Serial Pin Number Port No. I/O Config. Xemics Function Allotted No. 1. P 2.1 (Pin 21) 2 O System data 2. P 2.2 (Pin 22) 2 O System clock 3. P 2.3 (Pin 23) 2 O Data enable 4. P 2.4 (Pin 24) 2 O Chip enable 5. P 2.5 (Pin 25) 2 I/O Receiver/Transmission mode 6. P 2.6 (Pin 26) 2 O Transmit data 7. P 2.7 (Pin 27) 2 I Data clock 8. P 3.0 (Pin 30) 3 I Receive data

2.2.3 Functional Block Diagram

The functional block diagram of the MSP430 microcontroller is illustrated in Figure 5.

Figure 5: Functional block diagram for MSP430 microcontroller

17 The major functionalities that were utilized for the application are as follows:

2.2.3.1 Oscillator/Clock Subsystem

The basic clock module supports low system cost and ultra low-power consumption. Using three internal clock signals, efforts have been made to achieve the best balance of performance and low power consumption. The basic clock module can be configured to operate without any external components, with one external resistor, and an external crystal under complete software control.

The MSP430F149 clock module consists of three clock sources firstly

LFXT1CLK low-frequency/high-frequency oscillator that can be used either with low-frequency 32,768-Hz watch crystals, or standard crystals, resonators, or external clock sources in the 450-kHz to 8-MHz range. Secondly XT2CLK an optional high-frequency oscillator that can be used with standard crystals, resonators, or external clock sources in the 450-kHz to 8-MHz range; lastly

DCOCLK which is an internal digitally controlled oscillator (DCO) with RC-type characteristics. In this application a combination of LFXT1CLK and DCOCLK has been used for achieving a higher precision in timing and generating about 4 MHz of clock signal.

Based on these internal clock modules, three clock signals are available from the basic clock module. ACLK Auxiliary clock is the buffered LFXT1CLK clock source split into 1, 2, 4, or 8 parts. ACLK is software selectable for individual peripheral modules. The MCLK is software selectable as LFXT1CLK,

XT2CLK (if available), or DCOCLK. MCLK is used by the CPU and system and is

18 also split able in 1, 2, 4, or 8 parts. SMCLK: Sub-main clock is software

selectable as LFXT1CLK, XT2CLK (if available), or DCOCLK. SMCLK is

software selectable for individual peripheral modules. For the development of this system LFT1CLK module for clock signal generation has been used and for

source ACLK is utilized.

2.2.3.2 Flash Memory (JTAG)

The flash memory is programmed via the JTAG port, the bootstrap loader,

or in-system by the CPU. The CPU can perform single-byte and single-word

writes to the flash memory. This function module is used to download the C

program in the microcontroller memory. It utilizes a parallel port of the PC for interfacing the microcontroller. It has a power supply connection amongst its 25

pins parallel port connector to the microcontroller that provides around 2.5V input

voltage to the microcontroller.

2.2.3.3 ADC12 Module

The ADC12 module supports fast, 12-bit analog-to-digital conversions.

The module implements a 12-bit sampler, reference generator and a 16 word

conversion-and-control buffer. The conversion-and-control buffer allows up to 16

independent ADC samples to be converted and stored without any CPU intervention. ADC12 has greater than 200 kbps conversion rate, it has monotonic

12-bit converter with no missing codes. The module can sample-and-hold with

programmable sampling period controlled by software or timers A or B. It has

software selectable on-chip reference voltage generation (1.5 V or 2.5 V) and

19 software selectable internal or external reference. The ADC12 module has eight individually configurable external input channels. The conversion channels for internal temperature sensor, AVCC, and external references, the independent channel-selectable reference sources for both positive and negative references, selectable conversion clock source, single-channel, repeat-single-channel sequence, and repeat-sequence conversion modes. ADC core and reference voltage can be powered down separately an vector register for fast decoding of 18 ADC is available along with a 16 conversion-result storage registers.

2.2.4 Electrical Characteristics over Operating Temperature Range

The electrical characteristic of the MSP430 microcontroller are presented in Table 2 taken from the microcontroller’s datasheets.

Table 2: Electrical characteristics of MSP430 microcontroller

20 The maximum power consumption will occur in the active mode and is

fairly constant for the entire operating range of 40-80 ˚C. For a VCC of 2.2V the

maximum power required is 350 µA * 2.2V = 770 µW which is acceptable for human implants.

2.3 Digital RF Wireless UHF Transceiver XE1201A

The XE1201A is a half-duplex FSK transceiver for operation in the 433

MHz ISM band (optimized) and in the 300-500 MHz band. The modulation used

is the Continuous Phase (2 level) Frequency Shift Keying (CPFSK). The direct

conversion (zero IF) receiver architecture enables on-chip channel filtering.

The XE1201A includes a bit synchronizer so that glitch free data with

synchronized clock can directly be read by a low cost / low complexity micro-

controller. The transmitted power level can also be controlled via the bus. The

XE1201A meets the I-ETS300-220 standard and is available in a TQFP32

package.

2.3.1 Features

The XE1201A transceiver is very low-power ultra high frequency device. It

has a half-duplex operation enabling a one way communication with a data rate

up to 64 kbit/sec. It requires very few external components, has an internal bit

synchronizer and 3-wire bus for easy microcontroller interface. The output power

is programmable via bus.

The XE1201A is controlled via the 3-wire serial bus by a microcontroller

that addresses the 3 wires (SD - Serial Data, SC - Serial Clock, DE - Data

21 Enable) according to the format shown in Figure 6 a bit stream of 16 bits is fed

into the internal register (SD - pin8) with the Most Significant Bit (MSB) first and

is shifted during the low to high transition of the clock (SC - pin7). This serial

programming is enabled by the Data Enable pin (DE - pin2) which must be set to zero before the data transfer. The low to high transition of the Data Enable validates the register filling. Data is retained as long as the supply voltage (Vdd) is present.

Figure 6: Timing diagram for the three wire bus

22 2.3.2 Pin designations

Figure 7: Pin designations for the XE1201A transceiver

The XE1201A is a 16-bit, 32 pin transceiver as seen in Figure 7. Pins SD,

SC and DE form the basic bus interface in order to set the device registers. Pins

TXD, RXD and CLKD are used for data transmission, data clock generation and

data reception respectively. These pins are connected to the general purpose I/O

pins of the microcontroller. The TXD pin is configured to be an input pin in order to receive the data from the microcontroller that is further modulated and sent to

the antenna for transmission, whereas the RXD pin is configured internally to be

an output pin that writes data onto the microcontroller input pin. CLKD pin is an

internally configured output pin that provides a clock signal with the data rate set

in the XE1201A registers during the reception mode. Table 3 shows allocation of

various pins and functions.

23 Table 3: Pin designation for the XE1201A transceiver. S. No. Pin Name Pin Number Function Allotted 1. SD 8 System data 2. SC 7 System clock 3. DE 2 Data enable 4. EN 1 Chip enable 5. RXTX 15 Receiver/Transmission mode 6. TXD 17 Transmit data 7. CLKD 18 Data clock 8. RXD 19 Receive data

2.3.3 Functional Block Diagram

Figure 8: Functional block diagram for XE1201A transceiver

As mentioned before, the XE1201A is a half-duplex FSK single chip transceiver for operation in the 300-500MHz band with a data rate up to 64Kbit/s.

The modulation used is CPFSK. One of the main features of the XE1201A is a serial bus (3 pins) that is used to configure the transceiver in transmit, receive and enable mode. Figure 8 represents a combined functional diagram showing the receiver and transmission parts of the XE1201A. The receiver part of the

24 transceiver integrates a Low Noise Amplifier (LNA), a down converter function as well as channel filtering and demodulator, providing a fully integrated receiver from antenna to data stream.

The transmission part provides a complete path from data stream to antenna. The architecture is a direct up conversion with a programmable frequency deviation. The RF output power level can also be controlled via user programs. A few external components are necessary to build custom applications, such as antenna matching network, tank circuits, saw resonator for local oscillator, and a 4MHz crystal. The design of each of these external modules will be discussed in the following section.

2.3.4 External Components Design

2.3.4.1 SAW Resonator Circuit

The SAW resonator determines the carrier frequency. The frequency can

be chosen between 300-500 MHz approximately. The SAW resonator circuit is

shown in Figure 9. An inductor is placed in parallel to the SAW resonator in order

to compensate the influence of the parasitic capacitors Cp and the shunt static

capacitance of the resonator Cs. The shunt capacitance of a 433.92MHz SAW

resonator is approximately 1.9pF. Considering this value and Cp= 3.1pF, the

inductor value came out to be 27nH.

25 External Cp SWA SWB

Internal 27nH

SAW Cs

Figure 9: Saw resonator external circuit

2.3.4.2 LNA Tank Circuit

The function of the LNA tank circuit is to maximize the available power

gain (GPAV). The LNA tank circuit is shown in Figure 10. It has a parallel capacitor present between pins TLA and TLB. To compensate the influence of

Cp, a combination of inductors is used in the external circuitry. A capacitor C is placed parallel to Cp in order to reduce the values of inductors. The value of capacitor is considered to be 2.2pF. Since the circuit needs to resonate at

433.33MHz, the values of inductors are calculated as L1=L2=12nH.

VDD

L1 L2

C External TLA TLB

Internal

Cp

Figure 10: LNA tank circuit

26 2.3.4.3 Up Converter Tank Circuit

The Up-converter tank circuit is illustrated in Figure 11; it serves the same purpose as the LNA tank circuit. The component values are also the same.

L1=L2=12nH with C=2.2pF.

Cp Internal TPA TPB

External

C

L1 L2

VDD

Figure 11: Up-converter tank circuit

2.3.4.4 LO Tank Circuit

The internal local oscillator is connected externally to a tank circuit is shown in Figure 12. The LC resonance is created between TKA and TKC pins and TKB is grounded internally via capacitor C2. The component values remain the same as those of the tank circuits defined before, with L1=L2=12nH and

C=2.2pF.

27 Cp

Internal TKA TKB TKC External

C1

L1 L2

C2

Figure 12: LO tank circuit

2.3.5 Electrical Characteristics

The absolute ratings are supply voltage 2.4 V to 6 V and storage temperature -55°C to 150°C and operating temperature -40°C to 70°C for a ambient temperature Tamb = 25° C; VDD = 3.0 V; FLO = 433.92 MHz; +/- 125 kHz frequency deviation; 16 kbit/sec pseudo random bit sequence unless otherwise specified. Referring to the following electrical characteristics the device operates at 18 µW of power typically and hence adheres to the FCC regulation for medical implants. Considering the ideal electrical characteristics given in Table 4 and the overall functionality, this device was chosen for the implantable data acquisition system.

28 Table 4: Electrical characteristics of XE1201A transceiver

2.4 Maxim Silicon Oscillator

The MAX7375 is a silicon oscillator, intended to be a low-cost improvement replacing ceramic resonators, crystals, and crystal oscillator

modules. It is used as the clock source for microcontrollers and UARTs in 3V,

3.3V, and 5V applications.

The MAX7375 is a fully integrated oscillator, supplied at specific factory-

trimmed frequencies with a 50% duty cycle square-wave output. The oscillator

frequency is generated directly without the use of a phase-locked loop (PLL). No

additional components are used to set or adjust the frequency. Unlike typical

29 crystal and ceramic resonator oscillator circuits, the MAX7375 is highly resistant to vibration and EMI. The high output drive current and absence of high- impedance nodes also makes the oscillator less susceptible to dirty or humid operating conditions. Available in 3-pin space-saving SC70 and SOT23 packages, the MAX7375 is offered in standard and nonstandard factory-set frequencies ranging from 600 kHz to 9.99MHz. MAX7375 operates over the -

55°C to +135°C temperature range which will work for an implant at 37°C. This oscillator was selected as a reference oscillator for the XE1201A transceiver.

This helped in reducing the overall size of the circuit. It features a 2.7V to 5.5V operation, no requirement of external components and a ±10mA output drive current, made it attractive to be used in the system. This oscillator also has a fast startup time of 5µs and very low EMI susceptibility, no high impedance notes (No

PLL), a very low jitter and a tiny surface mount package (SC70, SOT23).

Figure 13 shows the pin connections for the oscillator.

Figure 13: Pin connections for MAX7375

2.5 External Battery Recharging System

30 With the recent progress in the development of implantable electronic devices, the question of long-term energy delivery is gaining importance. While percutaneous leads offer an adequate solution for short-term use, their application needs to be avoided in implantations with a long duration due to the high risk of infection and the constraints imposed on the patient. Generally a battery is used to provide a long term energy supply to an implant. The battery is embedded along with the implant and if it get exhausted, a procedure to replenish new energy is necessary. The only way to avoid surgical procedure is using an external source to deliver wireless energy in order to recharge the implanted batteries or provide on-line power to the system. A Transcutaneous

Energy Transfer System (TETS) that aids to recharge the implanted battery externally without any surgery was developed and implemented by another group member for this application.

2.6 Integration with Biochemical and Physiological Sensors

2.6.1 Challenges for Real Time Monitoring

As we are aware in-body communication systems pose unique challenges for integrated circuit designers. Implanted devices typically operate for seven to ten years, meaning that at every stage of design integrated circuit makers must pay strict attention to meeting long-term low-power performance demands. The human body is also not an ideal medium for transmitting an RF wave, with materials such as fat and muscle exhibiting varying resistance to electrical signals [4-6].

31 Another potential hurdle is the placement of the implanted device. A physician will locate the implant where it provides the best patient care and comfort, with little concern for RF propagation. Therefore, the transceiver must be designed to operate effectively from various depths and through unpredictable thickness of fat, muscle and skin. Biocompatibility is another issue for implanted transceivers. Low resistivity metals delivering superior RF performance are not necessarily the best choice for an in-body device.

With in-body sensors, today's reactive healthcare approach will be transformed into a more proactive system. In-body transceivers are currently under development, some with higher data rates (500Kbps) but a shorter operating range of two to four meters. Others are targeting longer-range operation (up to 10 meters) but with much lower data rates in the range of 10 to

50Kbps. All systems must transmit and receive at current well below 10mA at 3V.

2.7 Power Requirement Considerations

For RF integrated circuit design, optimizing the architecture for a given application is a key requirement when considering ultimate low-power consumption. For example, using direct conversion with a high modulation index for low data rate applications can reduce power. Where design freedom exists, choosing a modulation scheme that allows constant envelope techniques rather than high-level modulation can reduce power. Using digital signal processing within complete receiver or transmitter sections can also yield power efficiency benefits, even when considering data conversion requirements.

32 Circuit techniques, such as switching power amplifiers rather than linear or

semi-linear variants, can also be beneficial for low power consumption. However,

traditional RF design alone will not meet the low power requirements of the

medical industry. Implementing a deep-sleep mode is crucial for meeting desired

power performance. Many medical monitoring devices will have a reasonably low

duty-cycle and the RF transmitter must "turn-off" and "wake-up" on demand. Off-

the shelf transceivers with a sleep mode of 1µA have been available for many

years; hence the XE1201A and MSP430 seem to be a good fit to this system [30,

31, and 34].

2.7.1 Monitoring Implant Conditions

Though RF seems to provide a solution to a large number of problems; scientists are not yet able to record and sample data real time through the bloodstream. Technology advances are paving the way for medical advances in a rapid fashion. Implanted medical devices and on-body sensors are wirelessly communicating with health monitoring tools, providing patient health data in real- time and opening the door for innovative new treatments. There is a concern of the functioning of the implants and the reactivity of the material with the body part and the fluids it comes in contact. Also one needs to monitor the temperature of the implant in various operating modes, as the implant will cause more damage by harming the tissues it is close to. Hence a temperature sensor has been added to the implant to monitor the temperature of the implant.

33 2.8 Sensor Fabrication

Typical implantable orthopedic devices are primarily manufactured from

titanium alloys, cobalt-chrome-molybdenum alloys or stainless steels. Sensor

fabrication process development has been focused on the manufacture of strain

gages in this project. The processes involved can be divided into three general

areas: creation of an insulation layer, fabrication of the sensor and lead wire pat-

terns, and the application of a biocompatible/protective thin film coating. Silicon

oxide, chromium oxide and aluminum oxide thin films of 1 micron thickness have

been evaluated as insulating layers subsequent to deposition on all of the

previously listed implant materials. Aluminum oxide is most promising because it

is not only a good insulator with good affinity for the sensor component materials

but it has also shown promise as a bone in growth material (a bioactive glass).

Fracture compression plates composed of 6Al4V-titanium have been primarily

utilized for process development due to the moderate complexity of their design

and the current popularity of the alloy.

Strain gauges fabricated to this point consist of bismuth gauge with

surface dimensions of 50 x 750 microns with 0.5 micron thickness. Strain gages

constructed of the above stated materials for the dimensions mentioned exhibit a

gage factor of approximately 50. The integrated sensors have been mechanically tested in a half Wheatstone bridge configuration utilizing a passive resistor.

Fatigue tests to 10 million cycles have been conducted with no mechanical or electronic degradation of the integrated sensors has been reported hence it can

34 be considered to be safe to use sensors in the body not only to monitor the strain

on the spinal column but also other implant conditions.

2.9 Use of Inbuilt ADC12 and Multiplexer

The ADC12 module supports fast, 10-bit analog-to-digital conversions.

The module implements a 12-bit SAR core, sample select control, reference

generator, and data transfer controller (DTC). The DTC allows ADC12 samples

to be converted and stored anywhere in memory without CPU intervention. The

module can be configured with user software to support a variety of applications.

ADC12 features include a greater than 200 kbps maximum conversion rate, a

monotonic10-bit converter with no missing codes. It can sample-and-hold with

programmable sample periods. It has ability for conversion initiation by software

or Timer A and software selectable on-chip reference voltage generation (1.5 V

or 2.5 V). It has eight external input channels, conversion channels for internal temperature sensor, VCC, and external references, selectable conversion clock source, single-channel, repeated single-channel, sequence, and repeated sequence conversion modes. ADC core and reference voltage can be powered down separately for data transfer control and automatic storage of conversion results.

35 2.10 Integrated Temperature Sensor

Power Supply

Chip Select LM 71 Temp. Micro Clock NAND LabVIEW Sensor Output Front end Controller I/O gate

Resistor in series and (b) Capacitor in parallel

Figure 14: Temperature sensor interface

A thirteen bit digital temperature sensor (LM71 from National

Semiconductors) has been incorporated into the system to record the

temperature, in order to check if the system temperature rises so as to damage

the surrounding tissue. The sensor has an operating range of -40 to 150 °C. It

generates a 13 bit digital output representing temperature in the range 0 – 1FFF

in ‘hex’ hexadecimal). The temperature sensor communicates with the microcontroller and reports the temperature when triggered. The code

establishing chip communication was done in ANSI C and LabVIEW was used

for serial communication with the PC and front end. A detailed block diagram of

the temperature sensor interface is illustrated in the Figure 14. It can be noted

that LM71 operates with a micro-wire bus interface consisting of three

connections in SPI mode. The three connections are for chip select input, slave

clock and slave I/O respectively. The digital output from the temperature sensor

goes to the NAND gate to remove the offset in the voltage. A power supply

36 powers both the sensor and the microcontroller; the sensor output is fed back to

the microcontroller which reports back to the LabVIEW front-end in a user

operated PC. The entire code for the sensor and front end has been provided in

the appendix.

2.11 Flip-chip Technology

Flip chip technology describes the method of electrically connecting the die to the package carrier. The package carrier, either substrate or lead frame, then provides the connection from the die to the exterior of the package. In a standard packaging, the interconnection between the die and the carrier is made using wire. The die is attached to the carrier face up; a wire is bonded first to the

die, then looped and bonded to the carrier. Wires are typically 1-5 mm in length,

and 25-35 µm in diameter. In contrast, the interconnection between the die and

carrier in flip chip packaging is made through a conductive "bump" that is placed

directly on the die surface. The bumped die is then "flipped over" and placed face

down, with the bumps connecting to the carrier directly. A bump is typically 70-

100 µm high, and 100-125 µm in diameter.

The flip chip connection is generally formed one of two ways: using solder

or using conductive adhesive. The most common packaging interconnect is

solder, in either eutectic (63%Sn, 37%Pb) or high Pb (97%Pb, 3%Sn)

compositions, and solder interconnect is being used in the initial FC products.

The solder bumped die is attached to a substrate by a solder reflow process.

After the die is soldered, under-fill is added between the die and the substrate.

37 Under fill is a specially engineered epoxy that fills the area between the die and the carrier, surrounding the solder bumps. Once cured, the under-fill absorbs the stress, reducing the strain on the solder bumps, greatly increasing the life of the finished package.

Using flip chip interconnect offers a number of possible advantages to the user such as a reduced signal and power/ground inductance and a higher signal density in a much smaller overall size. The size reduction is a result of die shrink and reduced package foot print. The reduction in size also saves in the cost of material. This technology will be used in the future to reduce the size of the implantable data acquisition system [35].

38

3 Materials and Methods

In order to develop an implantable data acquisition system one needs to study the complete data transfer. Decide what circuitry will be needed to achieve communication without causing harmful effects to the body. Importantly protocol

needs to be set to make the communication accurate and error free. In this case

the system design involved an in depth analysis of data transmission and

development of an error-free algorithm. A description of system features and the

communication protocol are covered in this chapter. The main idea for this

system was to be able to control the implant by wireless means, to gather data

and make selection as per the users needs. Hence a two way communication as

demonstrated in Figure 15 needs to be established. First one needs to have an

uplink in order to command the implant and secondly a downlink to gather

information from the implant.

External world

Downlink Uplink

Implant device

Figure 15: Two way communication between implant and external controller

39

Power Supply

Physiological Sensors Microcontroller Transceiver

Figure 16: Uplink communication block diagram

The uplink communication is shown in Figure 16. It involves various functionalities such as receiving external command from the transceiver.

Microcontroller interprets the commands, also sampling sensor data upon request, and transmitting the requested data. Each of these functionalities was catered to by specific functions developed in Ansi C.

Power Supply

Antenna Transceiver Microcontroller User Front-end

Figure 17: Downlink communication block diagram

The downlink communication is illustrated in Figure 17. It involved

development of a user-friendly front-end which was done in LabVIEW, receiving

command from the user, interpreting the command, sending request over to the

implant for the data, receiving data from the implant, and displaying it to the user.

The flow diagrams and the developed codes are discussed later in this chapter.

40 3.1 Microcontroller and Transceiver Interface

The interface connections between microcontroller and the transceiver are displayed in the Figure 18. The transceiver is driven into transmission/reception modes using 10 pin connections. For controlling the transceiver operation, general purpose I/O ports of the microcontroller, port number 2 and 3 were used.

The pin connections are as per the discussion in chapter two. The three wire bus interface of XE1201A was controlled through pin 1-3 of port 2. Since both the devices operate in the same voltage range, their power supply pins were coupled to reduce circuitry. The RXTX pin of XE1201A was connected to pin P2.5 of the microcontroller, this enabled the transceiver to go in transmission or reception by changing the input voltage to the pin.

VDD-TO EXTERNAL GND SUPPLY

XE 1201A

MSP430F149 Figure 18: Schematic of microcontroller and transceiver interface

41 3.2 Evaluating Transceiver Performance in a Body Phantom

To determine if the medical telemetry data acquisition system will function

inside the human body, the system was tested in a saline solution with the same

specific gravity as blood. An aquarium of dimensions 76 cm long(x) by 30.5 cm

across(y) by 45.75 cm deep (z) was filled with saline. The saline had a specific

gravity of 1.05 mg/ml, which is the same specific gravity as blood. To protect the

electronics from the saline solution, a battery powered system was placed inside

a sealed plastic container. The test being conducted was to determine how deep

in the body the transceiver could be placed before miscommunication occurred

with an outside transceiver. To test communication between the transceivers a

ping-pong test was used to detect conductivity of the signal. During this

experiment the transceiver was set to operate at maximum power level of

+5dbm.

The experiment was carried out with different orientations of the implanted

device and the external one. The results were promising and showed the

communication between the devices uninterrupted for about 38 cm average in all

the configurations.

3.3 Device Driver Development: Portability and Tools

This section describes an overview of the device driver design for RF telemetry and its portability issues. Device drivers provide a software interface for accessing hardware from software. For the devices that were selected for this application development, a driver library for each device

42 was provided by the manufacturers in order to allow software access to the hardware services in its peripheral modules (UARTs, Timers, A/D

converter, I/O configuration settings, Clock selection and baud rate settings, etc).

The Peripheral module device driver was developed to take care of:

• Initialization (e.g. setting up of transceiver registers, setting up baud

rate or timer periods, and setting up the mode of operation.)

• Run-time control (e.g. sending character strings such as user

commands, sending the requested data)

• Interrupt handling (handling software interrupts such as timer, wake

up signal, etc)

Each of these parts will be discussed in details in the following sections.

3.3.1 Tool for Driver Development

The device driver programming was done in ANSI C with the use of

Texas Instrument’s MSP-FET430 Flash Emulation Tool (FET). The FET is the program development tool for the MSP430 ultra low power microcontroller. This tool consists of a number of software systems such as the workbench, the assembler, the C compiler, the linker, and the debugger.

The debugger software called C-SPY proved helpful in checking internal register values and memory usage of the controller. The current

43 version of the ANSI C compiler supports about 4KB of code, which was sufficient in the development of the current application.

3.3.2 Chip Initialization

Basic initialization of stack pointer, compiler environment and bus controller settings are done during this phase. This is the most vital part of device driver development, because the CPU will usually not interface

(accept command, interact or communicate) to external hardware unless some low-level configurations are made:

• Bus interface (address and data buses, chip-select signals).

• Memory configuration

• Interrupt system (IRQs, interrupt priorities and masks).

Once low-level configuration has been performed, program execution continues in the application program’s main() function, where the application logic and device drivers then start execution.

In this application setting up the transceiver’s bus interface was a significant part. As mentioned before in chapter 2, XE1201A has a 3-wire

bus interface for configuring its three special function registers (A,B and

C). The first two bits (D15 and D14) of the 16 bits configuration data determine

the A, B or C register access according to the truth table marked as Table 5.

44

Table 5: Truth table for XE1201A registers settings D15 D14 REGISTER NAME 0 0 REGISTER A 0 1 REGISTER B 1 0 REGISTER C 1 1 NOT USED

These three registers are filled by the data A13 to A0, B13 to B0 or C13 to C0

according to the value of D15 and D14.

• Register A is used to set the XE1201A mode (transmission, reception and

standby modes) and to select the receiver data rate.

• Register B is used for central frequency adjustment during transmission.

• Register C is used for frequency deviation set-up, transmitted power

adjustment and other auxiliary functions.

3.3.3 Bit Banging and UART Concepts

The data communication between the microcontroller and any hardware device can be achieved in two ways: Bit banging and using UART.

Bit banging involves transmitting data via the electrical connection by controlling the voltage of the connection through the user program in the microcontroller. Whereas UART is a method which is simpler and reliable that uses an inbuilt hardware control in the microcontroller to establish the serial communication.

In this application, the microcontroller receives data from the transceiver which corresponds to the clock signal generated by transceiver exclusively.

45 Hence in order to avoid the timing difference between the transceiver and the

microcontroller’s UART module, the bit banging methodology used was.

3.3.4 Software Interface for Accessing Hardware from a PC

The application developed has a user-friendly interface developed in

LabVIEW that has facility to send commands to the hardware in a way easily understandable to the user and accessing the implant information. The system is developed in such a way that the hardware waits to receive a command from the

user and an interrupt is evoked in order to wake up the implanted system with the

reception of the user command. This way a low power operation of the implant is

achieved. Once a program is downloaded onto the microcontroller, it stays in its

memory till the power supply remains uninterrupted. Hence before implanting the

chipset into the body, the microcontroller registers are set, and the program is put

into execution. The system is put into active mode upon reception of the user

command requesting sensor data. The current system features can be enhanced

further by building functions in order to change the device settings through user

commands, which is included in the future work.

3.3.5 Code Generation

Independent functions were developed to cater to specific functionalities.

These functions provide easy application development for other purposes too,

and not limited to the current application of spinal disc implant. A brief description

about functions is enlisted in Table 6.

46 Table 6: Device driver functions and their purpose

Bus Control Driver Functions Purpose void InitRFChip(void) Initializes the RF Chip registers using pre initialized global variable void SetRFMode(unsigned char mode); the XE1201 operating mode (Sleep, Receiver, Transmitter) WriteRegister(unsigned char address, Writes the register value at the given unsigned short value); address on the XE1201A

Communication Functions Purpose void SendRfFrame(unsigned char Sends a RF frame *buffer,unsigned char size,unsigned char *pReturnCode); void ReceiveRfFrame(unsigned char Receives a RF frame *buffer, unsigned char *size, unsigned char *pReturnCode); void SendByte(unsigned char b); Send a data of 8 bits to the transceiver LSB first unsigned char ReceiveByte(void); Receives a data of 8 bits from the transceiver LSB first Unsigned int Temperature_sensor() Triggers temperature sensor for temperature output.

Interrupt controller driver Purpose functions __interrupt void Timer_A(void) Timer A interrupt function

Serial Communication driver Purpose functions Void LabVIEW_Read(unsigned int Receives data from the microcontroller data) and displays it on the front end Void LabVIEW_Write(unsigned int Sends user command to the data) microcontroller for interpretation.

3.3.6 Implant Side Program Logic:

The uplink communication is initiated when the implant receives a wake- up signal from the external unit. The implant receives the user command that

was transmitted by the external chipset. This command is received in the form of

a data packet. The implant checks for the initial start bit and the preamble byte to

47 check for the protocol and identify its own packets. Upon reception of the

preamble byte, the user command i.e. data is received. This command is then

interpreted by the microcontroller. If the analog physiological sensor output is

desired then the request is directed toward the ADC to sample the desired

channel. The output of ADC is in the form of a “word”. If the output of a

temperature sensor is desired, then the corresponding I/O port is activated and

the I/O pin connected to the temperature sensor is triggered to trigger the sensor for its current temperature data.

The output of the required sensor is thus stored in a buffer and is further encapsulated in a data packet and sent over the RF link to the user end unit. The entire process is demonstrated in Figure 19.

48 START

Data detected on RXD pin

Receive preamble bits

No

If preamble = 0xAA

Yes Receive data bytes

Interpret command

Sample required sensor

Send data using Start 1 Preamble 2 Byte Stop bit protocol bit byte of data

STOP

Figure 19: Flow-chart for uplink communication

3.3.7 User-end Program Logic:

The downlink communication is initiated when user sends a command to the implant. The command entered by the user is written to the serial port. This command is received by the microcontroller in the form of a “word”. The protocol set for the communication includes a single data byte transmission at a time in a packet. Hence this word of command is split into two bytes consisting of lower 8

49 bits and upper 8 bits respectively. The command is then encapsulated into two data packets and sent over to the implant through the RF link. The transceiver and the microcontroller are then switched in a wait state where the system keeps waiting to receive a high pulse on the RXD pin of the transceiver, indicating reception of required data from the implant.

Once a data reception signal is detected by the transceiver, it looks for a proper protocol in the received packet. It first looks for the preamble byte that contains alternate 0s and 1s. If the preamble byte is received correctly, then the transceiver looks forward for the data bytes to be received. The data that is received is stored in a buffer, and is processed for further serial communication for displaying the information to the user. The data is encapsulated into packet following the RS232-C-Xon/Xoff protocol and is received by the LabVIEW program. This received data is in the form of a hexadecimal output generated by the ADC for the analog sensor output and needs to be processed to obtain actual sensor output voltage corresponding to the digital value given by the ADC. This conversion is done in the front end in LabVIEW program, and displayed to the user. The entire process is demonstrated with help of a flow-chart in Figure 20.

50

START

Receive command from LabView

Split command in 2 bytes

Set Protocol Start 1 Preamble 2 Byte Stop bit bit byte of data

Wireless communication

No Receive data bytes If preamble = 0xAA

Yes

Receive sensor output data bytes

Write to LabVIEW Send three start bits Alternate toggles

Process data Send word

Display Send stop bit

STOP

Figure 20: Flow-chart for downlink communication

51 3.3.8 Device Driver Portability

Although the implementation of the device driver functions are target-dependent and non-portable, the name and parameter list (the function prototypes) of the device driver functions provided in Table 6 to the application program are fairly standardized, thus increasing portability.

The current functions can be migrated to any new device by integrating the current device library details to the new driver library with the application logic.

3.4 Integrated Circuit Schematic

A combined circuitry of the RF Telemetry for medical implants is illustrated

in Figure 16. Initial application development was carried out on proto-boards that

consisted of wire wrapped connections between the controller and the

transceiver. The size of these initial proto-boards was about 20 cm X 15 cm.

Once the application software was completed, focus was switched over to reduce

the size of the combined circuitry of Xemics transceiver and MSP430

microcontroller interface. The circuitry was first tested in parts with minimum

required components connected with wire wrap connections, a requirement

analysis of each and every component in the circuit was made, and the

insignificant connections were eliminated. The final circuits were then integrated

together into one circuit. Once the complete circuit was finalized, and the

component values were decided, the circuit was developed in PCB design

52 software namely Allegro (Cadence) and Eagle 4.1.13. The PCB schematic is shown in Figure 21.

To reduce the size of the circuit the design aim was focused on designing

a two layer prototype based on the finalized circuit. While designing the PCB,

stress was given on utilizing more blind and buried ‘vias’ for the connections.

Including extra vias in the multi-layer PCB significantly increased the number of

connections without increasing the size. Figure 21 shows a logical diagram of the circuit components and the connections as required for the application.

Constructing a logical diagram helps in a better understanding of the circuit when required to trace the connections.

53

XE1201A Circuitry

Measurement Points

Microcontroller Circuitry

SAW Resonator

Figure 21: Schematic diagram of combined microcontroller and transceiver circuit Following points were considered while laying the design in the software:

• Leave at least 100 mils between components and the PCB edge

• Attempt to space out the components evenly horizontally and vertically,

and orient like printed circuit board components the same direction

whenever possible.

• When it was necessary to have components on both sides; sensitive,

heavy, or through hole components were placed on the primary side

• The PCB components were placed so as to minimize the trace lengths.

• Component to component distance was kept minimum 10 mils.

• Distance between solder pads was kept 10 mils.

• Trace width used was 8 mils.

Numerous boards were fabricated with gradual changes, by replacing bulky components and fixing the values of variable components. The final prototype was then fabricated from Advanced Circuits a picture of the final board is shown in Figure 22 (a), which was compact as compared to the original ones.

An initial prototype that was developed consisted of 2 layered boards, with dimensions of 10 cm X 10 cm. A four layered board will be developed later that will further condense the circuitry to a size of 7.5 cm X 7.5 cm. A further miniaturization will be done using flip-chip technology to obtain an applications specific IC for this application.

(a) ( b)

Figure 22: (a) 2 Layered (b) 4 Layered combined circuit boards

A mapping between the schematic and the printed circuit board is taken care of by the PCB designing software. The PCB design developed based on the above schematic is as shown in Figure 22. An inbuilt feature of the software called “Auto-Routing” was used to automatically route the connection between the components based on the above mentioned properties of trace width, solder pads distances etc. A final rearrangement of the components was done for a better appearance.

56

4 Results and Discussion

The first step in establishing the communication between the microcontroller and the transceiver was the setting up of registers of the Xemics transceiver. The difficulty in achieving this was that there is no facility of verifying the contents of the XE1201A registers. Following section illustrates the Xemics register set-up.

4.1 XE1201A Control Registers Initialization:

The bus interface of XE1201A was set according to the values as discussed in chapter 3. The configuration used for initialization of the special function registers was based on following:

For register A:

• RF_A_CLOCK_ENABLE_ON: Clock subsystem for the chip was enabled

• RF_A_CHIP_ENABLE_OFF: all the blocks of XE1201A were in a

deactivated state.

• RF_A_TRANSMITTER_MODE: The transceiver was set to transmitter

mode

• RF_A_BIT_SYNC_ON: Data synchronization block was activated.

• RF_A_BAUDRATE_9600: Baud rate was set to an initial value of

9600bps.

For register C:

57 • RF_C_POWER_P_5: Amplification power level was set to maximum.

• RF_C_INVERT_OFF: Received data inversion was disabled.

• RF_C_TRANS_AMP_ON: Transmitter output amplification was activated.

• RF_C_TRANS_DATA_BIT_0: Data transmission via the address bus was

deactivated.

• RF_C_FDEV_32.5: Frequency deviation of the transmitter was set to 125

KHz.

The XE1201A registers were set in the application program according to the above mentioned values. Register B is used to adjust the local oscillator frequency for the transceiver. In this application, it was not used during the initial initialization of the XE1201A chip.

Waveform generated from the program that was used to set up the registers, at a baud rate of 9600 bps is illustrated in Figure 23. The 16 bit data that sets up the three registers is seen clearly in the waveform. This data sets the transceiver in various modes with a modification of transmitter/receiver mode value of two bits from these 16 bits. The set up of the XE1201A registers is critical in the accurate functioning of the transceiver. The channel 2 waveform seen in Figure

23 is the clock signal generated corresponding to the data rate and the channel waveform reveals the bits sequence used to set up the registers. The waveform shown below is used to configure XE1201A in the transmitter mode.

58

Figure 23: Waveform showing XE1201A register setup

With these settings the transceiver was found to be functioning as required, and was able to communicate with the other microcontroller-transceiver module properly.

4.2 Error Rate in Data Communication and Efficiency

Software programs were developed to establish a synchronized

communication between the microcontroller-transceiver modules. With

appropriate setting of the registers and then controlling the RXD, TXD, RXTX and

the three wire bus interface of XE1201A, the communication mode can be set

and the data can be sent or received. Following waveforms show a negligible

rate of error in communication between the modules. It can be seen in Figure 24

that the transmitted waveform i.e. channel 1 (one on the top) and the received

waveform i.e. channel 2 are almost identical.

59

Figure 24: Communication waveform demonstrating synchronized communication at a data rate of 4800Hz.

A code was developed as a part of the other main programs to check the error in the communication. The microcontroller-transceiver sets were placed 1 meter apart. The communication between the sets was established and 10,000 packets were transferred and analyzed at the receiver end. The percent error in the received packets was found to be 0.01 for this particular set-up. This shows that the received data can be said to be identical to the transmitted one. A complete protocol for the communication on 4MHz link is represented in the block diagram in Figure 25.

1 Start bit 1 Preamble byte Data 1 Stop bit

Figure 25: Communication protocol

60

The protocol shown above is a product of continuous refinement through

the entire duration of this project. Changes were made to the 1 start byte

protocol. The protocol was modified to achieve an error free communication and from an initial error of about 17%, the error was reduced considerably. The transmission packet consists of a start bit, a byte of preamble followed by 8 bits of data and a single stop bit. This protocol ensures minimum data loss and is vital for maintaining the synchronization between the transmitter and receiver.

Another consideration in a communication system is the delay in communication that is time after which the transmitted data is received at the other end. Various causes leading to the delays in communication are wakeup time of the transceiver, response time, switching time between the transmission/reception modes, data setup time, and the clock rise/fall time for both the microcontroller and the transceiver, along with the signal transmission time. A waveform representing the delay in communication is as shown in Figure

26. The channel 1 waveform corresponds to the transmitted signal and the channel 2 waveform is the received signal.

61

Figure 26: Communication waveform representing delay in the communication.

The delay between the two waveforms can be seen at the beginning of the packet. The delay was found out to be nearly 0.22µs, which can be considered to be negligible.

4.3 Sensor Voltage Range and Sensitivity

4.3.1 Analog Sensors

The system is built for data acquisition with the strain sensors with an output in the range of 0-2.5V. The ADC converts the analog sensor output to its

12-bit digital representation and stores the result in conversion memory. ADC uses two programmable/selectable voltage levels (VR+ and VR–) to define the upper and lower limits of the conversion. In this application the reference voltage

VR+ is set to the input power supply of 3.1V, and VR– is set to ground level. The digital output (NADC) is 0XFFF in hexadecimal when the input signal is equal to

62 or higher than VR+, and zero when the input signal is equal to or lower than VR–.

The conversion formula for the ADC result is given by equation 2.

n V = (2) 4095*VRe Sensor output voltage (V) = ADC decimal output value (n)/ 4095 *

Reference voltage (VRe). Figure 27 reveals the performance of ADC for different sensor voltages. It can be noted, ADC shown by red dots follows a linear relationship with the input voltage variation.

Figure 27: Analog to digital conversion output.

The difference in the actual voltage and ADC output can be related to the noise, parasitic effects and ground loops. Ground loops are formed when return current from the A/D flows through paths that are common with other analog or digital circuitry. This current generates small, unwanted offset voltages that add

63 to or subtract from the reference or input voltages of the A/D converter. In addition to grounding, ripple and noise spikes on the power supply lines due to digital switching or switching power supplies can corrupt the conversion result.

To achieve higher accuracy separate analog and digital ground planes with a single-point connection is usually recommended.

4.3.2 Temperature Sensor

A temperature sensor was used along with the analog strain sensors to keep a check on the implant temperature. The temperature sensor LM71 has an inbuilt ADC that provides the output in 13 bit digital format. The circuit diagram and the configuration of the temperature sensor have been discussed in the chapter 2 section 2.9. The temperature sensor output for different temperatures is as shown in Table 7 provided by the data sheet for the sensor. The sensor was calibrated with this data to ensure accuracy [33].

Table 7: Temperature sensor output for various temperatures

Temperature Digital Output Binary Hex +150°C 0100 1011 0000 0011 4B03 +125°C 0011 1110 1000 0011 3E83 +25°C 0000 1100 1000 0011 0C83 +0.03125°C 0000 0000 0000 0111 0007 0°C 0000 0000 0000 0011 0003 -0.03125°C 1111 1111 1111 1111 FFFF −25°C 1111 0011 1000 0011 F383 −40°C 1110 1100 0000 0011 EC03

64 4.4 LabVIEW Front-end and Script Language Development

For simplicity and a better user interface, a user friendly front-end was developed in LabVIEW. The front panel of the system is illustrated in Figure 28 and the block diagram; programs are presented in Appendix 9.7. The front-end allows a user to send commands to the implant in simple language and check the sensor outputs on the screen. A customized script language was developed to

enable usage of easy language to send commands to the implant. About eleven

commands have been developed for this application in the form of

; for example, “snap1-5” command snaps all the

sensor outputs and displays it on the screen one by one sequentially. For

specifying a single sensor output request, command such as “snap1-1” will be

used. To avoid overheads on the system and prevent data redundancy, an

alphabet “s” representing word “snap” has been implemented in the script language.

65

Figure 28: Data acquisition system monitoring console

66 The front-end consists of two ‘string’ controls, one of which accepts input

from the user in terms of command, and the other box is used to display the

requested sensor output. A drop down menu is also available in the front-end to

choose the serial port being used for communication. The data rate set for the

PC-Microcontroller interface is 9600bps, with a simple packet protocol consisting

of eight data bits, one stop bits and no parity checking bits. This a standard

protocol used for a two wire interface with the COM ports. Because this is a

wired interface to the computer, the data error rate is almost negligible. The

LabVIEW program logic is developed so that once the user command is sent

across to the implant end, the LabVIEW program awaits the results for 3

seconds, and displays the results upon receiving them, otherwise returns an empty string indicating no data was received. Incase if any errors occur in the communication, an error code is returned in the error block on the lower side of the front-end, that is accompanied by a brief description about the error in the

string output of the error block. A status display is also included in this block to

display the communication status.

The sensors output is obtained in 12 bits from the analog to digital

converter of the microcontroller, which is received by the LabVIEW program in

terms of two bytes of data and processed further to display the exact sensor output. In case if temperature data is requested, then the data is displayed exactly as it is received without any further processing. A provision to change the timeout for the data reception from the implant is also provided on the front-end

67 in the form of a drop down list in terms of seconds. By default the value is set to

three seconds.

4.5 Body Phantom Experiment Results

The system was operated and tested in the lab and showed a good

communication through air for a distance of 3-5 meters. As discussed earlier,

there would be complications when the chipsets are implanted in the body.

Hence, the saline tank experiment was conducted to evaluate the performance under real life conditions. The experimental setup s described in chapter 3,

section 3.2. The experiment was carried out with different orientations of the

implanted device and the external one. The results were promising and showed

the communication between the devices uninterrupted for about 38 cm average

in the X direction (parallel to the plane of implant) in all the configurations, with

the implant held at a distance of 9 cm from the wall of the tank. Considering the

depth (Y direction) supported by the communication, the implant can be placed

about 9 cm -11.5 cm deep inside the body (in a direction perpendicular to the

surface of the body). Hence about 9 cm-11.5 cm thick saline liquid barrier is

acceptable for the current set of devices for proper communication. With this

depth, the implant was able to communicate with the external device for about 38

cm but the signal power was seen to be degrading with the increase in distance.

A distance of 6.5 cm in the air ( away from the body i.e. perpendicular to the surface of the body ) will support a strong communication between the devices up to a distance of 30.5 cm parallel to the body surface and about 10 cm inside

68 the body will be acceptable for a descent communication between the implant and the external device.

69

5 Conclusions and Future Work

The RF Telemetry system for implants was found to be functioning as per

expectations. Communication between the ICs was established and tested with considerably less error in the communication. The system is found to work well at a range of about 3-5 meters, without any difficulties. The communication link remained uninterrupted for a long period of time until the power supply was shut down. These results can be improved and the functioning can be extended to a

larger range of distance.

The current data acquisition system works efficiently for a smaller range of

distances. The distances tested were about 3-5 meters. The constraint here is that the maximum power gain at present that is supported by XE1201A is +5dbm.

To achieve a greater range, an additional amplifier module can prove helpful, that can boost the signal strength of the transmitter output. This amplifier stage can be coupled to the Low Noise Amplifier of the transceiver. Increasing the gain of the current LNA subsystem of XE1201A can also prove useful. A better antenna configuration can also be helpful in covering a larger range of distance.

Further, if a distance in the range of 50-80 km. needs to be achieved, then an external frequency up conversion module can be added to the current system, that will up convert the signals to communicate in the 2.4GHz range. This way even a real time monitoring of a patient can be achieved from a stationary base

station. The system can be made much more reliable and error free by using the

70 embedded UART functionality instead of bit banging methodology. The difficulty in doing so was tuning the resonant frequency of XE1201A to match that with the

timing of MSP430F149. This can be overcome by studying the XE1201A circuitry

so as to match the difference in the frequency of operation.

The data communication part of the data acquisition system was

successful, but the customized circuit development did not work as per

expectations. The custom developed circuits failed to perform; they worked well

in the reception mode but did not transmit efficiently. This could be attributed to a

drift in local oscillator frequency in the developed transceiver part of the circuitry,

or might be because of tolerances of the components used which can affect their

performance. In the development of analog circuit designs, there is always some

uncertainty as to how well the design will perform after implementation [36]. Also

the components used were of different make as from the original chipsets and

might have different internal properties.

A performance analysis of the system in the body phantom with testing

conditions more closer to the actual body conditions needs to be undertaken.

Currently only a saline solution to match the specific gravity of the blood was

used. The test could be further improved by introducing other factors such as

glucose and body temperature. A relation between the error rate in the

communication and the distance achieved from the implant placed inside the

body phantom and external communication unit would prove useful in accurate

analysis of implant performance inside body.

71 The script language that has been developed for the user commands

currently supports limited functionalities. These functionalities can be extended using the developed functions. Small compact programs can be developed that

utilize these functions and add more functionalities and control to the medical

implant. The circuitry for the data acquisition system has been implemented on a

2-layered printed circuit board, which is being tested currently. The size of the 2

layered board was reduced to 3.5 inches X 3.5 inches A multi-layered board can

even reduce the implant size. Further more, if an application specific IC is

developed for this application, which will considerably reduce the size of the

medical implant and can make it relatively easy for surgery. With the circuitry

developed as a part of this thesis, an analysis was made for condensing the

circuit into a single multi-layered package using the Flip-Chip technology, The

estimated size was about 2 mm X 2.5 mm for the complete implant. Such a small

size along with the low power electrical characteristics will definitely prove useful

in the emerging world of medical implants.

72

6 References

1. D. Edell, “Chronically implantable neural information transducers”, J. IEEE EMBS, Mini-Symposium on Neurotechnology session, (1996).

2. L. Alexander,“Miniaturized Thermoelectric Generator Powered by Body Heat”, Applied Digital Solutions Inc., White Paper (2002).

3. P. Troyk, M. Schwan, “Closed-loop class E transcutaneous power and data link for microimplants”, J. IEEE Transactions on Biomedical Engineering, 39(6) (1992).

4. T. Akin, K. Najafi, R. Bradley, “An implantable multichannel digital neural recording system for a micromachined sieve electrode”, Conference of solid-state sensors and actuators, 51-54 (1995).

5. E. Hochmair, “System optimization for improved accuracy in transcutaneous signal and power transmission”, J. IEEE Transactions on Biomedical Engineering, 31(2) (1984).

6. Rorie, J. F., John K. Simmerman, Rafic Z. Makki, Richard D. Peindl, “A High Level Language Implementation of a General Purpose Telemetry System for Biomedical Applications”, Proceedings of SSST (1996).

7. H. Higgins, “ Making Medical Diagnosis: An Out –Of-Body Experience”, J. Electronic Design, ED Online ID 10023 (2005).

8. K. Chang, RF and Microwave Wireless Systems, 3rd ed., John Wiley & Sons, 81-89 (2000).

9. S. Gibilisco, Handbook of Radio and Wireless Technology, 1st ed., McGraw-Hill, 95-97 (1999).

10. Stron M. “System Design of RF Receiver and Digital Implementation of Control logic” PhD. Thesis, University of Linkopings (2003).

11. S. N. Bhatti, K. M. T. McCarthy, G. Knight, G. Pavlou, "Secure management information exchange and digital modulation", Journal of Network and Systems Management, 4(3) (1996).

73 12. Hewlett Packard , Application Note 1298, “Digital Modulation in Communications Systems – An Introduction”, 1-44 (2002).

13. H. Hwei, “Schaum’s Outline of Analog and Digital Communication RF Avenue”, 2nd ed., McGraw Hills, 224-260 (2002).

14. J. Simon, and W. Lindsey “Optimum Performance of Suppressed Carrier Receivers with Loop Tracking,” IEEE Transactions on Communications, (25) (2), 215-227 (1977).

15. R. Barto, “ An Outline of Worst Case Analysis Requirements for Digital Electronics”,White paper, 1-2 (1999).

16. A. Burr, Modulation and coding for wireless communications, 2nd ed., 156- 165, Prentice Hall (2001).

17. J. Bajcsy, CV Chong, DA Garr, J Hunziker, H “On Iterative Decoding in Some Existing Systems” IEEE J. on Selected Areas in Communication, (19) (5), 883-890 (2001).

18. M. Mycal, “RF Digital Signalling Basics”, Mycal Labs © Technical Document, 1-3 (1995).

19. P. Maragos, J. Kaiser, T. Quatieri, “On amplitude and frequency demodulation using energy operators” Signal Processing, IEEE transactions. (19) (4), 1532-1550 (1999).

20. S. White, “Amplitude Modulation Detector”, J. Access Science, 10(2) 1036-1097 (2004).

21. Conxant System Inc, Application Note AN9623, “Packet Error Rate Measurements Using the PRISM® Chip Set (2003-02-12)”, 1-5 (2004).

22. R. Ziemer, Introduction to Digital Communication, 2nd ed., Prentice Hall, 458-500 (2001).

23. Yu Kou S. Lin and M. Fossorier “Low-Density Parity-Check Codes Based on Finite Geometries” IEEE TRANSACTIONS ON INFORMATION THEORY (47)(7), 2711-2736 (2001).

24. W. Levicky, B. D. Cameron, “Wireless Data Acquisition using Bluetooth Technology for Potential Implantable Medical Diagnostics”, Master’s thesis, University of Toledo (2003).

25. Federal Communications Commission, Document number FCC00-211, 1-10 (2000).

74

26. Federal Communications Commission, Document number FCC01-192, 80-82 (2000).

27. U.S. Department of Food and Drug Administration, Document number 1073, 1-5 (2000).

28. Federal Communications Commission, Document number FCC01- 191.doc, 80-82 (2000).

29. U.S. Department of Food and Drug Administration, Document number 210, 1-14 (1998).

30. Texas Instruments, Technical Document ,SLAS272F, 1-62 (2004).

31. Xemics Inc, Technical Document, XE1201A datasheet, 1-14, (2004).

32. Xemics Inc, Application Note AN1201A.02, 1-10 (2004).

33. National Semiconductors, Technical Document, LM71 datasheet, 1-13 (2005).

34. Maxim, Technical Document, MAX7275 datasheet, 1-7 (2004).

35. Zarlink Inc, “Ultra low-power RF Technology is opening new markets for medical device manufacturers”, J. MDT Medical Technology, 32-33 (2003).

36. Cadence Ltd, Dennis Fitzpatrick, “Improving design performance”, New Electronics Magazine, 19-19 (2001).

37. Peter Bradley," The Ultra-Low-Power Wireless Medical Device Revolution”, Medical Electronics Manufacturing Magazine (2005).

75

7 Appendix

7.1 Header file XE1201driver.h code /******************************************************************* ** File : XE1201driver.h ** ******************************************************************** ** Written by : Prachi Sonalkar ** ** ** ** Date : 03-02-2004 ** ******************************************************************** ** Description : XE1201 transceiver drivers implementation for the** ** XE8000 family products ** *******************************************************************/ #ifndef __XE1201DRIVER__ #define __XE1201DRIVER__

/******************************************************************* ** Include files ** *******************************************************************/ #include "Globals.h"

/******************************************************************* ** Global definitions ** *******************************************************************/

/******************************************************************* ** RF frame definition ** *******************************************************************/ #define RF_BUFFER_SIZE_MAX 64 #define RF_BUFFER_SIZE 64 #define SYNC_BYTE_FREQ 4

#define PREAMBLE 0xAA

/******************************************************************* ** RF State machine ** *******************************************************************/ #define RF_STOP 0x01 #define RF_BUSY 0x02 #define RF_RX_DONE 0x04 #define RF_TX_DONE 0x08 #define RF_ERROR 0x10 #define RF_TIMEOUT 0x20 #define RF_AFC_DONE 0x40

/******************************************************************* ** RF function return codes ** *******************************************************************/ #define OK 0x00

76 #define ERROR 0x01 #define RX_TIMEOUT 0x02 #define RX_RUNNING 0x03 #define TX_TIMEOUT 0x04 #define TX_RUNNING 0x05

/******************************************************************* ** Port A pins definitions ** ******************************************************************** ** * uC * XE1201 * P3.x ** *******************************************************************/ #define CLKD 0x40 //* In * Out * P2.6 #define RXD 0x20 //* In * Out * P2.5 //#define check 0X40

/******************************************************************* ** Port B pins definitions ** ******************************************************************** ** * uC * XE1201 * PBx ** *******************************************************************/

/******************************************************************* ** Port C pins definitions ** ******************************************************************** ** * uC * XE1201 * P2.x ** *******************************************************************/ /* Port 2 */ #define TXD 0x80 //* Out * In * P2.7 #define DE 0x08 //* Out * In * P2.3 #define EN 0x10 //* Out * In * P2.4 /* Port 3 */ #define SC 0x04 //* Out * In * P2.2 #define SD 0x02 //* Out * In * P2.1 /* Port 5 */ #define RXTX 0x01 //* Out * In * P2.0

/******************************************************************* ** XE1201 3 wire serial interface macros definitions ** *******************************************************************/ #define SrtInit() (P2OUT |= 0x00) #define SrtSetSCK(level) (level) ? (set_bit(P2OUT, SC)) : (clear_bit(P2OUT, SC)) #define SrtSetSO(level) (level) ? (set_bit(P2OUT, SD)) : (clear_bit(P2OUT, SD))

/******************************************************************* ** XE1201 definitions ** *******************************************************************/

/******************************************************************* ** XE1201 Operating modes definition ** *******************************************************************/ #define RF_SLEEP 0x00 #define RF_RECEIVER 0x01 #define RF_TRANSMITTER 0x02

/*******************************************************************

77 ** XE1201 Internal registers Address ** *******************************************************************/ #define REG_A 0x00 #define REG_B 0x01 #define REG_C 0x02

/******************************************************************* ** XE1201 default register values definition ** *******************************************************************/ #define DEF_REG_A 0x0000 #define DEF_REG_B 0x4000 #define DEF_REG_C 0x8000

/******************************************************************* ** XE1201 bit control definition ** *******************************************************************/ // Register A // Control mode bit #define RF_A_CTRL_MODE_REG 0x2000 #define RF_A_CTRL_MODE_PIN 0x0000 // Clock control #define RF_A_CLOCK_ALWAYS_ON 0x1000 #define RF_A_CLOCK_ENABLE_ON 0x0000 // Chip Enable #define RF_A_CHIP_ENABLE_ON 0x0800 #define RF_A_CHIP_ENABLE_OFF 0x0000 // Tx/Rx mode #define RF_A_RECEIVER_MODE 0x0400 #define RF_A_TRANSMITTER_MODE 0x0000 // Demodulator and bit synchronizer bypassing #define RF_A_BIT_SYNC_ON 0x0000 #define RF_A_DEMODULATOR_BYPASSED 0x0100 #define RF_A_BIT_SYNC_OFF 0x0140 // Receiver data rate #define RF_A_BAUDRATE_1200 0x002E #define RF_A_BAUDRATE_2400 0x0026 #define RF_A_BAUDRATE_4800 0x001E #define RF_A_BAUDRATE_9600 0x0016 #define RF_A_BAUDRATE_19200 0x000E #define RF_A_BAUDRATE_38400 0x0006 #define RF_A_BAUDRATE_57600 0x0001

// Register B // Test register #define RF_B_TEST_BITS 0x0000

// Register C // Transmitted output power #define RF_C_POWER_M_15 0x0000 #define RF_C_POWER_M_5 0x1000 #define RF_C_POWER_P_2_5 0x2000 #define RF_C_POWER_P_5 0x3000 // Data inversion bit #define RF_C_INVERT_ON 0x0800 #define RF_C_INVERT_OFF 0x0000 // Transmitted output amplifier enable #define RF_C_TRANS_AMP_ON 0x0100

78 #define RF_C_TRANS_AMP_OFF 0x0000 // Transmitted data bit #define RF_C_TRANS_DATA_BIT_1 0x0080 #define RF_C_TRANS_DATA_BIT_0 0x0000 // Modulator frequency deviation #define RF_C_FDEV_125 0x0020 #define RF_C_FDEV_62 0x000F

/******************************************************************* ** Timings section : all timing described here are done with the ** ** A&B counters cascaded ** *******************************************************************/ /******************************************************************* ** -- TX Bitrate -- ** ******************************************************************** ** The bitrate values depend on the RC frequency ** ** The following values corresponds to a 2.4576 MHz RC Freq ** ** Bitrate calculation formula ** ** ** ** RC osc frequency 2 457 600 ** ** CounterA&B value = ------= ------= 2048 ** wanted baudrate 1200 ** ** ** *******************************************************************/ #define TX_BAUDRATE_GEN_1200 2048 #define TX_BAUDRATE_GEN_2400 1024 #define TX_BAUDRATE_GEN_4800 512 #define TX_BAUDRATE_GEN_9600 256 #define TX_BAUDRATE_GEN_19200 128 #define TX_BAUDRATE_GEN_38400 64 #define TX_BAUDRATE_GEN_57600 43

/******************************************************************* ** -- XE1201 Recommended timings -- ** ******************************************************************** ** These timings depends on the RC frequency ** ** The following values corresponds to a 2.4576 MHz RC Freq ** ** Times calculation formula ** ** ** ** CounterA&B value = RC * wanted time = 2 457 600 * 90 us = 221** ** ** *******************************************************************/ #define T_CLK 8602 // 3.5 ms #define T_TW 221 // 90 us #define T_TR 221 // 90 us #define T_RT 73 // 30 us

/******************************************************************* ** ** ** // RF_BUFFER_SIZE * 8 * (SYNC_BYTE_FREQ + 1) \ \ ** CounterA&B value = || ------| * 128 Hz | + 1 ** \\ SYNC_BYTE_FREQ * BitRate / / ** **

79 ** The plus 1 at the end of formula is required for the highest ** ** baudrate as the resulting timeout is lower than the 1 / 128Hz ** *******************************************************************/ #define RF_FRAME_TIMEOUT(BitRate) (unsigned char)(double)((((double)((unsigned long)RF_BUFFER_SIZE * (unsigned long)8 * ((unsigned long)SYNC_BYTE_FREQ + (unsigned long)1)) / (double)((unsigned long)SYNC_BYTE_FREQ * (unsigned long)BitRate)) * (double)128) + (double)1)

/******************************************************************* ** Functions prototypes ** *******************************************************************/

/******************************************************************* ** Configuration functions ** *******************************************************************/

/******************************************************************* ** InitRFChip : Initializes the RF Chip registers using ** ** pre initialized global variable ** ******************************************************************** ** In : - ** ** Out : - ** *******************************************************************/ void InitRFChip(void);

/******************************************************************* ** SetRFMode : Sets the XE1201 operating mode (Sleep, Receiver, ** ** Transmitter) ** ******************************************************************** ** In : mode ** ** Out : - ** *******************************************************************/ void SetRFMode(unsigned char mode);

/******************************************************************* ** WriteRegister : Writes the register value at the given address ** ** on the XE1201 ** ******************************************************************** ** In : address, value ** ** Out : - ** *******************************************************************/ void WriteRegister(unsigned char address, unsigned short value);

/******************************************************************* ** ReadRegister : Not possible with XE1201 ** ******************************************************************** ** ReadRegister : Reads the pre initialized global variable that ** ** is the image of RF chip registers value ** ******************************************************************** ** In : address ** ** Out : value ** *******************************************************************/ //_U16 ReadRegister(_U8 address);

/******************************************************************* ** Communication functions **

80 *******************************************************************/

/******************************************************************* ** SendRfFrame : Sends a RF frame ** ******************************************************************** ** In : *buffer, size ** ** Out : *pReturnCode ** *******************************************************************/ void SendRfFrame(unsigned char *buffer,unsigned char size,unsigned char *pReturnCode); void SendRfFrame1(unsigned char *buffer,unsigned char size,unsigned char *pReturnCode);

/******************************************************************* ** ReceiveRfFrame : Receives a RF frame ** ******************************************************************** ** In : - ** ** Out : *buffer, size, *pReturnCode ** *******************************************************************/ void ReceiveRfFrame(unsigned char *buffer, unsigned char *size, unsigned char *pReturnCode);

/******************************************************************* ** SendByte : Send a data of 8 bits to the transceiver LSB first ** ******************************************************************** ** In : b ** ** Out : - ** *******************************************************************/ void SendByte(unsigned char b);

/******************************************************************* ** ReceiveByte : Receives a data of 8 bits from the transceiver ** ** LSB first ** ******************************************************************** ** In : - ** ** Out : b ** *******************************************************************/ unsigned char ReceiveByte(void);

/******************************************************************* ** Transceiver specific functions ** *******************************************************************/

/******************************************************************* ** AutoFreqControl : This routine do an automatic frequency ** ** correction by according to a predefined ** ** pattern sent by the transmitter ** ******************************************************************** ** ------Not yet implemented------** ******************************************************************** ** In : - ** ** Out : *pReturnCode ** *******************************************************************/ void AutoFreqControl(unsigned char *pReturnCode);

/*******************************************************************

81 ** Utility functions ** *******************************************************************/

/******************************************************************* ** Wait : This routine uses the counter A&B to create a delay ** ** using the RC ck source ** ******************************************************************** ** In : cntVal ** ** Out : - ** *******************************************************************/ //void Wait(unsigned int value); void Wait(int time_value);

/******************************************************************* ** TxEventsOn : Initializes the timers and the events related to ** ** the TX routines PA1 CntA&B ** ******************************************************************** ** In : - ** ** Out : - ** *******************************************************************/ void TxEventsOn(void);

/******************************************************************* ** TxEventsOff : Initializes the timers and the events related to ** ** the TX routines PA1 CntA&B ** ******************************************************************** ** In : - ** ** Out : - ** *******************************************************************/ void TxEventsOff(void);

/******************************************************************* ** RxEventsOn : Initializes the timers and the events related to ** ** the RX routines PA1 CntA&B ** ******************************************************************** ** In : - ** ** Out : - ** *******************************************************************/ void RxEventsOn(void);

/******************************************************************* ** RxEventsOff : Initializes the timers and the events related to ** ** the RX routines PA1 CntA&B ** ******************************************************************** ** In : - ** ** Out : - ** *******************************************************************/ void RxEventsOff(void);

#endif /* __XE1201DRIVER__ */

82 7.2 Header file Globals.h code

/******************************************************************* ** File : Globals.h ** ******************************************************************** ** Description : Definition of common typedefs, defines, macros, ** ** etc ... ** *******************************************************************/ #ifndef __GLOBALS__ #define __GLOBALS__ /******************************************************************* ** Soft generation control (RAISONANCE monitor usage) ** *******************************************************************/ #define usemonitor 0 #if usemonitor #include #else #define _Monitor_Init() #define _Monitor_SoftBreak #endif /******************************************************************* ** Soft generation control target type ** ** modify the TARGET value only ** *******************************************************************/

/******************************************************************* ** Uncoment if using Phyton PICE-XE ** *******************************************************************/ //#include "Types.h" #include #include "XE1201Driver.h" /******************************************************************* ** Global definitions ** *******************************************************************/

/******************************************************************* ** Protocol commands definitions ** *******************************************************************/

/******************************************************************* ** Macros definitions ** *******************************************************************/ #define set_bit(reg, bit) reg |= bit #define clear_bit(reg, bit) reg &= ~(bit) #define toggle_bit(reg, bit) reg ^= bit #define check_bit(reg, bit) (reg & bit) ? 1 : 0

#define InitializeWatchDog() RegSysCtrl |= 0x10 #define ResetWatchDog() asm("move %0, #0x0A"::"m"(RegSysWd));\ asm("move %0, #0x03"::"m"(RegSysWd))

/******************************************************************* ** Types definitions ** *******************************************************************/

#endif /* __GLOBALS__ */

83 7.3 Xe1201A - MSP430F149 Interface Receiver Code. /********************************************************************** ************************************ // Xe1201A - MSP430F149 interface Receiver code. // The code currently supports 38.4KHz of data reception. // For 9600 Baudrate reception, please change the RF_A_BAUDRATE option in the Xe1201A register_A setup to RF_A_BAUDRATE_9600 // The code is currently set for receiving 300X300 packets((outer_count) X (no_of_packets)) and counting and printing out // the packets with reception errors encountered with the error values being displayed at the end of the execution. *********************************************************************** ***********************************/

#include #include "string.h" #include "stdlib.h" #include "XE1201Driver.h" #include

#define FALSE 0 #define TRUE 1 volatile int timer = 0; unsigned char ReturnCode = -1; static unsigned char RFState = RF_STOP; // RF state machine static unsigned char *pRFFrame; // Pointer to the RF frame static unsigned char RFFramePos; // RF frame current position static unsigned char RFFrameSize; // RF frame size static unsigned short ByteCounter = 0; // RF frame byte counter static unsigned char PreMode = RF_SLEEP; // Previous chip operating mode volatile unsigned char EnableSyncByte = TRUE; // Enables/disables the synchronization byte reception/transmission static unsigned char SyncByte; // RF synchronization byte counter static unsigned char PatternSize = 4; // Size of pattern detection static unsigned char StartByte[4] = {0x69, 0x81, 0x7E, 0x96}; // Pattern detection values static unsigned long RFFrameTimeOut = RF_FRAME_TIMEOUT(1200); // Reception counter value (full frame timeout generation) static unsigned long RFBaudrate = TX_BAUDRATE_GEN_1200; // Transmission counter value (baudrate generation)

static unsigned char RFbuffer[RF_BUFFER_SIZE]; // RF buffer volatile unsigned char RFbufferSize; // RF buffer size volatile unsigned char EnableMaster = TRUE;// Master/Slave selection volatile unsigned char SendNextPacket = TRUE; // Indicates when to send the next frame

// XE1201 configuration registers values : A = 6416, B = 4000 , C = B1A0 unsigned short RegistersCfg[] = {

84 DEF_REG_A | RF_A_CTRL_MODE_PIN | RF_A_CLOCK_ENABLE_ON | RF_A_CHIP_ENABLE_OFF | RF_A_TRANSMITTER_MODE | RF_A_BIT_SYNC_ON | RF_A_BAUDRATE_9600, DEF_REG_B, DEF_REG_C | RF_C_POWER_P_5 | RF_C_INVERT_OFF | RF_C_TRANS_AMP_ON | RF_C_TRANS_DATA_BIT_0 | RF_C_FDEV_62 }; void main(void) {

int i=0;

//MSP430 Initialization WDTCTL = WDTPW + WDTHOLD; // Stop WDT BCSCTL1 = XT2OFF | RSEL2 | RSEL1 | RSEL0 ; // Select and initialize clock source BCSCTL2 = 0x00; //BCSCTL2 |= SELM1+SELM0; // MCLK = LFXT1 (safe) do { DCOCTL = DCO0 | DCO1; IFG1 &= ~OFIFG; // Clear OSCFault flag for (i = 0xFF; i > 0; i--); // Time for flag to set } while ((IFG1 & OFIFG) == OFIFG); // OSCFault flag still set?

P2DIR |= 0X9F; // Port two I/O initialization P1DIR |= 0XFD; // Port one I/O initialization InitRFChip(); // Call the initialization function.

_EINT(); // Enable interrupts SendRfFrame(RFbuffer, strlen(RFbuffer), &ReturnCode); // Begin communniaction by sending an alert signal for(;;) ReceiveRfFrame(RFbuffer, (unsigned char*)&RFbufferSize, &ReturnCode); // Function to Receive the packets sent from other system

}

/******************************************************************* ** SendRfFrame : Send a data packet to the transceiver ** ******************************************************************** ** In : data buffer, size of data in buffer, and errorcode ** ** Out : - ** *******************************************************************/ void SendRfFrame(unsigned char *buffer, unsigned char size, unsigned char *pReturnCode){ clear_bit(P2OUT, TXD); // Initialize the TXD pin

85 SetRFMode(RF_TRANSMITTER); // Switch mode to transmitter set_bit(P2OUT,EN); // Enable XE1201A set_bit(P2OUT,DE); // Set XE1201A into data operations. RFState |= RF_BUSY; // Set RF state to “busy” RFState &= ~RF_STOP;

SendByte(0XAB); // Send a byte by encapsulating it in protocol to form a packet.

RFState |= RF_STOP; // RF state changed to “stop” RFState &= ~RF_TX_DONE; // Tranmission completion state *pReturnCode = OK; // Return code for successive transmission } // void SendRfFrame(unsigned char *buffer, unsigned char size, unsigned char *pReturnCode)

/******************************************************************* ** SendByte : Send a data of 8 bits to the transceiver LSB first ** ******************************************************************** ** In : b ** ** Out : - ** *******************************************************************/ void SendByte(unsigned char b){ unsigned char bitCounter; // bitcounter to select bit transmission unsigned int i,j; timer=0; // clock timer variable initialized to zero P2DIR |= 0x9F; i=0; j=0;

for(bitCounter = 0x01; bitCounter != 0x00; bitCounter <<= 1){ timer=0; clock(); while(!timer) { _NOP(); } if (b & bitCounter){ set_bit(P2OUT, TXD); // Set voltage level high } else{ clear_bit(P2OUT, TXD); // Set voltage level zero //printf("0"); }

} }// end of SendByte function

86 /******************************************************************* ** ReceiveRfFrame : Receive a data packet from the transceiver ** ******************************************************************** ** In : data buffer, size of data in buffer, and errorcode ** ** Out : - ** *******************************************************************/ void ReceiveRfFrame(unsigned char *buffer, unsigned char *size, unsigned char *pReturnCode){

char b=0; char c=0; unsigned int i; unsigned int num=0;

P2OUT &= 0X00; P1OUT &= 0X00;

SetRFMode(RF_RECEIVER); // Set XE1201A into reception set_bit (P2OUT, EN); // Enable XE1201A set_bit (P2OUT, DE); // Enable data set_bit (P2OUT, RXTX); // Set transceiver into reception //printf("set!"); IE1 |= P2IE; // Enable Port 2 Interrupts IE2 |= P1IE; // Enable Port 1 Interrupts _EINT(); // Enable interrupts P2IES |= 0X00; // Select pins for Port 2 Interrupt /*Enable events (timeout) "CONTAINS COUNTERS SET UP FOR MSB AND LSB" */ P1IES |= 0X02; // Select pins for Port 1 Interrupt P2IFG &= 0X00; // Initialize Port 2 flags P1IFG &= 0X00; // Initialize Port 1 flags

b&=0X00; // Initialize input buffer to zero while(!(P1IN & CRXD)); // Wait to detect data on Port 1

P1IFG &= 0X00; // Initialize Port 1 flags to zero while(!(P2IFG & CLKD)); // Wait for next clock pulse P2IFG &= 0X00; // Initialize Port 1 flags to zero while(!(P2IFG & CLKD)); // Wait for next clock pulse

P2IFG &= 0X00; // Initialize Port 1 flags to zero while(!(P2IFG & CLKD)); // Wait for next clock pulse

/* Inverse logic for Serial COM Port communication, if high voltage seen on the input pin, a low is considered */

if(!(P1IN & CRXD)) b|=0X01; //bit0

P2IFG &= 0X00;

87 while(!(P2IFG & CLKD)); if(!(P1IN & CRXD)) b|=0X02; //bit1

P2IFG &= 0X00; while(!(P2IFG & CLKD)); if(!(P1IN & CRXD)) b|=0X04; //bit2

P2IFG &= 0X00; while(!(P2IFG & CLKD)); if(!(P1IN & CRXD)) b|=0X008; //bit3

P2IFG &= 0X00; while(!(P2IFG & CLKD)); if(!(P1IN & CRXD)) b|=0X10; //bit4

P2IFG &= 0X00; while(!(P2IFG & CLKD)); if(!(P1IN & CRXD)) b|=0X20; //bit5

P2IFG &= 0X00; while(!(P2IFG & CLKD)); if(!(P1IN & CRXD)) b|=0X40; //bit6

P2IFG &= 0X00; while(!(P2IFG & CLKD)); if(!(P1IN & CRXD)) b|=0X80; //bit7

/* Send no data for three packets duration to distinguish between characters */

P2IFG &= 0X00; do{ _NOP(); }while(!(P2IFG & CLKD));

P2IFG &= 0X00; do{ _NOP(); }while(!(P2IFG & CLKD));

P2IFG &= 0X00; do{

88 _NOP(); }while(!(P2IFG & CLKD)); // Delay ends here

/* Receive next character and store it in buffer c */

if(!(P1IN & CRXD)) c|=0X01; //bit0

P2IFG &= 0X00; do{ _NOP(); }while(!(P2IFG & CLKD));

if(!(P1IN & CRXD)) c|=0X02; //bit1

P2IFG &= 0X00; while(!(P2IFG & CLKD));

if(!(P1IN & CRXD)) c|=0X04; //bit2

P2IFG &= 0X00; while(!(P2IFG & CLKD));

if(!(P1IN & CRXD)) c|=0X008; //bit3

P2IFG &= 0X00; while(!(P2IFG & CLKD));

if(!(P1IN & CRXD)) c|=0X10; //bit4

P2IFG &= 0X00; while(!(P2IFG & CLKD));

if(!(P1IN & CRXD)) c|=0X20; //bit5

P2IFG &= 0X00; while(!(P2IFG & CLKD));

if(!(P1IN & CRXD)) c|=0X40; //bit6

P2IFG &= 0X00; while(!(P2IFG & CLKD));

if(!(P1IN & CRXD)) c|=0X80; //bit7

// check for errors and correct the data received if((c&0X80)&&(!(c&0X40))){ c<<=1; //printf(" cn= %x ",c);

89 }

if((c&0X80)&&(c&0X40)){ c>>=1; }

// printf("b=%c",b); // printf(" %c ",c);

/* Switch XE1201A to transmitter mode */

clear_bit(P2OUT, TXD); SetRFMode(RF_TRANSMITTER); set_bit(P2OUT,EN); set_bit(P2OUT,DE); RFState |= RF_BUSY; RFState &= ~RF_STOP; // RFFrameSize = size; pRFFrame = buffer;

/* Send the received user request over to the implant */ SendRfFrame(RFbuffer, strlen(RFbuffer), &ReturnCode);

}

}//end of receiver function

/******************************************************************* ** clock : Sub Routine to set the timimgs for communication ** ******************************************************************** ** In : - ** ** Out : - ** *******************************************************************/ clock(void) { WDTCTL = WDTPW +WDTHOLD; // Stop WDT BCSCTL1 = XT2OFF | RSEL2 | RSEL1 | RSEL0; // Set up clock sources DCOCTL = DCO0 | DCO1 | DCO2; // Set clock sources TACTL = TASSEL_2 | TACLR; // SMCLK, Clear Tar

CCR0 =390; // PWM Period CCTL0 = CCIE; // Set interrupt for counter P1DIR |= 0x0C; // P1.2 and P1.3 output IE1 |= P1IE; // Set Interrupt for Port 1 _EINT(); // P1IES |= 0X0C; TACTL |= MC0; // Start Timer_A in up mode }

90 /******************************************************************* ** Timer A Sub Routine : Sub Routine to set interrupts for Timer A * ******************************************************************** ** In : - ** ** Out : - ** *******************************************************************/

#pragma vector=TIMERA0_VECTOR __interrupt void Timer_A(void) { timer=1; // set timer value 1 CCTL0 &= 0; // Initialize counter to zero }

/******************************************************************* ** InitRFChip : Function to Initialize XE1201A ** ******************************************************************** ** In : - ** ** Out : - ** *******************************************************************/

void InitRFChip(void){ unsigned short i;

// Initializes XE1201 SrtInit(); for(i = 0; i < REG_C + 1; i++){ WriteRegister(i, RegistersCfg[i]); }

if((RegistersCfg[REG_A] & 0x003F) == RF_A_BAUDRATE_1200){ RFBaudrate = TX_BAUDRATE_GEN_1200; RFFrameTimeOut = RF_FRAME_TIMEOUT(1200); } else if((RegistersCfg[REG_A] & 0x003F) == RF_A_BAUDRATE_2400){ RFBaudrate = TX_BAUDRATE_GEN_2400; RFFrameTimeOut = RF_FRAME_TIMEOUT(2400); } else if((RegistersCfg[REG_A] & 0x003F) == RF_A_BAUDRATE_4800){ RFBaudrate = TX_BAUDRATE_GEN_4800; RFFrameTimeOut = RF_FRAME_TIMEOUT(4800); } else if((RegistersCfg[REG_A] & 0x003F) == RF_A_BAUDRATE_9600){ RFBaudrate = TX_BAUDRATE_GEN_9600; RFFrameTimeOut = RF_FRAME_TIMEOUT(9600); } else if((RegistersCfg[REG_A] & 0x003F) == RF_A_BAUDRATE_19200){ RFBaudrate = TX_BAUDRATE_GEN_19200; RFFrameTimeOut = RF_FRAME_TIMEOUT(19200); } else if((RegistersCfg[REG_A] & 0x003F) == RF_A_BAUDRATE_38400){ RFBaudrate = TX_BAUDRATE_GEN_38400; RFFrameTimeOut = RF_FRAME_TIMEOUT(38400); } else if((RegistersCfg[REG_A] & 0x003F) == RF_A_BAUDRATE_57600){

91 RFBaudrate = TX_BAUDRATE_GEN_57600; RFFrameTimeOut = RF_FRAME_TIMEOUT(57600); } else { RFBaudrate = TX_BAUDRATE_GEN_1200; RFFrameTimeOut = RF_FRAME_TIMEOUT(1200); } SetRFMode(RF_SLEEP); } // void InitRFChip(void)

/******************************************************************* ** SetRFMode : Sets the XE1201 operating mode (Sleep, Receiver, ** ** Transmitter) ** ******************************************************************** ** In : mode ** ** Out : - ** *******************************************************************/ void SetRFMode(unsigned char mode){ if(mode != PreMode){ if((mode == RF_TRANSMITTER) && (PreMode == RF_SLEEP)){ PreMode = RF_TRANSMITTER; set_bit(P2OUT, EN); clear_bit(P2OUT, RXTX);

} if((mode == RF_TRANSMITTER) && (PreMode == RF_RECEIVER)){ PreMode = RF_TRANSMITTER; set_bit(P2OUT, EN); clear_bit(P2OUT, RXTX); // P1OUT |= 0X01;

// printf("Entered xmitter after receiver"); } else if((mode == RF_RECEIVER) && (PreMode == RF_SLEEP)){ PreMode = RF_RECEIVER; set_bit(P2OUT, EN); set_bit(P2OUT, RXTX); printf(" set");

} else if((mode == RF_RECEIVER) && (PreMode == RF_TRANSMITTER)){ PreMode = RF_RECEIVER; set_bit(P2OUT, EN); set_bit(P2OUT, RXTX);

// printf("Entered receiver after transmitter"); } else if(mode == RF_SLEEP){ PreMode = RF_SLEEP; clear_bit(P2OUT, EN); // printf("entered sleep mode"); } else{ PreMode = RF_SLEEP; clear_bit(P2OUT, EN);

92 } } } // void SetRFMode(unsigned char mode)

/******************************************************************* ** WriteRegister : Writes the register value at the given address ** ** on the XE1201 ** ******************************************************************** ** In : address, value ** ** Out : - ** *******************************************************************/ void WriteRegister(unsigned char address, unsigned short value){ unsigned short bitCounter;

SrtInit(); clear_bit(P2OUT, DE); // Writes the Address for(bitCounter = 0x02; bitCounter != 0x00; bitCounter >>= 1){ if (address & bitCounter){ SrtSetSO(1);

} else{ SrtSetSO(0); } SrtSetSCK(1); SrtSetSCK(0); } // Writes the Data for(bitCounter = 0x2000; bitCounter != 0x00; bitCounter >>= 1){ if (value & bitCounter){ SrtSetSO(1); } else{ SrtSetSO(0); } SrtSetSCK(1); SrtSetSCK(0); } set_bit(P2OUT, DE); SrtSetSCK(1); SrtSetSCK(0);

} // void WriteRegister(unsigned char address, unsigned short value)

93 7.4 Xe1201A - MSP430F149 Interface Transmitter Code. //********************************************************************* ********** /********************************************************************** ************************************ // Xe1201A - MSP430F149 interface Transmitter code. // The code currently supports 38.4KHz of data reception. // For 9600 Baudrate reception, please change the RF_A_BAUDRATE option in the Xe1201A register_A setup to RF_A_BAUDRATE_9600 // The code is currently set for receiving 300X300 packets((outer_count) X (no_of_packets)) and counting and printing out // the packets with reception errors encountered with the error values being displayed at the end of the execution. *********************************************************************** ***********************************///********************************* *********************************************

#include #include "string.h" #include "stdlib.h" #include "XE1201Driver.h" #include volatile int timer = 0; unsigned char ReturnCode = -1; static unsigned char RFState = RF_STOP; // RF state machine static unsigned char *pRFFrame; // Pointer to the RF frame static unsigned char RFFramePos; // RF frame current position static unsigned char RFFrameSize; // RF frame size static unsigned short ByteCounter = 0; // RF frame byte counter static unsigned char PreMode = RF_SLEEP; // Previous chip operating mode volatile unsigned char EnableSyncByte = TRUE; // Enables/disables the synchronization byte reception/transmission static unsigned char SyncByte; // RF synchronization byte counter static unsigned char PatternSize = 4; // Size of pattern detection static unsigned char StartByte[4] = {0x69, 0x81, 0x7E, 0x96}; // Pattern detection values static unsigned long RFFrameTimeOut = RF_FRAME_TIMEOUT(1200); // Reception counter value (full frame timeout generation) static unsigned long RFBaudrate = TX_BAUDRATE_GEN_1200; // Transmission counter value (baudrate generation)

static unsigned char RFbuffer[RF_BUFFER_SIZE]; // RF buffer volatile unsigned char RFbufferSize; // RF buffer size volatile unsigned char EnableMaster = TRUE;// Master/Slave selection volatile unsigned char SendNextPacket = TRUE; // Indicates when to send the next frame

// XE1201 configuration registers values : A = 6416, B = 4000 , C = B1A0 unsigned short RegistersCfg[] = {

94 DEF_REG_A | RF_A_CTRL_MODE_PIN | RF_A_CLOCK_ENABLE_ON | RF_A_CHIP_ENABLE_OFF | RF_A_TRANSMITTER_MODE | RF_A_BIT_SYNC_ON | RF_A_BAUDRATE_9600, DEF_REG_B, DEF_REG_C | RF_C_POWER_P_5 | RF_C_INVERT_OFF | RF_C_TRANS_AMP_ON | RF_C_TRANS_DATA_BIT_0 | RF_C_FDEV_62 };

/******************************************************************* ** Configuration functions ** *******************************************************************/ void main(void) {

int i=0;

//MSP430 Initialization WDTCTL = WDTPW + WDTHOLD; // Stop WDT BCSCTL1 = XT2OFF | RSEL2 | RSEL1 | RSEL0 ; // Select and initialize clock source BCSCTL2 = 0x00; //BCSCTL2 |= SELM1+SELM0; // MCLK = LFXT1 (safe) do { DCOCTL = DCO0 | DCO1; IFG1 &= ~OFIFG; // Clear OSCFault flag for (i = 0xFF; i > 0; i--); // Time for flag to set } while ((IFG1 & OFIFG) == OFIFG); // OSCFault flag still set?

P2DIR |= 0X9F; // Port two I/O initialization P1DIR |= 0XFD; // Port one I/O initialization InitRFChip(); // Call the initialization function.

_EINT(); // Enable interrupts SendRfFrame(RFbuffer, strlen(RFbuffer), &ReturnCode); // Begin communniaction by sending an alert signal for(;;) Receive_from_Labview();

// Function to Receive the user command from LabVIEW

}

/******************************************************************* ** clock : Sub Routine to set the timimgs for communication ** ******************************************************************** ** In : - ** ** Out : - ** *******************************************************************/ clock(void) {

95 WDTCTL = WDTPW +WDTHOLD; // Stop WDT BCSCTL1 = XT2OFF | RSEL2 | RSEL1 | RSEL0; // Set up clock sources DCOCTL = DCO0 | DCO1 | DCO2; // Set clock sources TACTL = TASSEL_2 | TACLR; // SMCLK, Clear Tar

CCR0 =390; // PWM Period CCTL0 = CCIE; // Set interrupt for counter P1DIR |= 0x0C; // P1.2 and P1.3 output IE1 |= P1IE; // Set Interrupt for Port 1 _EINT(); // P1IES |= 0X0C; TACTL |= MC0; // Start Timer_A in up mode }

/******************************************************************* ** Timer A Sub Routine : Sub Routine to set interrupts for Timer A * ******************************************************************** ** In : - ** ** Out : - ** *******************************************************************/

#pragma vector=TIMERA0_VECTOR __interrupt void Timer_A(void) { timer=1; // set timer value 1 CCTL0 &= 0; // Initialize counter to zero }

/******************************************************************* ** InitRFChip : Function to Initialize XE1201A ** ******************************************************************** ** In : - ** ** Out : - ** *******************************************************************/

void InitRFChip(void){ unsigned short i;

// Initializes XE1201 SrtInit(); for(i = 0; i < REG_C + 1; i++){ WriteRegister(i, RegistersCfg[i]); }

if((RegistersCfg[REG_A] & 0x003F) == RF_A_BAUDRATE_1200){ RFBaudrate = TX_BAUDRATE_GEN_1200; RFFrameTimeOut = RF_FRAME_TIMEOUT(1200); } else if((RegistersCfg[REG_A] & 0x003F) == RF_A_BAUDRATE_2400){ RFBaudrate = TX_BAUDRATE_GEN_2400;

96 RFFrameTimeOut = RF_FRAME_TIMEOUT(2400); } else if((RegistersCfg[REG_A] & 0x003F) == RF_A_BAUDRATE_4800){ RFBaudrate = TX_BAUDRATE_GEN_4800; RFFrameTimeOut = RF_FRAME_TIMEOUT(4800); } else if((RegistersCfg[REG_A] & 0x003F) == RF_A_BAUDRATE_9600){ RFBaudrate = TX_BAUDRATE_GEN_9600; RFFrameTimeOut = RF_FRAME_TIMEOUT(9600); } else if((RegistersCfg[REG_A] & 0x003F) == RF_A_BAUDRATE_19200){ RFBaudrate = TX_BAUDRATE_GEN_19200; RFFrameTimeOut = RF_FRAME_TIMEOUT(19200); } else if((RegistersCfg[REG_A] & 0x003F) == RF_A_BAUDRATE_38400){ RFBaudrate = TX_BAUDRATE_GEN_38400; RFFrameTimeOut = RF_FRAME_TIMEOUT(38400); } else if((RegistersCfg[REG_A] & 0x003F) == RF_A_BAUDRATE_57600){ RFBaudrate = TX_BAUDRATE_GEN_57600; RFFrameTimeOut = RF_FRAME_TIMEOUT(57600); } else { RFBaudrate = TX_BAUDRATE_GEN_1200; RFFrameTimeOut = RF_FRAME_TIMEOUT(1200); } SetRFMode(RF_SLEEP); } // void InitRFChip(void)

/******************************************************************* ** SetRFMode : Sets the XE1201 operating mode (Sleep, Receiver, ** ** Transmitter) ** ******************************************************************** ** In : mode ** ** Out : - ** *******************************************************************/ void SetRFMode(unsigned char mode){ if(mode != PreMode){ if((mode == RF_TRANSMITTER) && (PreMode == RF_SLEEP)){ PreMode = RF_TRANSMITTER; set_bit(P2OUT, EN); clear_bit(P2OUT, RXTX);

} if((mode == RF_TRANSMITTER) && (PreMode == RF_RECEIVER)){ PreMode = RF_TRANSMITTER; set_bit(P2OUT, EN); clear_bit(P2OUT, RXTX); // P1OUT |= 0X01;

// printf("Entered xmitter after receiver"); } else if((mode == RF_RECEIVER) && (PreMode == RF_SLEEP)){ PreMode = RF_RECEIVER; set_bit(P2OUT, EN); set_bit(P2OUT, RXTX);

97 printf(" set");

} else if((mode == RF_RECEIVER) && (PreMode == RF_TRANSMITTER)){ PreMode = RF_RECEIVER; set_bit(P2OUT, EN); set_bit(P2OUT, RXTX);

// printf("Entered receiver after transmitter"); } else if(mode == RF_SLEEP){ PreMode = RF_SLEEP; clear_bit(P2OUT, EN); // printf("entered sleep mode"); } else{ PreMode = RF_SLEEP; clear_bit(P2OUT, EN); } } } // void SetRFMode(unsigned char mode)

/******************************************************************* ** WriteRegister : Writes the register value at the given address ** ** on the XE1201 ** ******************************************************************** ** In : address, value ** ** Out : - ** *******************************************************************/ void WriteRegister(unsigned char address, unsigned short value){ unsigned short bitCounter;

SrtInit(); clear_bit(P2OUT, DE); // Writes the Address for(bitCounter = 0x02; bitCounter != 0x00; bitCounter >>= 1){ if (address & bitCounter){ SrtSetSO(1);

} else{ SrtSetSO(0); } SrtSetSCK(1); SrtSetSCK(0); } // Writes the Data for(bitCounter = 0x2000; bitCounter != 0x00; bitCounter >>= 1){ if (value & bitCounter){ SrtSetSO(1); } else{ SrtSetSO(0); } SrtSetSCK(1); SrtSetSCK(0);

98 } set_bit(P2OUT, DE); SrtSetSCK(1); SrtSetSCK(0);

} // void WriteRegister(unsigned char address, unsigned short value)

/******************************************************************* ** SendRfFrame : Send a data packet to the transceiver ** ******************************************************************** ** In : data buffer, size of data in buffer, and errorcode ** ** Out : - ** *******************************************************************/ void SendRfFrame(unsigned char *buffer, unsigned char size, unsigned char *pReturnCode){ clear_bit(P2OUT, TXD); // Initialize the TXD pin SetRFMode(RF_TRANSMITTER); // Switch mode to transmitter set_bit(P2OUT,EN); // Enable XE1201A set_bit(P2OUT,DE); // Set XE1201A into data operations. RFState |= RF_BUSY; // Set RF state to “busy” RFState &= ~RF_STOP;

SendByte(0XAB); // Send a byte by encapsulating it in protocol to form a packet.

RFState |= RF_STOP; // RF state changed to “stop” RFState &= ~RF_TX_DONE; // Tranmission completion state *pReturnCode = OK; // Return code for successive transmission } // void SendRfFrame(unsigned char *buffer, unsigned char size, unsigned char *pReturnCode)

/******************************************************************* ** SendByte : Send a data of 8 bits to the transceiver LSB first ** ******************************************************************** ** In : b ** ** Out : - ** *******************************************************************/ void SendByte(unsigned char b){ unsigned char bitCounter; // bitcounter to select bit transmission unsigned int i,j; timer=0; // clock timer variable initialized to zero P2DIR |= 0x9F; i=0; j=0;

99

for(bitCounter = 0x01; bitCounter != 0x00; bitCounter <<= 1){ timer=0; clock(); while(!timer) { _NOP(); } if (b & bitCounter){ set_bit(P2OUT, TXD); // Set voltage level high } else{ clear_bit(P2OUT, TXD); // Set voltage level zero //printf("0"); }

} }// end of SendByte function

/******************************************************************* ** SendByte : Send a data of 8 bits to the transceiver LSB first ** ******************************************************************** ** In : b ** ** Out : - ** *******************************************************************/

Receive_from_Labview(void){ unsigned int b=0; unsigned int c=0; char t1,t2; int a=0; int i=0; double ans; int number=0; int idle = 0;

timer=0;

_EINT(); b&=0X00; while(!(P1IN & CRXD));

timer=0; clock(); while(!timer); if(!(P1IN & CRXD)) b |= 0X01;

timer=0; clock();

100 while(!timer);

if(!(P1IN & CRXD)) b |= 0X02;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) b |= 0X04;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) b |= 0X08;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) b |= 0X10;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) b |= 0X20;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) b |= 0X40;

timer=0; clock(); while(!timer);

101

if(!(P1IN & CRXD)) b |= 0X80; timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) b |= 0X100;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) b |= 0X200;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) b |= 0X400;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) b |= 0X800;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) b |= 0X1000;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) b |= 0X2000;

timer=0; clock();

102 while(!timer);

if(!(P1IN & CRXD)) b |= 0X4000;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) b |= 0X8000;

timer=0; clock(); while(!timer);

timer=0; clock(); while(!timer);

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) c |= 0X01;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) c |= 0X02;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) c |= 0X04;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) c |= 0X08;

103

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) c |= 0X10;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) c |= 0X20;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) c |= 0X40;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) c |= 0X80; timer=0; clock(); while(!timer);

timer=0; clock(); while(!timer);

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) c |= 0X100;

timer=0; clock(); while(!timer);

104 if(!(P1IN & CRXD)) c |= 0X200;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) c |= 0X400;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) c |= 0X800;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) c |= 0X1000;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) c |= 0X2000;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) c |= 0X4000;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) c |= 0X8000;

printf(" %c",b);

105 //printf("%c",c); for(i=1;i<9;i++) t1 = t1 | (b | 0X100*i); printf(" t1= %x",t1); ans= b*1; i=ans; //if(i>0) //printf(" %x",b); //printf("%x",c);

//if((b=='es'))//&&(c=='sn')) //ReceiveRfFrame(RFbuffer, (unsigned char*)&RFbufferSize, &ReturnCode); for(i=0;i<5;i++){ SendRfFrame(RFbuffer, strlen(RFbuffer), &ReturnCode); } //printf("sending"); //else //printf(" Bfor TS ");

set_bit (P2OUT, EN); set_bit (P2OUT, DE); set_bit (P2OUT, RXTX); }

/******************************************************************* ** ReceiveRfFrame : Receive a data packet from the transceiver ** ******************************************************************** ** In : data buffer, size of data in buffer, and errorcode ** ** Out : - ** *******************************************************************/ void ReceiveRfFrame(unsigned char *buffer, unsigned char *size, unsigned char *pReturnCode){

char b=0; char c=0; unsigned int i; unsigned int num=0;

P2OUT &= 0X00; P1OUT &= 0X00;

SetRFMode(RF_RECEIVER); // Set XE1201A into reception set_bit (P2OUT, EN); // Enable XE1201A set_bit (P2OUT, DE); // Enable data set_bit (P2OUT, RXTX); // Set transceiver into reception //printf("set!"); IE1 |= P2IE; // Enable Port 2 Interrupts IE2 |= P1IE; // Enable Port 1 Interrupts _EINT(); // Enable interrupts P2IES |= 0X00; // Select pins for Port 2 Interrupt /*Enable events (timeout) "CONTAINS COUNTERS SET UP FOR MSB AND LSB" */ P1IES |= 0X02; // Select pins for Port 1 Interrupt

106 P2IFG &= 0X00; // Initialize Port 2 flags P1IFG &= 0X00; // Initialize Port 1 flags b&=0X00; // Initialize input buffer to zero while(!(P1IN & CRXD)); // Wait to detect data on Port 1

P1IFG &= 0X00; // Initialize Port 1 flags to zero while(!(P2IFG & CLKD)); // Wait for next clock pulse P2IFG &= 0X00; // Initialize Port 1 flags to zero while(!(P2IFG & CLKD)); // Wait for next clock pulse

P2IFG &= 0X00; // Initialize Port 1 flags to zero while(!(P2IFG & CLKD)); // Wait for next clock pulse

/* Inverse logic for Serial COM Port communication, if high voltage seen on the input pin, a low is considered */ if(!(P1IN & CRXD)) b|=0X01; //bit0

P2IFG &= 0X00; while(!(P2IFG & CLKD)); if(!(P1IN & CRXD)) b|=0X02; //bit1

P2IFG &= 0X00; while(!(P2IFG & CLKD)); if(!(P1IN & CRXD)) b|=0X04; //bit2

P2IFG &= 0X00; while(!(P2IFG & CLKD)); if(!(P1IN & CRXD)) b|=0X008; //bit3

P2IFG &= 0X00; while(!(P2IFG & CLKD)); if(!(P1IN & CRXD)) b|=0X10; //bit4

P2IFG &= 0X00; while(!(P2IFG & CLKD)); if(!(P1IN & CRXD)) b|=0X20; //bit5

P2IFG &= 0X00; while(!(P2IFG & CLKD));

107 if(!(P1IN & CRXD)) b|=0X40; //bit6

P2IFG &= 0X00; while(!(P2IFG & CLKD)); if(!(P1IN & CRXD)) b|=0X80; //bit7

/* Send no data for three packets duration to distinguish between characters */

P2IFG &= 0X00; do{ _NOP(); }while(!(P2IFG & CLKD));

P2IFG &= 0X00; do{ _NOP(); }while(!(P2IFG & CLKD));

P2IFG &= 0X00; do{ _NOP(); }while(!(P2IFG & CLKD)); // Delay ends here

/* Receive next character and store it in buffer c */ if(!(P1IN & CRXD)) c|=0X01; //bit0

P2IFG &= 0X00; do{ _NOP(); }while(!(P2IFG & CLKD)); if(!(P1IN & CRXD)) c|=0X02; //bit1

P2IFG &= 0X00; while(!(P2IFG & CLKD)); if(!(P1IN & CRXD)) c|=0X04; //bit2

P2IFG &= 0X00; while(!(P2IFG & CLKD)); if(!(P1IN & CRXD)) c|=0X008; //bit3

P2IFG &= 0X00; while(!(P2IFG & CLKD));

108 if(!(P1IN & CRXD)) c|=0X10; //bit4

P2IFG &= 0X00; while(!(P2IFG & CLKD));

if(!(P1IN & CRXD)) c|=0X20; //bit5

P2IFG &= 0X00; while(!(P2IFG & CLKD));

if(!(P1IN & CRXD)) c|=0X40; //bit6

P2IFG &= 0X00; while(!(P2IFG & CLKD));

if(!(P1IN & CRXD)) c|=0X80; //bit7

// check for errors and correct the data received if((c&0X80)&&(!(c&0X40))){ c<<=1; //printf(" cn= %x ",c); }

if((c&0X80)&&(c&0X40)){ c>>=1; }

// printf("b=%c",b); // printf(" %c ",c);

for(i=0;i<640;i++){ timer=0; clock(); while(!timer); }

set_bit(P1OUT,CTXD); timer=0; clock(); while(!timer); a3=b&0XFF; //lsb // printf("a3=%x ",a3); a2=b&0XFF00; a2>>=8; a4=a2&0XFF;

// printf("a4=%x ",a4); Labview(a4);

////////////////////////c-s-c/////// clear_bit(P1OUT,CTXD); timer=0;

109 clock(); while(!timer); set_bit(P1OUT,CTXD); timer=0; clock(); while(!timer);

Labview(a3); clear_bit(P1OUT,CTXD); timer=0; clock(); while(!timer);

/* set_bit(P1OUT,CTXD); timer=0; clock(); while(!timer);

Labview(o3); clear_bit(P1OUT,CTXD); timer=0; clock(); while(!timer); set_bit(P1OUT,CTXD); timer=0; clock(); while(!timer);

Labview(o4); clear_bit(P1OUT,CTXD); timer=0; clock(); while(!timer); set_bit(P1OUT,CTXD); timer=0; clock(); while(!timer);

Labview(o5); clear_bit(P1OUT,CTXD); timer=0; clock(); while(!timer);*/ //} ///////////////////////} b=0X00;

return; } // void ReceiveRfFrame(unsigned char *buffer, unsigned char size, unsigned char *pReturnCode)

110 void Labview(unsigned int b){ unsigned char bitCounter; unsigned int i,j; char a; unsigned int cycles=0; //printf("lab"); timer=0; P1DIR |= 0XFD; i=0; j=0;

//printf("b=%x ",b); cycles =(32768/2400); timer=0; for(bitCounter = 0x01; bitCounter != 0x00; bitCounter <<= 1){

if (b & bitCounter){ clear_bit(P1OUT, CTXD); } else{ set_bit(P1OUT, CTXD); // printf("0"); } timer=0; clock(); while(!timer) { _NOP(); }

} }

111 7.5 Analog to Digital conversion module code //********************************************************************* ********* //Analog to Digital conversion module code //********************************************************************* *********

#include "msp430x14x.h" // Standard Equations void main(void) { volatile int a1; volatile int a2; volatile int a3; volatile int a4; volatile int a5;

WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer P6SEL |= ( BIT0 | BIT1 | BIT2 ); P6DIR &= ~( BIT0 | BIT1 | BIT2 ); ADC12CTL0 = ADC12ON | REFON | REF2_5V | SHT0_2; ADC12MCTL0 = INCH_0 | SREF_1; ADC12MCTL1 = INCH_1 | SREF_1; ADC12MCTL2 = INCH_2 | SREF_1; ADC12CTL1 = SHP | ADC12SSEL_2 | CONSEQ_1; ADC12IE = 0; ADC12CTL0 |= ENC; // Enable conversions ADC12IE = 0; while (1) { ADC12CTL0 |= MSC | ADC12SC | ENC; // May need to add delay here for weaker input signals //delay(1000); // Sampling closed, start conversion ADC12CTL0 &= ~ADC12SC;

adc_start(); a1=ADC12MEM0; a2 = ADC12MEM1; a3 = ADC12MEM2; printf(" %x",a1); } }

/* * adc_start() - begin A/D conversion * Cannot start conversion(s) without ENC=1 !!! */ adc_start(void) { // Enable ADC ADC12CTL0 |= MSC | ADC12SC | ENC; // May need to add delay here for weaker input signals // Sampling closed, start conversion ADC12CTL0 &= ~ADC12SC; }

112

/* * adc_read() - Reads A/D value from A/D input */ unsigned int adc_read(int channel) { int result[5];

// ADC12BUSY? while (ADC12CTL1 & ADC12BUSY); switch(channel) { case 0: result[0] = ADC12MEM0; break; case 1: result[1] = ADC12MEM1; break; case 2: result[2] = ADC12MEM2; break; case 3: result[3] = ADC12MEM3; break; case 4: result[4] = ADC12MEM4; break;

} return *result; }

113 7.6 Temperature sensor data communication code

/********************************************************************** ************************************ // Temperature sensor data communication code *********************************************************************** ***********************************/

#include #include "string.h" #include "stdlib.h" #include "XE1201Driver.h" #include

#define sensor_output 0X02 #define SC 0X01 #define CTXD 0x01 //* In * Out * P1.0 #define CRXD 0x02 //* In * Out * P1.1

#define FALSE 0 #define TRUE 1 static unsigned int inner_count=0; volatile unsigned char send; static unsigned int outer_count=0; static unsigned int icount=0; unsigned int data_buffer[200] = {0}; volatile int timer = 0; static unsigned int error=0; unsigned int no_of_packets=0; unsigned char ReturnCode = -1; static unsigned char RFState = RF_STOP; // RF state machine static unsigned char *pRFFrame; // Pointer to the RF frame static unsigned char RFFramePos; // RF frame current position static unsigned char RFFrameSize; // RF frame size static unsigned short ByteCounter = 0; // RF frame byte counter static unsigned char PreMode = RF_SLEEP; // Previous chip operating mode volatile unsigned char EnableSyncByte = TRUE; // Enables/disables the synchronization byte reception/transmission static unsigned char SyncByte; // RF synchronization byte counter static unsigned char PatternSize = 4; // Size of pattern detection static unsigned char StartByte[4] = {0x69, 0x81, 0x7E, 0x96}; // Pattern detection values static unsigned long RFFrameTimeOut = RF_FRAME_TIMEOUT(1200);

114 // Reception counter value (full frame timeout generation) static unsigned long RFBaudrate = TX_BAUDRATE_GEN_1200; // Transmission counter value (baudrate generation)

static unsigned char RFbuffer[RF_BUFFER_SIZE]; // RF buffer volatile unsigned char RFbufferSize; // RF buffer size volatile unsigned char EnableMaster = TRUE; // Master/Slave selection volatile unsigned char SendNextPacket = TRUE; // Indicates when to send the next frame

// XE1201 configuration registers values : A = 6416, B = 4000 , C = B1A0 unsigned short RegistersCfg[] = { DEF_REG_A | RF_A_CTRL_MODE_PIN | RF_A_CLOCK_ENABLE_ON | RF_A_CHIP_ENABLE_OFF | RF_A_TRANSMITTER_MODE | RF_A_BIT_SYNC_ON | RF_A_BAUDRATE_9600, DEF_REG_B, DEF_REG_C | RF_C_POWER_P_5 | RF_C_INVERT_OFF | RF_C_TRANS_AMP_ON | RF_C_TRANS_DATA_BIT_0 | RF_C_FDEV_62 };

/******************************************************************* ** Configuration functions ** *******************************************************************/

void main(void) {

int i=0;

//MSP430 Initialization WDTCTL = WDTPW + WDTHOLD; // Stop WDT BCSCTL1 = XT2OFF | RSEL2 | RSEL1 | RSEL0 ; //| DIVS_3 | FN5; BCSCTL2 = 0x00; //BCSCTL2 |= SELM1+SELM0; // MCLK = LFXT1 (safe) do { DCOCTL = DCO0 | DCO1; IFG1 &= ~OFIFG; // Clear OSCFault flag for (i = 0xFF; i > 0; i--); // Time for flag to set } while ((IFG1 & OFIFG) == OFIFG); // OSCFault flag still set?

P2DIR |= 0X9F; P1DIR |= 0XFD; P3DIR |= 0XFD;

_EINT();

115 for(;;){ Receive_from_Labview(); }

}

/******************************************************************* ** clock : Sub Routine to set the timimgs for communication ** ******************************************************************** ** In : - ** ** Out : - ** *******************************************************************/ clock(void) { WDTCTL = WDTPW +WDTHOLD; // Stop WDT BCSCTL1 = XT2OFF | RSEL2 | RSEL1 | RSEL0; // Set up clock sources DCOCTL = DCO0 | DCO1 | DCO2; // Set clock sources TACTL = TASSEL_2 | TACLR; // SMCLK, Clear Tar

CCR0 =390; // PWM Period CCTL0 = CCIE; // Set interrupt for counter P1DIR |= 0x0C; // P1.2 and P1.3 output IE1 |= P1IE; // Set Interrupt for Port 1 _EINT(); // P1IES |= 0X0C; TACTL |= MC0; // Start Timer_A in up mode }

/******************************************************************* ** Timer A Sub Routine : Sub Routine to set interrupts for Timer A * ******************************************************************** ** In : - ** ** Out : - ** *******************************************************************/

#pragma vector=TIMERA0_VECTOR __interrupt void Timer_A(void) { timer=1; // set timer value 1 CCTL0 &= 0; // Initialize counter to zero }

/******************************************************************* ** ReceiveRfFrame : Receive a data packet from the transceiver ** ******************************************************************** ** In : data buffer, size of data in buffer, and errorcode ** ** Out : - ** *******************************************************************/ void ReceiveRfFrame(unsigned char *buffer, unsigned char *size, unsigned char *pReturnCode){

116 unsigned int b=0; int a=0; int i=0; double ans; int number=0; int idle = 0;

P3OUT &= 0X00; //bits = 0; set_bit (P2OUT, EN); set_bit (P2OUT, DE); set_bit (P2OUT, RXTX); timer=0; IE1 |= P2IE; _EINT(); P2IES |= 0X60; // Enable events (timeout) "CONTAINS COUNTERS SET UP FOR MSB AND LSB"

b&=0X00; set_bit(P3OUT, SC); timer=0; clock(); while(!timer); clear_bit(P3OUT, SC); if(P3IN & sensor_output) b |= 0X8000;

timer=0; clock(); while(!timer); set_bit(P3OUT, SC); timer=0; clock(); while(!timer); clear_bit(P3OUT, SC);

if(P3IN & sensor_output) b |= 0X4000;

timer=0; clock(); while(!timer); set_bit(P3OUT, SC); timer=0; clock(); while(!timer); clear_bit(P3OUT, SC);

if(P3IN & sensor_output) b |= 0X2000;

117

timer=0; clock(); while(!timer); set_bit(P3OUT, SC); timer=0; clock(); while(!timer); clear_bit(P3OUT, SC); if(P3IN & sensor_output) b |= 0X1000;

timer=0; clock(); while(!timer); set_bit(P3OUT, SC); timer=0; clock(); while(!timer); clear_bit(P3OUT, SC); if(P3IN & sensor_output) b |= 0X800;

timer=0; clock(); while(!timer); set_bit(P3OUT, SC); timer=0; clock(); while(!timer); clear_bit(P3OUT, SC); if(P3IN & sensor_output) b |= 0X400;

timer=0; clock(); while(!timer); set_bit(P3OUT, SC); timer=0; clock(); while(!timer); clear_bit(P3OUT, SC);

if(P3IN & sensor_output) b |= 0X200;

timer=0; clock();

118 while(!timer); set_bit(P3OUT, SC); timer=0; clock(); while(!timer); clear_bit(P3OUT, SC);

if(P3IN & sensor_output) b |= 0X100;

timer=0; clock(); while(!timer); set_bit(P3OUT, SC); timer=0; clock(); while(!timer); clear_bit(P3OUT, SC);

if(P3IN & sensor_output) b |= 0X80;

timer=0; clock(); while(!timer); set_bit(P3OUT, SC); timer=0; clock(); while(!timer); clear_bit(P3OUT, SC); if(P3IN & sensor_output) b |= 0X40;

timer=0; clock(); while(!timer); set_bit(P3OUT, SC); timer=0; clock(); while(!timer); clear_bit(P3OUT, SC);

if(P3IN & sensor_output) b |= 0X20;

timer=0; clock(); while(!timer); set_bit(P3OUT, SC); timer=0; clock(); while(!timer);

119 clear_bit(P3OUT, SC); if(P3IN & sensor_output) b |= 0X10;

timer=0; clock(); while(!timer); set_bit(P3OUT, SC); timer=0; clock(); while(!timer); clear_bit(P3OUT, SC); if(P3IN & sensor_output) b |= 0X08;

timer=0; clock(); while(!timer); set_bit(P3OUT, SC); timer=0; clock(); while(!timer); clear_bit(P3OUT, SC); if(P3IN & sensor_output) b |= 0X04; timer=0; clock(); while(!timer); set_bit(P3OUT, SC); timer=0; clock(); while(!timer); clear_bit(P3OUT, SC); if(P3IN & sensor_output) b |= 0X02; timer=0; clock(); while(!timer); set_bit(P3OUT, SC); timer=0; clock(); while(!timer); clear_bit(P3OUT, SC); if(P3IN & sensor_output) b |= 0X01;

120

timer=0; clock(); while(!timer); /**************************************************** write code to extract the first 2 LSBs and recalculate the temperature.

*****************************************************/ //b>>=1; //printf(" %x", b); b &= 0XFFFC; b>>=3; //printf(" %d", b); ans= b*0.03125; i=ans; if(i>0) printf(" %d ",i); //ans=26; send=b; set_bit(P1OUT,CTXD); timer=0; clock(); while(!timer); Labview(send);

////////////////////////c-s-c/////// clear_bit(P1OUT,CTXD); timer=0; clock(); while(!timer); set_bit(P1OUT,CTXD); timer=0; clock(); while(!timer);

Labview(send); clear_bit(P1OUT,CTXD); timer=0; clock(); while(!timer);

//printf("%d ",ans); set_bit (P2OUT, EN); set_bit (P2OUT, DE); set_bit (P2OUT, RXTX); }

Receive_from_Labview(void){ unsigned int b=0; unsigned int c=0; int a=0; int i=0; double ans; int number=0;

121 int idle = 0;

timer=0;

_EINT(); b&=0X00;

while(!(P1IN & CRXD)); timer=0; clock(); while(!timer); if(!(P1IN & CRXD)) b |= 0X01;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) b |= 0X02;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) b |= 0X04;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) b |= 0X08; timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) b |= 0X10;

timer=0; clock();

122 while(!timer);

if(!(P1IN & CRXD)) b |= 0X20;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) b |= 0X40;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) b |= 0X80;

timer=0; clock(); while(!timer);

timer=0; clock(); while(!timer);

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) b |= 0X100;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) b |= 0X200;

timer=0; clock(); while(!timer);

123

if(!(P1IN & CRXD)) b |= 0X400; timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) b |= 0X800;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) b |= 0X1000;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) b |= 0X2000; timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) b |= 0X4000; timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) b |= 0X8000;

timer=0; clock(); while(!timer);

124 timer=0; clock(); while(!timer);

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) c |= 0X01;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) c |= 0X02;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) c |= 0X04;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) c |= 0X08;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) c |= 0X10;

timer=0; clock(); while(!timer);

125

if(!(P1IN & CRXD)) c |= 0X20; timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) c |= 0X40; timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) c |= 0X80;

timer=0; clock(); while(!timer); timer=0; clock(); while(!timer); timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) c |= 0X100;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) c |= 0X200;

timer=0; clock();

126 while(!timer);

if(!(P1IN & CRXD)) c |= 0X400;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) c |= 0X800;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) c |= 0X1000;

timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) c |= 0X2000; timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) c |= 0X4000; timer=0; clock(); while(!timer);

if(!(P1IN & CRXD)) c |= 0X8000;

127 ans= b*1; i=ans; if(i>0) printf(" %x",b); printf("%x",c);

if((b=='es')&&(c=='sn')) ReceiveRfFrame(RFbuffer, (unsigned char*)&RFbufferSize, &ReturnCode); else printf(" Bfor TS ");

set_bit (P2OUT, EN); set_bit (P2OUT, DE); set_bit (P2OUT, RXTX); }

void Labview(unsigned char b){ unsigned char bitCounter; unsigned int i,j; char a; unsigned int cycles=0; timer=0; P1DIR |= 0XFD; i=0; j=0; //printf("b=%x %x ",b,send); cycles =(32768/2400); timer=0; for(bitCounter = 0x01; bitCounter != 0x00; bitCounter <<= 1){

if (b & bitCounter){ clear_bit(P1OUT, CTXD); } else{ set_bit(P1OUT, CTXD); // printf("0"); } timer=0; clock(); while(!timer) { _NOP(); } }

} // void Sendbyte(unsigned char b)

128

7.7 LabVIEW program logic/diagram