Shop OBEX P1 Docs P2 Docs Learn Events
Propeller basics (use multiple cogs to run processes). need a little help with — Parallax Forums

Propeller basics (use multiple cogs to run processes). need a little help with

laser-vectorlaser-vector Posts: 118
edited 2010-07-29 01:23 in Propeller 1
hey, its been a long time since ive been here. i just started a new job and now have an opertunitie to learn the propeller! smile.gif i just purchased a propeller chip and professional board. ive been reading through the manual and im currently doing the project on page 124 where they are able to create an array of output objects {LED[noparse][[/noparse]6] : "Output"} and launch a method in multiple cogs {LED[noparse][[/noparse]NextObject].Start(18, 600_000, 300)}.

ok so i did it their way and it worked great, but during the whole time ive been playing with their example, i have also been making my own little program (which is very similar to what im learning) that has a little more intricacy.

Description: this is a type of led sequence, using 4 cogs to control the output state of 4 consecutive pins {0, 1, 2, 3, <or> 3, 2, 1, 0}. you can set the delay between pinstate changes, the number of times the loop will execute, what direction the sequence is moving, and if the outputs stay high or flip back off after the next output goes high
{eg. Trail = true: 1,0,0,0, > 1,1,0,0, > 1,1,1,0, > 1,1,1,1, > trail = falese: 1,0,0,0, > 0,1,0,0, > 0,0,1,0, > 0,0,0,1,}

this is my "sequence control" method call: LED[noparse][[/noparse]NextObject].Start(Pin, Count, Delay, Trail, Direction)
I would like to call the start method 4 times and load it into 4 cogs, then as those methods finish i would like to run them again but with different parameters (same pin of course!)
but every time the program loads, some of the outputs start acting weird. as if pins from one method can randomly override pins from another method. sometimes even whole processes stops (randomly in one, some or even all cogs depending on the values i set in sequence control..).
im not sure what i should be looking for, i tried changing a lot of things and re-reading some of the manual, but i really need some help

can anyone see whats wrong?
{----------------------------------------------object.spin----------------------------------------------}

CON
MAXLEDS = 4

OBJ
LED : "Output"

PUB Main
{Toggle pins at different rates, simultaneously}
   dira[noparse][[/noparse]0..15]~~
    LED[noparse][[/noparse]NextObject].Start(0, 50, 2_000_000, 0, 1)  
    LED[noparse][[/noparse]NextObject].Start(4, 50, 2_000_000, 0, 1)  
    LED[noparse][[/noparse]NextObject].Start(8, 50, 2_000_000, 0, 0)  
    LED[noparse][[/noparse]NextObject].Start(12, 50, 2_000_000, 0, 0)   
    repeat

PUB NextObject : Index
  repeat
    repeat Index from 0 to MAXLEDS-1
      if not LED[noparse][[/noparse]Index].Active
        quit
  while Index == MAXLEDS





{----------------------------------------------Output.spin----------------------------------------------}
VAR
  long Stack[noparse][[/noparse]9]                 
  byte Cog                     

PUB Start(pin, count, delay, trail, direction): Success
  Stop
  Success := (Cog := cognew(Toggle(pin, count, delay, trail, direction), @Stack) + 1)
  
PUB Stop
  if Cog
    cogstop(Cog~ - 1)

PUB Active: YesNo
  YesNo := Cog > 0

PUB Toggle(pin, count, delay, trail, direction)
dira[noparse][[/noparse]pin]~~
dira[noparse][[/noparse]pin+1]~~
dira[noparse][[/noparse]pin+2]~~
dira[noparse][[/noparse]pin+3]~~'
  repeat
 
      if direction > 0
        !outa[noparse][[/noparse]pin+0]
      else
        !outa[noparse][[/noparse]pin+3] 
     waitcnt(delay + cnt)
      if trail < 1
        if direction > 0
          !outa[noparse][[/noparse]pin+0]
        else
          !outa[noparse][[/noparse]pin+3]
    {---------------------}
      if direction > 0
        !outa[noparse][[/noparse]pin+1]
      else
        !outa[noparse][[/noparse]pin+2]     
     waitcnt(delay + cnt) 
      if trail < 1 
        if direction > 0
          !outa[noparse][[/noparse]pin+1]
        else
          !outa[noparse][[/noparse]pin+2]
    {---------------------}
      if direction > 0
        !outa[noparse][[/noparse]pin+2]
      else
        !outa[noparse][[/noparse]pin+1]     
     waitcnt(delay + cnt) 
      if trail < 1
        if direction > 0
          !outa[noparse][[/noparse]pin+2]
        else
          !outa[noparse][[/noparse]pin+1]
    {---------------------}
      if direction > 0
        !outa[noparse][[/noparse]pin+3]
      else
        !outa[noparse][[/noparse]pin]        
     waitcnt(delay + cnt) 
      if trail < 1
        if direction > 0
          !outa[noparse][[/noparse]pin+3]
        else
          !outa[noparse][[/noparse]pin+0]
  while Count := --Count #> -1
  cog~ 


   {----------------------}




The above will run one sequence on pins [noparse][[/noparse]0..3] [noparse][[/noparse]4..7] [noparse][[/noparse]8..11] and [noparse][[/noparse]12..15] they should all start running at once (and if delay and count are the same (as they are above) they should all end at pretty much the same time as well). the above works only sometimes and other times it crashes.

But now i also would like to add more sequences so that when the first four processes are finished, they have something else to do (like in the example below).
oh and by the way, this instantly locks up..

{----------------------------------------------object.spin----------------------------------------------}

