Download docx - digital oscilloscope

Transcript
Page 1: digital oscilloscope

PC-BASED DIGITAL OSCILLOSCOPE

MAIN PROJECTREPORT ON

PC-BASED DIGITAL OSCILLOSCOPE

USING PIC MICROCONTROLER

1 | P a g e Department Of Electronics and Communication Engineering

Page 2: digital oscilloscope

PC-BASED DIGITAL OSCILLOSCOPE

ABSTRACT

The digital oscilloscope attempts to achieve the same functionality as a traditional oscilloscope, using a PIC microcontroller for data acquisition (including appropriate analogue circuitry) which transfers the data to the PC (via USB). A Microsoft Windows based software application will then display the waveform as it would appear on a traditional CRT oscilloscope. This software application will have additional features not present on a traditional oscilloscope (e.g. printing / saving waveforms) with greater flexibly as additional features can be added as their developed without the need for new hardware. Additional function is added in the circuitry such as MULTIMETER MODE which enables the PC-scope to measure the circuit parameters like capacitance, resistance, current and voltage of the required component.

2 | P a g e Department Of Electronics and Communication Engineering

Page 3: digital oscilloscope

PC-BASED DIGITAL OSCILLOSCOPE

TABLE OF CONTENTS

1. INTRODUCTION 4

2. FUNDEMENTALS 5

2.1 THE BASIC CRT OSCILLOSCOPE 5

2.2 DIGITAL SAMPLING OSCILLOSCOPES 7

2.3 THE PIC MICROCONTROLLER 8

2.4 UNIVERSAL SERIAL BUS INTERFACE 10

3. THE PIC18F2550 MICROCONTROLLER 11

3.1 OVERVIEW OF THE 8-CHANNEL 10-BIT ADC 12

3.2 OVERVIEW OF THE HID USB PERIPHERAL 13

4. HARDWARE DEVELOPMENT 14

5.1 SIMPLIFIED BLOCK DIAGRAM 14

5.2 DESCRIPTION 15

5.3 DIGITAL CIRCUIT DIAGRAM 18

5.4 FLOWCHART 19

5. THE SCOPE PROGRAM 20

6.1 PIC PROGRAMME 20

6.2 VISUAL BASIC PROGRAM CODE23

6. FUTURE WORK31

7. SUMMARY AND CONCLUSION 32

8. REFERENCES 34

3 | P a g e Department Of Electronics and Communication Engineering

Page 4: digital oscilloscope

PC-BASED DIGITAL OSCILLOSCOPE

INTRODUCTION

An oscilloscope is a type of electronic test instrument that allows signal voltages to be viewed, usually as a two-dimensional graph of one or more electrical potential differences (vertical(Y) axis) plotted as a function of time or of some other voltage (horizontal(x) axis). Although an oscilloscope displays voltage on its vertical axis, any other quantity that can be converted to a voltage can be displayed as well. In most instances, oscilloscopes show events that repeat with either no change, or change slowly. The oscilloscope is one of the most versatile and widely-used electronic instruments.

Oscilloscopes are commonly used when it is desired to observe the exact wave shape of an electrical signal. In addition to the amplitude of the signal, an oscilloscope can show distortion and measure frequency, time between two events (such as pulse width or pulse rise time), and relative timing of two related signals. Some modern digital oscilloscopes can analyze and display the spectrum of a repetitive event

The digital oscilloscope attempts to achieve the same functionality as a traditional oscilloscope, using a PIC microcontroller for data acquisition (including appropriate analogue circuitry) which transfers the data to the PC (via USB). A Microsoft Windows based software application will then display the waveform as it would appear on a traditional CRT oscilloscope. This software application will have additional features not present on a traditional oscilloscope (e.g. printing / saving waveforms) with greater flexibly as additional features can be added as their developed without the need for new hardware. Additional function is added in the circuitry such as MULTIMETER MODE which enables the PC-scope to measure the circuit parameters like capacitance, resistance, current and voltage of the required component.

Digital oscilloscopes have two main advantages over traditional analogue scopes: -

1. The ability to observe slow and very slow signals as a solid presentation on the screen. Slow moving signals in the 10-100 Hz range are difficult to see and measure on a normal analogue oscilloscope due to the flicker of the trace and the short persistence of the spot on the screen.

2. The ability to hold or retain a signal in memory for long periods.

The PIC microcontroller has a built-in ADC (8, 10 or 12 bits) which has a voltage range of 0 to 5V. This voltage range is not ideal as most oscilloscopes have a much wider voltage range including negative voltages (e.g. -100 to 100V); hence an analogue circuit is required to reduce the voltage positivee signals so they fall between 2.5 and 5V and voltage negative signals between 0 and 2.5V (i.e. bipolar). The built-in ADC on the PIC is slow and will limit the maximum sampling frequency; hence an external Flash ADC with direct memory access will be required to produce a high-performance digital storage oscilloscope (e.g. AD9070 – 10Bit, 100MSPS ADC)

4 | P a g e Department Of Electronics and Communication Engineering

Page 5: digital oscilloscope

PC-BASED DIGITAL OSCILLOSCOPE

1. FUNDEMENTALS

