Professional Documents
Culture Documents
Pc-Based Digital Oscilloscope Using Pic Microcontroler: Main Project Report On
Pc-Based Digital Oscilloscope Using Pic Microcontroler: Main Project Report On
Pc-Based Digital Oscilloscope Using Pic Microcontroler: Main Project Report On
MAIN PROJECT
REPORT ON
PC-BASED
DIGITAL OSCILLOSCOPE
USING
PIC MICROCONTROLER
ABSTRACT
TABLE OF CONTENTS
1. INTRODUCTION 4
2. FUNDEMENTALS 5
2.1 THE BASIC CRT OSCILLOSCOPE 5
2.2 DIGITAL SAMPLING OSCILLOSCOPES 7
4. HARDWARE DEVELOPMENT 14
5.1 SIMPLIFIED BLOCK DIAGRAM 14
5.2 DESCRIPTION 15
5.3 DIGITAL CIRCUIT DIAGRAM 18
5.4 FLOWCHART 19
6. FUTURE WORK31
7. SUMMARY AND CONCLUSION 32
8. REFERENCES 34
INTRODUCTION
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
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)
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.
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.
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).
ANALOG
CIRCUITRY
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.
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.
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.
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 ADCON0 register, shown below, controls the operation of the A/D module.
The ADCON1 register, shown below, configures the functions of the port pins.
The ADCON2 register,shown below, configures the A/D clock source, programmed acquisition time
and justification
bit 7 ADFM: A/D Result Format Select bit bit 2-0 ADCS2:ADCS0: A/D Conversion Clock
1 = Right justified Select bits
0 = Left justified 111 = FRC (clock derived from A/D RC
bit 6 Unimplemented: Read as ‘0’ oscillator)(1)
bit 5-3 ACQT2:ACQT0: A/D Acquisition Time 110 = FOSC/64
Select bits 101 = FOSC/16
111 = 20 TAD 100 = FOSC/4
110 = 16 TAD 011 = FRC (clock derived from A/D RC
101 = 12 TAD oscillator)(1)
100 = 8 TAD 010 = FOSC/32
011 = 6 TAD 001 = FOSC/8
010 = 4 TAD 000 = FOSC/2
001 = 2 TAD
000 = 0 TAD(1)
HARDWARE DEVELOPMENT
SIMPLIFIED BLOCK DIAGRAM
OSCILLOSCOPE
Oscilloscop PROBE ANALOG ADC (10 bit
e PROBE CIRCUITRY
SELECTION resolution)
(vertical lift)
PIC18F2550 Personal
VOLTAGE USB interface
MICROCONTROLLER Computer
Measureme
nt
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
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.
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.
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.
FLOWCHART
start
Initialize
Ports
If scope mode=1
NO If Pin 11 = 0 NO
NO If Voltage =3.14V
yes
Stop
Timer
Read timer
Value
Output To
PC
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);
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';
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);
int X, Y;
byte buff0, buff1, buff2, buff3;
public Sniffer()
{
InitializeComponent();
}
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());
}
}
//MessageBox.Show(rec_data , "Char");
/* if (myData.ToString().Length == 1)
{
rec_data += "00";
}
if (myData.ToString().Length == 2)
{
rec_data += "0";
}
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);
}
}
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)
{
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, ex.Source);
}
}
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);
}
}
}
}
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 Mode
Sample 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.
• 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.
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.
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.
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