You are on page 1of 33

USB BASED OSCILLOSCOPE

A REPORT SUBMITTED TO

COMSATS INSTITUTE OF INFORMATION TECHNOLOGY

FOR THE DEGREE OF B.S COMPUTER ENGINEERING PROJECT ID: EE-11-029

June 2012

By Muhammad Junaid Khalid Muhammad Abbas Haider Asad Mehboob Awan Ammad Aslam

Electrical Engineering Department

Submission Form for Final-Year

F8
PROJECT ID TITLE

PROJECT REPORT
CIIT-WAH-EE-02-F8

EE-11-029
USB Based Oscilloscope

NUMBER OF MEMBERS

04

SUPERVISOR NAME

Muhammad Kamran Faiz


REG. NO. EMAIL ADDRESS

MEMBER NAME

Muhammad Junaid Khalid Muhammad Abbas Haider Asad Mahboob Awan Ammad Aslam

Fa08-bs(ce)-191 Fa08-bs(ce)-155 Fa08-bs(ce)-126 Fa08-bs(ce)-167

junaidkhalid2995@gmail.com abbashaider89@gmail.coma asad.awan19@gmail.com ammadaslam2009@gmail.com

CHECKLIST:
Number of pages attached with this form I/We have attached a complete Project Timeline YES / NO using the form CE-DP-35A I/We have enclosed the soft-copy of this document along-with the codes and scripts created by myself/ourselves My/Our supervisor has attested the attached document I/We confirm to state that this project is free from any type of plagiarism and misuse of copyrighted material
MEMBERS SIGNATURES

YES / NO YES / NO YES / NO

Supervisors Signature

Declaration
No portion of the work referred to in the dissertation has been submitted in support of an application for another degree or qualification of this or any other university/institute or other institution of learning.

MEMBERS SIGNATURES

Table of Contents
1 Introduction .......................................................................................................................................... 8 1.1 1.2 1.3 Motivations ................................................................................................................................... 8 Aims and objectives ...................................................................................................................... 8 About Oscilloscope ....................................................................................................................... 8 Oscilloscope Display .............................................................................................................. 8 Analyzing ............................................................................................................................... 8 Dual Channels ....................................................................................................................... 9 Reset Function ...................................................................................................................... 9

1.3.1 1.3.2 1.3.3 1.3.4 1.4 2

Description of Milestone............................................................................................................... 9

Background ......................................................................................................................................... 10 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 2.10 2.11 Signal .......................................................................................................................................... 10 Hand-drawn oscillograms ........................................................................................................... 10 Automatically paper-drawn oscillograph .................................................................................... 11 Photographic oscillograph .......................................................................................................... 11 Cathode ray tube ........................................................................................................................ 11 Digital Oscilloscope ..................................................................................................................... 11 Literature review......................................................................................................................... 12 Overview of USB ......................................................................................................................... 13 Layer ............................................................................................................................................ 13 Frames......................................................................................................................................... 14 Modes of data transmission ....................................................................................................... 14 Isochronous ......................................................................................................................... 14 Bulk...................................................................................................................................... 14 Structure of Bulk Transfer ................................................................................................... 14 Bulk Transfer Ends in Two Ways ......................................................................................... 15 Data Size in Bulk Transfers .................................................................................................. 15 Speed of Transfers .............................................................................................................. 15 Detecting and Handling errors ............................................................................................ 15 Interrupt .............................................................................................................................. 15

2.11.1 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8

5 2.11.9 2.12 2.13 Control ................................................................................................................................ 15

Enumeration ............................................................................................................................... 15 Universal Asynchronous Receiver/Transmitter .......................................................................... 16 Synchronous Communication Mode .................................................................................. 16 Asynchronous Communication Mode................................................................................ 16

2.13.1 2.13.2 2.14 3

How fast Data can send .............................................................................................................. 16

Design Specification and Platform Selection ...................................................................................... 18 3.1 Design overviews ........................................................................................................................ 18 USB Communicate With PC................................................................................................. 18

3.1.1 3.2

Design Specifications .................................................................................................................. 19 Inputs .................................................................................................................................. 19 PC Software ......................................................................................................................... 19 Mechanical Construction .................................................................................................... 19

3.2.1 3.2.2 3.2.3 3.3

Platform Selection....................................................................................................................... 19 Microcontroller Specifications ............................................................................................ 19

3.3.1 3.4 4

Software platform ....................................................................................................................... 20

Implementation and Testing ............................................................................................................... 21 4.1 4.2 4.3 Analysis of Electronic circuit for signal Acquisition..................................................................... 21 Microcontroller interfacing ......................................................................................................... 22 Development of window application .......................................................................................... 23 Opening Serial port ............................................................................................................. 24 Timeouts in Serial Communication ..................................................................................... 24