CON
MAXLEDS = 4

OBJ
LED : "Output"

PUB Main
{Toggle pins at different rates, simultaneously}
   dira[noparse][[/noparse]0..15]~~
    LED[noparse][[/noparse]NextObject].Start(0, 50, 2_000_000, 0, 1)  
    LED[noparse][[/noparse]NextObject].Start(4, 100, 1_000_000, 1, 1)  
    LED[noparse][[/noparse]NextObject].Start(8, 100, 1_000_000, 1, 0)  
    LED[noparse][[/noparse]NextObject].Start(12, 50, 2_000_000, 0, 0)

    LED[noparse][[/noparse]NextObject].Start(0, 100, 1_000_000, 1, 1)  
    LED[noparse][[/noparse]NextObject].Start(4, 50, 2_000_000, 0, 0)  
    LED[noparse][[/noparse]NextObject].Start(8, 50, 2_000_000, 0, 1)  
    LED[noparse][[/noparse]NextObject].Start(12, 100, 1_000_000, 1, 0) 

    LED[noparse][[/noparse]NextObject].Start(0, 50, 1_000_000, 0, 0)  
    LED[noparse][[/noparse]NextObject].Start(4, 25, 2_000_000, 0, 1)  
    LED[noparse][[/noparse]NextObject].Start(8, 25, 2_000_000, 0, 0)  
    LED[noparse][[/noparse]NextObject].Start(12, 50, 1_000_000, 1, 1)       
    repeat

PUB NextObject : Index
  repeat
    repeat Index from 0 to MAXLEDS-1
      if not LED[noparse][[/noparse]Index].Active
        quit
  while Index == MAXLEDS





thanks for any help!! tongue.gifjumpin.gif

Post Edited (laser-vector) : 7/26/2010 5:49:23 AM GMT

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2010-07-26 05:43
    Try increasing the stack size for your output object. The 9 longs are a bit on the optimistic size. Start with something high during debugging (e.g. 20). Later you can get the proper size by utilising the Stack Length object (available in the Propeller Tool library).

    In my test case with MAXLEDS set to 2 (demoboard) I need at least 11 longs stack for proper functionality.
  • laser-vectorlaser-vector Posts: 118
    edited 2010-07-26 19:52
    ok i tried adjusting from 9 longs to 20 longs (and others)

    it doesnt seem to change anything..
  • kuronekokuroneko Posts: 3,623
    edited 2010-07-27 00:37
    I took your Output.spin object unchanged except for a 20 long stack. My main object looks like this (demoboard, using pins 0..7 and 16..23):

    CON
      MAXLEDS = 4
    
    OBJ
      LED[noparse][[/noparse]MAXLEDS] : "Output"
    
    PUB Main
    {Toggle pins at different rates, simultaneously}
      dira := $00FF00FF             ' 0..7, 16..23
    
        LED[noparse][[/noparse]NextObject].Start(0, 50, 2_000_000, 0, 1)  
        LED[noparse][[/noparse]NextObject].Start(4, 100, 1_000_000, 1, 1)  
        LED[noparse][[/noparse]NextObject].Start(16, 100, 1_000_000, 1, 0) 
        LED[noparse][[/noparse]NextObject].Start(20, 50, 2_000_000, 0, 0)
    
        LED[noparse][[/noparse]NextObject].Start(0, 100, 1_000_000, 1, 1)  
        LED[noparse][[/noparse]NextObject].Start(4, 50, 2_000_000, 0, 0)  
        LED[noparse][[/noparse]NextObject].Start(16, 50, 2_000_000, 0, 1) 
        LED[noparse][[/noparse]NextObject].Start(20, 100, 1_000_000, 1, 0) 
    
        LED[noparse][[/noparse]NextObject].Start(0, 50, 1_000_000, 0, 0)  
        LED[noparse][[/noparse]NextObject].Start(4, 25, 2_000_000, 0, 1)  
        LED[noparse][[/noparse]NextObject].Start(16, 25, 2_000_000, 0, 0) 
        LED[noparse][[/noparse]NextObject].Start(20, 50, 1_000_000, 1, 1)       
    
        repeat
    
    PUB NextObject : Index
      repeat
        repeat Index from 0 to MAXLEDS-1
          if not LED[noparse][[/noparse]Index].Active
            quit
      while Index == MAXLEDS
    


    This gives me 3 sequences on the LED bar (single LED and a worm). They change direction and/or are swapped around. Then output stops (as there is no repeat for this functional block). So it does what it says on the tin.

    Maybe take a few steps back. Start with MAXLEDS = 1 (single pin group) and see if the sequence stays in the relevant pin group. Then increase MAXLEDS etc.
  • laser-vectorlaser-vector Posts: 118
    edited 2010-07-29 01:23
    hey kuroneko,

    thanks for taking a closer look at this, i kept reading through the manual and have realized a few mistakes i was making. i think the problem i was experiencing was when one object finished and another would start, that new object may have been controlling io's that another object was currently using (causing major conflicts...)

    as i said, it worked sometimes, i think it was because certain timing sequences got "lucky" and started just after a conflicting process had just stopped.. but im not sure if that was the case.

    however i have moved on a little from this and feel i have a little better of an understanding of whats going on internally. in fact im already doing graphics through VGA [noparse]:D[/noparse]

    so im a little excited to keep going, it seems that with these propellers, whenever i dont understand something ill take a step back, read a little about it, download some stuff from the exchange and wham! it hits me, "oh thats how you do it!!" scenario lol.

    so far all i can say is these things are amazing
Sign In or Register to comment.