Shop OBEX P1 Docs P2 Docs Learn Events
Nice way to get 2 cogs that are 180 degrees out of phase WRT HUB? — Parallax Forums

Nice way to get 2 cogs that are 180 degrees out of phase WRT HUB?

RaymanRayman Posts: 14,849
edited 2011-12-07 23:03 in Propeller 1
I'm trying to double throughput to an LED matrix array using two cogs instead of one.

Anyway, I'm not sure if this is possible, but if it is possible, I think I'll need two cogs that are 180 degrees out of phase with respect to the HUB.
So, I think I need, e.g., cog#0 and cog#4

But, this is unfamiliar territory for me, I've never cared before which cogs things are on...

Here's my current approach:

1. Start this driver first so that only the main Spin cog is being used before looking for 2 more cogs.
2. Start up the first cog.
3. Start up three dummy cogs
4. Start up the second cog.
5. Stop the three dummy cogs.

Is this approach guaranteed to work?
Is there a cleaner way?

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2011-12-07 15:34
    What about:
    coginit((cogid+1)&7, @primary,   @one)
      coginit((cogid+5)&7, @secondary, @two)
    
    There are other ways involving cognew but you have to be careful that you don't accidentally kill the caller cog (unless you can handle that). The &7 avoids overflow which would make coginit a cognew.
  • RaymanRayman Posts: 14,849
    edited 2011-12-07 15:41
    Thanks. I don't think I've ever used coginit... If you can specify the cog#, that is a great solution.
  • MagIO2MagIO2 Posts: 2,243
    edited 2011-12-07 22:45
    I thought that coginit is doing the &7 internally, so you could ommit it in the call itself. Is this wrong?
  • kuronekokuroneko Posts: 3,623
    edited 2011-12-07 23:03
    MagIO2 wrote: »
    I thought that coginit is doing the &7 internally, so you could ommit it in the call itself. Is this wrong?
    The manual states that 0..7 gives you coginit behaviour, 8..15 cognew. Turns out that anything greater 7 is treated as cognew. Under the assumption that an &%1111 is performed I fed %10000 into it but I still get cognew behaviour (not coginit(0, ...)).

    IIRC the old manual mentioned greater equal 8 for cognew (which is the reason I use/d &7). The interpreter does a max id, #8 which settles this argument I believe.
Sign In or Register to comment.