Monitor Timing

This stuff really isn't that complicated

It has been written A LOT, perhaps too much, about how to get a standard VGA adapter to work on arcade monitors. Unfortunately, some of it is plain wrong, while others complicate the matter too much - rest assured, this stuff REALLY isn't that complicated. I'l try to keep it short..

Basic operation of CRT monitors

CRT means cathode ray tube. You have an electron gun that accelerates electrons through a magnetic field, and when the electrons hit the front of the screen, it collides with phosphor particles that generate light. The magnetic field bends the path of the electrons, making different parts of the screen light up. This "gunning" of phospor is done in a predictable manner, starting from the top left, ending in the bottom right.

There is a pretty good guide here.

Basic timing



The figure above illustrate the different periods video timing consists of.

Horizontal duration and frequency

First you have the drawing of a a single line, starting on the left going right. How many lines that are drawn pr second is refered to as the Horizontal Frequency. If n lines are drawn pr second, one line should take 1/n seconds. I.e if you have a horizontal frequency of 10Hz, one line should take 1/10th of a second to draw. This period is called the Horizontal Scan Period

Normal VGA has a horizontal frequency of 31.5kHz; thus the electron beam uses 1/31500 seconds (31.75µS) to scan across the screen before starting the next line.

Arcade Monitors, are not that quick and has a horizontal freqyency of 15.72kHz (also referred to as CGA). This gives them a Horizontal Scan Period of 1/15720=63.61µS.

Vertical duration and frequency

The vertical frequency refers to how many complete frames that are drawn pr second. The duration is how long it takes to draw all the lines the frame consists of, rewind the electron beam to the top left and start over again. A common vertical frequency; also called refresh-rate; is 60Hz, or 60 frames pr second. If you draw 60 frames every second, one frame uses 1/60th of a second, or 16.67ms to complete. This is called the Vertical Scan Period

So far so good, and if you think these two sections were pretty basic, good for you, because the next one is simply a corollary.

Vertical resolution

Consider the following very carefully: "the number of lines multiplied by the time each line takes, equals the time of a complete frame". You can also put it this way:

number of lines*duration of line=duration of frame.

This seems logical and easy enough, but gives us an interesting relationship:

Now this is important stuff, as it tells us the relationship between the horizontal frequency, the vertical frequency (refresh rate), and number of lines. It is so important that I'm going to formulate it one more time, and put som number in:

Shuffling the symbols around a bit reveals three simple relationships:


With these relationships, we can draw some important conclusions:

    • Changing one parameter will also change the others.

Detailed timing

How long one line takes, is referred to as the Horizontal Scan Period. During the horizontal Scan Period, more than just gunning of phosphor takes place, and the period can be furter broken down to 4 (hA+hB+hC+hD) distinct parts with different durations and purposes:

    • A - Active Display - Color is sent to the monitor on the RGB pins(the picture you see), the higher the voltage, the brighter the colour.
    • C - Sync - The sync signal, telling the monitor to rewind the beam and start a new line (horizontal). A negative sync means that the signal goes from high to low, while a positive sync is the opposite; low to high. This is often refered to as the polarity of the sync.
    • B - Front Porch - Color quiet period before sync
    • D - Back Porch - Color quiet period after sync

Unfortunately, these periods, or combinations of them, are referred to using plethora of different terminology that makes it anything but easy to understand, I won't list them but one you should be aware of is blanking, which is the total quiet period (B+C+D).

The almighty pixelclock

The pixelclock is a piece of hardware that controls how long it should take to draw a pixel. Consider the following relationships:



Recalling that period A is the amount of time that actual pixels is received by the monitor, we can calculate what the pixelclock is supposed to be for a given resoluton. Lets take the standard VGA mode (640x480, 31kHz horizontal, 60Hz vertical), where period A should last 25.42µS: 25.42/640=0.03971875.







In the case of the linux kernel framebuffer modes, the unit is picoseconds. Lets have a look at a normal VGA mode, found in /etc/fb.modes

mode "name"
   geometry x y vx vy (v=virtual, size of memory framebuffer)
   timings pclock hbporch(D) hfporch(B) vbporch(D) vfporch(B) hsync(C) vsync(C)

mode "640x480-60"
    # D: 25.175 MHz, H: 31.469 kHz, V: 59.94 Hz
    geometry 640 480 640 480 8
    timings 39722 48 16 33 10 96 2
endmode

In this mode, 39722 is the pixelclock. Thus, in this mode the Horizontal Active Period should last 640*39722 picoseconds, or 25.42 µs (micro seconds). If you sum up A+B+C+D, you get (640+16+96+48)=800. 800*39722=31777600 picoseconds=31.7776µs scanperiod, sounds about right.

A note about pixeltime and making custom modes

When some people make their own modes, they seem to ignore the fact that all the parameters above work togheter, especially the relationship between the pixelclock and the various periods. I find it helpful to use the term pixeltime.

Let's say you want a mode on your VGA monitor that is 720x480; simply editing fb.modes and changing 640 to 720 might work, but you end up with something that you probably didn't anticipate. First off, you get a scan period of 880*39722=34955360 picoseconds=35µs. Your monitor should be able to handle this, but you will probably have to adjust it a bit to get it right. Furthermore, because you have changed the scan period, you have inadvertedly also changed the vertical timing periods, as they are functions of the horizontal total time. In this example, you end up with a vertical scanperiod of 525*35us, giving you a refreshrate of 1/525*35µs=54,4Hz, not the 60Hz you started with.

To make it totally clear: when dealing with monitor timings and resolutions, the pixels you specify are TIME UNITS, I call it pixeltime. Furthermore, making modes manually is probably not a great idea, this includes "tweaking" working modes with special utilities or programs - you will end up frustrated, unsatisfied, and either buying a 31khz arcade monitor, an ArcadeVGA card from Ultimarc, or the ultimate evil sin: fitting a normal monitor inside your cab.