Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 12:51 20 Nov 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : MM+: 1.8Msps dual channel oscilloscope

Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10619
Posted: 07:52am 25 Oct 2015
Copy link to clipboard 
Print this post

Something completely different



This is starter code for a 2 channel oscilloscope using a MM+ and a 800x480 SSD1963 display configured using the normal OPTION LCDPANEL command.

Starter code means that there is no GUI and of course to be properly useful the MM+ needs a programmable attenuator/gain stage building out of standard analogue hardware as a front end to the ADC.

However, the guts of the oscilloscope are fully worked in so far as it supports:

* 800x480 display divided into 10x8 divisions (the graticule lines are just visible in the picture)
* 2 channels at speeds up to 1.8 million samples per second per channel with 10-bit resolution
* continuous screen updates at a rate of 20 traces per second
* individual on/off channel switching
* programmable timebase specified in usec/division
* automatic display scaling if ADC cannot satisfy specified usec/division
* separately programmable amplitude for each channel in milli-volts per division
* free-running, or triggering off either one or both input channels with separately programmable positive or negative slope
* Trigger timeout that returns control to basic if no trigger occurs with 0.5 second


All of the above is controlled by one CFunction "scope":
i= scope(microsecondsperdivision, toggle, channel1buff(), channel2buff(), c1pos, c2pos, c1trig, c2trig ,c1mvperdivision,c2mvperdivision)


' Parameters for call to CFunction "scope"
'
' Returns the scaling factor used for the display or a large number if triggering is enabled and has timed out
' A scale factor of 1 means every x-coordinate has a unique value
'
' microsecondsperdivision: specifies the number of microseconds to scale the display for each graticle line
' note: durations less than 100uSec will use scaling. i.e.every other x-coordinate will be missed if scale = 2
' toggle: initialised to 0, used by the CFunction to control its double buffering
' channel1buff: buffer used for channel 1, used as 2 buffers of 800 x 16-bit words
' channel2buff: buffer used for channel 2, used as 2 buffers of 800 x 16-bit words
' y-position for channel 1: specifies the screen position of zero volts on channel 1 in rows from the bottom of the display
' use any negative number to turn off the channel
' y-position for channel 2: specifies the screen position of zero volts on channel 2 in rows from the bottom of the display
' use any negative number to turn off the channel
' trigger for channel 1
' specifies the ADC reading and direction to trigger the trace for channel 1 (-1024 to +1023)
' a zero value means triggering is disabled for this channel
' a positive value triggers when the ADC reading passes the trigger value in a positive going sense
' a negative value triggers when the ADC reading passes the absolute trigger value in a negative going sense
' trigger for channel 2
' specifies the ADC reading and direction to trigger the trace for channel 2 (-1024 to +1023)
' a zero value means triggering is disabled for this channel
' a positive value triggers when the ADC reading passes the trigger value in a positive going sense
' a negative value triggers when the ADC reading passes the absolute trigger value in a negative going sense
' NB: if both trigger levels are set to zero the scope will free run
' millivolts per division for channel 1 based on VDD=3.3V
' millivolts per division for channel 2 based on VDD=3.3V
'


Using this the current test main program is absolutely trivial:


CPU 120' The CFunction will automatically compensate for CPU speed but obviously the higher the speed the better
option explicit
option default none
dim integer i,j=0,toggle,channel1buff(400),channel2buff(400),microsecondsperdivision=50
dim integer y1pos=90, y2pos=30, c1mvperdivision=200, c2mvperdivision=1000, c1trig=400, c2trig=0

setpin 16,ain 'Channel 1
setpin 12,ain 'Channel 2

colour rgb(white),rgb(blue)
cls
font 2
do
i= scope(microsecondsperdivision, toggle, channel1buff(), channel2buff(), y1pos, y2pos, c1trig, c2trig ,c1mvperdivision,c2mvperdivision)
if i>1 and i<1024 and j=0 then
print "Warning reduced resolution x"+str$(i)
j=1
endif
if i>1024 then
PRINT "No trigger"
endif
text 2,2,"T:"+str$(microsecondsperdivision)+"us/div"
if y1pos>=0 then text 2,24,"C1:"+str$(c1mvperdivision)+"mv/div"
if y2pos>=0 then text 2,46,"C2:"+str$(c2mvperdivision)+"mv/div"
loop


If someone would like to build a GUI for this to allow all the various parameters to the scope function to be controlled using the touch screen, let me know

The Cfunction follows my usual route of being Basic coded into C. The only tricky bit is the code which sets up the ADC to run flat out continuously which was cribbed pretty much completely from the plib documentation.

The CFunction source and the complete Basic test program are attached.

2015-10-25_174312_scope.zip

