Shop OBEX P1 Docs P2 Docs Learn Events
Wrong cog switch — Parallax Forums

Wrong cog switch

comsolcomsol Posts: 7
edited 2007-06-07 12:39 in Propeller 1
Hello all folks,
I write the following code:

{{ Output.spin }}

VAR
long StackToggle24[noparse][[/noparse]18] 'Stack space for new cog
long StackToggle26[noparse][[/noparse]18] 'Stack space for new cog
byte Cog 'Hold ID of cog in use, if any
byte Success

OBJ

T24 : "Toggle24"
T26 : "Toggle26"


PUB Main
{{Start new blinking process in new cog; return True if successful.}}

cognew(T24.Toggle24, @StackToggle24)
cognew(T26.Toggle26, @StackToggle26)

'the same result I call the methode from the objects

'T26.Toggle26
'T24.Toggle24


and I create two objects:
Toggle24.spin
and Toggle26.spin

PUB Toggle24
{{Toggle Pin, Count times with DelayMS milliseconds in between. }}
dira[noparse][[/noparse]24]~~ 'Set I/O pin to output direction
repeat 'Repeat for Count iterations
!outa[noparse][[/noparse]24] ' Toggle I/O Pin
waitcnt(4_000_000 + cnt) ' Wait for Delay cycles 'Clear Cog ID variable

and

PUB Toggle26
{{Toggle Pin, Count times with DelayMS milliseconds in between}}
dira[noparse][[/noparse]26]~~ 'Set I/O pin to output direction
repeat 'Repeat for Count iterations
!outa[noparse][[/noparse]26] ' Toggle I/O Pin
waitcnt(4_000_000 + cnt) ' Wait for Delay cycles 'Clear Cog ID variable

the chip switched not from one cog to other
only the first object method a execute.

What's wrong???

Best Regards: Uwe Reinersmann

Post Edited (comsol) : 6/4/2007 8:10:54 PM GMT

Comments

  • KaioKaio Posts: 253
    edited 2007-06-04 20:59
    Uwe,

    if you call the cognew in each Toggle object it will work. So please add to each Toggle object a method start like this.
    PUB start(stack)
    
      cognew(Toggle24, stack)
    
    
    



    And in the main method use the following code.
      T24.start(@StackToggle24)
      T26.start(@StackToggle26)
    
    



    It seems that Spin can only initiate a new cog with a method of the current object correctly.

    Thomas
  • comsolcomsol Posts: 7
    edited 2007-06-07 12:39
    Hallo Thomas
    thank you for your fast response.
    The answer is competent and it works!
    many thanks and best regards: Uwe Reinersmann
Sign In or Register to comment.