4.3.1 4.3.2 5 6 7

Results ................................................................................................................................................. 27 Observation......................................................................................................................................... 29 Conclusion and Future Work .............................................................................................................. 30 7.1 7.2 Conclusion ................................................................................................................................... 30 Future work ................................................................................................................................. 30

Appendix A: Schematic Diagrams ....................................................................................................... 31

References .................................................................................................................................................. 33

Acknowledgement
In the name of ALLAH almighty who is the creator of everything in the universe and helps us in every step of life and help us to do this project. We are also thankful to our parents for their support and prayers. We are especially grateful to Mr. Muhammad Kamran Fiaz for his valuable support and guidance during the entire work. We express our sincere thanks to Dr. Sajid Siraj for project concealing and outrageous ideas as a project coordinator who helped us to complete our team work. Last but not least we would to express our deep gratitude to all our fellows and friends especially Mr. Asif Rizwan whose valuable suggestions and support helped us to complete our project.

Abstract
Nowadays more and more experiments are now personal computer (PC) assisted. The data acquisition systems we are using today are very expensive like digital oscilloscope so to provide portability and to reduce the cost we are designing the Universal serial Bus (USB) based oscilloscope. To interface with the device and for graph display a Graphical User Interface (GUI) is designed that is Oscilloscope window application.

Chapter 1
1 Introduction

This chapter provides an introduction about an oscilloscope (Oscilloscope) and research carried out how to develop an USB based oscilloscope.

1.1

Motivations

Scientist and Engineers used oscilloscope to analyze behavior of signals, while using oscilloscope they feel comfortable to check their electronics circuits response easily. Oscilloscope is a device which plot graph of signal over time, its become useful for measuring modulated signals, frequencies, propagation delays, and signal rise and fall time. In analog or digital oscilloscopes the graph display is form when electron beam strikes the fluorescent display screen same as television screen displays. So to provide portability and to reduce the cost of oscilloscope we are designing an USB based oscilloscope

1.2

Aims and objectives

Our objective is to provides technology to student of universities for testing of their circuits they have their have oscilloscope instead of searching labs apparatus due to low in cost each student can buy his own. Traditional oscilloscope needs maintenance every year, our product doesnt need maintenance like that.

1.3
1.3.1

About Oscilloscope
Oscilloscope Display

After the initial introduction we are going to presents how oscilloscope displays graphs which are the settings behind it. After the power given to oscilloscope a horizontal line display if it is not at zero coordinates try to adjust it by varying knob position, if after these settings still you are unable to see the line increase brightness and sharp the line with the help of buttons. You can also change the vertical display settings.
1.3.2 Analyzing

After the display setting finally you are able to test your circuits, so build your circuit first give input signal with the help of function generator, select channel if function generator have more than one channel. Adjust amplitude and type of signal whether its sinusoidal, square or any other format and attach probes of oscilloscope around any component of circuit around which you want to check the behavior.

CHAPTER 1: INTRODUCTION

Press acquire button of oscilloscope that acquire samples automatically and set best display setting according to the waveform, if you want to still display a signal press the stop button it stop to acquire samples and continuously displays the same signal until the run button press. Oscilloscope displays straight line for DC and sinusoidal for AC1. By varying voltage per division (V/div) you can take the sensitive readings at several levels which provide accuracy this button provides variable gain, also by varying time division (time/div) you can vary the frequency of signal. In 1ms/div have period of AC is 1000 HZ, while change it to 1 us/div AC signal have 1000000 HZ oscillations2. Normal graph displays in time domain voltage signal plot against time voltage is an electrical force presents in the circuit that produce current when electron flow, it also displays in frequency domain you can check your signal behavior in frequency domain, recent digital oscilloscope contains Fast Fourier transform (FFT) and Discrete Cosine Transform (DCT) function, signal FFT or DCT is taken and signal display in that form but these are very expensive. Constant voltage also measured by digital multi meter (DMM) but in mostly cases circuits checked by varying voltages so oscilloscope shows these changing on screen.
1.3.3 Dual Channels

Oscilloscope has two or more input channel thats select by channel select button due to this fact an opportunity to analyze two or more signal behavior at same time or by select display channel button.
1.3.4 Reset Function

Reset function is used to reset acquire and display setting of oscilloscope. Reset function turns off the display of signal after it single line came on zero axes. After a brief intro of oscilloscope functions moving to our project, the basic motive for doing this project is to develop a product that become familiar in market in future and reduce the cost of oscilloscope make it flexible and portable. Oscilloscope is one of the most helpful instruments available for testing electronic circuits having ability to show the signals at different nodes or points in the circuits. This USB based oscilloscope meets the functionality of traditional oscilloscope. In this Programmable Intelligent Computer (PIC) microcontroller is used for converting input analog signal into digital then transfer these digital values towards COM port then a window application will display the signal waveform on GUI application.