THE BASIC CRT OSCILLOSCOPE

An oscilloscope draws its trace with a spot of light (produced by a deflectable beam of electrons) moving across the screen of its CRT. Basically an oscilloscope consists of the CRT, a ‘time base’ circuit to move the spot steadily from left to right across the screen at the appropriate time and speed, and some means (usually a ‘Y’ deflection amplifier) of enabling the signal to deflect the spot in the vertical or Y direction.

This type of oscilloscope is known as a ‘real-time’ oscilloscope. This means that the vertical deflection of the spot on the screen at any instant is determined by the Y input voltage at that instant.

The basic oscilloscope is typically divided into four sections: the display, vertical controls, horizontal controls and trigger controls. The display is usually a CRT or LCD panel which is laid out with both horizontal and vertical reference lines referred to as the graticule. In addition to the screen, most display sections are equipped with three basic

controls, a focus knob, an intensity knob and a beam finder button. The vertical section controls the amplitude of the displayed signal. This section carries a Volts-per-Division (Volts/Div) selector knob, an AC/DC/Ground selector switch and the vertical (primary) input for the instrument. Additionally, this section is typically equipped with the vertical beam position knob.

5 | P a g e Department Of Electronics and Communication Engineering

Page 6: digital oscilloscope

PC-BASED DIGITAL OSCILLOSCOPE

The horizontal section controls the time base or “sweep” of the instrument. The primary control is the Seconds-per-Division (Sec/Div) selector switch.

Also included is a horizontal input for plotting dual X-Y axis signals. The horizontal beam position knob is generally located in this section. The trigger section controls the start event of the sweep. The trigger can be set to automatically restart after each sweep or it can be configured to respond to an internal or external event. The principal controls of this section will be the source and coupling selector switches. An external trigger input (EXT Input) and level adjustment will also be included.

In addition to the basic instrument, most oscilloscopes are supplied with a probe as shown. The probe will connect to any input on the instrument and typically has a resistor of ten times the 'scope's input impedance. This results in a .1 (-10X) attenuation factor, but helps to isolate the capacitive load presented by the probe cable from the signal being measured. Some probes have a switch allowing the operator to bypass the resistor when appropriate.

6 | P a g e Department Of Electronics and Communication Engineering

Page 7: digital oscilloscope

PC-BASED DIGITAL OSCILLOSCOPE

DIGITAL SAMPLING OSCILLOSCOPES

Digital sampling oscilloscopes use an ADC (analogue-to-digital converter) to converter analogue voltages to binary representation. The sampling rate specifies the number of samples taken per second. Figure demonstrates clearly how an analogue wave-form is digitally sampled and displayed onto the screen (LCD, Computer Monitor, etc…).

The PIC microcontroller has a built-in ADC (8, 10 or 12 bits) which has a voltage range of 0 to 5V. This voltage range is not ideal as most oscilloscopes have a much wider voltage range including negative voltages (e.g. -100 to 100V); hence an analogue circuit is required to reduce the voltage positive signals so they fall between 2.5 and 5V and voltage negative signals between 0 and 2.5V (i.e. bipolar).

7 | P a g e Department Of Electronics and Communication Engineering

ANALOG CIRCUITRY

Page 8: digital oscilloscope

PC-BASED DIGITAL OSCILLOSCOPE

THE PIC MICROCONTROLLER

A PIC (Peripheral Interface Controller) microcontroller is an IC manufactured by Microchip.

These ICs are complete computers in a single package. The only external components necessary are whatever is required by the I/O devices that are connected to

the PIC. PICs use the Harvard architecture. The Harvard architecture is an adaptation of the standard von Neumann structure with separate program and data memory: data memory is made up by a small number of 8-bit registers and program memory is 12 to 16-bits wide

EPROM, FLASH or ROM. Traditional CISC (Complex Instruction Set Computer) machines (Used in: 80X86,

8051, 6800, 68000, etc…) have many instructions (usually > 100), many addressing modes and it usually takes more than 1 internal clock cycle to execute. PIC microcontrollers are RISC (Reduced Instruction Set Computer) machines, which have 33 (12-bit) to 58 (15-bit) instructions, reduced addressing modes (PICs have only direct and indirect), each instruction

does less, but usually executes in one internal clock. A PIC's instructions vary from about 35 instructions for the low-end PICs to over 80

instructions for the high-end PICs. The instruction set includes instructions to perform a variety of operations on registers directly, the accumulator and a literal constant or the accumulator and a register, as well as for conditional execution, and program branching. Some operations, such as bit setting and testing, can be performed on any numbered register, but bi-operand arithmetic operations always involve W (the accumulator) ; writing the result back to either W or the other operand register. To load a constant, it is necessary to load it into W before it can be moved into another register. On the older cores, all register moves needed to pass through W, but this changed on the "high end" cores.

PIC cores have skip instructions which are used for conditional execution and branching. The skip instructions are: 'skip if bit set', and, 'skip if bit not set'. Because cores before PIC18 had only unconditional branch instructions, conditional jumps are implemented by a conditional skip (with the opposite condition) followed by an unconditional branch. Skips are also of utility for conditional execution of any immediate single following instruction.

