Shop OBEX P1 Docs P2 Docs Learn Events
Repeatedly starting and stopping a cog..... — Parallax Forums

Repeatedly starting and stopping a cog.....

th3jesterth3jester Posts: 81
edited 2011-04-18 14:23 in Propeller 1
Simple question:

Is it efficient/alright/okay if I continuously start and stop and restart a cog?

i.e.-
repeat
fMath.start
(do some math routines)
fMath.Stop

Comments

  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-04-18 13:47
    Should be no problem. A friend of mine used my encoder cog in this way. The start() method for that object allows the user to set min and max limits so every time he moved to a new field for input he would restart the object with the limits for that field. As long as the object has a stop() method (that stops the cog before attempting to restart) you should be okay.
  • MagIO2MagIO2 Posts: 2,243
    edited 2011-04-18 14:23
    efficient : NO , alright : yes , okay : depends ;o)

    efficient in terms of power consumption: depends on the average runtime of the COG. If you start it repeatingly you waste power for the startup process, where the COG has to load 512 LONGs from HUB RAM. The more often you start the COG inrelation to the runtime the more power you waste. If you can use a WAITCNT/WAITPEQ/WAITPNE you should prefere these for saving power.
    efficient in terms of execution speed: again you have the startup. Response time for external events is much faster when not restarting but keeping the COG in a loop.

    Alright: It won't harm the propeller. It's been build for that.

    Okay: As you can see from the previous answers, it simply depends on what the propeller has to do. Restarting a COG each second which has to generate a video signal is a bad idea in general. Starting and stopping COGs which are related to user-input/actions/instructions .. why not.
    If your design does not need high response times and you prefere an easy implementation for power saving or if you do not have enough COGs for having a "background" COG for all the tasks ...
Sign In or Register to comment.