Personal tools
User menu

Difference between revisions of "Simple USB Oscilloscope"

From Francois Louw

Jump to: navigation, search
(Hardware and Schematic)
 
Line 7: Line 7:
 
__TOC__
 
__TOC__
 
----
 
----
==A Simple USB Oscilloscope==
+
=A Simple/DIY USB Oscilloscope=
I have at many times wished that I had an oscilloscope. Given the prices, and shipping costs they are a bit too expensive for just hobbyist jobs. I have looked at USB oscilloscopes that are currently available, but starting at around $50 for one, that has a bit too high claims of sensing speed and accuracy, I realised that it will be a good weekend project to create one myself.
+
I have at many times wished that I had an oscilloscope. Given the prices, and shipping costs they are a bit too expensive for just hobbyist jobs. I have looked at USB oscilloscopes that are currently available, but starting at around $50 for one, that has a bit too high claims of sensing speed and accuracy, I realised that it will be a good weekend project to create a DIY USB Oscilloscope.
  
 
'''Note: This is not a high speed high precision replacement for a professional oscilloscope. This is meant for hobbyists who don't want to spend $50+ on something that is worth only $5. If you need professional quality readings, then get a proper oscilloscope.'''
 
'''Note: This is not a high speed high precision replacement for a professional oscilloscope. This is meant for hobbyists who don't want to spend $50+ on something that is worth only $5. If you need professional quality readings, then get a proper oscilloscope.'''
  
==Specifications==
+
[[File:Simple_USB_Scope.jpg|left|350px]]
 +
<br clear=all>
 +
 
 +
It's not pretty but it works!
 +
 
 +
=Specifications=
 
The goal was to create an Oscilloscope that is good enough for my ECU prototyping. Here are a list of the specifications for what I wanted.
 
The goal was to create an Oscilloscope that is good enough for my ECU prototyping. Here are a list of the specifications for what I wanted.
  
Line 28: Line 33:
 
Ok, well, all of that is good, except, as most projects go, the timeframe of just weekend didn't work, so in the end it took me 5 days to get it sorted. There are still a few minor bugs in the Windows code, and inefficient coding. But it works 100%!
 
Ok, well, all of that is good, except, as most projects go, the timeframe of just weekend didn't work, so in the end it took me 5 days to get it sorted. There are still a few minor bugs in the Windows code, and inefficient coding. But it works 100%!
  
==Hardware and Schematic==
+
=Hardware and Schematic=
 
The following is a bill of materials of what I used:
 
The following is a bill of materials of what I used:
 
*Microchip PIC32MX220F032B
 
*Microchip PIC32MX220F032B
 
*20MHz Crystal
 
*20MHz Crystal
 
*USB Cable
 
*USB Cable
*100nF Capacitor
+
*3.3V Low Drop Off Regulator
*2x 10nF Capacitor
+
*3mm LED
*4.7K Resistor
+
*ICSP Header
*Some other resistor values
+
*2x  10uF Capacitor
 +
*1x 100nF Capacitor
 +
*2x 10nF Capacitor
 +
*1x  4.7K Resistor
 +
*1x  1.0K Resistor
 +
*2x  1.8K Resistor
 +
*2x  2.5K Resistor
 +
*2x  8.2K Resistor
 
*Crocodile Clamp Cables
 
*Crocodile Clamp Cables
 
*Prototyping board (strip board)
 
*Prototyping board (strip board)
  
'''Note: Do not use the prototyping bread boards, where you can plug in and out the wires. They are horrible and especially with USB should not be used. They are basically and array of tiny antennae in there that pics up noise the whole time! If you use them and this doesn't work, then don't blame me! When using Strip Board, make sure to cut the tracks as short as possible on the underside to prevent noise.'''
+
'''Note: Do not use the prototyping bread boards, where you can plug in and out the wires. They are horrible and especially with USB should not be used. They are basically and array of tiny antennae in there that picks up noise the whole time! If you use them and this doesn't work, then don't blame me! When using Strip Board, make sure to cut the tracks as short as possible on the underside to prevent noise.'''
  
 
Here is the schematic.
 
Here is the schematic.
  
[[File:placeholder.png|left|300px]]
+
[[File:USBScopeSchematic.jpg|left|700px]]
 
<br clear=all>
 
<br clear=all>
  
Line 53: Line 65:
 
The voltage regulator is a simple linear low drop off regulator from ST Microelectronics. Any other regulator can also be used to drop the voltage to 3.3V.
 
