Shop OBEX P1 Docs P2 Docs Learn Events
Two COGS one scanline apart? — Parallax Forums

Two COGS one scanline apart?

Maybe this is ambitious, but is it possible (without too much pain) to start two COGS where one COG is literally ONE scanline ahead of the second?

So the "rendering" COG would just draw the pixels but another COG would be a scanline ahead so that it can manipulate data, etc.
I know this is done for tiles/sprites, etc. But is the timing usually that precise when it's done that way?

Thanks for any tips.

Comments

  • potatoheadpotatohead Posts: 10,261
    edited 2015-12-07 20:13
    It is done that way, and yes, it is that precise.

    One really easy device for doing this is to have the signal cog always set a value in the hub when it it is at the begin of a scanline.

    The render cog writes a different value, then watches for the change.

    Start your cogs up, and the first thing the render cog does is make the first scanline, then it waits for the signal cog to change the done value.

    When it sees the write from the signal or display cog, it makes another scanline ahead of the display cog.
  • The other way this is done is to use the system clock and WAITCNTs. This is done when the cogs have a precise time relationship with one another. During initialization, you have to allow enough time for the additional cogs to get loaded and started. At 80MHz, that's about 100us. You take the system clock value and add at least 8192 to it (512 * 16) plus a little extra. That's the time for the 1st WAITCNT. Add a scanline (in 12.5ns units) time to get the 2nd WAITCNT value. Repeat for more scanlines, then start up the cogs which end up waiting for those calculated times. After all the WAITCNTs finish waiting, the cogs are running precisely one scanline apart to the nearest 12.5ns. Several of the VGA drivers in the OBEX use this technique. Have a look at them.
  • Cluso99Cluso99 Posts: 18,069
    I have run 4 cogs, each precisely 1 clock apart, to sample and store all 32 I/Os. I could store ~1700 samples.
    Using 100MHz that means you can sample every clock (ie 10us).
    Setup is similar to Mike Green's post.

    So, yes, you can control all cogs precisely with respect to one another.
  • Awesome. Those are some great suggestions.

    Thanks!!
  • Note: see http://www.linusakesson.net/programming/propeller/pllsync.php for synchronizing multiple video output cogs.
  • Oh, I saw that before and forgot about that. Great resource.

    Thanks!
Sign In or Register to comment.