Need a recommendation
CannibalRobotics
Posts: 535
I have been unable to get my head wrapped around where a variable lives in the prop and how it is most efficiently referenced/modified from multiple cogs. Can someone recommend a good tech note on this aspect of the architecture/language.
Thanks,
Jim-
Thanks,
Jim-

Comments
You need to be a little more specific with your request, are you talking about intraobject or interobject, are you talking about assembly to assembly, assembly to spin, or spin to spin?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
as long as all cogs are started by cognew from the SAME *.SPIN-File
you can access them simply by the name of the variable
here is a demo which shows that
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 VAR long heart_stack[noparse][[/noparse] 20] long CogStack1[noparse][[/noparse] 20] long CogStack2[noparse][[/noparse] 20] long MyTestVar OBJ 'heart : "heartbeat" little object from the obex making an LED blink so i can see Prop is working debug : "FullDuplexSerial" PUB Main 'the FIRST PUB-Method inside a spinfile is ALWAYS the startpoint where the program starts to run 'heart.Start(27, 200) debug.start(31, 30, 0, 9600) MyTestVar := 100 debug.str(string("Start MyTestVar=")) debug.dec(MyTestVar) debug.Tx(13) cognew(M1,@CogStack1) cognew(M2,@CogStack2) repeat waitcnt(clkfreq + cnt) debug.str(string("MyTestVar=")) debug.dec(MyTestVar) debug.Tx(13) PUB M1 repeat waitcnt(ClkFreq * 3 + cnt) MyTestVar := 1 PUB M2 repeat waitcnt(ClkFreq * 5 + cnt) MyTestVar := 2if you want to access variables ACROSS different objects
define the variables in your top-object-file
and pass the ADRESS of the variables by using the "@"-operator (the adress-operator
now INSIDE the file MyObject.spin
there have to be variables for the pointervalues
best regards
Stefan
What you've posted seems unnecessarily complicated, like why are you using pointers?
You've got the simple case of a method (subroutine) that is running in its own cog with everything together in one object. Good!
Here it is simpler:
VAR Byte stack1[noparse][[/noparse]30], highTime CON maxHigh = 1200*80 minHigh = 975*80 totalTime = 20000*80 servoPin = 0 PUB main highTime := maxHigh cognew(PulseServo, @stack1) repeat until highTime < minHigh waitcnt(clkfreq + cnt) highTime := highTime - 100 PUB PulseServo | myTime 'This assumes that the pulseis going to an inverter (for 5VTTL conversion), and so the timing is reversed dira[noparse][[/noparse]servoPin]~~ ''Output Pins repeat myTime := highTime ' reference it once so, if it's changed between the waitcnt's, the timing will still be correct waitcnt(totalTime - myTime + cnt) outa[noparse][[/noparse]servoPin]~ waitcnt(myTime + cnt) outa[noparse][[/noparse]servoPin]~~Post Edited (Mike Green) : 11/4/2008 7:50:32 PM GMT