c0pperdragon / Amiga-Digital-Video

Add a digital video port to vintage Amiga machines
294 stars 30 forks source link

Lag measurement #25

Closed IanSB closed 3 years ago

IanSB commented 3 years ago

There have been quite a few questions about the lag of the RGBtoHDMI software. The theoretical lag is around 3.4 milliseconds which is the software timing difference between the computer's vertical sync pulse and the HDMI output's vertical sync pulse. It used to be a little lower but I had to increase it by around 1 millisecond to avoid tears when using the aspect ratio conversion and some other settings.

I also measured it using an oscilloscope as follows:

I connected a HDMI to VGA converter to the output of the Pi to give an analog output and then displayed flashing white frames on the source computer, one frame of white followed by 7 frames of black (the VGA converter I was using had minimal lag). I then connected the computer's green output and the VGA converter's green output to the oscilloscope with the following results:

This shows 4 flash frames. Yellow is the source computer and cyan is the output of the Pi zero via the VGA converter. DS1Z_QuickPrint75

Looking at this in closeup shows a difference of 3.6 milliseconds which is very close to the theoretical value above. The additional lag is likely due to the integer scaling in the Pi's scaler and the VGA converter. DS1Z_QuickPrint76

The lag will vary by a small amount depending on the source computer's refresh rate and the scaling settings (maybe plus or minus half a millisecond). It will also increase significantly when the menus are on screen because normally the data is sent so fast to the HDMI port there isn't enough time to draw a menu over it so to get the text on screen a delay has to be introduced to allow time to actually draw the text on top of the video although that doesn't really matter as you won't be playing games with the menus on screen.

c0pperdragon commented 3 years ago

For lag measurement to this precision at also makes a difference on which part of the screen the measurement is done. The original analog signal (lets only consider PAL here) has a line frequency of 15625. A standard digital 1920x1080x50 signal has a line frequency of 56250 which means it will show 14062 inputs lines per second (when quadrupling the lines). So the digital signal will have an added lag of 7us on every scan line further down.
So the lag should be about 1.8ms higher if measured on the bottom of the screen than when measured at the top of the screen. For different output resolutions this would also vary a bit.

You can easily make the comparision by creating a very slim blinking rectangle either at the top or at the bottom.