Wrong cog switch
comsol
Posts: 7
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
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
if you call the cognew in each Toggle object it will work. So please add to each Toggle object a method start like this.
And in the main method use the following code.
It seems that Spin can only initiate a new cog with a method of the current object correctly.
Thomas
thank you for your fast response.
The answer is competent and it works!
many thanks and best regards: Uwe Reinersmann