Shop OBEX P1 Docs P2 Docs Learn Events
question about cogs — Parallax Forums

question about cogs

I will try to post my code ....
'This is for blink project
    '    started Feg 24-2016
    '      cogblink

      
Con                         ' 
_Clkmode = Xtal1 + pll16x   '     
_Xinfreq = 5_000_000        '    
  high = 1                  'FEB 24-2016
  low = 0                   '               
  out = $FF                 
Var
  byte X
  long stack[40]                'for blink
  long stack1[40]                'for flash
 
Obj
  pst:"Parallax Serial Terminal"

Pub   main 

 DirA[0..7]:= out
 DirA[8..15]:= out
 DirA[16..23]:= out
 DirA[24..29]:= out   
 DirA[31]:=0
 DirA[30]:=1
 
 cognew (blink,@stack)
 cognew(flash,@stack1)

                     
    outA[27] := 1         'set to tx                                                     
    pst.Start(38_400)     'Set Terminal to 38400 baud

   X := 1
                          'pst knows pins 30,31
  repeat
        pst.Char("X")
        waitcnt(50_000_000+ cnt)
        pst.Char ("Z")
        waitcnt(50_000_000+ cnt)
                                                              

PUB blink

 if X==1
    repeat
       outA[1] := 1
       waitcnt(30_000_000 + cnt)
       outA[1] := 0
       waitcnt(30_000_000 + cnt)          
          
PUB flash
  if X==1
      repeat
         outA[2] := 1
         waitcnt(10_000_000 + cnt)
         outA[2] := 0
         waitcnt(20_000_000 + cnt)
that do not work

Comments

  • This was a simplification
    I would like to have seperate objects running in there own cogs.
    this example just keeps printing x,z ... and no blinking.
    what did I miss....?
  • Each cog has its own dira register to enable outputs via its own outa. So you have to set the diras in the new cogs, not in the parent cog.

    -Phil
  • In addition to the dira problem PhiPi pointed out, both of your cogs might stop immediately upon reaching the statement "if X == 1". They might not, though, if they haven't finished launching by the time the main cog does "X := 1", but I'm not a Spin timing expert. Do you instead want an empty "repeat until X == 1" loop that waits until X equals 1?
  • Hey! thanks... I put in the Dira and took out the if X, and it works. Its been a year or so since doing spin,
    and also, I think my brain is going away. thanks guys...
    Bill
Sign In or Register to comment.