8 | P a g e Department Of Electronics and Communication Engineering

Page 9: digital oscilloscope

PC-BASED DIGITAL OSCILLOSCOPE

The PIC architecture has no (or very meager) hardware support for automatically saving processor state when servicing interrupts. The 18 series improved this situation by implementing shadow registers which save several important registers during an interrupt.

In general, PIC instructions fall into 5 classes:

Operation on W with 8-bit immediate ("literal") operand. E.g. movlw (move literal to W), andlw (AND literal with W). One instruction peculiar to the PIC is retlw, load immediate into W and return, which is used with computed branches to produce lookup tables.

Operation with W and indexed register. The result can be written to either the W register (e.g. addwf reg,w). or the selected register (e.g. addwf reg,f).

Bit operations. These take a register number and a bit number, and perform one of 4 actions: set or clear a bit, and test and skip on set/clear. The latter are used to perform conditional branches. The usual ALU status flags are available in a numbered register so operations such as "branch on carry clear" are possible.

Control transfers. Other than the skip instructions previously mentioned, there are only two: goto and call.

A few miscellaneous zero-operand instructions, such as return from subroutine, and sleep to enter low-power mode.

9 | P a g e Department Of Electronics and Communication Engineering

Page 10: digital oscilloscope

PC-BASED DIGITAL OSCILLOSCOPE

UNIVERSAL SERIAL BUS INTERFACE

USB is a specification to establish communication between devices and a host

controller (usually personal computers). A USB (Universal Serial Bus) system has an

asymmetric design, consisting of a host, a multitude of downstream USB ports, and multiple peripheral devices connected in a tiered-star topology. Additional USB hubs may be included in the tiers, allowing branching into a tree structure with up to five tier levels. A USB host may have multiple host controllers and each host controller may provide one or more USB ports. Up to 127 devices, including hub devices if present may be connected to a single host controller.

USB devices are linked in series through hubs. There always exists one hub known as the root hub, which is built into the host controller. So-called sharing hubs, which allow multiple computers to access the same peripheral device(s), also exist and work by switching access between PCs, either automatically or manually. Sharing hubs are popular in small-office environments. In network terms, they converge rather than diverge branches.

A physical USB device may consist of several logical sub-devices that are referred to as device functions. A single device may provide several functions, for example, a webcam (video device function) with a built-in microphone (audio device function). Such a device is called a compound device in which each logical device is assigned a distinctive address by the host and all logical devices are connected to a built-in hub to which the physical USB wire is connected. A host assigns one and only one device address to a function.

USB endpoints actually reside on the connected device: the channels to the host are referred to as pipes. USB device communication is based on pipes (logical channels). A pipe is a connection from the host controller to a logical entity, found on a device, and named an endpoint. The term endpoint is occasionally incorrectly used for referring to the pipe. However, while an endpoint exists on the device permanently, a pipe is only formed when the host makes a connection to the endpoint. Therefore, when referring to the connection between a host and an endpoint, the term pipe should be used. A USB device can have up to 32 active pipes: 16 into the host controller and 16 out of the host controller.

10 | P a g e Department Of Electronics and Communication Engineering

Page 11: digital oscilloscope

PC-BASED DIGITAL OSCILLOSCOPE

THE PIC18F2550 MICROCONTROLLER

10-BIT ANALOG-TO-DIGITAL CONVERTER (A/D) MODULE

The Analog-to-Digital (A/D) converter module has 10 inputs for the 28-pin devices and 13 for the40/44-pin devices. This module allows conversion of an analog input signal to a corresponding 10-bit digital number.

The module has five registers:

• A/D Result High Register (ADRESH)

• A/D Result Low Register (ADRESL)

• A/D Control Register 0 (ADCON0)

• A/D Control Register 1 (ADCON1)

• A/D Control Register 2 (ADCON2)

ADCON0: A/D CONTROL REGISTER 0

The ADCON0 register, shown below, controls the operation of the A/D module.

bit 7-6 Unimplemented: Read as ‘0’

bit 5-2 CHS3:CHS0: Analog Channel Select bits

0000 = Channel 0 (AN0)

0001 = Channel 1 (AN1)

0010 = Channel 2 (AN2)

0011 = Channel 3 (AN3)

0100 = Channel 4 (AN4)

0101 = Channel 5 (AN5)(1,2)

0110 = Channel 6 (AN6)(1,2)

0111 = Channel 7 (AN7)(1,2)

1000 = Channel 8 (AN8)

11 | P a g e Department Of Electronics and Communication Engineering

bit 1 GO/DONE: A/D Conversion Status bit

When ADON = 1:

1 = A/D conversion in progress

0 = A/D Idle

bit 0 ADON: A/D On bit

1 = A/D converter module is enabled

0 = A/D converter module is disabled

Page 12: digital oscilloscope

PC-BASED DIGITAL OSCILLOSCOPE

ADCON1: A/D CONTROL REGISTER 1

The ADCON1 register, shown below, configures the functions of the port pins.

bit 7-6 Unimplemented: Read as ‘0’

bit 5 VCFG0: Voltage Reference Configuration bit (VREF- source)