1.4

Description of Milestone
Analysis of Electronic circuit for signal Acquisition Microcontroller (USB/Serial port) interfacing USB interfacing by using firmware Windows application development

10

Chapter 2
2
2.1

Background
Signal

Signals as referred in signal processing, communication systems, speech processing etc. It conveys information, shows behavior of functions or attributes of phenomenon. In real world any quantity exhibiting variation in time domain or space variation like in image, it provides information on the status of system. IEEE transactions on signal processing define the term of signal. The term signal includes audio, video, speech, image, communication, geophysical, sonar, radar, medical and musical signals Signals are very much used so it can be say that signals are building block of oscilloscope, coz oscilloscope used to analyze the signals. An oscilloscope called oscillograph previously, another version of oscilloscope is CRO and DSO used for viewing signals of variable voltages that plots time on X-axis and voltage on Yaxis. Sound signals converted into voltages and displayed on oscilloscope. Periodic signal repeat constantly after specific interval of time so multiples samples of signal acquires and displayed in steady form. Oscilloscope is usually calibrated so voltages over time can be read as is possible to view by human eye; this allows measuring of peak to peak voltages, frequency of periodic signals etc3. Oscilloscopes are used in different fields like medicine, engineering and science. These types of instruments are used for maintenance of electronic equipments. Specific purpose oscilloscopes are used in medicine field for analyzing heartbeat and to analyze behavior of automotive systems. In past CRO used for displaying the waveforms, as technology arrive CRT used in storage oscilloscope to store the waveform with fast analog to digital converters and signal processing. Here different types of previous oscilloscope are shown

2.2

Hand-drawn oscillograms

The earliest method of waveform for measuring voltage or current of spinning rotor was at specific points around axis of rotor was hectic and laborious with galvanometer no reading is taken out. After enhancement in the rotor, the waveform drawn on graph paper by noting angle of rotation and strength of meter at every position shown in figure 2-2.
Figure 2-2 Hand-Drawn Oscillogram

CHAPTER 2: BACKGROUND

11

Jules francois joubert was the first who introduced step by step method of wave measurement4.

2.3

Automatically paper-drawn oscillograph

An automated oscillograph used galvanometer for capturing waveforms, due to high frequency and speed of waveform when compared to slow reaction time the waveforms is not drawn correctly shown in figure 2-3. The device named Hospitalier ondograph was used for waveform measurement. This device charged capacitor automatically at hundredth wave; galvanometer uses the stored energy of capacitor during decaying process5.
Figure 2-3 Paper Drawn Oscillograph

2.4

Photographic oscillograph

It was necessary for the device photographic oscillograph to measure, direct measurement at enough speed and to use a very less mass measurement of system to compete the motion of concerned waves which are being measured. William Duddell had done this with the help of moving coil oscillograph, Figure 2-4 shows prototype of photographic oscillograph. This method give more accurate results than paper recorders but still improvement was there of images before they could be examined.
Figure 2-4 Photographic Oscillograph

2.5

Cathode ray tube


Cathode ray tube developed in late 19th century; at this stage CRT explore electrons.

Karl Ferdinand Braun was inventor of the CRT oscilloscope in 1897, by oscillating signal towards electrically charged deflector plates in a phosphor-coated CRT6.

2.6

Digital Oscilloscope

Walter LeCroy was invented Digital Storage Oscilloscope (DSO), after producing digitizers with high-speed for the research center CERN in Switzerland, LeCroy remains one of the three largest manufacturers of oscilloscopes in the world. This type of oscilloscope has

CHAPTER 2: BACKGROUND

12

many functions like FFT, frequency domain measurement, triangular form, square waveforms etc.

2.7

Literature review

