Shop OBEX P1 Docs P2 Docs Learn Events
Multiple Object starts — Parallax Forums

Multiple Object starts

kenmackenmac Posts: 96
edited 2007-08-07 12:21 in Propeller 1
I am confused about starting multiple Objects from the top Object.
As an example:
I tried the following, using LED's to indicate that the object is running:

Top object "test1.spin" needs to start 3 others "test2.spin, test3.spin, test4.spin" and continue with it's own code.

test1.spin

Obj
  t1:"test2"
  t2:"test3"
  t4:"test4"

pub main
  t1.start
  t2.start
  t3.start
  start

pub start
  repeat
    dira[noparse][[/noparse]16]~~
    !outa[noparse][[/noparse]16]
    waitcnt(5_000_000 + cnt)




test2.spin
pub start
 repeat
    dira[noparse][[/noparse]17]~~
    !outa[noparse][[/noparse]17]
    waitcnt(8_000_000 + cnt)




The other two Objects are similar to test2.spin, just using a different pin output.
The outputs just operate LED's .

I expected all Objects to run, plus the main one, but what happens is that only the first one actually runs.
It seems that the first has to complete before the next can start.
If that happens, then the next Object called will run.
This in effect is still serial control - how do we get them to run in parallel?
I tried opening Cogs in each - that didn't change anything.
The only way I could get them working in parallel was to incorporate the other Object methods within the top Object, then starting them in separate Cogs.

I have obviously missed something here, or completely misunderstood how it works.


kenmac

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Perth, Western Australia
Time Zone = GMT + 8

Comments

  • W9GFOW9GFO Posts: 4,010
    edited 2007-08-07 04:23
    My guess is that you need to tell each one to run in a new cog. The propeller manual has examples of how to do this, Chpater 3, page 106.
  • deSilvadeSilva Posts: 2,967
    edited 2007-08-07 05:11
    You obviously absolutely confused parallel running processes in COGs with SPIN's static modularization scheme of "Objects". Please read through the manual (or the education tutorials) to correct your concepts smile.gif
  • mirrormirror Posts: 322
    edited 2007-08-07 05:41
    var
      long stack[noparse][[/noparse]8]
     
    pub start
      CogNew(func, @stack)
     
    pub func
     repeat
        dira[noparse][[/noparse]17]~~
        !outa[noparse][[/noparse]17]
        waitcnt(8_000_000 + cnt)
    

    Here, try this for test2.spin.
  • kenmackenmac Posts: 96
    edited 2007-08-07 09:20
    mirror,
    As I said, I tried running the individual called Objects in their own Cogs.
    The result is the same - the first called Object (test2) is the only one to run.

    kenmac

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Perth, Western Australia
    Time Zone = GMT + 8
  • StefanL38StefanL38 Posts: 2,292
    edited 2007-08-07 10:37
    hello kenmac,

    just post your COMPLETE Sourcecode. Really ALL files that you use

    in the code posted yet there are no cognew-commands at all
    starting a new cog can ONLY be done by a cognew-command


    i think then it will be easy to find the point
    and then it will be easy to correct it to make it run as you want it to run

    best regards

    Stefan
  • CardboardGuruCardboardGuru Posts: 443
    edited 2007-08-07 11:38
    Objects are a completely different thing than cogs. Unless you make it otherwise, all code on all objects will run on the same cog. No parallelism at all. To make some code run on another cog you must use COGINIT or COGNEW, there is no other way.

    You say you tried that, but the only way we have of letting you know what you did wrong is if you post that code with the COGINITs or COGNEWs in.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Help to build the Propeller wiki - propeller.wikispaces.com
  • kenmackenmac Posts: 96
    edited 2007-08-07 12:21
    Fred,
    That was a typo - the code was so simple I just typed it in.
    It is of course t3:"test4"

    It's OK now - I have sorted it out.
    I have two different boards in use, one a developing project and the other the propstick
    When I started I was using the project board with it's associated pin numbers.
    Halfway thru testing I swapped to the propstick, which only has other pins in use.
    Of course, I forgot to change the code pin numbers, didn't I?
    It turned out that when I was testing the "including the Cogs" part, it was using the propstick.
    In that situation, it was working OK, but the LED's didn't light because they were on the wrong pins, except for test2!
    So, I basically fooled myself!
    At least I have confirmed that the method works, which I can now translate into the project.

    I must be getting too old for this stuff.
    Thanks for your input .

    kenmac

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Perth, Western Australia
    Time Zone = GMT + 8
Sign In or Register to comment.