1 = VREF- (AN2)

0 = VSS

bit 4 VCFG0: Voltage Reference Configuration bit (VREF+ source)

1 = VREF+ (AN3)

0 = VDD

bit 3-0 PCFG3:PCFG0: A/D Port Configuration Control bits:

12 | P a g e Department Of Electronics and Communication Engineering

Page 13: digital oscilloscope

PC-BASED DIGITAL OSCILLOSCOPE

ADCON2: A/D CONTROL REGISTER 2

The ADCON2 register,shown below, configures the A/D clock source, programmed acquisition time and justification

bit 7 ADFM: A/D Result Format Select bit1 = Right justified

0 = Left justified

bit 6 Unimplemented: Read as ‘0’

bit 5-3 ACQT2:ACQT0: A/D Acquisition Time Select bits111 = 20 TAD

110 = 16 TAD

101 = 12 TAD

100 = 8 TAD

011 = 6 TAD

010 = 4 TAD

001 = 2 TAD

000 = 0 TAD(1)

Overview of the HID USB Peripheral

The PIC18FX455/X550 device family contains a full-speed and low-speed compatible USB Serial Interface Engine (SIE) that allows fast communication between any USB host and the PIC microcontroller. The SIE can be interfaced directly to the USB, utilizing the internal transceiver, or it can be connected through an external transceiver. An internal 3.3V regulator is also available to power the internal transceiver in 5V applications. Some special hardware features have been included to improve performance. Dual port memory in the device’s data memory space (USB RAM) has been supplied to share direct memory access between the microcontroller core and the SIE. Buffer descriptors are also provided, allowing users to freely program endpoint memory usage within the USB RAM space. A Streaming Parallel Port has been provided to support the uninterrupted transfer of large volumes of data, such as isochronous data, to external memory buffers.

13 | P a g e Department Of Electronics and Communication Engineering

bit 2-0 ADCS2:ADCS0: A/D Conversion Clock Select bits111 = FRC (clock derived from A/D RC

oscillator)(1)

110 = FOSC/64

101 = FOSC/16

100 = FOSC/4

011 = FRC (clock derived from A/D RC

oscillator)(1)

010 = FOSC/32

001 = FOSC/8

000 = FOSC/2

Page 14: digital oscilloscope

PC-BASED DIGITAL OSCILLOSCOPE

HARDWARE DEVELOPMENT

SIMPLIFIED BLOCK DIAGRAM

14 | P a g e Department Of Electronics and Communication Engineering

CURRENTMeasurment

ADC (10 bit resolution)

Personal Computer

PIC18F2550MICROCONTROLLER

Oscilloscope PROBE

ANALOG CIRCUITRY

(vertical lift)

RESISTANCEMeasuremen

t

CAPACITANCEMeasurement

OSCILLOSCOPE

VOLTAGEMeasureme

nt

PROBE SELECTION

USB interface

Page 15: digital oscilloscope

PC-BASED DIGITAL OSCILLOSCOPE

DESCRIPTION

Measurement of Capacitance

Time-constant method.

If a direct voltage is suddenly applied to the series combination of a resistor and an initially discharged capacitor, the charge and the voltage on the capacitor increase exponentially toward their full magnitudes with a time constant equal in seconds to the product of the resistance in ohms and the capacitance in farads. Similarly, when a charged capacitor is discharged through a resistor, the charge and the voltage decay with the same time constant. Various methods are available for the measurement of capacitance by measurement of the time constant of charge or discharge through a known resistor.

In one such method the time required for the output voltage of an operational amplifier having a capacitor as a feedback component to increase to a value equal to the step-function input voltage applied through a resistor to its input is determined by an electronic voltage-comparison circuit and timer. With the assumption of ideal characteristics for the amplifier, such as infinite gain without feedback, infinite input impedance, and zero output impedance, the measured time interval is equal to the product of the values of the known resistance and the capacitance being measured. See also Operational amplifier.

Measurement of Resistance

15 | P a g e Department Of Electronics and Communication Engineering

Page 16: digital oscilloscope

PC-BASED DIGITAL OSCILLOSCOPE

Resistance measurement is done using the principle of Potential divider circuit. The resistance of an unknown resistor can be calculated by measuring the voltage across it when it is kept series in a potential divider circuit by the Equation given below.

If Vt is the total voltage, Vx the voltage across unknown resistor R2and Vk across the Known resistor R1, then R2 is given by

R2 =( Vt - Vx)*R1/Vk

Measurement of Current

Essentially, most of today’s ammeters are based on the fundamental theory of electricity, Ohm’s law. Modern ammeters are essentially voltmeters with a precision resistor, and using Ohm’s law, an accurate yet cost-effective measurement can be made.

Ohm’s Law – Ohm’s law states that, in an electrical circuit, the current passing through a conductor between two points is directly proportional to the potential difference (in other words, voltage drop or voltage) across the two points, and inversely proportional to the resistance between them.

The mathematical equation that describes this relationship is:

I = V/R

where I is the current in amperes, V is the potential difference between two points of interest in volts, and R is a circuit parameter, measured in ohms (which is equivalent to volts per ampere), called the resistance.

