Shop OBEX P1 Docs P2 Docs Learn Events
coginit vs cognew — Parallax Forums

coginit vs cognew

atirageatirage Posts: 2
edited 2006-12-18 11:56 in Propeller 1
Hello!
Just one quick question:
If you start a cog and then you stop it, can you restart it without loading the same piece of code again into that cog?
The documentation says about coginit that it can be used to restart a cog, but it does not specificy if it reloads the code also in this case.

Thx!

Comments

  • parskoparsko Posts: 501
    edited 2006-12-18 08:27
    Short answer is no.

    But, another way, if you can spare that cog, is to dedicate a pin, and use WAITPNE. Let the COG sit there until another COG toggles the pin.

    When you stop a COG, the cog ram is cleared. You must reload said cog to run it again.

    -Parsko
  • atirageatirage Posts: 2
    edited 2006-12-18 08:40
    I was afraid this will be the answer smile.gif
    I have a cog which loads a number of bytes from an external eeprom into hub memory using i2c and I have to use this cog a lot of times, so it would have been a good idea to just stop and restart it... something like a thread in the PC's. Anyway I guess I can use that pin toggling idea or even some locks.

    Thx again!
    Attila
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2006-12-18 11:56
    Rather than try and stop and start the cog just stop and start the program running in the cog, assign a variable in hub ram that will act as a flag and get the program to keep checking this, your other cogs can then stop and start the program at will. Its the same idea as using a pin except you are using ram instead.

    Graham
Sign In or Register to comment.