Shop OBEX P1 Docs P2 Docs Learn Events
Indeterminate cog termination with asm — Parallax Forums

Indeterminate cog termination with asm

BradCBradC Posts: 2,601
edited 2007-08-27 19:30 in Propeller 1
Have a _very_ simple program below that toggles a pin on 5 sec intervals in its own cog.
If I leave out the cogid and cogstop commands, it leaves the output pin enabled and set high.
I guess the space after the compiled program is being loaded with indeterminate data and the program gets stuck somewhere now allowing the cog to terminate.
Trap for young players.. (ie. me)


Anyone had a crack at low speed USB on the Prop yet? I'm beating my head against a a wall, but I'll get there unless someone beats me to it.


PUB Start : OK

OK := cognew(@enablecog, 0)





DAT



enablecog org

cogid cog

mov dira, #4

mov outa, #4

mov loop, #5

mov delay, cnt

add delay, Second

eloop waitcnt delay, Second

mov outa, #0

waitcnt delay, Second

mov outa, #4

djnz loop, #eloop

cogstop cog





loop long 5


Second long $17D78400


delay res 1

cog res 1

Comments

  • BradCBradC Posts: 2,601
    edited 2007-08-27 18:22
    Well, that formatted nicely.. anyway, you get the idea
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-27 18:30
    Please surround your code by
    [noparse][[/noparse] code]
    and
    [noparse][[/noparse] /code]
  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-27 18:44
    Yes, like any computer, if you don't put some kind of stop instruction at the end, it doesn't stop.

    The COGID/COGSTOP combination is the best because it makes the cog available for others to use. You can put a "jump to self" which lets the cog run at full speed or you can do a WAITCNT in a loop so the cog spends most of its time in a low power mode.

    For many practical uses, the cog is left to periodically check HUB memory for a command from some other part of the program so it looks for something new to do. Many of the I/O drivers work this way. They run mostly continuously looking for something to do whether an I/O pin change or some data left in a buffer for it to process.
  • BradCBradC Posts: 2,601
    edited 2007-08-27 19:30
    I thought (and we all know what thought did - planted a feather and thought he'd grow a chicken) that when the code finished the cog stopped itself.

    Having thought (there it is again!) about it a little harder I guess that only relates to spin. Asm is going to keep on grinding until you stop it.

    I don't often stop cogs actually, most of mine are kept pretty busy shuffling bits around, but in this case I'm debugging something and after 5 attempts (the "pull the pin high for 5 seconds") I decided to stop harassing the host and give it a rest. Rather than loop for eternity I thought I'd try and stop the cog. Mission accomplished.

    I can see I'm going to need to try some of the scope objects for this so I can see what is actually going on. I'm only using 3 cogs at the moment in any case.
Sign In or Register to comment.