Before doing anything you have to study its history, present and what future work can be done on it. As more and more achievement, publications and research work has been done in science and technology. Our task is to build a USB Based Oscilloscope for this purpose, we study some publications related to our project. To know about USB basics, inside USB, enumeration process, data transformation mode, how to host learn about devices, descriptors and the toolkits used for making general and custom drivers after doing many search at last but not least Mr. Ammad Aslam found USB complete 3rd edition by JAN AXELSON its a very interesting book to learn about USB, like its name USB complete. After studying about USB, next task is to select a microcontroller thats done everything we need our first search is stop to microchip DSPIC30F2020 it made for signal processing purpose but is does not contain built in USB port thats y we drop it. Our project coordinator Dr. Sajid Siraj suggest us to use a PIC18F4550 because it contains built in analog to digital converter (adc) and USB port so we decided to use it. To know about embedded systems a book studied named PIC microcontroller and embedded system by Mazidi and Real time embedded system course is studied. For sending data towards COM port by using USB, we studied many libraries made by CCS C compiler but the useful libraries for our desired work is CDC.H and USB.H, by using function of these libraries data is send towards COM port. For serial communication the material studied is rs232 and UART protocol 7, also studied about level conversion process which is done by using max232 from the text book PIC microcontroller and Embedded system by Muhammad Ali Mazidi8 and introduction to serial communication9. For designing GUI first decided to make it in visual c# but our project supervisor Mr. Kamran Fiaz suggested us to make it in visual C++ because its currently used in the market. For learning visual C++ we took some books10 of visual C++ from library and also start searching it on internet, we also studied some publish papers related to USB oscilloscope. In 2007 a Publication named Virtual Oscilloscope Based on USB has already been done and its published at eight international conferences on electric measurement and instruments. After this we move forward to study some embedded application based on PIC microcontroller. For data transferring purpose we use USB as host to communicating with PC1. Another IEEE publication studied named A low cost PC Based Virtual Oscilloscope the purpose of studying this research paper is to convert RS232 emulate over USB bus. This research paper includes parallel port use for the transfer of data.

CHAPTER 2: BACKGROUND

13

Another research paper of IEEE publication on 13th July 2008 namely A PC Based Real time Oscilloscope was also helpful for our project. This includes data transfer method PC to MC and a GUI interface for display of data.

2.8

Overview of USB

Because we are designing USB Oscilloscope firstly we study about PIC18F4550 USB. PIC18f4550 have compatibility of both low and full speed USB serial interface engine (SIE) which gives fast data rate between PIC microcontroller and USB host using built in transceiver which is connected with external transceiver to give power to the internal transceiver an internal 3.3v regulator available in 5v application. PIC184550 have dual port memory access to SIE and microcontroller11.

2.9

Layer

An USB specification is structured into layered frame work shown in Figure 2-9 endpoints, data moved to this level. Endpoint 0 must be control endpoint, when device connected to bus endpoint 0 configure the device12.
Device

Configuration

Interface

Interface

Endpoint

Endpoint

Endpoint

Endpoint

Endpoint

Figure 3-4 USB layer

CHAPTER 2: BACKGROUND 2.10 Frames

14

Communication on the bus is framed into 1 ms time slots. A frame contains transactions towards different devices and endpoints Figure 2-10 shows the example of transaction in frame (fig 17.9 data sheet 17.10.2).

Figure 3-5 USB Frames

2.11 Modes of data transmission


There are four modes of transmission of data Isochronous Bulk Interrupt Control

2.11.1 Isochronous

This type of transfer used for large amounts of data with time delivery sure and data integrity not ensured. This mode used in streaming applications where data loss in small amount is not critical such as audio video streaming13.
2.11.2 Bulk

This type of transfer used for large amounts of data. The main difference between isochronous and bulk transmission is, it ensured data integrity and timeliness is not ensured 14. We are using bulk transfer mode because in this data integrity is ensured.
2.11.3 Structure of Bulk Transfer

Bulk transfer consists of one or more in or out transactions, bulk tractions is like half duplex either all IN transactions or all OUT transactions. If transferring data in both directions so for this a separate pipe is used.

CHAPTER 2: BACKGROUND
2.11.4 Bulk Transfer Ends in Two Ways

15

When the expected amount of data has transferred When a transaction contains either zero data bytes or another number of bytes that is less than the endpoints maximum packet size USB protocol doesnt define the amount of data in bulk transformation mode, to specify this host can use class specific or vendor specific protocol. Transmission begins with a header file this header file specifies number of bytes that transferred or device or host specify amount of data. For bus time conserve the host use PING protocol in high speed bulk transfers. In bulk transfer when high speed device communicate with low speed or high speed device host use split transactions for transferring data15.
2.11.5 Data Size in Bulk Transfers

In bulk transfer maximum packet size of 8, 16, 32 or 64 bytes when operating in full speed mode it may be 512 bytes in high speed mode. In enumeration process host read maximum packet size for each bulk endpoint from device descriptor. Amount of data transfer may be less than, equal to or also may be greater than maximum packet. The data transactions are done in multiple transactions if data not fit in single packet16.
2.11.6 Speed of Transfers

There is not any dedicated bandwidth for bulk transfer but bulk transfers are completely eventually. When bus is idle bulk transfer use most of bandwidth so due to this specification bulk transfer is fastest17.
2.11.7 Detecting and Handling errors

