Pass values from cogs to cogs
I am running a Ping object in a new cog, that I want to write the resulting value which is updated every loop interation to a shared
ram location where another object executing in a loop in a different cog would access it.
How would I do this. The manual doesn't elude to technique.
I basically want to perform a similiar operation of writing a value to a shared value as done in the bs2p using the scratchpad ram.
·
ram location where another object executing in a loop in a different cog would access it.
How would I do this. The manual doesn't elude to technique.
I basically want to perform a similiar operation of writing a value to a shared value as done in the bs2p using the scratchpad ram.
·
Comments
If you've got the PING code and the other code in separate objects, the variables themselves are not known between objects. The easiest way to handle this is to put the shared variable in your main program's variable area and to pass the address of this variable (like @variable) to the PING object and your other object, then reference it using LONG[noparse][[/noparse] addressOfVariable ].
Look at the description of the address operator (@) and the LONG / WORD / BYTE keywords in the manual.
This article is also 'good' reading on the subject:
http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/vol7/col/NV134.pdf
Code for the article can be found here:
http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/vol7/code/NV134.zip
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Mike
Here is an excerpt
In main program I have:
Clock.Init(_XINFREQ) ' set up clock for accurate 10/second
Clock.SetClock(_CLKMODE) ' video update rate
Clock.MarkSync
tv.start(TVPin)
BS2.Start(31,30) 'Initialize BS2 Object
tv.str(string($A,1,$B,1))
tv.str(string("Initialize..."))
stop
ok := cog := cognew(ping.Millimeters(PING_Pin),@stackPing) + 1
waitcnt(clkfreq + cnt)
In the object referenced in under OBJ I have:
PUB Millimeters(Pin) : Distance
''Measure object distance in millimeters
repeat
stackPing := Distance := Ticks(Pin) * 10_000 / TO_CM ' Distance In Millimeters
waitcnt(clkfreq / 100 + cnt)
What am I doing wrong? I have a LONG stackping declared in each VAR section of both object files.
There are lots of other problems with your program. For example, it's not well documented, but you can't have a COGNEW or COGINIT that starts a method in another object. It won't work. You can start a method in the same object as the COGNEW or COGINIT which only calls a method in another object. That works, but not what you've given (ie: cognew(ping.Millimeters ...)
You might have a look at BoeBotBasic which you can download from the Propeller Object Exchange. It's a large and complicated program, but there is a PING routine that runs in its own cog and there's not a lot of code that's involved. The main cog tells the PING cog to start a measurement by setting a variable to 0 or -1 (I don't remember). The PING cog finishes by setting the variable to the actual distance, then waits for the variable to be set to 0 or -1 again.
All of the code involved is in the main object (BoeBotBasic.spin).
Thank you for your assistance and direction. I moved the methods from the PING object into the main object and everything is now working as expected.
Jim