Shop OBEX P1 Docs P2 Docs Learn Events
Cog memory use — Parallax Forums

Cog memory use

I am trying to make an output (P0) blinking using an new cog in my program.
If I put everything in one Cog the program works fine but as I define a new cog there is nothing that happens at the output.
Output 1 is just an additional signal to drive the direction of my stepping motor. This part of the program has been taken out of the Blinker cog.

Can anyone give me some feedback please

Comments

  • ElectrodudeElectrodude Posts: 1,657
    edited 2016-01-18 15:50
    Try removing the call to Go at the end of Blinker.

    Go will repeat without Blinker telling it to, since it's in a different cog and is in a repeat.
  • I've attached a slightly more advanced blinker for your consideration (those last three words get used frequently this time of year in Hollywood).
  • Thanks for the info to remove the Go instruction. But how can I tell the main cog that the cog with the Blinking method has ended his task?
  • One way you could do it is to set up a flag variable. Define a byte in your main cog's variables and make that one of the parameters that get passed to the blinking cog. Have your main cog, at startup, set that byte equal to 0, then periodically poll to see if it's been set to 1 by the blinky cog. Have the blinky cog set it to 1 after it's finished. Bata bing.
  • Do you main as a local variable of the method calling the cog or under the VAR of the main program ?
    Apparently this does not work by declaring the variable global in the VAR section but I wil test it to see if it works as a local variable of the main cog.
    I went way back to the "Propeller Education Kit labs:fundamentals" under the section methods and cogs lab. This starts with a very simple program called "CallBlink.spin. This does not work either and is even not calling a cog.
    Is there something wrong with my processors??
  • You'd have to define it in such a way that the Blinker cog can see it, so that means either defining it in the same Spin object as the Blinker method, or passing the blinker method the address of the variable you want it to signal somehow.

    I've attached a modified version. I have no way to test this at work, so I can't guarantee that it compiles correctly, but it should convey the idea.
  • Check out page 76 of the Propeller Manual v1.2, COGNEW. In the description you see there's a parameter list, where you include variables to pass to the new cog separated by commas. That is where you'd pass the DoneBlinking variable to the new cog if the new cog is going to run spin and not PASM. For PASM there's a different method, but literally any obex PASM project can be used to see how PASM parameter passing works.
  • Thanks guys,
    This really helped me to get on with the propeller.
Sign In or Register to comment.