Shop OBEX P1 Docs P2 Docs Learn Events
Waitvid glitch - request for more timing information. — Parallax Forums

Waitvid glitch - request for more timing information.

Linus AkessonLinus Akesson Posts: 22
edited 2008-07-25 02:45 in Propeller 1
Hi!

I would like to request more detailed information from Parallax, regarding the
internal timing of waitvid and rdlong. Let me explain why.

I'm experimenting with a true colour VGA mode, based on the following unrolled loop:

                rdlong  r1, addr           ' 7 cycles
                waitvid r1, #%%3210   ' 5 cycles
                add     addr, #4          ' 4 cycles

                rdlong  r1, addr           ' 7 cycles
                waitvid r1, #%%3210   ' 5 cycles
                add     addr, #4          ' 4 cycles

                ... (120 times)




The video PLL is running at 80 MHz just like the system clock, and VSCL has
been set up with a pixel size of 4 and a frame size of 16.

In order for this to work, the hub round robin scheme has to be in perfect sync
with the video frames. This is achieved like so:
  • 1. Make sure all video frame sizes (including sync frames and porches)
    are even multiples of 16 clocks (viz. one hub cycle).
  • 2. Measure the unrolled loop using the system clock. If the entire loop
    takes anything other than 120 x 16 cycles, then the video generator and
    the hub are out of sync. In that case, temporarily adjust one of the
    upcoming video frames by 1 clock (e.g. set the frame size to 15 instead
    of 16). Following a boot, this could happen on 0..15 consecutive lines,
    but after that, the entire system will stay in sync due to bullet 1
    above.

This scheme appeared to work, because my test picture showed up on the monitor
(a TFT). Furthermore, if I deliberately set up the loop measuring routine to
expect another value, the monitor wouldn't sync at all, as expected.

So far, so good. Now for the mysterious bit:

I discovered that my test picture wasn't 100% correct. For one thing, it was
offset slightly to the right and there was garbage along the left border.
Further scrutiny revealed lots of small pixel errors which I hadn't seen before
(due to the image being dithered).

To make a long story short, the video generator wasn't clocking in new data
from waitvid. It was skimming the data bus during the rdlong operation, reading
off the correct colour bytes, but getting garbage (probably the lower bits of
addr) into the pixel shifter.

I duly went on to comment out all of the waitvid instructions, and was still
able to see the picture, with the same bit errors. Fine.

This is consistent with the idea that if you miss your deadline with waitvid,
the video generator picks up whatever's on the internal buses. But in that
case, how could the waitvid instruction possibly take 5 cycles?
We're measuring
it, remember!

Could there by any chance be a glitch in the system, by which waitvid fails to
deliver its bits while also failing to delay?

Of course, I'm well aware that this could be a silly little bug in my code,
staring me in the face, so I'm asking you forum people to experiment with this
as well, and see if you can come up with the same phenomenon.

But please, Parallax team, give us a more detailed specification of the
internal timing of the instruction pipeline, hub interaction and video
hardware!

