DPScope - Build Your Own USB/PC-Based Oscilloscope
544401 Views, 507 Favorites, 0 Comments
DPScope - Build Your Own USB/PC-Based Oscilloscope
If you have questions, feel free to contact me directly at
Email: mailto:dpscope.contact@gmail.com (dpscope.contact@gmail.com)
You might also want to visit my DPScope website at: Webpage: http://dpscope.freevar.com/
From there you can also download the PC software, user manual and a lot of other documentation.
Instrument Specifications
Below you see the specifications of the instruments. If you are familiar with oscilloscopes you will see that the DPScope has pretty much all the features you'd expect from a decent lower-end instrument.
If you aren't a number freak, feel free to skip this page as fast as you can :-)
On the next page I'll discuss a few of the key specifications.
Input:
Number of channels: 2
Analog bandwidth: > 1.3 MHz
Input impedance: 1 MOhm || 15 pF
Probe connection: BNC
Usable probe types: Standard 1:1, 1:10, 1:20 probes
Vertical (voltage) scale:
Vertical sensitivity (20 divisions):
- 5 mV/div to 1 V/div (1:1 probe)
- 50 mV/div to 10 V/div (1:10 probe)
- 100 mV/div to 20 V/div (1:20 probe)
Vertical offset: 0 - 20 divisions
Maximum voltage range
-12V ... 20V (1:1 probe)
-120V ... +200V (1:10 probe)
-240V ... +400V (1:20 probe)
Probe compensation: yes (2 kHz calibration output)
Offset adjustment: yes
Horizontal (time) scale:
Max. sample rate (single shot): 1 MSample/sec
Max. sample rate (repetitive signals): 20 MSamples/sec
Timebase settings (scope mode): 0.5 usec/div ... 1 sec/div
Timebase settings (datalogger/roll mode): 0.5 sec/div ... 1 hr/div
Trigger:
Trigger source: CH1, CH2, auto (free run)
Trigger polarity: rising edge, falling edge
Trigger noise reject: yes (selectable)
Pre-trigger capability (i.e. can show what happened
before the trigger event): 0 - 20 divisions
Post-trigger delay (delayed scan, to look at the
signal long after the trigger event but with high
resolution): 0 - 200 divisions
Acquisition:
Record length (normal mode): 200 points/channel
Record length (FFT mode): 400 points/channel
Max. screen refresh rate: up to 40+ frames/sec
Datalogger mode (roll mode): yes (data can be logged to file in real time)
Display:
Real-time FFT: yes
FFT filters: Rectangular, Hanning, Hamming, Blackman
Averaging: yes (2 / 5 / 10 / 20 / 50 / 100)
X-Y mode: yes
Display styles (can be combined): Points, Vectors (Lines), Infinite Persistence
Time and level measurements: yes (using cursors)
Save & Restore:
Waveform export (e.g. to Excel):yes (CSV format)
Save/restore of scope setups: yes
PC Software:
PC connection: USB, 500 kbaud
PC software: Windows 2000, XP (SP3), Vista, 7
Minimum screen size: 800 x 600 pixel
Mechanical construction:
Power supply: through USB (5V / 250mA)
(external supply 7.5 - 9V / 300mA optional)
Approx. size (in enclosure): 4.5" x 2.6" x 1.2" (114 mm x 66 mm x 31 mm)
Component count: ~50
Solder connections to make: ~200
Required skill level for assembly: moderate; only through-hole components and DIP
packages (no surface mount or fine pitch parts)
Printed circuit board: Professional printed circuit board with corrosion-resistant, gold-plated pads and contacts (not cheap solder finish), with silkscreen
to denote component locations.
Enclosure: Sturdy ABS plastic enclosure with custom glass-fiber front- and back-panel, silkscreen. All
holes pre-drilled - no drilling required.
Microcontroller and USB interface: Fully pre-programmed; no programming required
Key Specs
First, it is a two-channel instrument. This is a very important feature. Many low-end oscilloscopes offer only a single channel, which is a severe handicap: It doesn't allow you to look at two signals in relation to each other (e.g. clock signal and data signal), e.g. to see which one changes first and by how much. It also prevents you from triggering on a signal different from the one you want to look at. Thus I consider two channels an absolute must for any serious oscilloscope; everything else is a toy, not a real instrument.
Second, the bandwidth - the DPScope has about 1.3 MHz. While that may sound small compared to "big iron" scopes, it actually is quite usable for a large variety of tasks (in parentheses I show the approximate maximum frequency in the particular application):
- audio (20 kHz)
- infrared remote control signals (38 kHz)
- ultrasound (200 kHz)
- servo signals (a few kHz)
- bio signals, medical instruments (< 100 Hz)
- I2C (1 MHz)
- RS-232 (115 kHz)
- one-wire
- SPI (as long as <= 1 MHz)
The capture rate is a very important measure as well; it needs to be fast enough so ideally you instantly any changes on the signal or to the scope settings - this makes for a very responsive feel during practical use of the scope. Now that means it should at least be around 15 - 20 records per second (your eye isn't much faster than that anyway). The DPScope manages to do around 35 - 40 frames/sec (assuming a sufficiently fast timebase setting), so passes that criterion easily.
The DPScope also offers a datalogger mode (roll mode) for slow sample rates (between 10 samples/sec and 1 sample/hour); in that mode the waveform continuously scrolls to the left, and you can record it directly into a file. That's very useful to record slow-varying signals, e.g. temperature.
But now let's dive into the design, and start with some pictures!
Design Overview
The analog-to-digital converters (ADCs) take the analog signals and convert them into digital numbers. The sample logic controls the sampling process and the storage of the converted data in the capture memory. The trigger circuitry decides when to start the sample process.
The controller takes care of setting signal gains and offset, setting up the sample logic, selecting trigger source, trigger level, and trigger polarity, and communicating the the PC.
As you can see, the dsPIC30F2020 microcontroller allows to implement most of it without external circuitry - controller, memory, sample logic, analog-to-digital converter (ADC), trigger and trigger level control all reside within a single chip. This makes the design very compact, inexpensive, and easy to build.
USB interface to the PC as well as power supply for the scope are provided by the FTDI232R serial-to-USB converter cable - again a very user-friendly solution since there is nothing to assemble.
Circuit Schematic
If you want to get the schematic with better resolution (which is much easier to read), you can download it in PDF format.
Input Stage / Analog Frontend (part 1)
First, the incoming signal is attenuated by a factor of 4. This increases the maximum voltage range to 20V. Since the subsequent circuits cannot deal with negative voltage (to keep the circuit simple, the scope has only a single +5V supply and no negative supply), the only way to measure negative signals is to shift them up with a programmable offset voltage (between 0 and 4 V) provided by a digital-to-analog converter (shown later). This way the scope can display voltages between -12V and +20V max with a 1:1 probe (-120V to +200V with a 1:10 probe - but be VERY CAREFUL whenever working with such high voltages!).
The offset is fed in on the bottom of the voltage divider (between C12 - which buffers fast transients - and R2).
The input divider deserves some further consideration. It is a so-called compensated attenuator and consists of a combination of a fixed ohmic divider (R1 and R2) and an adjustable capacitive divider (C19 and C6). The reason for adding the capacitive divider is the fact that the protection diodes (D1 and D2) as well as the input of the op-amp (OP1.1) have some unavoidable parasitic capacitance in the order of a few pF. With only R1 and R2 this would create a low-pass R-C filter (the divider feeding the parasitic capacitance which would need some time to charge up), severely limiting the achievable bandwidth.
Quick estimate: output impedance of the divider is R1 || R2 = 187 kOhm, parasitic C_par maybe 20 pF, that would give a time constant of 187k * 20p = 3.74us and a bandwidth of just 0.35/3.74 = approx. 90 kHz). This is much too low for our scope!
The solution - if you can't beat them, join them. Adding the capacitive divider and adjusting it to the same division ratio (1:4) as the resistive divider makes the frequency response flat from DC to light (at least in theory - but close enough for our purpose). The necessary condition is:
(C6 + C_par) / C19 = R1 / R2
Adjustment is done with C19. Since nothing comes for free in life, it's not surprising there is a price to pay - the capacitive divider causes the scope's input impedance to drop for higher frequencies. Still this is a worthwhile tradeoff and thus such a compensation can be found in virtually every oscilloscope.
Input Stage / Analog Frontend (part 2)
conduction as well as in recovery) and have low input capacitance. On the other hand, given the high input resistance value (750 kOhm) they don't need to shunt a lot of current even at large
overvoltages at the scope input.
The signal is then fed into a simple op-amp follower stage (OP1.1, which is one of the four op-amps inside the Microchip MCP6024). This buffering is also necessary because the following stage (the MCP6S22 programmable-gain amplifier or PGA) does not react kindly to an input source with too high an impedance - wild oscillations would be the result (yes, I tried and it is true!). The input divider's output impedance (R1||R2) is around 187 kOhm while the PGA requires a source impedance of less than 1 kOhm.
The buffered signal drives one of the PGA's inputs (CH0) directly, and also feeds the input of a 1:10 gain stage that produces a signal amplified by 10, which in turn goes to CH1 of the PGA. That way the PGA can choose between less pre-amplification for large input signals, and large amplification for small signals. The PGA has a specified bandwidth (not gain-bandwidth product!) of between 2 and 12 MHz (depending on amplification setting), so we are in safe territory here; the scope actually uses only gain settings of 1, 2, 5, and 10 - according to my experiments higher settings (up to gain = 32 would be possible) are quite sensitive and tend to exhibit excessive noise (an indication that oscillation may not be far away).
The MCP6024 has a gain-bandwidth product of 10 MHz, which is more than sufficient for the buffer stage (gain = 1, so BW = 10 MHz), but marginal for the gain=10 stage (OP1.2) - we can only expect ~1 MHz of bandwidth here, and the other stages (buffer stage, PGA, ADC inside the microcontroller) will further reduce that number somewhat. For that reason I added C14 which increases the gain at higher frequencies. It is chosen so that the gain increase starts approximately at the frequency where otherwise the gain would start to drop off, that way the flat gain region is extended to higher frequencies. On my prototypes I measured a gain-stage bandwidth of around 800 kHz without this compensation but almost 1.3 MHz with C14 in place - quite some bang (50% improvement) at virtually no cost! Its effect is also clearly visible - much faster settling transitions - when using the scope to look at a fast-rising square wave. Ideally C14 would be adjustable, but its value is not overly critical so I stuck with fixed 100pF which was very close to the optimum I determined experimentally as well as by simulating the stage with Microchip's free Spice tool. If C14 were too larger, overshoot would occur.
The resistor trimmer (VR1) is here to allow minor offset adjustments in the high-gain path. The main reason for this is leakage current through the clamp diodes (D1, D2) which introduces a small positive offset onto the signal. This offset is small, but becomes noticeable when multiplied by 10. (VR1 also impacts the exact gain, but the effect is small enough to be ignored (less than 1%), especially when compared to the tolerances of the gain-setting resistors (R7, R8).
Input Stage / Analog Frontend (part 3)
channel gain (amplification) without any moving parts like relays. This reduces cost, component count, size, and improves reliability (no mechanical wear-out) at the same time. The only reason I can see why this isn't more widely used in other oscilloscopes is that there aren't many PGAs available for very high bandwidths (several 100 MHz or even GHz). But for the DPScope with it's design goal of 1 MHz or maybe slightly above this is just what the doctor ordered - the PGA's minimum specified gain is 2 MHz.
Since the two selectable inputs of the PGA are fed with signals differing by a factor of 10, with the PGA we can effectively choose a total amplification of 1, 2, 5, 10, 20, 50, and 100 only use gain settings 1, 2, 5, and 10.
The microcontroller controls the PGA through a standard SPI interface consisting of three signal lines - clock, data, and chip select.
The output of the PGA feeds the analog-to-digital converter (ADC) inside the dsPIC microcontroller. It also drives into a second input which goes to a comparator inside the dsPIC. This comparator creates an interrupt whenever the input voltage crosses a certain, programmable threshold in a pre-defined direction (rising or falling signal level, respectively; this is also called a rising - or falling - edge). The threshold voltage is generated by a 10-bit digital-to-analog converter (DAC) inside the dsPIC (it's amazing how much peripherals Microchip has put inside a single, inexpensive microcontroller - all this reduces cost and complexity of the scope a lot). Since the DAC can only produce up to 2.5V (i.e. half the maximum signal level), the easiest solution was to divide the incoming signal by two with a voltage divider (R14 and R15). That way the trigger threshold can be set anywhere within the incoming signal range.
Finally, on the right you see the external 12-bit digital-to-analog converter (DAC, a Microchip MCP4822) which sets the offset for the input signal. It has two independent output channels, one used for each of the two scope input channels. The microcontroller drives the DAC through the SPI interface as well (the dsPIC uses the chip selecty (CS) line of the respective device - DAC, PGA1 or PGA2 - to determine which device is getting the SPI data at any given time).
Microcontroller
First and most important, it has an analog-to-digital converter that can acquire samples at 2 MSamples/sec. At least that's what the spec seems to say at first glance. The reality is - it can acquire two channels simultaneously at 1 MSample/sec each, and the Microchip marketing guys simply added those two numbers... anyway, that's perfectly fine for us because we need two channels anyway. The ADC has a resolution of 10 bits, but in order to maximize acquisition speed and reduce memory requirements only the upper 8 bits get used (i.e. one byte per sample). The reason for using a 128 MHz clock is the same - at that speed the dsPIC is just barely fast enough to repeatedly sample two channels and store the data into internal memory at 1 MHz sample rate.
The analog bandwidth of the ADC is well above 1 MHz, so it's not a limiting factor in the signal chain. For sample rates faster than 1 MSample/sec - up to 20 MSamples/sec - the DPScope employs a technique called "equivalent time sampling" - basically it runs at 1 MSample/sec real sample rate and acquires only a subset of the data points at each sweep, and then overlays two or more subsequent sweeps (each with slightly increased start delay after the trigger) for a composite picture with higher effective timing resolution. You can read more details about this technique in the Tektronix application note "The XYZ of oscillscopes".
The second great feature of this microcontroller is a set of comparators with finely controllable threshold (10 bit resolution); most other Microchip devices have only very coarse compare threshold steps. These comparators are all we need to implement a full-blown scope trigger with adjustable threshold and selectable edge polarity (rising or falling edge, respectively), which cuts down on overall component count and thus cost and complexity.
The only sore point with this dsPIC is its small RAM size - just 512 bytes. Some of that is taken up by program overhead (e.g. global variables, parameter stack and so on), and it was a challenge to get at least 200 bytes per channel (actually 205, since this works out to 410 points for FFT - where only one channel as acquired at a time - and 410 is 4/5 of the 512 points needed for the FFT, which makes interpolating it to 512 points fairly straightforward); a future version of the scope may use a different dsPIC device (but right now there isn't any that has all the other features, runs at 5V, and is available in DIP package). Adding external RAM is not an option either - first, it would add cost and complexity, second, the dpPIC does not have enough output pins to control it, and third, at maximum sample rate there is no time for additional control tasks anyway. But 200 points is good enough for a full display, and in most applications the DPScope's delayed trigger capability provides exactly the same functionality that a longer capture memory would.
Finally, the dsPIC supports SPI and USART communication, which it uses to control the other devices in the DPScope (adjustable gain amplifiers, offset DAC) and communicate with the PC, respectively.
USB Interface, Power Supply
On the PC side there is a driver that emulates a RS-232 connection as well, so the scope application only has to deal with a standard serial connection, too. Data transfer rate is still a respectable 500 kBaud (the converter cable could go up to 1 Mbaud but the transmitted data volume is too small to really need full bandwidth - each record is approx. 0.5 KByte, so even at 40 frames/sec this amounts to just 20 KByte/sec or around 200 kBaud average serial data rate (note that each data byte needs a start bit and a stop bit, so for each byte actually 10 bits are sent).
The interface uses software handshaking (the scope responds to each transmission from the PC with an acknowledge packet), so while CTS and RTS are physically connected - just in case a later revision wants to use them - they are not used in the current design.
The converter cable also makes the USB port's 5V supply available. The DPScope needs about 250mA of supply current, a USB port can provide up to 500 mA, so the scope can get its power from the USB line and does not need an external power supply. One word of caution though, some USB ports have rather large variation in supply voltage (sometimes down to little more than 4V). In my experience this is mostly true when connecting to an unpowered USB hub or when many other power-hungry devices are connected to the same USB hub, so try to avoid this. The DPScope assumes a 5V supply and uses that as its voltage reference, so while it will function even at lower voltage, any deviation directly impacts its voltage accuracy. Some USB ports (laptops are notorious) are also quite noisy, this will show up as noise on the measured signals.
If you are absolutely unable to provide close to 5V from USB, or the USB supply turns out to be too noisy, then the DPScope allows to use an external power supply (7.5V/500mA). All you need to do is add the regulator (REG, a simple 7805 linear regulator) and a buffer capacitor (C5), hook up the power supply, and set the jumper (PWR_SEL) to "external supply". REG and C5 are very generic types and should be available in any hobby electronics store (and in any case are most likely already in your drawer).
Board Layout
The final layout is shown below. You can see that I placed the components in a logical order: To the left, close to the BNC probe connectors, is the input circuitry (attenuator, input amplifier, clampd diodes, probe compensation). In the middle is the offset DAC and the programmable gain amplifiers, follower by the dsPIC microcontroller. On the right finally you have the USB cable connector and the power supply. All the chips are placed in the same orientation (pin 1 is bottom left, notch is left) to minimize the chance for assembly mistakes.
As for the trace layout, the ground plane is a solid copper fill on the bottom plane - this minimizes supply inductance and provides some shielding against interference. The power supply traces are made pretty wide (50 mil / 2.25mm) since they carry considerable current, and again to minimize inductance. With some exceptions the top ayer carries the vertical traces, and the bottom layer the horizontal traces.
Now let's see how to build up this scope in practice!
Assembly - Tools
Assembly Step 1: Unpacking the Kit
Assembly Step 2: Components
Assembly Step 3 - Component List
Assembly Step 4 - Component Placement
Assembly Step 5: Installing the First Part - R19
Assembly Step 6: Soldering the First Part
Assembly Step 7: Next Components
Assembly Step 8: Remaining Resistors
Assembly Step 9: Capacitors
Note: Be careful when installing C9 – it has to be put in with correct polarity. The negative side of C9 is clearly labeled with a white stripe and “-” (minus) symbols – make sure you install it as shown in the pictures below with this white strip facing inwards on the PCB!
Assembly Step 10: Diodes
Assembly Step 11: Trimmers, Resonator, Jumper
Assembly Step 12: First Socket
(3) Press the socket onto the board and re-heat both of these solder joint – this allows the socket to sit flush against the board. Visually inspect the socket to make sure this is really the case.
(4) Only now solder all the other pins.
Assembly Step 13: Remaining Sockets
Assembly Step 14: BNC Connectors; Frontpanel
Assembly Step 14: BNC Connectors; Frontpanel
Only now solder the BNC connectors onto the board – start with the clamped-in feet, and finish with the signal wires. The clamped feet will need a lot of solder to fully fill up the mounting holes – don’t be shy, because that’s the only thing holding the PCB in place.
Assembly Step 15: LED Indicator
The frontpanel now holds the LED securely in place. Turn the board around and solder the LED’s legs onto the board.
Assembly Step 16: IC Installation
Note 2: There are two different types of the 8-pin ICs – make sure you install them in the correct locations as shown in the picture below. Installing them in the wrong place (or the wrong orientation) will destroy them when you power up the oscilloscope. You can distinguish the chips by the labels printed on them (two are labeled MCP6S22, one is labeled MCP4822).
Assembly Step 17: USB Cable
Assembly Step 18: Probe Calibration Output
Put the two terminal turrets (not shown) into the holes and solder them on. The long part of the turret points to the outside of the backpanel.
Assembly Step 19: Putting It All Together
Congratulations – your oscilloscope is fully assembled!
Assembly Step 20: Software Installation
• The oscilloscope software
First install the USB driver – follow the installation guide for that. Note that the installer will actually install two different drivers on your computer, i.e. go through two installation cycles. Make sure to complete both of them.
Then install the DPScope software as well (unpack the files and click on Setup.exe).
The DPScope’s frontpanel LED should blink a few times and then stay on. The blinking should last for about one second total. If that’s the case then your oscilloscope has just passed the first functional test!
Note 1: The DPScope software needs a screen resolution of at least 1024 x 768 pixels.
Note 2: It is recommended to connect the DPScope to a USB port of your computer itself, or to a powered USB hub. Unpowered hubs tend to have large voltage drops, and the DPScope’s level accuracy is dependent on a steady 5V supply voltage from the USB. You can test the voltage by connecting a voltmeter to the pins labeled “+” and “-” on the expansion header (bottom right on the PCB).
Assembly Step 21: Software Start
Now we need to make two simple adjustments to optimize the scope performance.
Assembly Step 22: Offset Adjustment
With a small screwdriver you can now adjust the offsets of the two channels:
Assembly Step 22: Offset Adjustment
Assembly Step 23: Probe Compensation
• In the “Levels” menu move the sliders “CH1” and “CH2” a bit below the middle.
• Connect the probes to the calibration outputs on the back side of the oscilloscope:
• In the DPScope window on your PC select Utilities à Probe Compensation. A small window with instructions will pop up.
• With a small non-metal screwdriver you can now adjust the probe compensation capacitors (C18 and C19, respectively).
• On the right side you see examples for overcompensated, undercompensated, and compensated probes.
• The adjustment is correct when the displayed signals are nice square waves with sharp corners, i.e. when there is neither overshoot (sharp peaks after each transitions) nor slow settling (rounded edges).
• At the same time, you have tested the scope’s acquisition circuitry.
Scope Software
One neat feature is the FFT (frequency display) mode - in this mode the software performs a real-time Fast Fourier Transform (FFT) on the data, so you see the frequency spectrum of the signal(s). This is a great tool e.g. to pinpoint small periodic noise that would be difficult to see in the normal scope display, and also to acquire an intuitive feel for the frequency domain.
Another mode is the X-Y-mode where you plot one signal versus the other (instead of both signals versus time). This allows quick characterization of components and phase shifts.
For a detailed description you should download the DPScope User Manual.
Attached below are a few screenshots that show the DPScope in action.
All Done!
Now put the bottom cover on the instrument and screw it shut with the four Philips screws.
Webpage: http://dpscope.freevar.com
From there you can also download the PC software, user manual, drivers, and other documentation.
If you still have questions do not hesitate to contact me at mailto:dpscope.contact@gmail.com (dpscope.contact@gmail.com)