Shop OBEX P1 Docs P2 Docs Learn Events
Launching into a new cog — Parallax Forums

Launching into a new cog

Penguin-fachPenguin-fach Posts: 11
edited 2011-12-22 06:50 in Propeller 1
As a newbie to the Propeller I would really appreciate it if someone would clarify something for me.

I have an application where an LCD will update a virtual date display in response to pulses: one day increment per pulse. The pulses are generated by another method. For my test code I have a top method that for the purposes of the test will generate the pulses using a timing loop. There are two other objects; one controls the LCD and the other performs the date calculations and assembles the displayed text.

My question is how best to launch the date display into another cog? Am I correct in understanding that once a method is launched into a new cog that this method has to have a repeat loop. If I were to launch a method into a new cog and that method only runs once what happens to the newly launched cog once the method ends and what happens to any associated data?

Comments

  • Clive WakehamClive Wakeham Posts: 152
    edited 2011-12-08 14:40
    Without the repeat statement then it just pauses there, the data is still there. So unless you use one of the other statements like "coginit" in which you can restart it......
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-12-08 15:08
    PF,

    Here's a tiny demo for launching a new cog.


    If you post your code we could help more.
    VAR
      long stack[50]
    
    PUB Main
    
      cognew(DisplayMethod, @stack)
      repeat
        ' Main method's loop
    
    PUB DisplayMethod
    
    ' do one time only stuff here.
    ' it's a good idea to set IO pins from within the cog that will use them.
      repeat
        ' DisplayMethod's loop
    

    I would avoid using "coginit" unless you really know what you're doing. (I personally have never used it.)
  • Duane DegnDuane Degn Posts: 10,588
    edited 2011-12-08 15:11
    Without the repeat statement then it just pauses there, the data is still there. So unless you use one of the other statements like "coginit" in which you can restart it......

    As I said in my other post, I haven't use coginit. I don't think the cog pauses without a loop; I believe it stops and you'd have to relaunch it. (I'm not sure about this, in most cases you want a loop to keep the cog alive.)
  • Mike GreenMike Green Posts: 23,101
    edited 2011-12-08 15:22
    Have a look at the Propeller Education Kit Labs for examples of this. Keep in mind that, when you start up a method in another cog using COGNEW (or COGINIT) and that method exits by falling through the end or with an explicit RETURN, that cog will be stopped. This is true of the main method of your program also which is started by the bootloader using a COGINIT. That's why the REPEAT is there, so that cog will keep going.

    Each cog has its own I/O registers, so you have to initialize them using the cog that will use the I/O pins. This is particularly true for I/O pins used as outputs.
  • Penguin-fachPenguin-fach Posts: 11
    edited 2011-12-22 06:50
    Many thanks for the helpful replies. As with many of these issues, playing around explains so much.

    Regards, Simon
Sign In or Register to comment.