Shop OBEX P1 Docs P2 Docs Learn Events
Getting a phsa/b value from another cog, Nothing works — Parallax Forums

Getting a phsa/b value from another cog, Nothing works

mosquito56mosquito56 Posts: 387
edited 2008-01-22 21:55 in Propeller 1
I want to transfer the value of a phsa,b value back to my print module. It works in the other cog but will not return to the main module.

I have tried every combination I can think of

var
long time


pub start
time:=gettime.time
term.dec(time)

other cog:
var
long time

pub gettime:returnvalue
time:=phsb
return time

Help

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
······· "What do you mean, it doesn't have any tubes?"

······· "No such thing as a dumb question" unless it's on the internet

Technologically challenged individual, Please have pity.

Post Edited (mosquito56) : 1/22/2008 9:50:13 PM GMT

Comments

  • MacGeek117MacGeek117 Posts: 747
    edited 2008-01-21 21:54
    Unfortunately, this doesn't work: (personal experience!)
    pub gettime:returnvalue
      time:=phsb
    return time
    
    

    It should read:
    PUB GetTime : returnvalue
      returnvalue := phsb
    return
    

    RoboGeek

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "I reject your reality and subsitute my own!"

    Adam Savage, Mythbusters
    www.parallax.com
    www.goldmine-elec.com
    www.expresspcb.com
    www.jameco.com
    ·
  • Mike GreenMike Green Posts: 23,101
    edited 2008-01-21 22:04
    The special registers like PHSA and PHSB exist in each cog. When you reference them from Spin, you're referring to the register in the cog that's running the Spin interpreter that's interpreting your code. You could have several cogs running the Spin interpreter and executing the same Spin routine. Each would reference its own copy of PHSA. The only way to transfer any of this information to another cog is to copy it to a hub memory location or send it via an I/O pin to somewhere where the other cog can reference it.
  • mosquito56mosquito56 Posts: 387
    edited 2008-01-21 22:34
    I tried the return method, no go.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ······· "What do you mean, it doesn't have any tubes?"

    ······· "No such thing as a dumb question" unless it's on the internet

    Technologically challenged individual, Please have pity.
  • DavidMDavidM Posts: 626
    edited 2008-01-21 22:40
    HI Mosquito56!

    This may work for you . ( its a different approach)
    I "think" you you are trying something I wanted to do a few days ago ( I could be wrong )

    Have a look at my post called "Passing Variables by reference more than 1 level deep?" ( about 1 page back from here )

    Basically, you have to pass the variable as a reference from the main method by using the @ symbol. ( I assume you have your code in another OBJECT ). From then on, the methods ( including the COG, you refer to the variable as a "referenced" variable ( I call it a pointer )

    Try this.. ( Note, I could be wrong! As I am a beginner myself)

    Step 1) Define your variable in the VAR Block in your main method ( as normal ) and declare your object

    VAR
    LONG MyVariable
    OBJ
    MyMethod : "MyObject.spin"

    Step 2) When you what to send the variable to another OBJECT ( from the main method) use the @ symbol so it passes a pointer to the address of the variable ( the actual value will not be passed at this time)

    MyObject.MyMethod (@MyVariable)

    Step 3) In your calling method ( which is a separate object) create a new variable name. Make sure you use a different variable name , I just add "Ptr" ( for pointer) to the end of the same variable name, or you could use "Address"

    MyCallingMethod ( MyVariablePtr)

    Step 4) When you want to read that variable use the LONG[noparse]/noparse syntax

    temp := LONG[noparse][[/noparse]MyVariablePtr]

    Step 5) When you want to Write to the variable

    LONG[noparse][[/noparse]MyVariablePointer] := temp ( i think in your case, use "PHSB" instead of "temp"

    Step 6 ) OPTIONAL, if you want to pass that variable onto another method / object / cog ( but not the main method) use the same variable "pointer" and not the "@" symbol again.

    Hope this helps

    regards

    Dave M
  • mosquito56mosquito56 Posts: 387
    edited 2008-01-21 23:09
    Dave, I followed you post very carefully but I think you were only trying to pass a variable value. I didn't want to input because I am too new at this.

    I can pass variables with no problem. I saw this LONG [noparse][[/noparse] MyReferencedVariable ] : = 1 ( to write the variable) and the long in from totally confused me.

    I am trying to set pin1 hi· when phsa rolls over in the second cog.

    1st cog reads the pin and if hi adds to the cnter.

    ·repeat

    ·if outa[noparse][[/noparse]1]:=1
    ··· outa[noparse][[/noparse]1]:=0
    ··· timercnt++
    ··· term.dec(timercnt)
    ··· term.out($0D)

    Pub· starttimer
    ·· if phsb>oldcnt
    ···· oldcnt:=phsb
    ···· outa[noparse][[/noparse]1]:=1
    ···· 'term.dec(phsb) for testing if phsb is changing like I expect



    p.s. I have tried

    res value 1 in hopes of writing to hub memory but it didn't work. How do you write to hub memory? I thought it was @value but still no luck


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ······· "What do you mean, it doesn't have any tubes?"

    ······· "No such thing as a dumb question" unless it's on the internet

    Technologically challenged individual, Please have pity.

    Post Edited (mosquito56) : 1/21/2008 11:47:51 PM GMT
  • DavidMDavidM Posts: 626
    edited 2008-01-22 00:36
    Hi mosquito56

    Can you please post all of your code!

    I will try to help you..

    I can't see how you are starting your cog?
    What I explained was how to pass a variable ADDRESS not its value , you need to do this if you want to work with variables OUTSIDE of the MAIN METHOD i.e An external spin object.

    So you need to have at least TWO spin files.
    eg
    MyMainProgram.spin
    MyCounter.spin


    MyCounter.spin will run the cog and return values back to MyMainProgram.Spin
    It will do this by using LONG[noparse][[/noparse]MyVariablePointer] := counter which will update the VALUE of MyVariable back in your main program


    But again , please post all of your code smile.gif

    regards


    Dave M
  • mosquito56mosquito56 Posts: 387
    edited 2008-01-22 01:21
    Dave, thanx for the idea. As soon as I get a chance I will try your idea.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ······· "What do you mean, it doesn't have any tubes?"

    ······· "No such thing as a dumb question" unless it's on the internet

    Technologically challenged individual, Please have pity.
  • mosquito56mosquito56 Posts: 387
    edited 2008-01-22 20:16
    · Dave, I tried your method no luck.



    Mike: I have pin 18 counting of phsa with led connected. It blinks once per second.

    The bug has to be here in my main program

    if outa[noparse][[/noparse]18]:=1

    ···· outa[noparse][[/noparse]18]:=0
    ··· ·timercnt++
    term.dec(timercnt)
    term.out($0D)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ······· "What do you mean, it doesn't have any tubes?"

    ······· "No such thing as a dumb question" unless it's on the internet

    Technologically challenged individual, Please have pity.
  • DavidMDavidM Posts: 626
    edited 2008-01-22 21:55
    Hi mosquito56,

    Can you please post ALL OF YOUR CODE. smile.gif !!!


    Then we can have a proper look at it,

    Don't forget to use the CODE buttons when you post.

    or just post the SPIN files.

    regards

    Dave M
Sign In or Register to comment.