Silly Newbie question - Inputs/Outputs and Cogs
TCP71
Posts: 38
First,
I am not a programmer, but am working on a basic control system.
I have a quick question about Running code inside a separate cog.
I have a number of inputs and outputs specified in a PUB object inside my main program in Cog 0( or whatever default cog things go to). I would like to have temporary control of the same inputs/outputs for a bit of code I would like to run in another cog. Any easy way to do this. It seems none of the inputs are available to the code in the new cog, once they've been specified and initialized within the main cog.
Be gentle...I'm dense.
I am not a programmer, but am working on a basic control system.
I have a quick question about Running code inside a separate cog.
I have a number of inputs and outputs specified in a PUB object inside my main program in Cog 0( or whatever default cog things go to). I would like to have temporary control of the same inputs/outputs for a bit of code I would like to run in another cog. Any easy way to do this. It seems none of the inputs are available to the code in the new cog, once they've been specified and initialized within the main cog.
Be gentle...I'm dense.
Comments
Every COG has its own DIRA (and DIRB) and OUTA register and thus needs to be initialized after being started. You would pass the DIRA and OUTA values to the newly started COG as parameters that are then used to setup the local registers. If you start a Spin method in a new COG, you can just pass the values as parameters to the method you're calling.
Your main cog needs to keep its hands off the same ports for the time the other COG is doing something on them, or you may not see the results you expect: output bits are logically ORed together if multiple COGs write to them.
If keeping the signal levels during the switch to the new COG is critical, you may need to wait with disabling the main COG's output pins until the new COG has taken over.
The easiest way to achieve this is to temporarily set DIRA[noparse][[/noparse]31..0] := 0 in the main COG and later on, when the other COG is finished, restore the DIRA value you saved in some local variable.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Pullmoll's Propeller Projects
Post Edited (pullmoll) : 5/11/2010 6:06:39 PM GMT