If you have the hardware give it a run - I think you will be further impressed with what the MM+ is capable of.

Possible enhancements:
True single shot mode with extended trace length
After the fact trace magnification and scrolling
user controllable pre and post triggering (e.g. 25% of trace pre-trigger
etc........

Edited by matherp 2015-10-26
 
viscomjim
Guru

Joined: 08/01/2014
Location: United States
Posts: 925
Posted: 08:52am 25 Oct 2015
Copy link to clipboard 
Print this post

Matherp, you never cease to amaze me. This is awesome!
 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1681
Posted: 08:58am 25 Oct 2015
Copy link to clipboard 
Print this post

Cool!

Thanks Peter!

Regards
Michael
causality ≠ correlation ≠ coincidence
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3308
Posted: 12:46pm 25 Oct 2015
Copy link to clipboard 
Print this post

Yes, this is awesome!

What is even more amazing is that a CFunction is a difficult environment to develop for - yet Peter makes it look so easy.

Brilliant.
Geoff Graham - http://geoffg.net
 
Zonker

Guru

Joined: 18/08/2012
Location: United States
Posts: 772
Posted: 03:00pm 25 Oct 2015
Copy link to clipboard 
Print this post

Wow... Peter.. This is amazing.. Had no idea something like this was doable..

In the Do loop, the function will wait for the trigger or if none, will collect the samples, update the screen display and then return to the MM basic section of code. In the example you just loop to the top and do it again, as fast as it will go...

So, if a GUI control CtrlVal value was passed to the Cfunction to control the scope display, every call into the Cfunction should respond to the latest values past to it...

I have a 7" SDD1963 connected to an Explore64 board. I hope this is an OK hardware setup for the test... One Question.. If the scope display takes up the whole screen when updated, how can the GUI objects get any "screen space" to be changed by the end user..? would you have to stop calling the Cfunction, select the setup screen(s) needed to be changed, then return to fast looping..?

Would there be a way to limit the size to the scope display area so the GUI controls can co-exist on the display and be changed when wanted...?

If my setup is OK, I will get this tested this week, and see if GUI objects will change the scope display

What a toy...!
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9757
Posted: 03:09pm 25 Oct 2015
Copy link to clipboard 
Print this post

Dear God, is there no stopping this man? (rhetorical)

Awesome.
Smoke makes things work. When the smoke gets out, it stops!
 
Lou

Senior Member

Joined: 01/02/2014
Location: United States
Posts: 229
Posted: 05:30am 26 Oct 2015
Copy link to clipboard 
Print this post

Awesome for sure !!
I would love to see this develop into a real test instrument.

Peter, you are amazing. Thanks for all you do,

Lou
Microcontrollers - the other white meat
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10619
Posted: 05:59am 26 Oct 2015
Copy link to clipboard 
Print this post

  Quote  I would love to see this develop into a real test instrument.


This looks interesting as a front end amplifier. Very cheap
 
Zonker

Guru

Joined: 18/08/2012
Location: United States
Posts: 772
Posted: 11:36am 26 Oct 2015
Copy link to clipboard 
Print this post

Sweet find Pete..!

It looks like they will be simple to use code wise...

I noticed playing around with the scope Cfunction, that when you erase the old trace screen data, you paint it back to blue... So, for now, will use blue background...

Will invest more playtime tonight and try some basic GUI things to change the call values...

P.S. - Thanks for the new toy...
 
Zonker

Guru

Joined: 18/08/2012
Location: United States
Posts: 772
Posted: 04:31pm 28 Oct 2015
Copy link to clipboard 
Print this post

First Try - Scope GUI..

I know it's not much yet, but wanted to get some feedback...
The attached code is from the first Matherp post on the SSD1963 code.

I tried to keep the scope CFunction running all the time.
The two simple screens just adjust time and ch1, ch2 screen positions.





but, I ran into trouble trying to adjust the trace position in real time.



I seems that the Cfunction doesn't cleanup behind the position change...

Probably something I'm not doing right yet...

2015-10-29_023049_scope_gui_SSD1963.zip

Anyway, will keep at it, time permitting... (go bed now)...

Yikes... And now a logic analyzer display too... Awesome Peter..!
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10619
Posted: 10:29pm 28 Oct 2015
Copy link to clipboard 
Print this post

  Quote  It seems that the Cfunction doesn't cleanup behind the position change...


Zonker, please see the thread on the single code version. I will only now keep this one updated. I've included additional functionality to deal with your problem.
 
geodav
Newbie

Joined: 09/05/2014
Location: Australia
Posts: 12
Posted: 06:18am 11 Feb 2022
Copy link to clipboard 
Print this post

Wow, how good is that, love your work brother
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025