The voltage regulator is a simple linear low drop off regulator from ST Microelectronics. Any other regulator can also be used to drop the voltage to 3.3V.
  
==Firmware==
+
=Firmware=
  
To create the firmware I used MPLabX 1.60 with Microchip's XC32 V1.20 Compiler. This was programmed with the ICD3 programmer/debugger. I also used Microchip's Application Library 2013-02-15 USB Stack. The USB mode used is the LibUSB Generic Driver.
+
To create the firmware I used MPLabX 1.60 with Microchip XC32 V1.20 Compiler. This was programmed with the ICD3 programmer/debugger. I also used Microchip's Application Library 2013-02-15 USB Stack. The USB mode used is the LibUSB Generic Driver.
  
'''NOTE: The USB VID and PID that I use are Microchip's VID and an arbitrary chosen PID to differentiate between my other projects. I am not licensed to use that PID. Do not use that PID! I have requested a PID from Microchip, but have not yet received a response.'''
+
'''NOTE: The USB VID and PID that I use are Microchip VID and an arbitrary chosen PID to differentiate between my other projects. I am not licensed to use that PID. Do not use that PID! I have requested a PID from Microchip, but have not yet received a response.'''
  
The firmware is very simple. I have two 3kB circular buffers, each for one channel. The PIC samples the A2D every 4000 cpu ticks. The PIC is running at 50MHz, meaning every tick is 0.02uS and 4000 ticks are 80uS. This gives a sampling rate of 12500 samples per second, or 12.5KHz. Every read gives a value for both channels.  
+
The firmware is very simple. There are two 3kB circular buffers, each for one channel. The PIC samples the A2D every 4000 cpu ticks. The PIC is running at 50MHz, meaning every tick is 0.02uS and 4000 ticks are 80uS. This gives a sampling rate of 12500 samples per second, or 12.5KHz. Every read gives a value for both channels.  
  
 
The LED is used as an indicator of when the buffers are full. (Used to show if your computer is reading it too slow)
 
The LED is used as an indicator of when the buffers are full. (Used to show if your computer is reading it too slow)
Line 65: Line 77:
 
The main loop is used to send the channel data alternating between channel 1 and 2, emptying the buffers. Timer1 is used to interrupt the main loop, sample the data and add data to the buffer.
 
The main loop is used to send the channel data alternating between channel 1 and 2, emptying the buffers. Timer1 is used to interrupt the main loop, sample the data and add data to the buffer.
  
USB Packet structure is done first by writing the endpoint 0x81, then the packetsize, then the channel number. This results in a max of 61 bytes of data (61 samples) per packet to be sent to the computer.
+
USB Packet structure is done first by writing the endpoint 0x81, then the packetsize, then the channel number followed by samples. This results in a max of 61 bytes of data (61 samples) per packet to be sent to the computer.
  
==Windows Software==
+
=Windows Software=
 
