Microcontroller
This project was started to create a basic oscilloscope using a PIC18F4550 and an on chip analog to digital converter to obtain sample voltage data. A MMA7455LR1 accelerometer was also connected via the SPI interface to obtain XYZ axis data. The microcontroller was programmed using a C compiler to obtain data and send it to the PC. A USB stack was implemented from scratch to learn more about the USB protocol. Data sent to the PC is received by the WinUSB driver after setting up the driver for the device in Windows. A C++ program was initially written for testing and later a .NET implementation to display the data in WPF.
.NET and the Garbage Collector
The .NET framework is a managed virtual machine and memory is allocated, moved and deallocated automatically. Difficulties arise when connecting .NET to unmanaged code like the WinUSB library. When calls are made from .NET to WinUSB the memory addresses are passed specifying where to store data. If the garbage collector moves memory around or cleans up objects they will no longer point to the correct address that will be returned in unmanaged code. Care must be taken to pin managed objects in memory to prevent their addresses being moved and dispose of unmanaged objects after use to eliminate memory leaks.

Oscilloscope
The oscilloscope was tested by sampling the voltage output of a 555 clock pulse hooked up to an LED and a capacitor circuit. The sample data clearly illustrates the charging and discharging of the capacitor. The second test illustrates the discharging of another capacitor circuit.


Accelerometer
The accelerometer was first tested by moving the breadboard back and forth and side to side as can be seen at the beginning of the first two graphs. The table was then hit to create a vibration most easily seen on the last graph. The last graph also has a negative value due to gravity. The breadboard was then lifted and rotated along all axes.

