Shop OBEX P1 Docs P2 Docs Learn Events
Example program for multi Cog usage — Parallax Forums

Example program for multi Cog usage

I have perused various areas to find an example of a super simple program using 2 Cogs.

I'm looking for something straightforward, such as reading a logic input, storing it in the Shared memory, then reading it from another cog and outputting it to another logic pin.

I would appreciate a link to something simple for me to play around with.

Thanks

Preben

Comments

  • evanhevanh Posts: 16,112

    The built-in method is "cogspin( NEWCOG, [method()], [reserved stack] )"

    Looking through the library I see a few that use it. jm_ez_sound.spin2 is probably the most accessible.

  • KaioKaio Posts: 266
    edited 2024-12-09 10:49

    @Preben said:
    I have perused various areas to find an example of a super simple program using 2 Cogs.

    The DEBUG_demo_multi.spin2 in the examples folder of Propeller Tool is a simple one.
    You need to "Enable DEBUG" in the Run menu first and then "Load RAM" from Run menu or simply F10. Then you should see the debug messages coming from all started cogs.

  • Here's a simple example that uses on cog to read a button, write the state to a hub variable, then uses another cog to read that hub variable to update the state of an LED. Yes, this is an obtuse way to light an LED with a button, but it shows the mailbox interface that how Px cogs share values with each other.

    Technically, four cogs are running

    • main Spin2 program
    • serial cog for terminal
    • button monitor
    • LED updater
  • Precisely the type of program(s) I was looking for :-)

    However, I did run into a problem running Jon's "Multi-cog" program under Spin Tools IDE.

    It complained about line 136, but I think it was the Pin Configuration "Con" in line 130 that was the issue. (Source register/constant can't exceed $1FF)
    I don't know the instructions well enough yet to debug this, so please advise.

    Thanks

    Note to the IDE tool: It looks like I don't open the IDE with a program when double-clicking on its icon in Explorer.
    Opening from the inside works fine. If I had a program open the last time I used the IDE, that program would come up, but not the one I clicked on.

  • This is an error in the internal compiler of Spin Tools IDE, and I'm sure @macca will address it. I ran my program inside Spin Tools IDE using PNut to compile and load the code into RAM.

    You can work around the issue like this (which is compatible with the Spin Tools compiler).

  • I got the program(s) running!

    Thanks

Sign In or Register to comment.