Error detecting done in bulk transfers, if a device does not doing handshaking or receives NAK handshake so host sends data twice time. To ensure no data is lost data toggles are used. Full speed device support all transfer types and low speed device limited to interrupt and control.
2.11.8 Interrupt

This type of transfer ensured timeliness for small blocks of data also data integrity ensured.
2.11.9 Control

This type provides for device setup control18

2.12 Enumeration
When device attach to the bus after it host start enumeration process to start identify the device. Firstly host interrogates the device gathering information like power consumption, data size, descriptor and protocol19.

CHAPTER 2: BACKGROUND 2.13 Universal Asynchronous Receiver/Transmitter

16

A universal Asynchronous receiver/transmitter (UART) is the component of systems thats used for serial and parallel communication. A UART takes data from serial port and converted into sequential form; at receiving end another UART converts this sequential form to serial. In previous decades serial transmission is commonly used with help of modems for communication between computers without establishing networks. In UART both Asynchronous and synchronous transmission used but in our case Asynchronous transmission is used. A UART usually in form of integrated circuit used for serial communication over a PC or any other device contains serial port, now UART is commonly used in microcontroller to communicate with computer20 different protocols are used for the transmission of data and mostly are compatible with each other in this case RS-232 used21.
2.13.1 Synchronous Communication Mode

Synchronous communication require after each transformation an end bit is required that shows from one end data transfer complete other one should start conversation. In synchronous mode from both ends data cant send simultaneously from both ends22.
2.13.2 Asynchronous Communication Mode

Asynchronous term used where data can be intermittently transmitted instead of steady stream data transfer mode, like a telephonic conversation is asynchronous because both people can talk simultaneously and interrupted each other. In asynchronous communication no clock signal is transmitted with data, receiving end has its own way to time itself for able to receive incoming data. In rs232 these parameters are set before starting the transmission, transmitter end keep sending 1 when transmission line idle thats show link is up, sends 0 starting bit before each byte transmitted and stop it 1. In asynchronous data transfer mode receiver must distinguish between valid data and noise for this start bit and stop bit used. In rs232 asynchronous mode is used.

2.14 How fast Data can send


Speed of data transfer can be set in baud rate higher the baud rate higher the data sending rate that sets how many bits per second send. For example 1200 baud rate means 1200 bits sends per second In rs232 some standard speed of transmission 1200 2400 9600 38400 115200

CHAPTER 2: BACKGROUND
115200 is the highest baud rate for serial communication 9600 baud rate is used that means

17

1/9600= 0.104 ms if you transmit 8 bits of data the last one 8*0.104ms=0.832 ms, each byte requires starting and stop bit so actual speed is 10*0.104 ms= 1.04 ms So data rate is 1/time that is 1/1.04 ms = 0.96 Kbytes per second

On physical layer
1 is sent using -10v between -5V to -15V 0 is sent using 10v between 5V to 15V

18

Chapter 3
3
3.1
3.1.1

Design Specification and Platform Selection


Design overviews
USB Communicate With PC

PIC18F4550 Microcontroller
Analog Input Analog to Digital Converter USB port (D+ /D- pins)

Hardware Portion Software Portion

Personal Computer
Window Application Graphical User Interface Controls
Store Graph Display Visual C++ Communication Class Device Driver USB Port

Show

Controls

Virtual COM Port

CHAPTER 3: DESIGN SPECIFICATION AND PLATFORM SELECTION 3.2 Design Specifications

19

3.2.1 Inputs Number of channels: 1 Probe Connection: BNC Usable Probe type: Standard 1:1 probes 3.2.2 PC Software PC connection: USB 1.1 and 2.0 PC software: Windows 2000, XP (SP3) 3.2.3 Mechanical Construction Power supply: Trough USB (5V / 250mA) (No external Power source is required) Approx. size (in enclosure): 4.5 x 2.5 x 1.2 (114 mm x 66 mm x 31mm) Approx. Components used: 18

3.3
3.3.1

Platform Selection
Microcontroller Specifications

PIC is a family of Harvard architecture microcontrollers made by microchip technology derived from the PIC1640 originally developed by General instruments microelectronics division23. PIC stands for Programmable intelligent computer. PICs are popular due to its low cost, wide availability, extensive collection of application notes, free development tool, serial programming and built in USB. We chose PIC 18F4550 microcontroller by microchip technology because it contain 13 ADC channels, 32 Kbytes of flash memory and is compactable with C compiler optimized architecture. The Pin description of PIC18F4550 shown in Figure 2-1. It contains 10 bits built in ADC module with positive and negative voltage references. It also has a well-built USB 2.0 available for low speed (1.5Mb/s) and full speed (12Mb/s) and requires a low voltage supply24. To program the PIC microcontroller we are using MPLAB integrated Development Environment (IDE), it is a tool for the development of embedded applications 25. For doing this project we are using MPLAB IDE as a microcontroller programming apparatus for built execution file with extension of hex with the help of communicating driver class (CDC) and after it the hex file is loaded in PIC18F4550 with the help of USB boot loader 26. First we take two analog input signals at channel 1 (AN0) & channel 2 (AN1) then convert it to digital using PIC18F4550 ADC, after it digital value are stored in a integer type then