Ammeter Operation – Today’s ammeters have an internal resistance to measure the current across the particular signal. However, when the internal resistance is not enough to measure larger currents, an external configuration is needed.

To measure larger currents, you can place a precision resistor called a shunt in parallel with the meter. Most of the current flows through the shunt, and only a small fraction flows through the meter. This allows the meter to measure larger currents.

Any resistor is acceptable, as long as the maximum expected current multiplied by the resistance does not exceed the input range of the ammeter or data acquisition device.

When measuring current in this fashion, you should use the smallest value resistor possible because this creates the smallest interference with the existing circuit. However, smaller resistances create smaller voltage drops, so you must make a compromise between resolution and circuit interference.

Given Figure shows a common schematic of current measurement across a shunt resistor.

16 | P a g e Department Of Electronics and Communication Engineering

Page 17: digital oscilloscope

PC-BASED DIGITAL OSCILLOSCOPE

Connecting a Shunt Resistor to a Measurement

Using this approach, the current is not actually directed into the ammeter/data acquisition board but instead through an external shunt resistor. The largest current we can measure is theoretically limitless, provided the voltage drop across the shunt resistor does not exceed the working voltage range of the ammeter/data acquisition board.

17 | P a g e Department Of Electronics and Communication Engineering

Page 18: digital oscilloscope

PC-BASED DIGITAL OSCILLOSCOPE

DIGITAL CIRCUIT DIAGRAM

18 | P a g e Department Of Electronics and Communication Engineering

Page 19: digital oscilloscope

PC-BASED DIGITAL OSCILLOSCOPE

FLOWCHART

19 | P a g e Department Of Electronics and Communication Engineering

Initialize Ports

Read Pin2 and Pin3

Output To PC

Set Pin 12 =1

Read Port 4,5

Start Timer

If Voltage =3.14V

If scope mode=1

Read timer Value

If Pin 11 = 0

start

Stop Timer

yes

yes

NO NO

yes

NO

Page 20: digital oscilloscope

PC-BASED DIGITAL OSCILLOSCOPE

THE SCOPE PROGRAM

PIC PROGRAMME

#define SCOPE_MODE PORTA.F4#define CH1_PIN 0#define CH2_PIN 1#define CURRENT_PIN 2#define RESISTANCE_PIN 3#define BUTTON_CAPMEASSURE PORTC.F0#define PIN_CAPMEASURE PORTC.F1#define ADC_CAPMEASURE 4unsigned char k, adcRes;unsigned char userWR_buffer[64];char *text = "MIKROElektronika Compilers ER \r\n";void interrupt(){ HID_InterruptProc();}void Init_Main(){ INTCON = 0; INTCON2 = 0xF5; INTCON3 = 0xC0; RCON.IPEN = 0; PIE1 = 0; PIE2 = 0; PIR1 = 0; PIR2 = 0;

ADCON1 = 0B00001000 ; CMCON |= 7;

TRISA = 0xFF; TRISB = 0; TRISC = 0B11111101;

LATA = 0xFF; LATB = 0; LATC = 0B11111101; }void main(){ char i; TRISB = 0; Init_Main();

HID_Enable(&userWR_buffer, &userWR_buffer);

20 | P a g e Department Of Electronics and Communication Engineering

Page 21: digital oscilloscope

PC-BASED DIGITAL OSCILLOSCOPE

Delay_ms(1000); Delay_ms(1000); while(1) { if(SCOPE_MODE) { userWR_buffer[0]= ADC_Read(CH1_PIN)>>2; while (!HID_Write(&userWR_buffer, 1)); } else { userWR_buffer[0] = 'C'; while (!HID_Write(&userWR_buffer, 1)); userWR_buffer[0] = 'U'; while (!HID_Write(&userWR_buffer, 1)); userWR_buffer[0] = 'R'; while (!HID_Write(&userWR_buffer, 1)); userWR_buffer[0] =Adc_Read(CURRENT_PIN)>>2; while (!HID_Write(&userWR_buffer, 1));

userWR_buffer[0] = 'R'; while (!HID_Write(&userWR_buffer, 1)); userWR_buffer[0] = 'E'; while (!HID_Write(&userWR_buffer, 1)); userWR_buffer[0] = 'S'; while (!HID_Write(&userWR_buffer, 1)); userWR_buffer[0] =Adc_Read(RESISTANCE_PIN)>>2; while (!HID_Write(&userWR_buffer, 1));

Delay_Ms(50); if(BUTTON_CAPMEASSURE == 0) { // Wait 1 second Delay_Ms(1000); PIN_CAPMEASURE = 1; // Turn On Timer1 PIR1.TMR1IF = 0; PIE1.TMR1IE = 0; T1CON = 0B00110100; TMR1L = 0; TMR1H = 0; T1CON.TMR1ON = 1; // Measure voltages level reaches until 3.14V (ie 155) while(1) { adcRes = ADC_Read(ADC_CAPMEASURE) >> 2; if(adcRes >= 155) { // Stop Timer1 T1CON.TMR1ON = 0; userWR_buffer[0] = 'C';

21 | P a g e Department Of Electronics and Communication Engineering

Page 22: digital oscilloscope

PC-BASED DIGITAL OSCILLOSCOPE

while (!HID_Write(&userWR_buffer, 1)); userWR_buffer[0] = 'A'; while (!HID_Write(&userWR_buffer, 1)); userWR_buffer[0] = TMR1L; while (!HID_Write(&userWR_buffer, 1)); userWR_buffer[0] =TMR1H; while (!HID_Write(&userWR_buffer, 1)); PIN_CAPMEASURE = 0; break; } if(PIR1.TMR1IF) { T1CON.TMR1ON = 0; PIR1.TMR1IF = 0; break; } } } } } Delay_ms(1000); HID_Disable();

}

