How to Avoid sitting in a repeat loop?
Regor
Posts: 19
I'm looking for techniques/best practices in keeping power consumption to a minimum when you have a main cog that reponds to various properties on Object in other Cogs
Minimal example using 3 cogs.
1 Cog is waiting for a Pin to go low in response to motion detection
1 Cog is waiting for a Pin to go low for IR
"main" Cog sits in a loop making a method call into the other COGS object to determine their state.
The cogs waiting for the Pins to go low can use a wait but I don't know how to avoid keeping the Main Cog from sitting in a loop polling the other cogs.
Ideally, what I think I would want is·a wait command that could wait on one or more memory locations or a timeout value so if a set of mount of time does go by the main cog could perform some "idle" tasks but I don't see a way of doing this.
Ways I've thought of.
1) Use assembly but the main cog would still be spinning in a loop.
2) Add a Pause on the main loop and have the other cogs set their value and not clear it until the main cog·asks for the value.
3) Add a Pause to main loop and have cogs buffer their state changes along with the cnt time when the state changed.
·
Minimal example using 3 cogs.
1 Cog is waiting for a Pin to go low in response to motion detection
1 Cog is waiting for a Pin to go low for IR
"main" Cog sits in a loop making a method call into the other COGS object to determine their state.
The cogs waiting for the Pins to go low can use a wait but I don't know how to avoid keeping the Main Cog from sitting in a loop polling the other cogs.
Ideally, what I think I would want is·a wait command that could wait on one or more memory locations or a timeout value so if a set of mount of time does go by the main cog could perform some "idle" tasks but I don't see a way of doing this.
Ways I've thought of.
1) Use assembly but the main cog would still be spinning in a loop.
2) Add a Pause on the main loop and have the other cogs set their value and not clear it until the main cog·asks for the value.
3) Add a Pause to main loop and have cogs buffer their state changes along with the cnt time when the state changed.
·
Comments
Post Edited (TChapman) : 4/4/2007 7:51:50 PM GMT
1) You can test the state of the other cogs only every few milliseconds using a WAITCNT in the REPEAT loop.· (Like "WAITCNT(CLKFREQ / 1000 + CNT)" to pause for 1ms).
2) Since either condition requires that an I/O pin be low, you could use a WAITPNE in the main cog waiting for either I/O pin to be low, then go check the specifics from each of the other cogs.· (Like "WAITPNE(|<pinA+|<pinB,|<pinA+|<pinB,0)").· I don't have my manual handy, so I'm not positive about the WAITPNE format.
·