PDA

View Full Version : Getting a phsa/b value from another cog, Nothing works



mosquito56
01-22-2008, 04:28 AM
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

MacGeek117
01-22-2008, 04:54 AM
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 (http://www.parallax.com/)
www.goldmine-elec.com (http://www.goldmine-elec.com)
www.expresspcb.com (http://www.expresspcb.com)
www.jameco.com (http://www.jameco.com)
·

Mike Green
01-22-2008, 05:04 AM
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.

mosquito56
01-22-2008, 05:34 AM
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.

DavidM
01-22-2008, 05:40 AM
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[] syntax

temp := LONG[MyVariablePtr]

Step 5) When you want to Write to the variable

LONG[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

mosquito56
01-22-2008, 06:09 AM
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 [ 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[1]:=1
··· outa[1]:=0
··· timercnt++
··· term.dec(timercnt)
··· term.out($0D)

Pub· starttimer
·· if phsb>oldcnt
···· oldcnt:=phsb
···· outa[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

DavidM
01-22-2008, 07:36 AM
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[MyVariablePointer] := counter which will update the VALUE of MyVariable back in your main program


But again , please post all of your code http://forums.parallax.com/images/smilies/smile.gif

regards


Dave M

mosquito56
01-22-2008, 08:21 AM
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.

mosquito56
01-23-2008, 03:16 AM
· 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[18]:=1

···· outa[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.

DavidM
01-23-2008, 04:55 AM
Hi mosquito56,

Can you please post ALL OF YOUR CODE. http://forums.parallax.com/images/smilies/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