Shop OBEX P1 Docs P2 Docs Learn Events
General Propeller interaction questions — Parallax Forums

General Propeller interaction questions

Kris CardoenKris Cardoen Posts: 46
edited 2012-06-11 01:03 in Propeller 1
Hi,

I'm quite new to propeller programming, so I have a few general questions :smile:

1. The communication between cogs can be made by using public varaibles? For instance one cog waits with repeat until a global variable changes, before is starts a certain action. Is that a correct appoach?

2. How do one use multible prop boards? Do you connect a few imput/output ports between the different controllers and use hi/Lo signals for interaction? Or is there a more efficient way. I would use the two boards in the same robot, so wireless is not required.

3. Since I use several obex objects, I would like to know if there is a easy way to check the number of concurrent cogs in use. I know the command to identify the current cog, but since the objects manage the allocation and usage themselves in the backgound an overview of cogs usered per prop board would be nice....if possible of course

Any hints or info would be much appricated. No complex examples just the general information plz.

Regards,
Kris

Comments

  • SRLMSRLM Posts: 5,045
    edited 2012-06-10 13:23
    1. Global is a bit of a misnomer. Rather, one cog watches a memory location. Everything is done by addresses.
    2. You can use serial objects such as FullDuplexSerialPlus to communicate between Propellers. Just connect the TX line of the one Propeller to the RX line of the other, and vice versa.
    3. No. Cog allocation is dynamic, not compile time, so the compiler can't know how many cogs are in use. You'll have to walk through your code yourself to see how many cogs are in use.
  • Mike GreenMike Green Posts: 23,101
    edited 2012-06-10 13:52
    1) Think of this sort of interaction as sending commands (or data) from one cog to another via a shared memory location. For many such routines, a zero represents no command while non-zero values specify an action to be performed or data to be passed. One cog puts a non-zero value into the shared location and the other cog waits for a non-zero value to appear, then acts on it. When it's done, the 2nd cog puts a zero into the common location to indicate that it's done. The first cog in the meantime waits for a zero to appear before putting another command there.

    2) It's usually best to put a 2.2K resistor between the two Propeller pins that are connected together. This protects the I/O pins from damage from programming errors where both I/O pins are set to output mode, but with one outputting a low level and the other outputting a high level.

    3) OBEX objects usually indicate in their documentation whether they start up a cog to perform their actions or not. Anything that's buffered will usually use a cog.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-06-10 14:18
    1. The communication between cogs can be made by using public varaibles? For instance one cog waits with repeat until a global variable changes, before is starts a certain action. Is that a correct appoach?

    If the cogs are running Spin code then you can communicate with global variables from within a single object. So yes, you can have one cog wait for a global variable to change before starting a different portion of the program.

    If the cog is running PASM code then you'll need to use the technique Mike mentioned.
    2. How do one use multible prop boards? Do you connect a few imput/output ports between the different controllers and use hi/Lo signals for interaction? Or is there a more efficient way. I would use the two boards in the same robot, so wireless is not required.

    There's lots of different ways this has been done. A serial connection is probably the easiest. You'll need to decide what protocol to use. Do you use an end of message character? Fix length messages? Indicate the size of the message somewhere in a header? There are pros and cons to each approach.
    3. Since I use several obex objects, I would like to know if there is a easy way to check the number of concurrent cogs in use. I know the command to identify the current cog, but since the objects manage the allocation and usage themselves in the backgound an overview of cogs usered per prop board would be nice....if possible of course

    There's an object that does this. I don't recall the name of it. I haven't used it myself. I just keep track of how many cogs I've used.

    I often add a comment in the "OBJ" section next to any objects that use a separate cog.
  • Cluso99Cluso99 Posts: 18,069
    edited 2012-06-10 22:52
    I posted an object that displays various system parameters including used and available cogs
    Thread... http://forums.parallax.com/showthread.php?139897-Display-Prop-Info-(clockfreq-avail-cogs)
    It's also in the OBEX Tools section, and its part of my version of a Propeller OS (type ver although it aso displays this on booting).
  • Heater.Heater. Posts: 21,230
    edited 2012-06-10 23:09
    Any software that can determine the number of cogs in use in a running program will almost certainly fail if the program is dynamically starting and stopping cogs. For example having determined that you have a free cog you try to start another, which then fails because some other process has started a cog in the mean time.
    Conversely in most programs a fixed number of cogs is started and run for the life of the program.
    Given that why bother. A quick scan through the source of the objects you are using will tell you how many cogs the program will need. Probably easier/quicker to do than setting up some code to count them for you at run time.
  • Kris CardoenKris Cardoen Posts: 46
    edited 2012-06-11 00:36
    Thanks for all the geat info! If I understand it correctly there is no limit, only my own skills ... :lol:
  • Heater.Heater. Posts: 21,230
    edited 2012-06-11 01:03
    They used to sell computers and such with the pitch "uses limited only by your imagination".

    At which point I'd think "not going to get much then am I".
Sign In or Register to comment.