Shop OBEX P1 Docs P2 Docs Learn Events
Variables & Cogs — Parallax Forums

Variables & Cogs

Travis M. BestTravis M. Best Posts: 9
edited 2009-11-23 05:50 in Propeller 1
First I Want To Thank Everyone So Far For All Their Help I've Learned Alot On The Propeller Chip. Thanks To Everyone's Help. I do have another Issues and that is I am try to read and write to variables between cogs what is the best way to do this??

Thanks
Travis

Comments

  • FredBlaisFredBlais Posts: 380
    edited 2009-11-23 05:20
    In Spin or in ASM? In Spin, I think that you should pass the address (@) of where your data is in memory, so the other cog can use this as a pointer (with byte, word and long command)
  • Mike GreenMike Green Posts: 23,101
    edited 2009-11-23 05:38
    If you have two cogs running Spin code, the variables are all in the hub (main) ram and you can just read and write the same variables.

    If you have two cogs running Spin code in different objects, the variable names are not available outside the object(s). One object can call a routine in the other object to set the variable to some value or to return (get) the value of the variable. You can also call a routine in another object that returns the address of a variable which can be used to set or get the variable value (using LONG, WORD, or BYTE). You do have to be careful about two separate cogs trying to change the same variable(s) at the same time.

    If you want more specific suggestions or examples, you're going to have to explain in more detail what you're trying to do.
  • FredBlaisFredBlais Posts: 380
    edited 2009-11-23 05:50
    Yeah, I forgot to say that my example is for spin code for 2 differents file [noparse]:)[/noparse]
    It could also be useful to know if he was talking about main ram, or cogs 512 long, but I suspect it's about the main ram, hehe.If it's main ram and same file, he don't have to worry about address things, just use the variable name, simple as that!

    Anyway, I'm just reformulating what the forum master has said (Mike) but he did it better than me :P
Sign In or Register to comment.