-
Notifications
You must be signed in to change notification settings - Fork 70
Plotting the data
If you have compiled the sketch with serial support, you can control the scope with some simple serial commands.
The "s" command will spit out the contents of the data buffer (all of the most recent samples).
The output of the serial "s" command is a list of number pairs where the first value is a time offset since the trigger event, and the second value is the raw output value of the ADC.
The scope is too simple to know the attenuation factor you are using, so it makes no sense to scale these values in the scope software, you can use your plotting software to do this for you.
I use gnuplot to show the data, but you can use Excel or whatever meets your needs.
GnuPlot is available for Mac, Linux and Windows here => http://www.gnuplot.info/
There are lots of good tutorials for gnuplot, but it is actually very simple to use.
http://www.gnuplotting.org/plotting-data/
Lets look at a real world example. Take the following screen full of data as captured by the scope.
We can render this in GnuPlot and see a lot more detail. You will also notice that the aliasing on the 320x240 screen becomes pretty obvious. This is one respect where an analogue oscilloscope is arguably better than a digital one. On the analogue scope you would see an obvious fuzz of lines, but the limited resolution and lack of ant-aliasing in our plotting leaves us with a jagged plot that is markedly different from the actual data.
Here is a JPEG of a plot of the same set of data from the PWM output on the test pin of my STM32-O-Scope - from this it is possible to estimate the PWM period... I make it about 549.199 Hz which is not what is stated on the leaflabs help pages but interestingly agrees with this comment. http://forums.leaflabs.com/topic.php?id=9339
... and for comparison, a plot of the data from the scope after I used a real oscilloscope probe in place of the jumper wire.
You can see a lot more detail in the plots than the screen shot. For example the second shot shows noticeably less noise than the first.
The above plot took only two commands in gnuplot to render - I pasted the serial output lines in to a file called STM32-O-Scope1.csv then ran gnuplot as follows.
gnuplot> set style line 1 lc rgb '#05FA26' lt 1 lw 1 pt 7 ps 1.5 # --- Set line style 1 as hex colour green
gnuplot> plot 'STM32-O-Scope1.csv' with lines ls 1 # --- Plot our graph with lines of line style 1
... as I said... very simple. You can add titles, labels, change the scaling, plot a subset of the data and use all manner of other enhancements and gnuplot tricks, but I'll leave that up to you.
The first suggestion while experimenting would be to zoom in on the plot... try something like...
plot [100:1000] 'STM32-O-Scope1.csv' with lines ls 1
.. which will let you see samples 100 to 1000... and all that fuzz will start to make sense.
Here is a slightly more sophisticated gnuplot script which plots a file called "serial3.dat" and adds labels and titles.
# Gnuplot script file for plotting data in file "serial3.csv"
# This file is called serial3.gplot
set autoscale # scale axes automatically
unset log # remove any log-scaling
unset label # remove any previous labels
set xtic auto # set xtics automatically
set ytic auto # set ytics automatically
set title "STM32 Oscilloscope plot"
set xlabel "Time (microseconds)"
set ylabel "Signal (mV)"
set linestyle 2 linetype rgb "green"
plot "serial3.dat" using 1:2 title 'Channel 1' with lines linetype 2
plot [1000:1100] "serial3.dat" using 1:2 title 'Channel 1' with linespoints linetype 2
Now would seem like a good time to read the GnuPlot manual http://www.gnuplot.info/docs_5.0/gnuplot.pdf