PIC based Oscilliscope

INTRODUCTION

CODE

VIDEO

PICTURES

BLOCK DIAGRAM & SCHEMATICS

LOG

INTRODUCTION:

  I have seen many examples of microcontroller oscilliscopes on the web and have had an itch to build one myself.  In order to accomplish this my initial thought is to sample an input (ADC) at consistant time increments and then display the waveform on a graphic lcd display.  If I want to change the time scale I can just change the rate of time between samples, and if I want to increase the voltage scale I can scale the measured values by some multiple.

 With that basic concept, this project will require an ADC, microcontroller, graphic lcd, and some form of input.  After doing a bit of search for the LCD display this link was selling a 4 inch display with touch screen for a mere $25 (which is dirt cheap for that type of resolution if you check sparkfun or other website).  So now I had the display and the input source, though more thought will be needed to have graphical interface, the next item to tackle was the ADC.  I had a few 24bit Microchip microcontrollers that had onboard ADC that could sample at 1.1 Msps, as they were designed to be optimized for digital signals.  Not only that but they can sample multiple channels at one time which would be good for a two channel oscilliscope (if I decide to upgrade later on).  The chip is a dsPIC33FJ128GP802, and it also has the capability to do sampling in the background while filling up an onboard DMA so that the only work in code will be to draw the display, plot the data, and handle inputs.  The dsPIC33 is a 16 bit processor as opposed to the 8 bit processors which makes math on larger values much easier and quicker.  On that same note, it also can run up to 40 MIPS so there should be plenty of speed if math operation may be needed to do an FFT or other analysis of data.

Initially in testing I was interfacing the touch screen with an onboard ADC of the microcontroller, but after thinking about how that ties up a resource I decided to go with a dedicated touch screen controller the AR1010, which is another Microchip product.  I'm not trying to show a bias, I was able to get free samples of both chips (uC and Touch Controller) so they kept the budget low, and I really like the organization of datasheet put out by Microchip.

There is still one looming problem, and that is the fact that the dsPIC only works at voltage levels of 3.5 volts.  This isn't very useful if 5/12/24 volt waveforms want to be analyzed (I left out 120 because of safety issue that I don't want to mess around with).  So in order to scale down the signal I'll need some sort of voltage divider network and an opamp to isolate and match the impedance of the dsPIC's ADC input.  Basically I would rather destroy a generic op amp before I hurt the main controller of this project.  An idea I found from Texas Instrument was this, and I have ordered samples of their opamps to try and design this circuit but they don't come in a DIP package.  Another idea I found was here, which is from an AVR base oscilliscope and it just uses some generic opamps.

So above breifly explains the hardware, the theory of software is to draw/plot data on the display using a layered method (see lcd controller datatsheet S1D13700) where the plot is on the back layer and the graph lines and touch interface displays are on the front.  This way only the plot has to be redrawn every time the buffer fills.  In order to have clear signal (ie the waveform isn't always bouncing around) there has to be some type of trigger.  For this I am going to try to use the onboard comparater and DAC of the dsPIC to start the sampling at a consistant voltage level that is inphase (positive going or negative going) with the previous sample.  The DAC will act as the reference point and allow for an adjustable trigger, while the comparator will allow for an interupt when a threshold is passed.

FUTURE:

 As of now there is a generically working oscilliscope and spectrum analyzer that display the wave form and can calculate the frequency.  The input buffering was tested but never completed because the op-amps were creating a lot of noise, so for demo purposes only signals with less than 1.5 volts peak to peak with an offset of 1.5 volts D.C. were injected.  This ensured that the dsPIC was not destroyed by voltages that were too high for the adc input.  The simplest way to buffer is to linearly scale it down with a resistive voltage divider network, but again a D.C. offset will be needed to counter negative going current.

  The future improvements that I plan on incorporating are first to have a voltmeter state to allow this device to behave just as a hand-held voltmeter displaying numeric readings.  Second, I would like to have a frequency counter state that has a higher accuracy than the current FFT by taking more samples (currently only 256-future 1028).  A third improvement would be to have a better translation of what the volts per division are in the oscilloscope, and just in general more functionality (measure volts P-P, max and mins, level shifting).  Fourth I would like to add a second channel since there are more pins available on the microcontroller. The last improvment that I have in mind is better functionality of the spectrum analyzer, because the frequency read isn't always correct when changing the time per division scale, and I'd like to have tick marks to show what frequency the end of the screen is and a few points in between.  A thought of another improvment, though I probably won't act upon it, is to add an SD card slot for data logging and saving waveform readings.

  Most of the above modifications can be handled with just software changes so little modifications would be needed to the physical layout.  This makes for a relatively cheap upgrade, and by adding more functionality it improves the chances of people being interested in such a product. Here is a link to a similar product that is comparable to what I am trying to build.  I beleive that my product could be mass produced for under 35 dollars and sold competetively for about 50 dollars.

COST:

Graphic LCD w/Touch Screen:      $25      (Volume pricing will be lower)

dsPIC33FJ128GP802:                  Sample (Volume pricing $4.17)

AR1010:                                       Sample (Volume Pricing $1.27)

--------------------------------------------------------------------------------------------

Actual Project Costs:                  $25

Actual Cost to mass produce:      >$30 (estimated <$35 at mass production)

CODE:

PIC Oscilliscope.zip

VIDEO:

PICTURES:

             Frequency Domain (Spectrum Analyzer)                                                          Sine Wave

                                  Square Wave                                                           Triangular Wave

 

                           Board Layout

BLOCK DIAGRAM & SCHEMATICS:

 

            Block Diagram                                                                          Schematics

LOG:

3-23-2011: Used Microchips code example for dsPic ADC to read values and store in the onboard DMA, but wasn't able to get usable values.  Will need to reread datasheet and code settings.

3-26-2011: Able to used the code example to only read one channel and store understandable values based on the input voltage to analog input.

3-27-2011: Ported LCD code from website (meant for PIC18F) to dsPic33F using the onboard Parrallel Master Port (PMP).  Able to display graphics and text just like website examples.

3-29-2011: Able to get onboard comparator of dsPic to trigger ADC reads at set trigger voltage values, and then turn off ADC timer once both DMA buffers are full to plot values.  Plotted values coincide with voltages at the input, and a generic signal is seen when touching the input with figures.  Appling input with a signal generator shows a much cleaner plot and a sine, square, and triangle wave inputed are viewable on the LCD display.

4-8-2011: Able to use touch screen chip with Microchips touchscreen software to give valid coordinates of screen touches. Next will have to create code to interpret the locations and create a GUI for the user to interact with.

4-15-2011: Use all three layers of LCD controller to display a more fluid trace.  Grid is drawn on layer one, the trace is drawn on layer two then layer two is turned on.  When new trace is ready layer three is erased and the new trace is drawn on layer three, at which point layer two is turned off and layer three is turned on.  This just continues back and forth as new traces are achieved.

4-16-2011: Designed a graphical user interface for the touch screen to adjust volts per division, time per division and trigger level.  Soft buttons are inverted to give acknowledgement of a press.  They are debounced in software.

4-24-2011: Added an FFT state to o'scope to display the freqency spectrum and power magnitude.  Frequency can be calculated, but isn't currently displayed.

4-24-2011: Frequency calculated from FFT is now displayed (only gives ball park results +/-3% or so)