Best regards,
Linus

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-07-15 16:19
    Linus,

    I don't know if this has any bearing on your problem, but if your program relies on the video PLL having any particular phase relationship with the system clock — even thought they're both the same frequency — you may encounter difficulties. Also, it was demonstrated in a different thread that the correct timing for the waitxxx instructions is 6+ clocks, not the 5+ stated in the docs. (Even though the timiing discussed there was for waitpeq, which relates to external (hence, asynchronous) events, waitvid is equally affected by asynchronicity, as I alluded to here.)

    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Still some PropSTICK Kit bare PCBs left!

    Post Edited (Phil Pilgrim (PhiPi)) : 7/15/2008 4:30:09 PM GMT
  • Linus AkessonLinus Akesson Posts: 22
    edited 2008-07-15 16:40
    Phil Pilgrim (PhiPi) said...
    Linus,

    I don't know if this has any bearing on your problem, but if your program relies on the video PLL having any particular phase relationship with the system clock — even thought they're both the same frequency — you may encounter difficulties.

    You're quite right. That did cross my mind, actually. But it still doesn't explain why the loop completes in 16 cycles. Waitvid is supposed to wait for the video generator to drop by, so if the video generator has already fired, waitvid should take something like 16 cycles to complete.
    Phil Pilgrim (PhiPi) said...
    Also, it was demonstrated in a different thread that the correct timing for the waitxxx instructions is 6+ clocks, not the 5+ stated in the docs. (Even though the timiing discussed there was for waitpeq, which relates to external (hence, asynchronous) events, waitvid is equally affected by asynchronicity, as I alluded to here.)

    I read that thread too, but I doubt that it's the whole truth, since I measured my loop using CNT, and got a result that was incompatible with that idea. My waitvid instructions take 5 cycles. But they fail to deliver to the video generator.

    Best regards,
    Linus
  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-07-15 16:44
    Actually not all waitxxx are alike, waitpeq/waitpne are 6+, but waitcnt is 5+. What is waitvid? don't know, it hasn't been re-tested like the others, the mechanism to test it's execution can be difficult unless you know the "heartbeat" of the video generator. One thing I'll share, in the waitpne/waitpeq the extra clock cycle occurs after the event, not before. So if waitvid is 6+ the extra clock cycle would occur after the handoff. But I have a suscpicion that waitvid is 5+ as well since the ending mechanism is similar to waitcnt where the cog is released immediately after and there is no logic evaluation of external events like there is with waitpeq/waitpne.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-07-15 16:57
    Linus can you share the code that establishes the video generator? And give a synopsis of the mode you are setting it up for?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-07-15 17:36
    Linus Akesson said...
    Waitvid is supposed to wait for the video generator to drop by, so if the video generator has already fired, waitvid should take something like 16 cycles to complete.
    That will depend on the internal mechanism. For example, if the video circuitry sets a bit when it scoops up its data that waitvid reads and resets when it continues, that bit may well persist for waitvid to pick up, even though it missed its appointment. OTOH, if the trigger for waitvid to continue is merely transient, it will have to wait for the next appointment, as you suggest.

    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Still some PropSTICK Kit bare PCBs left!
  • Linus AkessonLinus Akesson Posts: 22
    edited 2008-07-15 17:45
    Paul Baker (Parallax) said...
    Linus can you share the code that establishes the video generator? And give a synopsis of the mode you are setting it up for?

    Sure thing! The VGA mode is 640x480 with active low syncs, and it's for the propeller demo board. I'm attaching the source code.
  • potatoheadpotatohead Posts: 10,260
    edited 2008-07-15 19:12
    Very interesting!!

    And welcome to our guilty pleasure. Your CRAFT demo was outstanding!

    I've observed that if a waitvid is running...

    (and just how exactly does one stop one from running, once started? I remain confused by this.)

    ...and the next one has been executed BEFORE the running one works through it's frame, all will be good.

    So then it's a race condition of sorts, isn't it?

    Say one makes changes in the VSCL. That does not impact the currently running waitvid, meaning the one it does impact has to do something to change the behavior for the next frame. That something takes some time, right?

    I'll bet it needs a cycle at least to do what it does, or the next frame won't be proper.

    What about this bit of code?

    
                   if_nz   jmp     #adjust
                            waitvid metapixels, #0
                            nop   <---- Can't the 'add addr, #4' go here?  (adjust your constant so this works)
    
                            ' Unrolled loop follows. 120 fetches of 4 pixels each.
    
                            rdlong  r1, addr
                            add     addr, #4 <---- and get rid of this one?
                            waitvid r1, #%%3210
    
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller Wiki: Share the coolness!

    Chat in real time with other Propellerheads on IRC #propeller @ freenode.net
  • AleAle Posts: 2,363
    edited 2008-07-15 19:14
    Paul,

    we tested and re-verified (with oscillograms) and it is 6+. I do not remember the thread name....
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-07-15 19:48
    Paul,

    Since the extra clock in waitpeq/ne occurs after the event, could it be due to the event getting synchronized with the system clock, rather than because of the compare operation? This could explain the difference between waitpeq/ne and waitcnt, since the latter is already (inherently) synchronized, but also requires a compare.

    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Still some PropSTICK Kit bare PCBs left!
  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-07-15 19:52
    Phil you could be correct, I don't have access to the schematic of the chip so it's nigh impossible to root out what exactly is going on.

    Ale, which instruction are you refering to, waitvid?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • AleAle Posts: 2,363
    edited 2008-07-15 20:23
    Waitcnt smile.gif
  • BaggersBaggers Posts: 3,019
    edited 2008-07-15 20:33
    Hi Linus,

    Welcome to the forums, great inspiring demo by the way, can't wait to see what you've got install for the prop [noparse]:)[/noparse]

    Baggers.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    http://www.propgfx.co.uk/forum/·home of the PropGFX Lite

    ·
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-07-15 20:48
    The synchronization issue is still a bit baffling to me. In Cliff Biffle's example, the minimum time for waitpeq was six clocks, even when the inputs had been held in a matching state. This would imply, if synchronization was the reason for the extra clock, that the synchronization process begins with the instruction and is not carried out in parallel using separate hardware (e.g. D flipflops). On the other hand, the video hardware can do its own synchronization to the system clock, before a waitvid instruction begins. If this is the case, the answer to the minimum waitvid time could be "both", when the choices are "5 clocks" and "6 clocks". Linus' experience seems to indicate 5 clocks, since his code segments each take 16 clocks. But if his waitvids are late every time, and if my set/reset theory for the waitvid trigger (above) is correct, the waitvids, being late, don't have to wait on the video circuitry for synchronization. However, if a waitvid does make its appointment in time, it may have to wait that extra clock for synchronizaiton from the video circuitry. Does that make sense? Or have I fallen prey to circular reasoning — in addition to bald speculation? smile.gif

    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Still some PropSTICK Kit bare PCBs left!
  • potatoheadpotatohead Posts: 10,260
    edited 2008-07-24 16:53
    I'm bumping this one.

    Had a bit of time to run the code. I used a HYDRA board, as that is what I had handy. On my LCD monitor, I get "out of range" and no signal. [noparse]:([/noparse]

    Any progress, test results from others? I'm interested in the topic.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller Wiki: Share the coolness!

    Chat in real time with other Propellerheads on IRC #propeller @ freenode.net
  • kuronekokuroneko Posts: 3,623
    edited 2008-07-25 00:09
    Paul Baker (Parallax) said...
    Ale, which instruction are you refering to, waitvid?
    waitcnt: posting 11/12 http://forums.parallax.com/showthread.php?p=725782
  • potatoheadpotatohead Posts: 10,260
    edited 2008-07-25 02:45
    Thanks! I was looking for that thread.

    I'm quite sure it's my picky monitor too. Have a CRT to try it on this weekend.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller Wiki: Share the coolness!

    Chat in real time with other Propellerheads on IRC #propeller @ freenode.net
Sign In or Register to comment.