Getting a phsa/b value from another cog, Nothing works
mosquito56
Posts: 387
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
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
It should read:
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
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
······· "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.
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
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
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
regards
Dave M
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
······· "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.
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.
Can you please post ALL OF YOUR CODE. !!!
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