CHAPTER 3: DESIGN SPECIFICATION AND PLATFORM SELECTION

20

transmit these towards PC using USB, This process running continuously until next input signal detected.

3.4

Software platform

For designing GUI first decided to make it in visual C# but our project supervisor Mr. Kamran Fiaz suggested us to make it in visual C++ because its currently used in the market. For learning visual C++ we took some books27 of visual C++ from library and also start searching it on internet, we also studied some publish papers related to USB oscilloscope.

21

Chapter 4
4
4.1

Implementation and Testing


Analysis of Electronic circuit for signal Acquisition

Before doing analysis of signal acquisition firstly we make signal calibration circuit in which several operational amplifiers used to attenuate the signal and phase shift. The microcontroller Analog to digital converter (ADC) has fixed input voltage range from 0 5v. Signals smaller than this range having reduced resolutions and higher voltage signal get clipped. We need a circuitry that attenuate and amplify the input signal suitable for ADC (Figure 4-1)

Figure 4-1: Input Stage of Channel 1

CHAPTER 4: IMPLEMENTATION AND TESTING

22

After doing voltage divider then we applies superposition principle we calculate voltage or current across any resistor by adding all voltages and current source acting alone then all other independent source replace by short circuit and the entire individual currents source replaced by open circuit28. After it attenuated the input signal and biased to some extend DC level (0 5V) as requirement of ADC input.

4.2

Microcontroller interfacing

The Microcontroller built in ADC ranges from input range of 0 to 5v. This range is fixed or constant. Since the input signal that the scope is supposed to measure can span a wide range from quite small to quite large, input stage is used that can attenuate or amplify the input signal to make it useful for the ADC. The circuit first tested shown in figure 4-2 first circuitry get input signal then convert this analog signal to digital by using microcontroller built in ADC.. After ADC digital data send towards com port by using built in USB of PIC18F4550.

Figure 4-2: Microcontroller Interfacing

CHAPTER 4: IMPLEMENTATION AND TESTING


In case of measuring signal having negative voltage, so shift them up with the help of offset amplifier.

23

4.3

Development of window application

Next move in making of our project is designing of window application that contains oscilloscope function in GUI form. Starting of our work is learning of visual C++ and installation of visual studio, after taking some tutorials of visual C++ from MSDN we start working on visual studio. First thing thats done is reading of data from COM port and saving of data. Figure 4-2 shows the flow chart of Window application.

Figure 4-2: Flow chart

CHAPTER 4: IMPLEMENTATION AND TESTING


4.3.1 Opening Serial port

24

Serial port opening can be done by using Win32 file by using CreateFile function thats ope n a handle to a communication resource, like specify COM3 opens a handle for serial port 3. If COM 3 is used by another resource so CreateFile fails, after it any thread of the process can use handle returned by CreateFile. The CreateFile calling process uses the handle in the DeviceIoControl function to send control codes towards device29. CreateFile function sets the following attributes Read/write access for specified resource Handle can inherit by child process Handle can uses asynchronous I/O operations

Win32 supports both synchronous and Asynchronous file I/O operations on serial link, while using rs232 asynchronous I/O operations is used. ReadFile function reads data from communication resource and WriteFile function writes data on communication resource like COM port.
4.3.2 Timeouts in Serial Communication

Timeouts define handle for communication that sets time-out parameters for the behavior of read and write operations, after the specific timer elapse ReadFile or WriteFile operatios conclude. Each timer specifies interval for a timer elapses; the system notifies the window associated with the timer. Accuracy of a timer depends on the system clock rate and on application how it retrieves messages from message queue. Two types of time-outs are enabled An internal time out occur when timer of reception of character exceeds from defined time A total time out occur when read operations exceeds from a defined time

To change the time outs SetCommTimeouts function and to determine time out values 30 GetCommTimeouts function used .

CHAPTER 4: IMPLEMENTATION AND TESTING

25

