Shop OBEX P1 Docs P2 Docs Learn Events
Lissajous Patterns — Parallax Forums

Lissajous Patterns

HannoHanno Posts: 1,130
edited 2009-11-17 02:52 in Propeller 1
Years ago people discovered that you can create nice shapes using the XY mode of oscilloscopes and function generators. Now it's easy with ViewPort and the Propeller. Check out this screenshot:
lissajous.JPG

This code uses ViewPort to let you choose between drawing a circle, a spinning coin, or drawing arbitrary shapes. Read more here:
en.wikipedia.org/wiki/Lissajous_curve

Here's the code:
{***********************************************
* (C) 2009 myDanceBot.com, Inc.                *
* Use the XY plot to analyze two channels      *
* AppletImage=time.gif                         * 
************************************************

This program shows how you can use ViewPort's XY plot
to plot different Lissajous patterns as generated by
the Propeller.
http://en.wikipedia.org/wiki/Lissajous_curve

This spin program produces 3 different signals which you can analyze.

When ViewPort connects to this program, it will display
the signals on the "analog" view.  The xy plot graphs the
screen's worth of data from the two channels.}
CON
 _clkmode        = xtal1 + pll16x
 _clkfreq        = 80_000_000
 clk8192=_clkfreq/8192
OBJ
 vp    :       "Conduit"  'transfers data to/from PC
pub run|ch1,ch2,mode,a,b,phase,hz1,hz2,n,m
   'setup viewport
  vp.config(string("var:ch1(min=-100000,max=100000),ch2(min=-100000,max=100000),mode,a,b,phase")) 
'send 2 channels as longs and receive mode,a,b,phase parameters
  vp.config(string("dso:view=[noparse][[/noparse]ch2,ch1],timescale=20ms/div")) 'view ch1,ch2 in dso view at 5ms/div
  vp.config(string("edit:mode(default=0,mode=slider,label=[noparse][[/noparse]circle,spincoin,custom]),a(default=1,mode=text),b(default=1,mode=text),phase(default=2048,mode=text)"))
  ' edit mode with a selector, other parameters with textbox
  vp.config(string("start:analog")) 'start in the analog mode: shows spectrum analysis, xy, and oscilloscope
  vp.share(@ch1,@ch2)
  
  hz1:=10
  hz2:=2
  a:=1
  b:=1
  phase:=2048
  repeat
    n:=cnt/clk8192*hz1
    m:=cnt/clk8192/hz2        
    case mode
      0:ch1:=sin(n+phase) 'generates a circle
        ch2:=sin(n)
      1:ch1:=sin(n+phase) 'generates a spinning coin  
        ch2:=sin(n)/$100 *sin(m)/$100                  
      2:ch1:=sin(a*n+phase) 'generates a pattern dependent on a,b and phase
        ch2:=sin(b*n)
      
pub sin(x) | y, q ' x is 0 to 2^13 (0 to 8191) for 0 to 360 degrees
q := (x  >> 11) & 3 ' two highest bits of 13 are the quadrant, 0, 1, 2 or 3
y := (x & $7ff) << 1 ' 0 to 90- degrees, are contained in 11 bits, shift left one for Word offset
' this is the address offset into the sine table in hub rom
' note: the parentheses are important for operator precedence
case q ' select quadrant 0,1,2,3
  0 : result := word[noparse][[/noparse]$E000 + y] '
  1 : result := word[noparse][[/noparse]$F000 - y] ' 2049 angles, 16 bit sin(angle) values corresponding 0 to 90 degrees.
  2 : result := -word[noparse][[/noparse]$E000 + y] ' the same table is folded over and mirrored for all 360 degrees
  3 : result := -word[noparse][[/noparse]$F000 - y] ' value returned in the range of -$ffff to +$ffff
return                                                     


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Co-author of the official Propeller Guide- available at Amazon
Developer of ViewPort, the premier visual debugger for the Propeller (read the review here, thread here),
12Blocks, the block-based programming environment (thread here)
and PropScope, the multi-function USB oscilloscope/function generator/logic analyzer

Comments

  • JavalinJavalin Posts: 892
    edited 2009-11-16 08:47
    very nice.

    Have you seen Sparkfun sell a generator which creates a clock? I wondered how that was done - but your post kinda explains that.

    http://www.sparkfun.com/commerce/product_info.php?products_id=9306

    James
  • Toby SeckshundToby Seckshund Posts: 2,027
    edited 2009-11-16 08:58
    Back in the early days of CRT television it was muted that instead of generating sawtooth scans for line and field that a lissajous could sweep the tube surface. This would have saved all the retrace periods, and even allow for just one sync pulse per field allowing almost 20% more active screen time. It would have made colour tricky though.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Style and grace : Nil point
  • heaterheater Posts: 3,370
    edited 2009-11-16 09:15
    I think you mean "mooted".

    Years ago I worked on radar systems that used "penetron" tubes. These were huge round radar CRTs displaying aircraft dots, maps and text using vector graphics. Colour was achieved by having layers of different phosphors on the front. Winding up the electron beam voltage caused it to penetrate to deeper into the layers and light up different colours.

    en.wikipedia.org/wiki/Penetron

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • Toby SeckshundToby Seckshund Posts: 2,027
    edited 2009-11-16 09:42
    I like that. Colour by different grade of hammer.

    I was thinking there would be even more screen time without the frame blankings

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Style and grace : Nil point
  • HannoHanno Posts: 1,130
    edited 2009-11-16 18:26
    Javalin-
    I like the "clock" idea! Who wants to give it a try?
    Hanno

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Co-author of the official Propeller Guide- available at Amazon
    Developer of ViewPort, the premier visual debugger for the Propeller (read the review here, thread here),
    12Blocks, the block-based programming environment (thread here)
    and PropScope, the multi-function USB oscilloscope/function generator/logic analyzer
  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2009-11-17 02:52
    As cool as that is, with the flexibility of the Propeller, you could, more easyly, project it onto a screen using the graphics object. But hey, what fun would that be?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Computers are microcontrolled.

    Robots are microcontrolled.
    I am microcontrolled.

    But you·can·call me micro.

    Want to·experiment with the SX or just put together a cool project?
    SX Spinning light display·
    Want cheap wholesale electronic parts?
    Transistor parts wholesale
Sign In or Register to comment.