Shop OBEX P1 Docs P2 Docs Learn Events
I got the cognew blues! — Parallax Forums

I got the cognew blues!

Thomas FletcherThomas Fletcher Posts: 91
edited 2011-06-21 12:03 in Propeller 1
I have only used cognew indirectly using other objects.

I wanted to blink a pin in the background,
but the code below does not work.

When I uncomment the method blinkled it works,
but the method does not work when I run it with cognew.


CON
         _clkmode        = xtal1 + pll16x
         _xinfreq        = 5_000_000
VAR

  long pin
  long high,low
  long blinkstack[noparse][[/noparse]32]
 
PUB startledcog

   
   low := 7
   high := 7
   pin := low
   dira[noparse][[/noparse]low..high]~~


   high++
   'blinkled
   cognew(Blinkled, @blinkstack)

PUB Blinkled
   repeat  
       repeat until pin == high
          !outa[noparse][[/noparse]pin]
          pin++
          waitcnt(55_00000 + cnt)
    pin:=low
     

Comments

  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2010-04-01 20:34
    You are only declaring pins 7..7 (that would be just 7) outputs and then outputting on pins higher then that. The default is input. If you would have it repeating a

    dira[noparse][[/noparse]pin]~~

    with every repeat loop in the BlinkLed PUB then it should work.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't click on this.....

    Use the Propeller icon!! Propeller.gif

    You had better not start ANOTHER PropII thread.
  • Thomas FletcherThomas Fletcher Posts: 91
    edited 2010-04-01 20:43
    Man, you guys are fast. That fixed it. Thanks. Weird. I thought it
    was something to do with cognew and I was looking in the wrong
    place all afternoon.
  • kuronekokuroneko Posts: 3,623
    edited 2010-04-02 01:19
    Thomas Fletcher said...
    I thought it was something to do with cognew and I was looking in the wrong place all afternoon.
    In a way it was. You defined dira behaviour for the main cog (which exits after cognew). The cog started by cognew needs its own dira/outa setup.
  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2010-04-02 02:01
    Good! This is the first time that my advice has worked!

    I must say that I would have never thought of this exept that I, too, have run into this problem multiple times, mainly forgetting the dira all together!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't click on this.....

    Use the Propeller icon!! Propeller.gif

    You had better not start ANOTHER PropII thread.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-04-02 03:14
    Eh, no. The point that kuroneko was making is that dira was set in the top level cog, but that those settings have no effect whatsoever in another cog. Each cog has its own dira register and, to create an output in any cog, it's own dira bits have to be set for the output pins.

    -Phil
  • SarielSariel Posts: 182
    edited 2011-06-21 10:15
    I am having a hard time wrapping some concepts up in my head, and I was hoping that someone could lend a different explanation to me. It is along the lines of:
    those settings have no effect whatsoever in another cog.

    here is the scenerio:
    Top file runs in cog 0, and that calls the cog start method in "Object A"
    "Object A" in it's init, starts cog1 with an infinite loop.
    Later on, Top file needs "Method Z" from "Object A". Method Z is not used by the infinite loop in cog 1.

    I am just about positive that the infinite loop will not prevent this from happenening. If this the case, does it run "Method 1" in cog 0, or would it run it in cog 1, interrupting the loop?

    I really hope that made sense to everyone. If not, I can try to re-phrase it.
  • AribaAriba Posts: 2,690
    edited 2011-06-21 11:14
    Hello Sariel

    Yes, you can call your MethodeZ in the sub-objectA. It will run in Cog0, if called from the Top object. You can the same methode also call from your "infinite cog1 Loop", then it will run in cog1. It's the Spin interpreter in a cog that decides in which cog a methode is executed and not the methode, or the object.

    Hope this helps

    Andy
  • SarielSariel Posts: 182
    edited 2011-06-21 11:51
    Ahh. gotcha. I thought that was how it went, but I could not be sure. Good to have someone verify this a little for me. THank you.
  • MicrocontrolledMicrocontrolled Posts: 2,461
    edited 2011-06-21 12:03
    This thread is a year old.
Sign In or Register to comment.