After it configuration of communication port is done by using. Baud rate, parity bit and stop bit settings a timer wait in an infinite loop until data is available at specified COM port. After receiving data on COM port our next task is to save this data by using serial communication in visual c++. For serial communication a library is used named SerialCom.h, to access the Serial ports WriteComPort is used this function have two parameters first one is COM port and second one is character to send by using serial communication, if necessary com port baud rate is changed by CBR_baudrate otherwise its default value is 9600. Data written on COM port can be handled by CreateFile structure and WriteFile function used to send data at COM ports. While data receiving on COM port is little more complex by using of ReadByte function reads data from COM port if not data available on COM port so it will hand because it will wait in an infinite loop. First thing for doing serial communication is open the COM port of computer from which data is read or sends. In our case we only want to read data from COM port so by opening port we are able to read data from port after it timer used thats wait in an infinite loop until data is available at COM port31. Next step is designing of GUI and call functions of serial communication in pushbuttons, in designing of GUI MFC class is used, design of GUI given below in figure 4-3.

Figure 4-3: GUI of oscilloscope

CHAPTER 4: IMPLEMENTATION AND TESTING

26

1st in run button port opening is done that wait in an infinite loop until data is available at COM port, stop key close the port and stop taking from COM port and clear function exit the application, channel setting, time division and frequency division is also done by channel select, time divisions and frequency divisions buttons. For displaying input signal on oscilloscope a library of oscilloscope.h used, by implementing control of oscilloscope it shows last N points of user data. It contains up to eight channels for displaying signal in different domains, channels are defined in header file in OSC_MAX_CHANNELS parameter. Oscilloscope having zoom ability in X and Y both axis, zoom out is done by right key of mouse hold CTRL key for full zoom out. First open port is done that enables COM port for serial communication, Sampling rate increase by pressing tab of last point button it will increase frequency division.

27

Chapter 5
5 Results

After testing of signal acquisition circuit and serial interfacing the results are given below:

Figure 5-1 shows ADC results

CHAPTER 5: RESULTS

28

Figure 5-2 shows Digital Data at COM Port

Figure 5-3: shows Signal on Oscilloscope

29

Chapter 6
6 Observation

During start of this project we face some problems in our country DSPIC30F2020 is not available so we leave it because it does not contain USB port but its designed for signal processing applications, we move towards PIC18F4550. It contains built in ADC and USB port but unfortunately its also not available in Rawalpindi and Islamabad so we finally buy it from Hall road Lahore. After installation of MP LAB IDE we start learning of programming of PIC18F4550 but in market different types of compilers are available, after long discussion on these with our project supervisor and coordinator we decided to work on CCS C compiler because in this C language is used thats easy to understand and we have smart grip on it. After compilation of ADC coding we burn it on microcontroller using MP LAB ICD toolkit, Mr. Muhammad Abbas gave unfortunately 12v input instead of 5v because he cant recognize power supply knob so like a small cracker blast occur and microcontroller burn. While working on hardware designing Mr. Asad test different types of circuits that are work quite efficient in simulation but in bread board form they dont work properly so be patient during hardware designing. Finally after solving the complication in hardware Mr. Asad designed the PCB, Mr. Asif Rizwan helps us in the designing of PCB. During PIC18F4550 USB coding Mr. Junaid found many problems sometimes program is compiled successfully but sometime in same program errors come in header file of PIC18F4550 thats occurred due to CCS C compiler PWD installation fault. Another problem we are facing that is searching of firmware for USB to communicate with operating system, for this we post it at different forums but no one tell the exact one that is suitable for CCS C compiler. During PIC C compiler help exploring we found lot of helpful data, finally we found communication driver class (CDC) that used to interact USB with operating system. While using CDC we used usb_cdc_puts(*str) but this function does not work properly, after it we used usb_put_packet(endpoint,data,len,timeout) in this we cant set a specific endpoint. After a two to three weeks troubleshoot to these problems cant solved by anyone, so it has been decided to use printf(usb_cdc_putc()) by using this function and trouble shooting of circuit interfacing task is completed and got data on COM port.

30

Chapter 7
7
7.1

Conclusion and Future Work


Conclusion

Oscilloscope involves many applications in electronic signal acquisition circuits, its constructed on the basis of electronic circuit, programming of microcontroller and an application. A PC based portable and having in low cost an oscilloscope that contains many features is designed for educational purpose due to its limited input range , its a stunned breakthrough in making of traditional intelligent instruments. In comparison with traditional oscilloscope USB oscilloscope provides better portability and cheap in cost, display oscilloscope waveform and having ability to save it to put in documentation.

7.2

Future work

