Why doesn't COGINIT work?
TheTech69
Posts: 51
in Propeller 1
Why does the following snippet of code work but the latter does not?
cog := COGNEW(method, @stack) +1 'This works
cog := COGINIT(COGID, method, @stack) + 1 'Does NOT work
Thank you,
Jason
cog := COGNEW(method, @stack) +1 'This works
cog := COGINIT(COGID, method, @stack) + 1 'Does NOT work
Thank you,
Jason
Comments
-Phil
COGINIT doesn't return a value (see the manual), that's the error (aside from what others have said).
In your code you are restarting the current cog pointing to 'method'.
Thank you.
That is to say, if you only want to execute methods sequentially then you do not need to start a second COG to run them. Which as you say will run them simultaneously, in parallel.
Hmm...thinks....are your "time sensitive" methods written in PASM? That would change things a bit.
Actually I do use the coginit to start pasm routines in specific cogs. Multiple cogs with specific functions running. Each function is assigned to a particular cog of my choosing and when the mainline runs, each cog is initialized and ready to do what it should. But I also realize that I need to allow for that in the design and make sure that calling another cog does not hammer what is already running. A project I have been working with currently uses a cog to start a timebase cog, and three ADCs all using the common timing from the time cog so that all three ADCs capture their samples at the same point in time.
One reason could be that you need COG-IDs in a certain order, to use for indexing in code.
Usually all COGs are equal, but there are some exceptions. I think @Lonesock stumbled on it first and @kuroneko verified it, that some COGs can access some Pins a little faster then other ones.
see FSRW pasm for more info
But if you do not NEED to, it is 'better' to use COGSTART instead.
Enjoy!
Mike
But the problem comes when you are mixing and matching Spin objects that you have not written yourself. Perhaps they come from OBEX or from a forum post or wherever. Then it's better not to have to worry about fixed assignments of code to COGs. In the same way that we use library functions in other languages and don't care what memory locations those functions end up at.
If all of your code is under your control then do what you like.