Shop OBEX P1 Docs P2 Docs Learn Events
Starting a new cog in spin — Parallax Forums

Starting a new cog in spin

PhilldapillPhilldapill Posts: 1,283
edited 2008-01-28 01:07 in Propeller 1
I'm having trouble starting a new cog with a spin function. I've used the generic cognew line from most other objects. The object with these functions is Clock.

PUB Start
· okay := cog := cognew(TickTock,cogSpace) + 1

PUB TickTock | clkcnt
· clkcnt := cnt
· repeat
··· incSec
··· waitcnt(clkcnt += clkfreq)

cogSpace is just a LONG. Here is the problem: When I try to call Clock.Start from my Main in the other cog, the main cog seems to freeze and won't get passed the Clock.Start call. Any ideas?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-01-28 01:00
    For a start, the 2nd parameter has to be the address of a space to use for the stack for that cog's interpreter. Unless you have a good idea of how much stack space to provide, I'd suggest 20 to 30 longs. Your cognew call should look like "cognew(TickTock,@cogSpace)" with cogSpace declared as "long cogSpace[noparse][[/noparse] 20 ]".
  • PhilldapillPhilldapill Posts: 1,283
    edited 2008-01-28 01:07
    Ah! That's the problem. I suppose the stack is used for storing temp variables and such, and if you don't have enough space, it gets funky... Thanks Mike!
Sign In or Register to comment.