Oscilloscope tested with sinusoidal waveform, for plotting of square, triangular and ramp function future work can be done on it. Window application is restraint for displaying signal having high frequency due to low sampling rate in hardware. To add constant gain in signal programmable gain amplifier (PGA) can be used to increase gain of signals, serial peripheral interface (SPI) is used for this work. The application display signal in time domain, for displaying in form of frequency domain and FFT domain work can also be done on it in future. Hardware design unable to differentiate between AC and DC while displaying, further modification can done on potting of AC and DC signals separately. More consequently by using of various types of microcontrollers like DSPIC it is possible to increase sampling rate for higher frequency reading. To make it auto set like digital oscilloscope a circuitry is made that converts any input range to suitable microcontroller range for doing PGA may be used. To provide more portability further modification can be done on it by designing a similar application for smart phones for example Android, make hardware compatible with Android after designing of driver. Jango toolkit may be used for driver development but it is little bit costly. Another way to send data on android phone using of Xbee, by using of this data easily sends towards android phone after receiving of data similar waveform plots in smart phone.

31

Chapter8
8 8.1 Appendix A: Schematic Diagrams Input Stage and USB Interfacing

CHAPTER 8: APPENDIX

32

8.2

Input stage

33

References
1 2 3

http://www.physics.nus.edu.sg/pc2193/Manual_files/PC2193%20Basic%20Electronics-Oscilloscope.pdf www.physics.mun.ca/~cdeacon/labs/2055/oscilloscope.pdf

Kularatna, Nihal (2003), "Fundamentals of Oscilloscopes", Digital and Analogue Instrumentation: Testing and Measurement, Institution of Engineering and Technology, pp. 165208, ISBN 978-0-85296-999-1 4 Hawkins (1917, pp. 18411846)
5 6 7 8

http://en.wikipedia.org/wiki/Oscilloscope_history#cite_note-4 http://en.wikipedia.org/wiki/Oscilloscope_history#cite_note-9

europe.lutron.com/techInfo/InstallGuides/040134b200210.pdf PIC microcontroller and Embedded system by Muhammad Ali Mazidi Chapter 7, page 255 and chapter 13, page 483 9 www.sena.com/download/tutorial/tech_Serial_v1r0c0.pdf 10 Visual C++ by Mickey Willims and David Bennett part 2, page 119 and page 233 11 PIC18f4550 Datasheet, 17.10 Overview of USB 12 PIC18F4550 datasheet, 17.10.1 LAYERED FRAMEWORK 13 PIC18F4550 datasheet, 17.10.3 TRANSFERS USB Complete: Everything You Need to Develop USB Peripherals, Third Edition by Jan Axelson, chapter 3, Page 69 14 PIC18F4550 datasheet, 17.10.3 TRANSFERS 15 USB Complete: Everything You Need to Develop USB Peripherals, Third Edition by Jan Axelson, chapter 3, Page 69 16 USB Complete: Everything You Need to Develop USB Peripherals, Third Edition by Jan Axelson, chapter 3, Page 69 17 USB Complete: Everything You Need to Develop USB Peripherals, Third Edition by Jan Axelson, chapter 3, Page 71 18 PIC18F4550 datasheet, 17.10.3 TRANSFERS 19 PIC18F4550 datasheet, 17.10.5 ENUMERATION 20 http://en.wikipedia.org/wiki/Universal_asynchronous_receiver/transmitter
21 22

http://www.freebsd.org/doc/en_US.ISO8859-1/articles/serial-uart/index.html www.sena.com/download/tutorial/tech_Serial_v1r0c0.pdf 23 http://www.datasheetarchive.com/dl/Databooks-1/Book241-407.pdf 24 iqi Tew; Bok-Min Goi; , "Oscilloscope: A PC-based Real Time Oscilloscope," Innovative Technologies in Intelligent Systems and Industrial Applications, 2008. CITISIA 2008. IEEE Conference on , vol., no., pp.92-97, 12-13 July 2008 doi: 10.1109/CITISIA.2008.4607341 http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=4607341&isnumber=4607323 25 MPLAB Integrated Development Environment.[Online].Microchip Technology Inc. http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en019469&part=SW00 7002. 26 Microchip Bootloader. [Online]. 2008 Microchip Technology Inc. http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2124&param=en022627 27 Visual C++ by Mickey Willims and David Bennett part 2, page 119 and page 233 28 Ng Wee Lee, Tan Meng Tong. (2006, February 17). Home. [Online]. The University of Newcastle, Australia 29 http://msdn.microsoft.com/en-us/library/windows/desktop/aa363858%28v=vs.85%29.aspx 30 http://msdn.microsoft.com/en-us/library/windows/desktop/aa363261%28v=vs.85%29.aspx 31 http://msdn.microsoft.com/en-us/library/windows/desktop/aa365467%28v=vs.85%29.aspx

You might also like