Shop OBEX P1 Docs P2 Docs Learn Events
Can't stop processes with COGSTOP — Parallax Forums

Can't stop processes with COGSTOP

WolfbrotherWolfbrother Posts: 129
edited 2010-01-23 16:19 in Propeller 1
I'm almost sorry to post this one, except I can't see the answer no matter what I try.

When I exit my main repeat loop, I thought I understood that it starts executing the next instruction out of the loop you just finished. So in my code I tried to stop the motors from spinning by using COGSTOP.( commented out for the moment) ·That didn't work, so then I tried passing zeroing values to the motors. That hasn't worked either. Using the serial terminal, I can see that I get to the DONE, but what's happening?

Thanks in advance,

Dave

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2010-01-23 01:59
    What makes you so sure that your motors are assigned to cogs 1 to 4? It's not as simple as counting your own calls to cognew, starting other objects may consume cogs as well.
  • WolfbrotherWolfbrother Posts: 129
    edited 2010-01-23 02:04
    I just followed the example in the lab, to get the idea that they started in that order.

    So does that mean I should use COGINIT and force them to be 1..4? I just followed the example in the lab, to get the idea that they started in order. If that isn't the best method what would be?

    Thanks,

    Dave
  • BradCBradC Posts: 2,601
    edited 2010-01-23 02:07
    Cognew returns the cog number it just started. I'd use

    X := cognew(mycog, @stack)

    ..

    Cogstop(X)

    If you really want to do it that way.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Life may be "too short", but it's the longest thing we ever do.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-01-23 02:56
    Never use coginit! (And rip out the manual page that describes it.) Always start a cog with cognew and save the return value for later use with cogstop.

    -Phil
  • WolfbrotherWolfbrother Posts: 129
    edited 2010-01-23 04:31
    Hi all,

    Thanks for the suggestions. I took the advice and modified the code to return which cog was started. I also used the serial terminal to output this info to my screen. It returns a 5, so I am guessing that's correct. But when I use cogstop(dcmtrcog) it still doesn't stop the cog for the motor. I also changed where I zero the motor speed out and it doesn't change the motor speed at all. It's like it doesn't reach these instructions, but it does print "done" to my screen. What am I missing?
  • kuronekokuroneko Posts: 3,623
    edited 2010-01-23 05:03
    The cog you start and which runs DEMO_Example starts another cog (PWM.Start) which effectively does all the work. So when you stop dcmtrcog its child cog keeps running. You better take a step back and sort out the life-cycle of all your objects [noparse];)[/noparse]
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-01-23 07:05
    Typically, any object you start should have a stop routine that takes care of the cleanup, such as calling the stop routines of any objects it's started and stopping any cogs it has spawned.

    -Phil
  • WolfbrotherWolfbrother Posts: 129
    edited 2010-01-23 16:19
    Hi, I added a PWM.stop to the code at the end and now the motor stops just fine. I really didn't understand that with the objects created they typically do all the bookkeeping for things like this. I'm also a bit (a lot actually) over my head with the software, but I'll never get better unless I keep working at it. Thanks to everyone who helps on the forum, I'm getting things to work. I'm still far more comfortable with the stamp, but I much prefer the power of the propeller. This program will have 4 different motors running at the same time and that just wouldn't have happened with the stamp.

    Thanks,

    Dave
Sign In or Register to comment.