22 | P a g e Department Of Electronics and Communication Engineering

Page 23: digital oscilloscope

PC-BASED DIGITAL OSCILLOSCOPE

VISUAL BASIC GUI PROGRAM CODE

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms; using UsbLibrary;using Microsoft.VisualBasic;

namespace UsbApp{ public partial class Sniffer : Form { Bitmap bmp = new Bitmap(800, 800);

Color PlotColor = Color.Yellow;

int X, Y; byte buff0, buff1, buff2, buff3;

public Sniffer() { InitializeComponent(); }

private void usb_OnDeviceArrived(object sender, EventArgs e) { this.lb_message.Items.Add("Found a Device"); toolStripStatusLabel1.Text = "Found a Device"; }

private void usb_OnDeviceRemoved(object sender, EventArgs e) { if (InvokeRequired) { Invoke(new EventHandler(usb_OnDeviceRemoved), new object[] { sender, e }); } else { this.lb_message.Items.Add("Device was removed"); toolStripStatusLabel1.Text = "Device was removed"; } }

private void usb_OnSpecifiedDeviceArrived(object sender, EventArgs e) { this.lb_message.Items.Add("PCScope was found");

23 | P a g e Department Of Electronics and Communication Engineering

Page 24: digital oscilloscope

PC-BASED DIGITAL OSCILLOSCOPE

toolStripStatusLabel1.Text = "PCScope was found";

//setting string form for sending data string text = ""; for (int i = 0; i < this.usb.SpecifiedDevice.OutputReportLength - 1; i++) { text += "000 "; } this.tb_send.Text = text; }

protected override void OnHandleCreated(EventArgs e) { base.OnHandleCreated(e); usb.RegisterHandle(Handle); }

protected override void WndProc(ref Message m) { usb.ParseMessages(ref m); base.WndProc(ref m); // pass message on to base form }

private void btn_ok_Click(object sender, EventArgs e) { try { this.usb.ProductId = Int32.Parse(this.tb_product.Text, System.Globalization.NumberStyles.HexNumber); this.usb.VendorId = Int32.Parse(this.tb_vendor.Text, System.Globalization.NumberStyles.HexNumber); this.usb.CheckDevicePresent(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }

private void btn_send_Click(object sender, EventArgs e) { try { string text = this.tb_send.Text + " "; text.Trim(); string[] arrText = text.Split(' '); byte[] data = new byte[arrText.Length]; for (int i = 0; i < arrText.Length; i++) { if (arrText[i] != "") { int value = Int32.Parse(arrText[i], System.Globalization.NumberStyles.Number); data[i] = (byte)Convert.ToByte(value); }

24 | P a g e Department Of Electronics and Communication Engineering

Page 25: digital oscilloscope

PC-BASED DIGITAL OSCILLOSCOPE

}

if (this.usb.SpecifiedDevice != null) { this.usb.SpecifiedDevice.SendData(data); } else { MessageBox.Show("Sorry but your device is not present. Plug it in!! "); }

} catch (Exception ex) { MessageBox.Show(ex.ToString()); } }

private void usb_OnSpecifiedDeviceRemoved(object sender, EventArgs e) { if (InvokeRequired) { Invoke(new EventHandler(usb_OnSpecifiedDeviceRemoved), new object[] { sender, e }); } else { this.lb_message.Items.Add("PCScope was removed"); toolStripStatusLabel1.Text = "PCScope was removed"; } }

private void usb_OnDataRecieved(object sender, DataRecievedEventArgs args) { try { if (InvokeRequired) { try { Invoke(new DataRecievedEventHandler(usb_OnDataRecieved), new object[] { sender, args }); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } else { string rec_data = "";//"Data: "; foreach (byte myData in args.data) { ProcessByte(myData); rec_data = myData.ToString();

25 | P a g e Department Of Electronics and Communication Engineering

Page 26: digital oscilloscope

PC-BASED DIGITAL OSCILLOSCOPE

//MessageBox.Show(rec_data , "Char");

/* if (myData.ToString().Length == 1) { rec_data += "00"; }

if (myData.ToString().Length == 2) { rec_data += "0"; }

rec_data = rec_data + myData.ToString(); //+" ";*/

rec_data += Strings.Chr(myData); }

this.lb_read.Items.Insert(0, rec_data); if (lb_read.Items.Count > 1000) lb_read.Items.Clear(); } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Error); } }

private void ProcessByte(byte theByte) { try { int vADC; if (Tab.SelectedIndex == 0) { try { this.Y = 255-theByte; // Received Value if (this.Y >= 500) this.Y = 500; bmp.SetPixel(this.X, this.Y, PlotColor); if (this.Y > 0) vADC = this.Y;

picScope.Image = bmp;

this.X = this.X + 1; if (this.X >= 500) { bmp.Dispose(); bmp = new Bitmap(800, 800); picScope.Image = bmp; X = 1; } } catch (Exception ex) {

26 | P a g e Department Of Electronics and Communication Engineering

Page 27: digital oscilloscope

PC-BASED DIGITAL OSCILLOSCOPE

toolStripStatusLabel1.Text = "Error Occured: " + ex.Message; } } else if (Tab.SelectedIndex == 1) { if (theByte != 0) { buff0 = buff1; buff1 = buff2; buff2 = buff3; buff3 = theByte; } // Current / Capaciance ? if (buff0 == Strings.Asc('C')) { try { if (buff1 == Strings.Asc('U') && buff2 == Strings.Asc('R')) { // Calculate and display Capacitance lblCurrent.Text = "CURRENT: " + Strings.Format(buff3 * 0.01961, "0.00"); Application.DoEvents(); } } catch (Exception ex) { } try { if (buff1 == Strings.Asc('A')) { // Calculate and display capacitance double cap = (buff3 * 256) + buff2; lblCapacitance.Text = "CAPACITANCE: " + Strings.Format(buff3 * 0.01961, "0.00"); Application.DoEvents(); } } catch (Exception ex) { } } else if (buff0 == Strings.Asc('R')) { try { if (buff1 == Strings.Asc('E') && buff2 == Strings.Asc('S')) { // Calculate and display resistance lblResistance.Text = "RESISTANCE: " + Strings.Format(buff3 * 0.01961, "0.00"); Application.DoEvents(); } } catch (Exception ex) { } } } } catch (Exception ex) {

27 | P a g e Department Of Electronics and Communication Engineering

Page 28: digital oscilloscope

PC-BASED DIGITAL OSCILLOSCOPE

MessageBox.Show(ex.Message, ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Error); } return; } private void usb_OnDataSend(object sender, EventArgs e) { this.lb_message.Items.Add("Some data was send"); toolStripStatusLabel1.Text = "Some data was send"; }

private void Sniffer_Load(object sender, EventArgs e) { try { toolStripStatusLabel1.Text = "Scanning for device";

} catch (Exception ex) { MessageBox.Show(ex.Message, ex.Source, MessageBoxButtons.OK,

MessageBoxIcon.Error); }

}

private void timer1_Tick(object sender, EventArgs e) { btn_ok_Click(sender, e); }

private void button5_Click(object sender, EventArgs e) { MessageBox.Show("Under Contruction"); }

private void button6_Click(object sender, EventArgs e) { MessageBox.Show("Under Contruction"); }

private void button7_Click(object sender, EventArgs e) { MessageBox.Show("Under Contruction"); }

private void button8_Click(object sender, EventArgs e) { MessageBox.Show("Under Contruction"); }

private void button3_Click(object sender, EventArgs e) { try { System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.EnableRaisingEvents = false; proc.StartInfo.FileName = Application.StartupPath + "\\resps.exe"; proc.Start();

28 | P a g e Department Of Electronics and Communication Engineering

Page 29: digital oscilloscope

PC-BASED DIGITAL OSCILLOSCOPE

} catch (Exception ex) { MessageBox.Show(ex.Message, ex.Source); } }

private void button4_Click(object sender, EventArgs e) { try { System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.EnableRaisingEvents = false; proc.StartInfo.FileName = Application.StartupPath + "\\resps.exe"; proc.Start(); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.Source); } }

private void button2_Click(object sender, EventArgs e) { try { System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.EnableRaisingEvents = false; proc.StartInfo.FileName = Application.StartupPath + "\\resps.exe"; proc.Start(); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.Source); } }

private void button1_Click(object sender, EventArgs e) { try { System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.EnableRaisingEvents = false; proc.StartInfo.FileName = Application.StartupPath + "\\resps.exe"; proc.Start(); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.Source); } }

private void button9_Click(object sender, EventArgs e) {

29 | P a g e Department Of Electronics and Communication Engineering

Page 30: digital oscilloscope

PC-BASED DIGITAL OSCILLOSCOPE

try { System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.EnableRaisingEvents = false; proc.StartInfo.FileName = Application.StartupPath + "\\resistance.exe"; proc.Start(); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.Source); } }

private void TabPage1_Click(object sender, EventArgs e) {

}

}}

