Personal tools
User menu

Difference between revisions of "Simple USB Oscilloscope"

From Francois Louw

Jump to: navigation, search
(Hardware and Schematic)
Line 55: Line 55:
 
==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 arae 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 65:
 
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==
Line 74: Line 74:
 
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 105: Line 105:
 
[[File:placeholder.png|left|300px]]
 
[[File:placeholder.png|left|300px]]
 
<br clear=all>
 
<br clear=all>
 +
 +
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==

Revision as of 07:02, 18 April 2013