Shop OBEX P1 Docs P2 Docs Learn Events
stopping a cog than restarting it — Parallax Forums

stopping a cog than restarting it

lockadoclockadoc Posts: 115
edited 2010-01-23 03:42 in Propeller 1
I ask before in the Forum about trying to pause a method , and was hinted at way to do it, but just could not grasp it.I've been trying different ways to do it with no luck.I made this simple object to try it out on and have been at it for a couple of days. Could some-one please show me where I'm being dumb ? I've tried using COGSTOP and COGINIT by looking at the two books I have , don't think thats the way· to do it.

Bill S
Louisville KY.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-01-22 20:49
    There is no way for one cog to make another cog pause. A cog can pause itself for a period of time by using WAITCNT and it can pause waiting for a specific pattern of I/O pin states using WAITPNE or WAITPEQ. That's all.

    If two cogs need to interact, they can signal each other, usually by one cog using a byte that is set to some value that the other cog checks periodically. If that byte is some value (say 1), then the 2nd cog stops doing whatever it's doing except checking the byte. If the byte gets changed to zero, it starts doing whatever it's supposed to do (and continues to check the byte's value.

    Post Edited (Mike Green) : 1/22/2010 8:56:44 PM GMT
  • John AbshierJohn Abshier Posts: 1,116
    edited 2010-01-22 20:50
    The variable shiftcogID in butcog is a complete different variable from shiftcogID in shift. It butcog it starts as zero and is never changed. The line cogstop (shiftcogId -1 ) tries to stop cog -1. I don't know how Spin handles in invalid cogID. Shift needs to pass the variable shiftcogID back to test1top who then provides it to butcog.

    John Abshier
  • Mike GreenMike Green Posts: 23,101
    edited 2010-01-22 20:57
    @John - Spin doesn't check the cogid value. It simply passes that value to a COGSTOP instruction which uses only the least significant 3 bits for its operand and stops that cog, no matter which cog it is.
  • StefanL38StefanL38 Posts: 2,292
    edited 2010-01-22 22:01
    Hello Bill,

    stopping a cog is not a selfpurpose. So please tell us what is the bigger thing behind it.

    If you tell the forum what you want to achieve in the end.
    You wrote about pausing a method. I think you want to achive that something "is done" for a certain time
    and then controlled by whatever "not to be done" for a certain time.

    Most simple way to do this is a repeat-loop with an if-condition.

    best regards

    Stefan
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-01-22 22:08
    Bill,

    I believe the attached demo does what you want -- and notice that it's all wrapped up in one nice, tidy file! tongue.gif

    In the main loop a background button debouncer is launched into its own cog. When a button is pressed this cog will change the value of a variable called status which is used by the sequencer cog.

    Next a sequencer cog is launched. Note that it reports its id so that it can be stopped from another cog. It also uses an extern value called steptime to affect how it runs, and it will stop in its tracks when the program is put into pause mode (status == 1).

    After 30 seconds the sequencer is killed -- just to show you that it can be done.

    Spend some time with it; until you fully come to grips with how this works you'd just be spining your wheels and starting new threads that all lead back to the same project.


    BTW, there is no need to include the Propeller tool in your archives, you're just wasting Parallax server space. Those of us who would help you have it. Just use

    File >> Archive >> Project

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon McPhalen
    Hollywood, CA
  • Brian RileyBrian Riley Posts: 626
    edited 2010-01-23 03:42
    JonnyMac said...
    Bill,

    Spend some time with it; until you fully come to grips with how this works you'd just be spining your wheels and starting new threads that all lead back to the same project.


    Jon, took your advice and played ... and played ... some things had been bothering me about cogs ... now they are quite clear ... thanks!

    The sequencer looks neat on the PPDB!

    I uploaded what I did in case anyone else wants something more to play with ... I commented most of my additions/changes

    cheers ... BBR

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    cheers ... brian riley, n1bq, underhill center, vermont
    The Shoppe at Wulfden
    www.wulfden.org/TheShoppe/
Sign In or Register to comment.