30 | P a g e Department Of Electronics and Communication Engineering

Page 31: digital oscilloscope

PC-BASED DIGITAL OSCILLOSCOPE

FUTURE WORK Clearly there is a lot of additional development work that can be done to improve

the design of this low cost PC-based quad channel real-time / storage oscilloscope. This chapter will briefly highlight areas of the design that merits improvement and additional features to make the scope more powerful, reliable, flexible, and commercially marketability.Control Protocol

Obviously the first thing that needs to be finished, is the control protocol allowing for the scope program to directly control the sample rate, enable / disable channels, real-time / storage mode, chop or alternate, etc… .

Storage ModeSample a finite number of samples storing them into RAM. Once the memory is full

(or the preset number of samples has been reached) the PIC will stop sampling and transfer the data to the PC, when ACK (acknowledgement) is received from the PC the PIC will start sampling again. There is enough information contained in this report to implement this feature, clearly the scope program and PIC software needs modification.

TCP / IP Internet CommunicationsRemote monitoring / control of oscilloscope from anywhere in world, for example

the machine actually connected to the scope hardware (running in slave mode) relays real-time data through the internet using the TCP / IP internet protocol, the scope program on the other end (master program), receives the data and draws the waveforms as normal. The scope program operating in slave mode has its controls disabled, hence only the master scope program controls the PIC, via the internet and via the slave scope program. Problem the internet (unless using broadband technology, e.g. ASDL, fibre optic) is slow and commonly suffers from net congestion, hence this feature is only useful for slow sampling rates, unless storage mode is used. For example an ECG signal only requires a sample rate of 120 Hz, clearly the internet is capable of transferring this data in real-time without any problems, hence a doctor can remotely diagnosis an ECG signal in real-time.