This part is a bit more difficult. I have used Qt 4.7, with MinGW, and QWT 6.1.0rc3. Qt can be found [http://qt-project.org/downloads here] with MinGW. QWT for Qt can be found [http://qwt.sourceforge.net/ here]. '''Follow the QWT Installation instructions to the letter!''' Please don't contact me if you cant get QWT to work, search on the internet and on forums.
 
This part is a bit more difficult. I have used Qt 4.7, with MinGW, and QWT 6.1.0rc3. Qt can be found [http://qt-project.org/downloads here] with MinGW. QWT for Qt can be found [http://qwt.sourceforge.net/ here]. '''Follow the QWT Installation instructions to the letter!''' Please don't contact me if you cant get QWT to work, search on the internet and on forums.
  
Line 74: Line 86:
 
After compiling and loading the firmware on the PIC, plug it into the computer and then Windows will search for drivers. Point windows to the drivers found in this projects download section. Or alternatively if you have changed the PID value, then you need to uncompress the LibUSB-win32 and in the bin folder you need to run inf-wizard.exe to create a driver set for your device.
 
After compiling and loading the firmware on the PIC, plug it into the computer and then Windows will search for drivers. Point windows to the drivers found in this projects download section. Or alternatively if you have changed the PID value, then you need to uncompress the LibUSB-win32 and in the bin folder you need to run inf-wizard.exe to create a driver set for your device.
  
The Qt software links dynamically to the libusb driver. Ensure that the drivers are installed successfully and that you have a LibUSB-win32 device in device manager.
+
The Qt software links dynamically to the libusb driver. Ensure that the driver is installed successfully and that you have a LibUSB-win32 device in device manager.
  
 
When running the Qt Interface application there are two calibration values. The first value is the offset, and the second is the full range divider. To calculate these values, connect the input signal to the ground wire and adjust Cal1 until the graph displays 0. Then connect the input signal to the 3.3V regulated voltage of the PIC. Adjust the Cal2 value unitl it shows 3.3V. '''Do not use the USB 5V as a reference. The USB voltage is 5.1-5.2V most of the time and not precise 5V.''' Remember this device uses 5% or 10% resistors, meaning that the calibration is not perfect. Some nonlinear effects may be observed.
 
When running the Qt Interface application there are two calibration values. The first value is the offset, and the second is the full range divider. To calculate these values, connect the input signal to the ground wire and adjust Cal1 until the graph displays 0. Then connect the input signal to the 3.3V regulated voltage of the PIC. Adjust the Cal2 value unitl it shows 3.3V. '''Do not use the USB 5V as a reference. The USB voltage is 5.1-5.2V most of the time and not precise 5V.''' Remember this device uses 5% or 10% resistors, meaning that the calibration is not perfect. Some nonlinear effects may be observed.
  
The Windows application sets up the display, and then generates a thread to read the USB. This separate thread is necessary because the QWT display routines are blocking and slow. Without the separate thread the USB reading is too slow.
+
The Windows application sets up the display, and then generates a thread to read the USB. This separate thread is necessary because the QWT display routines are blocking and slow. Without the separate thread the USB reading is too slow and the PIC buffers will overflow.
  
Global circular buffers are used to read the data periodically then display them. The display updates at 10Hz. More updates slows down the system. Due to the nature of Qt and QWT libraries the QWT display needs to run in its own thread.
+
Global circular buffers are used to read the data periodically then display them. The display updates at 10Hz. More display updates slows down the system. Due to the nature of Qt and QWT libraries the QWT display needs to run in the main application thread.
  
 
The USB reading can be optimised further, I was just lazy and this works. If anyone updates it and improves send me the code then I will integrate it or I can link to your site!
 
The USB reading can be optimised further, I was just lazy and this works. If anyone updates it and improves send me the code then I will integrate it or I can link to your site!
Line 86: Line 98:
 
Here is a screenshot of both channels reading signals
 
Here is a screenshot of both channels reading signals
  
[[File:Simple_USB_Scope_Screenshot.jpeg|center|500px]]
+
[[File:Simple_USB_Scope_Screenshot.jpeg|center|700px]]
 +
<br clear=all>
  
==Everything Together==
+
=Everything Together=
 
When you add everything together, you have a simple but effective USB oscilloscope that is good enough for everyday projects. As a Checklist remember to do the following (preferably in order)
 
When you add everything together, you have a simple but effective USB oscilloscope that is good enough for everyday projects. As a Checklist remember to do the following (preferably in order)
  
Line 102: Line 115:
 
I hope that you enjoy the scope! I am very interested in people using this or improving it. Let me know if you use this then I will add a link to your implementation!
 
I hope that you enjoy the scope! I am very interested in people using this or improving it. Let me know if you use this then I will add a link to your implementation!
  
Here is a small Youtube Video of the USB Oscilloscope in action!
+
Here is a small Youtube Video of the USB Oscilloscope in action! I connected the headphone output of the computer to the two channels (left and right) and played music. There is no audio because no audio came out of the computer.
[[File:placeholder.png|left|300px]]
+
 
<br clear=all>
+
{{#ev:youtube|o_BagGRptk8}}
 +
 
 +
 
 +
As stated before, the software has major room for improvement, and maybe someday I will get round to do it. But in the meantime, feel free to use this and improve! Remember to link to this site and share your design!
  
==Download==
+
=Download=
'''Everything here is provided under the [Gplv3] licence. Do not claim this as your own, do not make money from this, release your version also as open source. Give back to the community.'''
+
'''Everything here is provided under the [[Gplv3]] licence. Do not claim this as your own, do not make money from this, release your version also as open source. Give back to the community.'''
  
 
[http://aeif.info/files/usbscope/binaries.zip Precompiled Firmware, drivers and Windows software.] This is the complete binary package, you don't have to install Qt, QWT, MinGW or compile anything.
 
[http://aeif.info/files/usbscope/binaries.zip Precompiled Firmware, drivers and Windows software.] This is the complete binary package, you don't have to install Qt, QWT, MinGW or compile anything.

Latest revision as of 12:03, 24 July 2014