PC – BASED OSCILLOSCOPE USING MSP430 by Joemmer T. Antonio A Design Report Submitted to the School of Electrical Engineering, Electronics Engineering, and Computer Engineering in Partial Fulfillment of the Requirements for the Degree Bachelor of Science in Computer Engineering Mapua Institute of Technology August 2011 Approval Sheet Mapua Institute of Technology School of EECE This is to certify that we have supervised the preparation of and read the design report prepared by Joemmer T. Antonio entitled PC-Based Oscilloscope using MSP430 and that the said report has been submitted for final examination by the Oral Examination Committee. ___________________ Wei-Chih Hu, Ph.D. Design Adviser As members of the Oral Examination Committee, we certify that we have examined this design report, presented before the committee on September 5, 2011, and hereby recommended that it be accepted in partial fulfilment of the requirements for the degree in Bachelor of Science in Computer Engineering. ____________________ Engr. Dionis Padilla Panel Member _____________________ Panel Member ________________________ Engr. Noel Linsangan Chairman This design report is hereby approved and accepted by the School of Electrical Engineering, Electronics Engineering, and Computer Engineering in partial fulfilment of the requirements for the degree in Bachelor of Science in Computer Engineering. ________________________ Felicito Caluyo, Ph.D. Dean, School of EECE ii TABLE OF CONTENTS TITLE PAGE…………………………………………………………………………………………………i APPROVAL SHEET……………………………………………………………………………………….ii TABLE OF CONTENTS………………………………………………………………………………….iii LIST OF TABLES…………………………………………………………………………………………iv LIST OF FIGURES…………………………………………………………………………….…….……v ABSTRACT………………………………………………………………………………….………..…...vi Chapter 1: DESIGN BACKGROUND AND INTRODUCTION………………………………..1 Background…………………………………………………………………...……….1 Statement of the Problem……………………………….………………….…...2 Objectives of the Design………………………….………………………….……3 Significance and Impact of the Design……………………………….………4 Scope and Delimitation………………………….…………………………………5 Definition of Terms………………………………………………………………….6 Chapter 2: REVIEW OF RELATED DESIGN LITERATURE AND STUDIES...............9 Chapter 3: DESIGN PROCEDURES..................................................................15 Chapter 4: TESTING, PRESENTATION, AND INTERPRETATION OF DATA..........33 Chapter 5: CONCLUSION AND RECOMMENDATION.........................................38 Conclusion...............................................................................38 Recommendation.....................................................................39 REFERENCES….………………………………………………………………….……………………..40 APPENDIX………………………………………………………………………….……………………..41 Appendix A: Pictures of the Design……..…………………………………………….42 Appendix B: Program Listing…………………………………………………………….43 iii LIST OF TABLES Table 3.1: Voltage Division Circuit Data………..……………………………………………..22 Table 3.2: Voltage Off-Set Circuit Data………………………………………………………..23 Table 3.3: Voltage Division Circuit Connections and Registers………………………..30 Table 3.4: Voltage Off-Set Circuit Connections and Registers….……………………..31 LIST OF FIGURES Figure 3.1: Block Diagram of the PC-Based Oscilloscope using MSP430.…………15 Figure 3.2: Analog Front-End Circuit Input and Output Representation.…………19 Figure 3.3: Voltage Divider Formula…………………………………………………………..21 Figure 3.4: Voltage Off-Set Circuit Formula……………………………………………….…23 Figure 3.5: Voltage Off-Set Circuit Diagram………………………………………………….24 Figure 3.6: Analog Front-End Circuit Schematic Diagram……………………………….25 Figure 3.7: MSP430 Input and Output Representation…………………………………..27 Figure 3.8: PC Program Screenshot………………………..…………………………………..31 Figure 3.9: Data Transfer Flowchart of PC Program….…………………………………..32 Figure 4.1: Sinusoidal Wave Input, 10 Vpp at 10 Hz………………………………….....34 Figure 4.2: Sinusoidal Wave Input, 10 Vpp at 100 Hz………………………………......35 Figure 4.1: Sinusoidal Wave Input, 10 Vpp at 250 Hz………………..………………....36 Figure 4.1: Sinusoidal Wave Input, 10 Vpp at 500 Hz……………………….……….....36 Figure 4.1: Sinusoidal Wave Input, 10 Vpp at 1 KHz………………………………….....37 iv ABSTRACT An oscilloscope is an essential electronic measuring tool used for experimenting and data analysis on projects that involve visual representation of digital signals. The project, entitled „PC-based Oscilloscope using MSP430‟, is an adaptation of a digital oscilloscope using the combination of a personal computer and MSP430. It is developed to be able to provide a low-cost device that performs basic oscilloscope functions such as drawing the electrical signal in a voltage-against-time graph and digitally control the signal which would be very beneficial for small scale hobbyist, enthusiasts and students alike. The prototype is able to perform similar oscilloscope function using MSP430‟s analog-to-digital conversion capability. It is digitally controlled and display using a PC. It allows the user to observe electrical signals by displaying a graph of voltage against time on the PC. The input signal can be digitally controlled through a program in the PC. Keywords: Oscilloscope, PC, MSP430. v Chapter 1 DESIGN BACKGROUND AND INTRODUCTION This chapter discusses an overview of the design. This includes the purpose, objective, significance and scope of the design. Some technical terms that were used for the documentation were discussed at the end of this chapter. Background An Oscilloscope is a test/measuring instrument that is capable of displaying electrical signals by plotting them in a 2D plane using voltage-againsttime graph. It is one of the most essential digital devices that engineers, researchers and electronic enthusiast need in analyzing, testing and developing electronic devices. However, though an oscilloscope is a very useful and important tool, it is very expensive especially for small scale prototype developers such as students. And some full scale oscilloscopes that are available on the market have functions that small scale prototype makers like students don‟t need most of the time. The project, entitled „PC-based Oscilloscope using MSP430‟, is an adaptation of a digital oscilloscope using the combination of a personal computer and MSP430. It is developed to be able to provide a low-cost device that performs basic oscilloscope functions such as drawing the electrical signal in a voltage-against-time graph and digitally controlling the signal. These functions that the PC-based Oscilloscope has are those functions that most common 1 prototype maker needs. It performs real-time and is composed of three major parts, the Analog front-end circuit, the MSP430 and the PC. The prototype is able to perform similar oscilloscope function using the combination of MSP430‟s analog-to-digital conversion capability, the Analog Front-End Circuit‟s ability to control the input voltage and the PC‟s capability to visually display the output graph. It is digitally controlled and displayed using a PC. It allows the user to observe electrical signals by displaying a graph of voltage against time on the PC. The system is digitally controlled through the PC and is capable of adjusting incoming analog signal to achieve the desired visual output. Statement of the Problem An oscilloscope is an essential tool for electronic prototyping, research and data gathering. The majority of the oscilloscopes in the market are highly expensive and provides a very wide range of capability that most of the small scale prototype developer and students don‟t need anymore. Full-scale industry quality oscilloscope ranges from $1,500 to $3,000, a price that would be very unwise to spend if you would not be using its full capabilities. Undergraduate students of Dr.Hu, professor of the bio-signal processing laboratory where the internship of the designer was done, are in need of a simple personal signal analyser/oscilloscope that they could use for their class 2 whenever their professor asks them to analyze and test prototypes they make in their class at their own home. There is also a need for a logic signal analyzer/oscilloscope that students, developers and enthusiast can easily build on their own and be used for their school works and data gathering. It is not economically wise for students to purchase their own personal oscilloscope to suffice their need for a simple signal analyzer. Objective of the Design The main objective of the design is to be able to design and develop a practical, digitally-controlled, PC-based oscilloscope that performs the basic capability of a regular oscilloscope. By stating „practical‟, it should be able to provide the basic function of an oscilloscope which is to display the visual representation of an analog signal through the PC and be able to digitally-control the signal for adjustment, specifically through voltage division and voltage offset. Full-scale industry quality oscilloscope ranges from $1,500 to $3,000 (www.testequipmentdepot.com), a price that would be very unwise to spend if you would not be using its full capabilities. This design should be able to supply the need of Dr.Hu‟s undergraduate students for a simple logic signal analyser/oscilloscope that they could personally use and could be built on their own. The cost of the design should also be lower 3 than the market price of full scale oscilloscope otherwise it would not be beneficial for students. Significance and Impact of the Design The project will enable students, hobbyists and electronic enthusiasts to have their very own logic analyser/oscilloscope at a very low cost compared to the actual oscilloscope. It will enable them to see and analyse electrical signals using their personal computer. This shall provide people their own personal oscilloscopes that they could use at a fraction of the market cost of an oscilloscope. It shall also encourage more students and enthusiast to engage more in digital design and electronic prototyping with having their own personal oscilloscope. Small scale researches will also be able to perform various researches that need the use of an oscilloscope for data gathering. The design would allow small-scale electronics enthusiasts to be able to test electrical signals that are generated by their prototype without the expense of a full scale oscilloscope which is very expensive. Since it is part of the design objective to develop an oscilloscope where students, engineers, hobbyists and electronics enthusiasts can build on their own, it would create an inviting environment for those who are interested in the field of electronic prototyping to involve themselves to this field of engineering and science. 4 Scope and Delimitation Scopes: 1. The prototype is able to accept external analog input signal up to 20 Vpp. 2. It can plot any kind of waveform as long as it is within the boundary of 20 Vpp. 3. It is capable of adjusting the input signal through voltage division by the factors 20, 16, 10 and 6. 4. It is capable of off-setting the signal by .25 V, .50 V, .75 V and 1 V. 5. It displays the output waveform in the PC using a C++ based program written using Borland C++ Builder version 6. 6. It saves the incoming digital data from the MSP430 to a text file. Delimitations: 1. It is not capable of providing frequency measurement. 2. Does not provide industry quality precision. 3. Limited to only four options for voltage division and four options for voltage offset. 4. Can only accommodate one input signal at a time. 5. Can only handle a maximum of 20 Vpp at 1000 Hz. 5 Definition of Terms: 1. Oscilloscope - An electronic instrument that produces an instantaneous trace on the screen of a cathode-ray tube corresponding to oscillations of voltage and current. 2. PC (Personal Computer) - A computer built around a microprocessor for use by an individual. Personal computers have their own operating systems, software, and peripherals, and can generally be linked to networks. 3. MSP430 - A mixed-signal microcontroller family from Texas Instruments. Built around a 16-bit CPU, the MSP430 is designed for low cost, and specifically, low power consumption embedded applications. The architecture dates from the 1990s and is reminiscent of the DEC PDP-11. 4. Analog – Expressed by means of one or more physical properties that can express any value along a continuous scale. For example, the position of the hands of a clock is an analog representation of time 5. Digital - Expressed in discrete numerical form, especially for use by a computer or other electronic device 6. Microcontroller - (sometimes abbreviated µC, uC or MCU) A small computer on a single integrated circuit containing a processor core, memory, and programmable input/output peripherals. Microcontrollers are designed for embedded applications, in contrast to the microprocessors used in personal computers or other general purpose applications. 6 7. Multiplexer - A device that interleaves several activities; a switching device. (computing, telecommunications) A device that combines several input signals into a single output signal. 8. USB - Universal Serial Bus Type of serial bus that allows peripheral devices (disks, modems, printers, digitizers, data gloves, etc.) to be easily connected to a computer. A “plug-and-play” interface, it allows a device to be added without an adapter card and without rebooting the computer (the latter is known as hot-plugging). The USB standard, developed by several major computer and telecommunications companies, supports data-transfer speeds up to 12 megabits per second, multiple data streams, and up to 127 peripherals. 9. Operational Amplifier - Amplifier whose output voltage is proportional to the negative of its input voltage and that boosts the amplitude of an input signal many times, i.e., has a very high gain. It is usually connected so that part of the output is fed back to the input. Operational amplifiers were originally developed to be used in synthesizing mathematical operations in analog computers, hence their name. Because of recent advances in semiconductor technology, they have become available as integrated circuits. They are widely used when a closely controlled amount of gain or some form of signal processing is necessary in an electronic system. 7 Chapter 2 REVIEW OF RELATED DESIGN LITERATURES AND STUDIES This chapter includes the compiled research works and studies that are related to the design. The contents of this chapter are used as reference for the development of the design. The designer used the following related articles, research works and inventions as a reference which will aid in having an in-depth understanding about the design that the designer is working on. In the application report entitled, “Implementing IrDA with the MSP430”, by Melisa Nunez-Arzuaga and Andreas Dannenberg, it shows the capability of the MSP430 to provide a demonstration application for Windows-based PCs. In this report, an application was written on C programming language and shows an IrDA connection between a PC and the MSP430 IrDA stack by using standard Windows API calls only. The hardware design for this application focuses on the interfacing of the MSP430F149, the MSP430FG4619, and the MSP430F2274 with the SHARP GP2W0110YPSF IrDA transceiver device. Other MSP430 family members can be used as well, depending on the requirements of the end application. The SHARP GP2W0110YPSF was selected because it follows all ISO specifications stipulated for IrDA V1.0. The fact that this part can be used at a 3.0-V level is a benefit when interfacing with the MSP430, because no external circuitry is necessary to adapt the voltage levels. It also needs only three signals for interfacing with the 8 microcontroller: transmit, receive, and shutdown. This leaves most of the MCU pins free for other purposes. This report also states the usage of an external circuit connected to the MSP430 which validates the capability of the microcontroller to interact with other circuitry connected to it. The PC demonstration application supplied with this application report is provided as both C source code and as an executable single-file Win32 command line application. It has been decided to develop the software as a command line application to make it both easy to understand and also compatible with all common Windows-based C development systems such as Microsoft Visual C++ or Borland C++. The demonstration software requires at least Windows 2000 or Windows XP operating system and a properly installed infrared port. This IR port can either be integrated (such as those found in notebook computers) or provided by an external Windows-supported IrDA adaptor (for example, the Actisys ACTIR220L+). The current Windows operating systems come with a built-in IrDA stack that implements various IrDA communication modes, such as the 9-wire IrCOMM mode. This mode can easily interface with external devices like PDAs, cell-phones, and the presented MSP430 IrDA stack. Microsoft decided to expose the IrDA stack through the Windows sockets library rather than by providing virtual COM ports. If virtual COM ports need to be used, then additional thirdparty driver software such as IrCOMM2k is required. However, the more elegant 9 approach is to perform IrDA communication by using the standard Windows built-in driver model as shown in this demonstration application. Murugavel Raju wrote the application report classified under mixed signal processing entitled “Ultrasonic Distance Measurement with the MSP430”. This application report describes a distance-measuring system based on ultrasonic sound utilizing the MSP430F413 ultralow-power microcontroller. The system transmits a burst of ultrasonic sound waves towards the subject and then receives the corresponding echo. The MSP430 integrated analog comparator Comparator_A is used to detect the arrival of the echo to the system. The time taken for the ultrasonic burst to travel the distance from the system to the subject and back to the system is accurately measured by the MSP430. Assuming the speed of sound in air at room temperature to be 1100 ft/s, the MSP430 computes the distance between the system and the subject and displays it using a two-digit static LCD driven by its integrated LCD driver. The distance is displayed in inches with an accuracy of ±1 inch. The minimum distance that this system can measure is eight inches and is limited by the transmitter‟s transducer settling-time. The maximum distance that can be measured is 99 inches. The amplitude of the echo depends on the reflecting material, shape, and size. Sound-absorbing targets such as carpets and reflecting surfaces less than two square feet in area reflect poorly. The maximum measurable range is lower for such subjects. If the amplitude of the echo received by the system is so low that 10 it is not detectable by the Comparator_A, the system goes out of range. This is indicated by displaying the error message E. The devices used to transmit and receive the ultrasonic sound waves in this application are 40-kHz ceramic ultrasonic transducers. The MSP430 drives the transmitter transducer with a 12-cycle burst of 40-kHz square-wave signal derived from the crystal oscillator, and the receiver transducer receives the echo. The Timer_A in the MSP430 is configured to count the 40-kHz crystal frequency such that the time measurement resolution is 25 μs, which is more than adequate for this application. The measurement time base is very stable as it is derived from a quartz-crystal oscillator. The echo received by the receiver transducer is amplified by an operational amplifier and the amplified output is fed to the Comparator_A input. The Comparator_A senses the presence of the echo signal at its input and triggers a capture of Timer_A count value to capture compare register CCR1. The capture is done exactly at the instant the echo arrives at the system. The captured count is the measure of the time taken for the ultrasonic burst to travel the distance from the system to the subject and back to the system. The distance in inches from the system to the subject is computed by the MSP430 using this measured time and displayed on a two-digit static LCD. Immediately after updating the display, the MSP430 goes to LPM3 sleep mode to save power. The Basic Timer1 is programmed to interrupt the MSP430 every 205 milliseconds. The interrupt signal from the Basic Timer1 wakes up the MSP430 to repeat the measurement cycle and update the display. 11 In the application report written by Lutz Bierl entitled “MSP430 Universal Synchronous Asynchronous Receive/Transmit Communication Interface”, it gives a short overview for the use of the MSP430 universal synchronous, asynchronous receive/transmit communication interface (USART) as an RS232 interface, also called a serial-controller interface (SCI). Tested software examples, with and without the use of the interrupt capability, are given for the transmission and the reception of UART (universal asynchronous receive/transmit) signals. Full duplex mode is used for all examples running in active mode and low power mode 3 (LPM3). On the software simulation side, George P. Banky, a professor from Faculty of Engineering and Industrial Sciences, Swinburne University of Technology, Melbourne, Australia, wrote a paper entitled “Using circuit simulator software in the study of electronic circuit behaviour”. His paper reports on a pilot research project that investigated the use of a digital circuit simulation software, EasySim, in the study of digital electronics in the first year of an undergraduate engineering course. The ultimate aim of this research, completed in 2005, will be to investigate the student experience with such software and its effect on one of their study outcomes (that is their exam results). Students were encouraged to use the tool during their normal learning activities. Those who used the software found it to be helpful. Statistical analysis of exam results for the pilot group indicated a strong relationship between the exam marks obtained and the time spent using the software. 12 In his summary, he stated that even though the sample size of this pilot study was small and probably biased, in that only interested students responded to the survey, there is enough strong trending to suggest that within the small group of students those who used the software tool perceived a benefit to their study of digital electronics concepts. Also there was a strong trending between the times spent using EasySim and the exam results for the students who responded to the survey. Further for the whole subject group of students those who did well in the digital electronics exam question also did well in the rest of the exam paper. Since this relationship was also found for the responding group, it may be concluded that in answering the exam questions there is no benefit to the students who used the software simulator as a study aid. There is enough evidence to support further investigation by repeating this research in 2005, ideally using a more comprehensive simulation software tool, probably Electronic Workbench , with a larger participating group of students who will be using the software for a longer period of time (about 14 weeks) and more often (for assignments and laboratory preliminary submissions as well as for private study) in order to try to establish any statistical significance in the observed trends. 13 Chapter 3 DESIGN PROCEDURES This chapter discusses the procedures that were followed in the development of the experiment. This includes the Block Diagram, the Experiment‟s Flowchart and the discussion on how the Experiment was developed. Design’s General Block Diagram Analog Front-End Circuit MSP430 PC Figure 3.1 Block Diagram of the PC-Based Oscilloscope using MSP430 Figure 3.1 shows the basic block diagram of the design process. The project is composed of a three-part design process, the Analog Front-End Circuit, MSP430 and the Windows-PC Software. Each design stage is essential to the next because each stage requires the output from the adjacent stage to act as its input to be able to perform its function. The relationship of the three stages is show in Figure 3.1. 14 Each block represents a specific design process unique to the others, which will all be separately discussed later. Individual design block requires a different approach to the others and entails a different design approach. The first design block, named as “Analog Front-End Circuit”, is a circuit that is designed to act as the analog signal receiver of the circuit. This part involves pure hardware designing of circuit that is capable of limiting and adjusting the incoming analog signal that would be safe and usable for the next stage of the design, which is in the MSP430. This stage involves a combination of multiplexing the signal to which direction or path in needs to go to be able to perform the necessary adjustment the user intends to do. Each of these paths corresponds to a specific voltage division factor and voltage off-set. The second design block involves the designing of a program that shall be embedded in the MSP430 microcontroller. This program shall be able to perform various functions such as conversion of analog input to digital output, transmission of the digitized data to the PC through the USB and synchronization of the two. In this part, a program called „IAR Embedded Workbench‟ was used to write and to load the designed program to the MSP430. Pin configurations of registers and its purpose were one of the most critical parts of this design block. This design block plays the most important role in the whole design as it acts as the mediator for the two other design blocks. Both of the two design blocks (The Analog Front-End Circuit and the PC) is connected to this block and is constantly communicating to the two said blocks in a synchronous manner. The timing and 15 speed of transfer of data towards the PC is programmed and configured in this part of the design. Improper synchronization shall result into a distorted output waveform in the latter part of the project, which is in the displaying of the waveform done in the last part of the design. The MSP430 is placed on its builtin circuitry readily available in the laboratory. It is interfaced using a Serial-toUSB connection, which also comes along in the package of the said microcontroller. The program that was embedded in MSP430 is written in C programming language. The third design block involves the use of a personal computer using Windows operating system. This part of the design involves the output medium for the prototype. Using a previously designed program that enables the computer to capture and plot data that was received from the MSP430, the prototype is capable of displaying the output signal that was produced from the circuit by means of the window-type computer program that was part of this phase. One of the key factors in this part of the design is the assigning of values that needs to be passed through USB connection towards the MSP430 that shall act as the trigger on how much will the voltage division and the voltage offsetting should be done. For prototype purposes, voltage division and voltage offset options was limited to four choices only. Each choice was represented by a button in the program which triggers the program to send a byte towards the transmit part of the USB unto the MSP430, which uses that byte as a signal on to 16 which path should the signal flow. Further design process shall be discussed later. Part 1: Analog Front-End Circuit The first step in the whole design process is the designing of the analog circuit that will be able to reduce and adjust the input signal to its desired state. The MSP430 microcontroller is only capable of accepting input within the range of 0 to +3.0 volts. Besides the said limit, the MSP430 clips the signal off up to the said boundaries. To enable the project to be able to accept signal from +3.1 volts up to 20 volts, it requires an analog circuit that will adjust the incoming signal before it enters the MSP430. This requires the circuit needs to be able to perform voltage division and to off-set the signal up to the required range of 0 to +3 volts. A visual diagram that represents the ideal output of this circuit is shown in Figure 3.2. 17 Figure 3.2: Analog Front-End Circuit Input/Output Representation For prototyping purposes, the design was initially made to perform voltage division and voltage off-set with four options for both. Voltage Division can be done by factors of 20, 16, 10 and 6. Voltage off-set can be done by .25 v, .50 v, .75 v and 1 v. Choosing between these options can be done through the software that was developed on the stage-3 of the design, the Window-Type Program on the PC. The first design issue is on how the signal will be controlled under said voltage division and voltage off-set condition. In order to do so, an analog multiplexer/demultiplexer shall be used in order properly control where the signal should flow. This said multiplexer should also be able to be fully controllable by a digital signal that will be generated by the MSP430 that was triggered due to a control button in the window-type program. It has also been part of 18 consideration in this part of the design is the availability of the multiplexer that is capable of providing the needed functions. The use of the Analog Multiplexer/Demultiplexer (74HC4067) is fit for the requirement of the task it needs to fulfill. It has 15 readily available input/output ports and one common input/output. It is also controlled by 5-bit signal that can be generated through the MSP430. With the use of 74HC4067, it enables the circuit to be digitally controlled by the MSP430 through its four Select pins and one Enable pin. These pins (S0, S1, S2, S3, and E) receive logic signals that are generated by MSP430 through selection done in the PC. An Op-Amp (L234) was used to be able to implement voltage off-setting. The design requirement requires two set of input adjustment that needs to be done to the input signal, voltage division and voltage off-set. The first 4067 is used for selection on how much will the input signal be divided. Four channels were used to correspond for the division factors of 20, 16, 10 and 6. The second 4067 is used for selection on how much the reduced signal will be off-sat. Four channels were also used to correspond for the .25 v, .50 v, .75 volt and 1 volt off-set. Channel 8, 10, 11 and 12 were both used for the two 4067‟s corresponding to each of the division factor and the corresponding voltage offset. The first stage of the analog front-end circuit deals with the voltage division of the incoming input signal. Voltage division is necessary to be able to properly display the proper waveform of the input signal. The MSP430 can only 19 accept signal from 0 volt to +3 volts. The voltage division part of the design aims to reduce incoming signal to 1 Vpp, which is suitable for output display. Conventional voltage divider circuits were used in this part of the design. The 74HC4067 is capable of acting as either a multiplexer or a demultiplexer, the input signal was connected to the pin 1 of the IC, which was labelled as common input/output port. This part of the design requires an input coming from the MSP430 in the form of 4-bit data select and 1-bit enable. The input signal is generated in the MSP430 as digital signal which were connected to the pins 10, 11, 13 and 14 for the channel select and to pin 15 for the enable pin. Figure 3.3: Voltage Divider Circuit Since the prototype requires four voltage division factors, specifically 20, 16, 10 and 6, each of these factors corresponds to a channel that should provide 20 an output of 1 Vpp per channel. As expected, each channel should correspond to the amount of Vpp as input to be able to arise with at least 1 Vpp so the MSP430 can accept it. Computation for the values of each resistor is shown in table 3.1. Voltage Division Circuit Channel Division Factor Vin R1(Ohms) R2 (Ohms) Expected Vout I8 By 20 20 Vpp 19k 1k 1 Vpp I10 By 16 16 Vpp 15k 1k 1 Vpp I12 By 10 10 Vpp 9k 1k 1 Vpp I14 By 6 6 Vpp 5k 1k 1 Vpp Table 3.1: Voltage Division Circuit Values Table After the voltage division has been done, shown in figure 3.2, the expected output will pass below the 0 V boundary. This will produce clipping the voltage divided input signal again as the MSP430 can only accept incoming signal ranging from 0 volt to +3 volts. In order to remedy this problem, a digitally controllable voltage offsetting circuit was implemented. Using an op-amp voltage offset circuit, shown in figure 3.4, the designed was able to positively offset the signal by .25 volt, .50 volt, .75 volt and 1 volt. This was done by series of calculations using the formula shown in figure 3.4. 21 Figure 3.4: Voltage Off-Set Formula Using the formula shown in figure 3.4, specific values had been acquired, which is show in table 3.2 below. Voltage Off-Set Circuit Channel Offset Factor Gain R1 (Ohms) Expected Vout I8 .25 Volt 1 1k 1 Vpp I10 .50 Volt 1 1k 1 Vpp I12 .75 Volt 1 1k 1 Vpp I14 1 Volt 1 1k 1 Vpp Table 3.2: Voltage Off-Set Circuit Values Table The input voltage coming from the voltage division circuit is referred to as V1, while the V2 was acquired from a controlled DC source generated from the MSP430. Like what was done in the first multiplexer, channel was also selected by means of the digital signal coming from MSP430 towards the analog front-end circuit to act as a selector. Once the channel was selected, the selected DC signal 22 along with the output of the voltage divided signal passes through an op-amp to perform the offsetting of the signal, as shown in figure 3.5. Figure 3.5: Voltage Off-Set Circuit Diagram The final output signal that was generated through the analog front-end circuit was connected to the MSP430 as its primary input signal that will be processed. The final circuit design is shown in figure 3.6. 23 Figure 3.6: Analog Front-End Circuit Diagram 24 Part 2: MSP430 The second stage of the project involves the programming of MSP430 to enable it to work as the mediator between the Analog Front-End Circuit (Stage1) and the PC (Stage-3). The design uses a pre-designed MSP430 circuit board which was assembled and constructed. The pre-designed MSP430 circuit board also includes a serial-to-USB connector which makes it capable of being interfaced with a personal computer for embedding and burning purposes. The MSP430 incorporates a 16-bit RISC CPU, peripherals, and a flexible clock system that interconnect using a von-Neumann common memory address bus (MAB) and memory data bus (MDB). Partnering a modern CPU with modular memory-mapped analog and digital peripherals, the MSP430 offers solutions for demanding mixed-signal applications. It has embedded emulation capability. Dedicated embedded emulation logic resides on the device itself and is accessed via JTAG using no additional system resources. With this capability, unobtrusive development and debug with full-speed execution, breakpoints, and single-steps in an application are supported. The MSP430 needs to act as mediator between the Analog Front-End Circuit (Stage-1) and the PC (Stage-3). To be able to do so, certain information in various forms needs to be passed from one stage to the other, as shown in figure 3.7. 25 Analog Front-End Circuit INPUT: (From MSP430) > Logic Select signals for 4067 ( For pins S0, S1, S2, S3, E ) MSP430 PC (Window-Type Program) INPUT: (From MSP430) > Digitally Converted Signal (Through USB) ----------------------------------- ----------------------------------- OUTPUT: (To MSP430) OUTPUT: (To MSP430) >Adjusted Input ( After passing the Voltage Divider and Off-Set. ) >Select signal for 4067 ( As strings, Through USB ) Figure 3.7: MSP430 Input/Output Diagram Analyzing these set of requirements, it is very essential to understand the concepts of digital input/output, UART and ADC functions of the MSP430. Each of these three components plays a vital role so that the MSP430 can perform its needed operation. As shown in the diagram above, the MSP430 does most of the work in this project. It performs the two most important part of the project, The Analog-to-Digital conversion and the conversion of String Input from PC to logic signal for MSP430. MSP430 devices have up to six digital I/O ports implemented, P1 - P6. Each port has eight I/O pins. Every I/O pin is individually configurable for input or output direction, and each I/O line can be individually read or written to. Ports P1 and P2 have interrupt capability. Each Interrupt for the P1 and P2 I/O lines can be individually enabled and configured to provide an interrupt on a rising 26 edge or falling edge of an input signal. All P1 I/O lines source a single interrupt vector, and all P2 I/O lines source a different, single interrupt vector. The ADC12 module supports fast, 12-bit analog-to-digital conversions. The module implements a 12-bit SAR core, sample select control, reference generator and a 16-word conversion-and-control buffer. The conversion-andcontrol buffer allows up to 16 independent ADC samples to be converted and stored without any CPU intervention. The universal synchronous/asynchronous receive/transmit (USART) peripheral interface supports two serial modes with one hardware module. In asynchronous mode, the USART connects the MSP430 to an external system via two external pins, URXD and UTXD. UART mode is selected when the SYNC bit is cleared. Using the combination of these three elements of the MSP430, the design would be able to sustain the need of what it needs to perform. The selection for voltage division and voltage off-set is done in stage3(PC). In this process, the program on the Computer will send a data (represented as a string) to MSP430 through the USB using its UART function that will signal the MSP430 to what signals it needs to send to the analog frontend circuit. The signal exchange and equivalents were tabulated below for clearer representation. The output signal that is being generated by the front-end circuit undergoes analog-to-digital conversion through MSP430. The MSP430 is set at 27 Repeat-Single-Channel Mode. It uses MCLK (Master Clock) as its clock source, and is set to perform continuous conversion automatically as soon as the previous conversion is done (MSC). However, the built-in ADC clock divider is set to divide the clock by factor of eight. The converted signal is then passed to the PC through USB port using its UART capability. The data were sent as 8-bit data each sequence (CHAR). The UART is set at 8MHz (MCLK) at 115200 signals per second (Baud Rate). This process enables the analog electrical signal to be sent to the PC for visual representation. The MSP430 Circuit Board was powered by an AC Adapter. It supplies 3.3 V DC for the front-end circuit. A 3.3 V supply for the front-end circuit board was chosen to compensate for the 3.3 V logic signal that MSP430 outputs as high logic signal. The embedded programming was written in C language using IAR Workbench IDE and was downloaded and burned in the chip through MSP430 USB-Debug Interface (MSP-FET 430UIF). 28 PORT 2 4067 Channels P 2.0 P 2.1 P 2.2 P 2.3 P 2.4 P2OUT PC Input By 20 I8 0 0 0 0 1 0x10 a (0x63) By 16 I10 0 0 1 0 1 0x14 b (0x64) By 10 I12 0 0 0 1 1 0x18 By 6 I14 0 0 1 1 1 0x1C ENABLE S0 S1 S2 S3 c (0x65) d (0x66) Table 3.3: Voltage Division Connections and Registers Table 3.3, entitled Voltage Division Connections and Registers, shows the connections between the 4067 multiplexer to the MSP430. It also shows the relationship between the signal that is sent from the computer (PC Input) towards the MSP430. For example, as the PC sends out signal „a‟ (0x63), the MSP430 recognizes it as a „By 20 Voltage Division‟ and will be sending the signal 0x10 out through port 2. This event will then trigger the MSP430 to send out logic signals to its ports 2.0, 2.1, 2.2, 2.3 and 2.4. Ports 2.0, 2.1, 2.2, 2.3 and 2.4 are connected to 4067‟s ENABLE, S0, S1, S2 and S3, respectively. 29 PORT 1 4067 Channels P 1.0 P 1.1 P 1.2 P 1.3 P 1.4 P1OUT PC Input By .25v I8 0 0 0 0 1 0x10 a (0x63) By .50v I10 0 0 1 0 1 0x14 b (0x64) I12 0 0 0 1 1 0x18 I14 0 0 1 1 1 0x1C ENABLE S0 S1 S2 S3 By .75v By 1.0v c (0x65) d (0x66) Table 3.4: Voltage Off-Set Connections and Registers Like that of Table 3.3, Table 3.4, entitled Voltage Offset Connections and Registers, shows the connections between the second 4067 multiplexer to the MSP430 for its voltage off-Setting function. Like the voltage division part, this part of the design also uses the same principle and the same logic flow. It shows the relationship between the signal that is sent from the computer (PC Input) towards the MSP430. For example, as the PC sends out signal „a‟ (0x63), the MSP430 recognizes it as a „By 20 Voltage Division‟ and will be sending the signal 0x10 out through port 1. This event will then trigger the MSP430 to send out logic signals to its ports 1.0, 1.1, 1.2, 1.3 and 1.4. Ports 1.0, 1.1, 1.2, 1.3 and 1.4 are connected to 4067‟s ENABLE, S0, S1, S2 and S3, respectively. 30 PART 3: PC (Window-Type Program) The third part of the project involves the use of a personal computer as an input device for voltage division select and voltage off-set select and as an output device to display and plot the digitized analog input signal. Using a previously written program for ECG (BCB_ECG_0611_FINAL), the project used its capability to acquire and plot data that is being sent through the USB. Initialization in using the program includes the selection of COM port where the USB is connected, and a built-in filestream system that saves the digital signals that is being sent in the PC as a text file. Additional function was added to the said program to enable it to send data to the MSP430 through the USB. Refer to Table 1 and Table 2 for the respective data that was sent. The program was programmed using Borland C++ Builder 6. Figure 3.8: Window-type Program Screenshot 31 Figure 3.9: Data Transfer Flowchart of PC Program 32 Chapter 4 PRESENTATION AND INTERPRETATION OF DATA This chapter details the data and results from the experiment. The interpretation and explanation of different data and result are emphasized on this chapter. During the design process, each design stage conducted trials and simulations before the actual construction of the design. Each stage was separately verified to be able to establish its functionality. For the first part (Analog Front-End Circuit), simulations and testing were done using NI Multisim program. For the MSP430 program, simulation and debugging were done using the program IAR Embedded Workbench. After simulation and testing were done, the design was put to assembly. Each design stage was connected to the other as designed. Afterwards, testing and analysis were done. During this testing, the design was subjected under a 10 Vpp sinusoidal wave input at various input frequencies. The input signals show to be at 10 Vpp, which can be seen in the screenshot that follows. A small discrepancy in terms of the voltage amplitude can be observed, However, it is acceptable since the voltage visual waveform is very clear thus enabling it to perform as a logic signal analyzer. 33 For the initial testing, the design was subjected to a sinusoidal 10 Vpp input at 10 Hz. The output is shown in figure 4.1. At 8MHz (MCLK) at 115200 signals per second (Baud Rate) The only major concern in displaying the proper visual output is the frequency of the incoming signal if it can have a proper timing with the baud rate of the MSP430. Figure 4.1 : Sinusoidal Wave Input, 10 Vpp at 10 Hz As the figure 4.1 shows, the design was able to clearly plot and draw the input signal, which is a 10 Vpp sinusoidal waveform at 10 Hz. Having this result, the testing and analysis continues for the same input voltage and same waveform but under different frequency to determine the design‟s capability to respond to a faster input signal. 34 Several other frequencies were tried to be able to challenge the capability and the capacity of the 115200 baud rate if it would display the following frequencies with clarity. At figure 4.2, 4.3, 4.4 and 4.5, frequencies were set at 100 Hz, 250 Hz, 500 Hz and 100 Hz respectively. Figure 4.2: Sinusoidal Wave Input, 10 Vpp at 100 Hz Figure 4.2 shows, the design was still able to clearly plot and draw the input signal, which is a 10 Vpp sinusoidal waveform at 100 Hz. Comparing the visual representation of the same input waveform with a different frequency, this shows that the design can better visually represent the input waveform at 100 Hz. Having this result, the testing and analysis continue for the same input voltage and same waveform again but under different frequency to determine the design‟s capability to visually represent an input waveform. 35 Figure 4.3: Sinusoidal Wave Input, 10 Vpp at 250 Hz Figure 4.4: Sinusoidal Wave Input, 10 Vpp at 500 Hz As the figure 4.3 and figure 4.4 show, the design was still able to clearly plot and draw the input signal, which is a 10 Vpp sinusoidal waveform at 250 Hz 36 and a 10 Vpp sinusoidal waveform at 500 Hz, respectively. Figure 4.3 shows clear representation of the input waveform. Figure 4.4, however, can still show the waveform but it starting to look crowded and difficult to analyze compared to the previous input signals. Figure 4.5: Sinusoidal Wave Input, 10 Vpp at 1 KHz Analyzing these results, it shows that the design is able to clearly represent waveforms up to 1 KHz. And as the design shows its capability to plot a full sinusoidal wave, other wave shapes would eventually arrive with the same result. 37 Chapter 5 CONCLUSION AND RECOMMENDATION This chapter presents the conclusion of the experiment, as well as the recommendations for future researches in enhancing the experiment‟s capabilities. CONCLUSION The design prototype was able to perform visual representation of an analog electrical input signal by plotting it to a window-type program in computer. The analog electrical input signal can be digitally adjusted (i.e., voltage division and voltage off-set) through the PC program by sending data to the MSP430 which enables the MSP430 to provide specific logic signals for the analog front-end circuit. It can properly graph the sent data with clarity up to 1 KHz. The design could also plot and draw other types of waveform as long as it is bounded by the limit of the microcontroller. The design procedure in building the prototype is easy and can be done by everyone who has basic knowledge in electronics and C programming. The total design cost is very low comparing to today‟s market price of oscilloscopes and can be easily built by students and enthusiasts. 38 RECOMMENDATION The prototype shows that the project can still be developed and improved by implementing and employing other oscilloscope functions such as vertical and horizontal graph adjustment and measuring capability for frequency and other variables present in an electrical signal. As for this stage of the design, it can be used for personal use only and not for projects with a very strict precision need. It could also be further developed to use more than a single channel of input, maximizing the free registers of the system. 39 REFERENCES Harsha Rao (September 2004) , Implementing a Bidirectional Wireless UART Application With TRF6903 and MSP430 Andreas Dannenberg (October 2006) , MSP430 USB Connectivity Using TUSB3410 Steve Underwood (2006) , Capacitive Touch Sensing with MSP430 Melisa Nunez-Arzuaga and Andreas Dannenberg (June 2007) , Implementing IrDA With The MSP430 Murugavel Raju (October 2001) , Ultrasonic Distance Measurement With the MSP430 MSP430 IAR Embedded Workbench® IDE User Guide for Texas Instruments MSP430 Microcontroller Family, © Copyright 1996–2005 IAR Systems. George P. Banky (2005), Using Circuit Simulator Software In The Study Of Electronic Circuit Behaviour 40 APPENDICES 41 APPENDIX A. Pictures of the Design 42 APPENDIX B. Program Listing #include <msp430x14x.h> #define Num_of_Results 4 static unsigned int results1[Num_of_Results]; static unsigned int results2[Num_of_Results]; char temp; char voltdiv; char offset; void main(void) { volatile unsigned int i; WDTCTL = WDTPW+WDTHOLD; BCSCTL1 &= ~XT2OFF; do { IFG1 &= ~OFIFG; for (i = 0xFF; i > 0; i--); } while ((IFG1 & OFIFG)); BCSCTL2 |= SELM_2 + SELS; P5DIR |= BIT4; P6SEL |= 0x03; P3SEL |= 0x30; // Stop watchdog timer // XT2on // Clear OSCFault flag // Time for flag to set // OSCFault flag still set? // MCLK = SMCLK = XT2 (safe) //initialization - adc // Enable A/D channel inputs // P3.4,5 = USART0 TXD/RXD P1DIR |= 0x1F; P2DIR |= 0x1F; ADC12CTL0 = ADC12ON+MSC; // Turn on ADC12, set sampling time ADC12CTL1 = SHP+CONSEQ_3+ADC12SSEL_2+ADC12DIV_7; // Use sampling timer, single sequence ADC12MCTL0 = INCH_0; // ref+=AVcc, channel = A0 ADC12MCTL1 = INCH_1+EOS; // ref+=AVcc, channel = A1 ADC12IE = 0x03; ADC12CTL0 |= ENC; ADC12CTL0 |= ADC12SC; // Enable ADC12IFG.3 // Enable conversions // Start conversion 43 //uart part ME1 |= UTXE0 + URXE0; UCTL0 |= CHAR; UTCTL0 |= SSEL1; UBR00 = 0x45; UBR10 = 0x00; UMCTL0 = 0x00; UCTL0 &= ~SWRST; IE1 |= URXIE0; // Enable USART0 TXD/RXD // 8-bit character // UCLK = SMCLK // 8MHz 115200 // 8MHz 115200 // 8MHz 115200 modulation // Initialize USART state machine // Enable USART0 RX interrupt _EINT(); } //uart part while(1) { // while (!(IFG1 & UTXIFG0)); // TXBUF0=ADCMEM0; } // USART0 TX buffer ready? #pragma vector=ADC_VECTOR __interrupt void ADC12ISR (void) { static unsigned int index = 0; P5OUT ^= BIT4; //results1[index] = ADC12MEM0; //results2[index] = ADC12MEM1; //TXBUF0=ADC12MEM0>>4; //temp1=ADC12MEM1>>4; while (!(IFG1 & UTXIFG0)); TXBUF0=ADC12MEM0>>4; (index+1)%Num_of_Results; } #pragma vector=UART0RX_VECTOR __interrupt void usart0_rx (void) { while (!(IFG1 & UTXIFG0)); // Move results, IFG is cleared // Move results, IFG is cleared // USART0 TX buffer ready? //index = // USART0 TX buffer ready? // while(1) //{ 44 temp = RXBUF0; // RXBUF0 recieves data. if(temp==0x61 || temp==0x62 || temp==0x63 || temp==0x64) { voltdiv=temp; } else if(temp==0x65 || temp==0x66 || temp==0x67 || temp==0x68) { offset=temp; } if(voltdiv==0x61) { P2OUT = 0x10; } else if(voltdiv==0x62) { P2OUT = 0x14; } else if(voltdiv==0x63) { P2OUT = 0x18; } else if(voltdiv==0x64) { P2OUT = 0x1c; }; if(offset==0x65) { P1OUT = 0x10; } else if(offset==0x66) { P1OUT = 0x14; } else if(offset==0x67) { P1OUT = 0x18; } else if(offset==0x68) { 45 P1OUT = 0x1c; }; } 46