31 | P a g e Department Of Electronics and Communication Engineering

Page 32: digital oscilloscope

PC-BASED DIGITAL OSCILLOSCOPE

SUMMARY AND CONCLUSION

FEATURES

Displays on PC various analog waveforms like 1) Sine2) Triangular3) rectangular

Computes and display circuit parameters like1) Capacitance2) Voltage3) Resistance4) Current

Plug and play USB interface to PC

Main Advantages of Digital over Analogue Scopes

• The ability to observe slow and very slow signals as a solid presentation on the screen.

The PCBO has a very interactive GUI making it more convenient to use than conventional oscilloscopes. The circuit is extremely cheap and easy to make.

Possible Applications For This Pc Based Oscilloscope: -

Monitoring of sound waves, which are difficult to monitor on a traditional oscilloscope due to the low frequencies involved.

Monitoring of an ECG signal, again because this is such a low frequency traditional oscilloscopes would have difficultly monitoring such a signal. ECG data could be logged and emailed directly to the doctor for diagnosis, or perhaps real-time TCP/IP internet communication so that the doctor could remotely monitor the ECG signal in real-time.

Monitoring of serial communications, for example RS485 works on the principal of differential voltages between two cables twisted together; hence the PC based oscilloscope could be used to view serial communications. Two oscilloscope channels would be used, and the PC software will automatically add the two channels together producing a virtual trace (A+B). Note this PC based oscilloscope is also suitable for RS422 communication where there are separate transmit and receive lines (2 sets of differential twisted par cables), hence all four scope channels can be used producing two virtual traces (VC1 = CH1 + CH2, VC2 = CH3 + CH4). This monitoring of serial communication is extremely useful for educational usage (e.g. learning how serial data is transmitted).

32 | P a g e Department Of Electronics and Communication Engineering

Page 33: digital oscilloscope

PC-BASED DIGITAL OSCILLOSCOPE

The PC based oscilloscope is ideal for demonstration purposes, for example using data projector a class of student could be introduced to the oscilloscope, with real waveforms being monitored (signal generator, or even a microphone for sound waves) and displayed on a large projector display.

Because of the low cost of the PC based oscilloscope, it is economical for a school / technical college to have large quantities available for students. Unlike traditional analogue scopes which are expensive and students are forced to share equipment, because it is not economical to purchase enough scopes for every student.

33 | P a g e Department Of Electronics and Communication Engineering

Page 34: digital oscilloscope

PC-BASED DIGITAL OSCILLOSCOPE

REFERENCES

http://xoscope.sourceforge.net http://www.datasheetcatalog.com/datasheets_pdf/A/D/C/0/ADC0804.shtml http://www.datasheetcatalog.com/datasheets_pdf/7/4/L/S/74LS245.shtml http://parapin.sourceforge.net/doc/parapin.html http://tomcat.apache.org/download-55.cgi http://www.codecomments.com/archive248-2004-4-182225.html http://www.stardeveloper.com/articles/display.html?article=2003090401&page=1 http://www.frank-buss.de/echoservlet/ http://www.yolinux.com/TUTORIALS/LinuxTutorialPosixThreads.html http://www.dgp.toronto.edu/~mjmcguff/learn/java/07-backbuffer/ The Complete Reference JAVA 2 By Herbert Schildt, McGraw Hill Publishers. http://www.j-nine.com/pubs/applet2servlet/index.htm http://forum.java.sun.com/thread.jspa?forumID=48&threadID=391594 http://forums.fedoraforum.org/showthread.php?t=47591&highlight=tomcat http://www.developer.com/java/data/article.php/3417381 http://www.sci.usq.edu.au/staff/leighb/graph/ http://javaboutique.internet.com/educational/ http://tecfa.unige.ch/guides/java/staf2x/ex/jdbc/coffee-break/ http://javaboutique.internet.com/SimplePlot/source.html http://www.csupomona.edu/~pbsiegel/www/stujav.html http://servlets.com/jservlet2/examples/ch10/index.html

34 | P a g e Department Of Electronics and Communication Engineering