Shop OBEX P1 Docs P2 Docs Learn Events
Spin and COGS — Parallax Forums

Spin and COGS

inakiinaki Posts: 262
edited 2006-04-06 21:25 in Propeller 1
If I write all my stuff in Spin is it possible to use more than one COG at the same time ?
I understand that the Spin interpreter uses a COG for itself while the Spin code is read from the main RAM.
So, are·the other·seven COGs idle ?

Is there any way in Spin to use several COGs at the same time ? If so, how this·is done ? Are there more than a single SPIN interpreter running or there is some code generated on the fly for a COG ?







▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔

Comments

  • Martin HebelMartin Hebel Posts: 1,239
    edited 2006-04-05 19:33
    All Spin code is stored in the general 32K of RAM. Each cog has an interpreter which can read and execute the code you tell it to.

    The cognew() inctruction is used to start a new cog and tell it which code to run.

    Look over some of Dave's example/tutorial programs posted on this board.

    -Martin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Martin Hebel
    Southern Illinois University Carbondale - Electronic Systems Technologies

    Personal Links with plenty of BASIC Stamp info
    StampPlot - Graphical Data Acquisition and Control
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-04-06 17:47
    Inaki,

    Yes, you can use more than one cog at a time with Spin.· If you look at the attached files you'll find an object called Timer.· The key element is a method called updateTimer that gets launched into its own cog where -- when enabled -- it updates the timer registers 100 times per second.· You see that the top level object, Timer_Test, simply calls the showTimer method to display the current HH:MM:SS.XX value.

    Update: I found a sync error in the timer and I have made several other improvements.· I will take this object and create a new one called RTC that will include clock and calendar functions.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax

    Post Edited (Jon Williams (Parallax)) : 4/7/2006 6:06:25 AM GMT
  • inakiinaki Posts: 262
    edited 2006-04-06 19:21
    Thanks Martin. Jon, very good example to illustrate the use of two cogs in Spin.

    I was asking because I hear all the time that in order to execute code in a COG it must be written in assembler. I did not realize that when cognew is invoked a new Spin interpreter is launched.

    So, if I understand well, the call to cognew(updatetimer) means that a new Spin interpreter is launched in a new COG to manage that routine. Is this right ?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-04-06 21:25
    Yes, cognew will launch the new cog and load the interpreter IF the program to be run from the new cog is Spin. You can load custome assembly programs with cognew as well.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
Sign In or Register to comment.