Shop OBEX P1 Docs P2 Docs Learn Events
How to Avoid sitting in a repeat loop? — Parallax Forums

How to Avoid sitting in a repeat loop?

RegorRegor Posts: 19
edited 2007-04-04 19:15 in Propeller 1
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.











·

Comments

  • T ChapT Chap Posts: 4,223
    edited 2007-04-04 19:15
    Well, if you were to have the main cog also do it's call once a pin state has changed, you could do WAITPEQ or WAITPNE in all 3 cogs. The main cog and the other cogs can still wait on the same pin, then do their work when the pin changes, this will save some power when waiting.

    Post Edited (TChapman) : 4/4/2007 7:51:50 PM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2007-04-04 19:15
    You have a couple of choices:
    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.


    ·
Sign In or Register to comment.