Personal tools
User menu

Difference between revisions of "Simple USB Oscilloscope"

From Francois Louw

Jump to: navigation, search
(Created page with "<metadesc>Simple USB Oscilloscope</metadesc> <metakeywords>USB, Oscilloscope, PIC32, microchip, pic, pic32mx220, libusb, qt, windows, firmware, c, qwt, hobby</metakeywords> [[...")
 
Line 9: Line 9:
 
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 one myself.
  
'''Note: This is not a high speed high precision replacement for a professional oscilloscope. This is meant for hobbyists who doesn'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==
 
==Specifications==
Line 44: Line 44:
  
 
[[File:placeholder.png|left|300px]]
 
[[File:placeholder.png|left|300px]]
 +
<br clear=all>
  
 
There are no PCB layout or gerber files, this is simple enough so that anyone can implement their own PCB. Or just use strip board.
 
There are no PCB layout or gerber files, this is simple enough so that anyone can implement their own PCB. Or just use strip board.
 +
 +
The analog input part is a simple offset and divider circuit. It divides the input voltage into a range of 3.3 Volts and offsets it to allow negative input voltages.
  
 
==Firmware==
 
==Firmware==
Line 53: Line 56:
 
'''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'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.'''
  
The firmware is very simple. I have two 3kB circular buffers, each for one channel. The PIC samples the A2D at 20000 times per second. Every read gives a value for both channels. This results in a sampling rate of 20KHz per channel.
+
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 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 60: Line 63:
  
 
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. This results in a max of 61 bytes of data (61 samples) per packet to be sent to the computer.
 +
 +
==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.
 +
 +
You also need LibUSB-win32 that you can find [http://sourceforge.net/projects/libusb-win32/files/libusb-win32-releases/1.2.6.0/ here].
 +
 +
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.
 +
 +
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.
 +
 +
===Interface Software===
 +
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.
 +
 +
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.
 +
 +
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!
 +
 +
==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)
 +
 +
*Install MPlabX and XC32
 +
*Program Firmware on PIC
 +
*Download and uncompress libUSB-win32
 +
*Create driver set
 +
*Install drivers
 +
*Install and configure Qt and MinGW
 +
*Install QWT
 +
*Compile Windows software
 +
 +
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!
 +
 +
==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.'''

Revision as of 06:26, 18 April 2013