View Full Version : Looking for guidance, examples, etc on how to launch a process in another cog
11-09-2011, 11:37 PM
I have a main loop running a menu and I want to start other routines from the menu and keep them going but still need to have control of the main menu loop and get some data from the routine running external of the main loop. I am guessing I need to run these other routines in another cog?
If anyone can suggest some good examples or reading material on this type of thing it would be greatly appreciated.
11-10-2011, 12:06 AM
The cognew method will be your friend. You can launch a Spin method -- usually constructed as an infinite loop -- into another cog and then share data and methods from your top object with that "background" cog. It takes a little getting used to but once you grasp the concept it can be very powerful.
11-10-2011, 12:49 AM
Thanks Jon. If there is a tutorial on doing this it would be great to read and learn from.
I have attached a visual of what I'm trying to understand.
11-10-2011, 12:59 AM
OK. I used cognew and my routine is running ok in its own cog while I am still able to run the menu system in the main routine. Now I need to learn how to pass data and variables back and forth.
What do I need to learn to do this? Any references?
11-10-2011, 01:16 AM
I'm reading chapter 5 "Methods & Cogs Lab" in the Propeller Education manual... this may have what I need to learn. Comments welcome from the forum.
11-10-2011, 01:32 AM
just make sure you declare about 100 longs for your new cog.
Forgetting to do this is a common mistake....
11-10-2011, 03:51 AM
Ok I'm stuck here- I have a method running in its own cog that I launched with cognew. I want to inquire from my main method a variable (value) from the cognew launched method. I haven't found information yet for the procedure for doing so. Can someone show me a framework of how this type of thing works?
11-10-2011, 04:22 AM
If both main method and helper method reside in the same SPIN file then sharing a global VAR is easiest:
dira := 1
outa := shared // 100 > 50
waitcnt(clkfreq/50 + cnt)
If the helper method lives in a different object (different SPIN file) then you have to communicate the address of said variable. So either the main program tells the child object what the address is (e.g. child.setup(@shared)) in which case the child object accesses shared through long[address]++ or it asks the child object what the address is (e.g. address := child.getAddr) and then uses the returned address like value := long[address].
11-10-2011, 11:57 AM
Kuroneko thanks that helps I think I understand now. The main and helper are both in same spin file. I was making it harder as if they were in seperate spin files. That will be a lesson for another day.
Edit: Got it to work! Thanks. :)