Please direct comments, criticism,
and suggestions for improvement to lib/X11/doc
If your monitor is in it, you can probably skip the rest of this document!
You may need to scale some of the timing numbers if the clock used to
generate the mode in the database doesn't match what your card has available,
but that's easy.
Knowing how the display works is essential to understanding what numbers to put
in the various fields in the file Xconfig. Those values are used in the lowest
levels of controlling the display by the XFree86 server.
The display generates a picture from a series of dots. The dots are arranged
from left to right to form lines. The lines are arranged from top to bottom to
form the picture. The dots emit light when they are struck by the electron
beam inside the display. To make the beam strike each dot for an equal amount
of time, the beam is swept across the display in a constant pattern.
The pattern starts at the top left of the screen, goes across the screen to the
right in a straight line, and stops temporarily on the right side of the
screen. Then the beam is swept back to the left side of the display, but down
one line. The new line is swept from left to right just as the first line was.
This pattern is repeated until the bottom line on the display has been swept.
Then the beam is moved from the bottom right corner of the display to the top
left corner, and the pattern is started over again.
Starting the beam at the top left of the display is called the beginning of a
frame. The frame ends when the beam reaches the the top left corner again as
it comes from the bottom right corner of the display. A frame is made up of
all of the lines the beam traced from the top of the display to the bottom.
If the electron beam were on all of the time it was sweeping through the frame,
all of the dots on the display would be illuminated. There would be no black
border around the edges of the display. At the edges of the display the
picture would become distorted because the beam is hard to control there. To
reduce the distortion, the dots around the edges of the display are not
illuminated by the beam even though the beam may be pointing at them. The
viewable area of the display is reduced this way.
Another important thing to understand is what becomes of the beam when no spot
is being painted on the visible area. The time the beam would have been
illuminating the side borders of the display is used for sweeping the beam back
from the right edge to the left and moving the beam down to the next line. The
time the beam would have been illuminating the top and bottom borders of the
display is used for moving the beam from the bottom-right corner of the display
to the top-left corner.
The adapter card generates the signals which cause the display to turn on the
electron beam at each dot to generate a picture. The card also controls when
the display moves the beam from the right side to the left and down a line by
generating a signal called the horizontal sync (for synchronization) pulse.
One horizontal sync pulse occurs at the end of every line. The adapter also
generates a vertical sync pulse which signals the display to move the beam to
the top-left corner of the display. A vertical sync pulse is generated near
the end of every frame.
The display requires that there be short time periods both before and after the
horizontal and vertical sync pulses so that the position of the electron beam
can stabilize. If the beam can't stabilize, the picture will not be steady.
In a later section, we'll come back to these basics with definitions,
formulas and examples to help you use them.
There are some fundamental things you need to know before hacking an Xconfig
entry. These are:
This section explains what the specifications above mean, and some other
things you'll need to know. First, some definitions. Next to each in parens
is the variable name we'll use for it when doing calculations
Another way to look at the formula we derived above is
Available frame-buffer RAM may limit the resolution you can achieve on color or
gray-scale displays. It probably isn't a factor on displays that have only two
colors, white and black with no shades of gray in between.
For 256-color displays, a byte of video memory is required for each visible
dot to be shown. This byte contains the information that determines what mix
of red, green, and blue is generated for its dot. To get the amount of memory
required, multiply the number of visible dots per line by the number of
visible lines. For a display with a resolution of 800x600, this would be 800
x 600 = 480,000, which is the number of visible dots on the display. This is
also, at one byte per dot, the number of bytes of video memory that are
necessary on your adapter card.
Thus, your memory requirement will typically be (HR * VR)/1024 Kbytes of VRAM,
rounded up. In the example case, we'd need (936 * 702)/1024 = 642K. So if
you have one meg, you'll have extra for virtual-screen panning.
However, if you only have 512K on board, then you can't use this resolution.
Even if you have a good monitor, without enough video ram, you can't take
advantage of your monitor's potential. On the other hand, if your SVGA has one
meg, but your monitor can display at most 800x600, then high resolution is
beyond your reach anyway.
Don't worry if you have more memory than required; XFree86 will make use of it by
allowing you to scroll your viewable area (see the Xconfig file documentation
on the virtual screen size parameter). Remember also that a card with 512K
bytes of memory really doesn't have 512,000 bytes installed, it has 512 x 1024
= 524,288 bytes.
If you're running SGCS X using an S3 card, and are willing to live with 16
colors (4 bits per pixel), you can set depth 4 in Xconfig and effectively double
the resolution your card can handle. S3 cards, for example, normally do
1024x768x256. You can make them do 1280x1024x16 with depth 4.
Warning: this method was developed for multisync monitors. It will probably
work with fixed-frequency monitors as well, but no guarantees!
Start by dividing DCF by your highest available HSF to get the number
of horizontal sweeps per second available.
For example; suppose you have a Sigma Legend SVGA with a 65MHz dot clock, and
your monitor has a 55KHz horizontal scan frequency. The quantity (DCF / HSF)
is then 1181.
Now for our first bit of black magic. You need to round this figure to the
nearest multiple of 8. This has to do with the VGA hardware controller used by
SVGA and S3 cards; it uses an 8-bit register, left-shifted 3 bits, for what's
really an 11-bit quantity. Other card types such as ATI 8514/A may not have
this requirement, but we don't know and the correction can't hurt. So round
the usable horizontal scans per second figure to 1176.
This figure (DCF / HSF rounded to a multiple of 8) is the minimum HFL you can
use. You can get longer HFLs (and thus, possibly, more horizontal dots on the
screen) by setting the sync pulse to produce a lower HSF. But you'll pay with
a slower and more visible flicker rate.
As a rule of thumb, 80&percnt of the horizontal frame length is available for
horizontal resolution, the visible part of the horizontal scan line (this
allows, roughly, for borders and sweepback time -- that is, the time required
for the beam to move from the right screen edge to the left edge of the next
raster line). In this example, that's 944 ticks.
Now, to get the normal 4:3 screen aspect ratio, set your vertical resolution
to 3/4ths of the horizontal resolution you just calculated. For this
example, that's 708 ticks. To get your actual VFL, multiply that by 1.05
to get 743 ticks.
About that 4:3 --- a ratio of 4:3 for width to height of the displayed area
approximates the Golden Section, (1 + sqrt(5))/2. Human beings seem to be
wired to find this kind of rectangle pleasant to look at; accordingly, video
tubes and the standard resolutions such as 800x600, 640x480 and 1024x768 all
approximate it. Though it's psychologically magic, it's not technically
magic; nothing prevents you from using a non-Golden-Section ratio if that
will get the best use out of your screen real estate.
So, HFL=1176 and VFL=743. Dividing 65MHz by the product of the two gives
us a nice, healthy 74.4Hz refresh rate. Excellent! Better than VESA standard!
And you got 944x708 to boot, more than the 800 by 600 you were probably
expecting. Not bad at all!
You can even improve the refresh rate further, to almost 76 Hz, by using the
fact that monitors can often sync horizontally at 2khz or so higher than
rated, and by lowering VFL somewhat (that is, taking less than 75&percnt of 944 in
the example above). But before you try this "overdriving" maneuver, if you
do, make *sure* that your monitor electron guns can sync up to 76 Hz vertical.
(the popular NEC 4D, for instance, cannot. It goes only up to 75 Hz VSF).
So far, most of this is simple arithmetic and basic facts about raster
displays. Hardly any black magic at all!
OK, now you've computed HFL/VFL numbers for your chosen dot clock, found the
refresh rate acceptable, and checked that you have enough VRAM. Now for the
real black magic -- you need to know when and where to place synchronization
pulses.
The sync pulses actually control the horizontal and vertical scan frequencies
of the monitor. The HSF and VSF you've pulled off the spec sheet are nominal,
approximate maximum sync frequencies. The sync pulse in the signal from the
adapter card tells the monitor how fast to actually run.
Recall the two pictures above? Only part of the time required for
raster-scanning a frame is used for displaying viewable image (ie. your
resolution).
Horizontal Sync:
By previous definition, it takes HFL ticks to trace the a horizontal scan line.
Let's call the visible tick count (your horizontal screen resolution) HR. Then
Obviously, HR < HFL by definition. For concreteness, let's assume both start
at the same instant as shown below:
The Xconfig file Table of Video Modes contains lines of numbers, with each line
being a complete specification for one mode of X-server operation. The fields
are grouped into four sections, the name section, the clock frequency section,
the horizontal section, and the vertical section.
The name section contains one field, the name of the video mode specified by
the rest of the line. This name is referred to on the "Modes" line of the
Graphics Driver Setup section of the Xconfig file. The name field may be
omitted if the name of a previous line is the same as the current line.
The dot clock section contains only the dot clock (what we've called DCF) field
of the video mode line. The number in this field specifies what dot clock was
used to generate the numbers in the following sections.
The horizontal section consists of four fields which specify how each
horizontal line on the display is to be generated. The first field of the
section contains the number of dots per line which will be illuminated to form
the picture (what we've called HR). The second field of the section indicates
at which dot the horizontal sync pulse will begin. The third field indicates
at which dot the horizontal sync pulse will end. The fourth field specifies
the total horizontal frame length (HFL).
The vertical section also contains four fields. The first field contains the
number of visible lines which will appear on the display (VR). The second
field indicates the line number at which the vertical sync pulse will begin.
The third field specifies the line number at which the vertical sync pulse will
end. The fourth field contains the total vertical frame length (VFL).
Example:
Q. The example you gave is not a standard screen size, can I use
it?
A. Why not? There is NO reason whatsoever why you have to use 640x480,
800x600, or even 1024x768. XFree86 driver lets you config your hardware with a
lot of freedom. It usually takes two to three minutes to come up the right
one. The important thing to shoot for is high refresh rate with reasonable
viewing area. not high resolution at the price of eye-tearing flicker!
Q. It this the *only* resolution given the 65Mhz dot clock and
55Khz HSF?
A. Absolutely not! You are encouraged to follow the general procedure and
do some trial-and-error to come up with a setting that's really to your liking.
Experimenting with this can be lots of fun. Most settings may just give you
nasty video hash, but nothing you do can actually damage a multi-sync monitor
(unless you somehow force your card to clock it at way above its bandwidth ---
if you stick reasonably close to the highest resolution the monitor is
documented to support this can't happen).
Beware fixed-frequency monitors! This kind of hacking around *can* damage
them.
Q. You just mentioned two standard resolutions. In Xconfig, there are many
standard resolutions available, can you tell me whether there's any point in
tinkering with timings?
A. Absolutely! Take, for example, the "standard" 640x480 listed in the
current Xconfig. It employs 25Mhz driving frequency, frame lengths are 800
and 525 => refresh rate ~ 59.5Hz. Not too bad. But 28Mhz is a commonly
available driving frequency from many SVGA boards. If we use it to drive
640x480, following the procedure we discussed above, you would get frame
lengths like 812 and 505. Now the refresh rate is raised to 68Hz, a
quite significant improvement over the standard one.
Q. But how about interlace/non-interlace?
A. At a fixed dot clock, an interlaced display is going to flicker
worse than a non-interlaced one, which is why the market has
moved away from them.
What you buy with the increased flicker is higher resolution with a slower
dot clock. If the DCF were fast enough (say 90MHz or up) even interlacing
wouldn't produce flicker -- but at present speeds, interlaced monitors are
a bad idea for X.
Q. Can you summarize what we have discussed so far?
A. In a nutshell:
Here's another hypothetical:
An adapter card has a 40 MHz clock rate. A display has a range of horizontal
sync rates from 30 KHz to 37 KHz. The minimum number of dots per line is
40,000,000/37,000 = 1,081.081, or approximately 1,081 dots per line.
We'll use this number of dots per line in the following calculations. So each
line on our display must have at least 1081 dots. We round this up to 1088 to
make it divisible evenly by eight. Now let's assume that the horizontal sync
pulse should be 3.8 microseconds long. We need to find out how many dots it
takes to make a 3.8 microsecond pulse. We do this by first finding out how
many microseconds are in one dot. Since there are 40,000,000 dots per second,
1/40,000,000 is the number of seconds per dot.
1/40,000,000 = .000000025 = .025 microseconds per dot
Thus the number of dots for a 3.8 microsecond sync pulse is
3.8 microseconds = D dots x .025 microseconds/dot
or
D dots = (3.8 microseconds) / (.025 microseconds/dot) = 152 dots
So we have 1088 dots per line, 800 of which are the illuminated ones, with 152
for the sync pulse. (Note that 152 is evenly divisible by eight. If it
weren't we would round it up until it was evenly divisible.) This leaves us
the task of calculating the time before and after the sync pulse that is
necessary for the display.
The rule of thumb for this is that we need about 30 ticks of guard time. In
this particular case, allocating 32 dots is convenient, because all the other
quantities are divisible by 8. This results in the timing being 800 dots for
the viewable area, 152 dots for the pulse, and 1088 - (800 + 152) = 136 dots
to divide between the two other times. Half of 136 is 68 dots, so 68 dots are
placed between the illuminated dots and the sync pulse, and 68 dots are placed
after the sync pulse. The horizontal numbers in the Xconfig line then become
800 (800+68) (800+68+152) (800+68+152+68)
or
800 868 1020 1088
Now we want to calculate the vertical numbers. To begin, we must remember
that the vertical numbers are not in terms of dots or microseconds per dot,
but are expressed as numbers of lines! So we have to calculate how much time
it takes to display a single line. That's easy, because we know each line is
1088 dots and each dot is .025 microsecond. Each line is, therefore,
(1088 dots/line) x (.025 microseconds/dot) =
27.2 microseconds/line
Since we chose 800 visible dots per line, let's choose the number of lines to
be such that the ratio of horizontal to vertical is 4 to 3. Thus, 800 is 4 x
200, so the number of visible lines should be 3 x 200 = 600. Our target
resolution is 800x600.
We know that a vertical sync pulse should be in the range of 50 to 300
microseconds. If we chose 150 microseconds as a typical sync pulse, we find
how many lines 150 microseconds is by dividing 150 by 27.2 microseconds per
line.
(150 microseconds/pulse) / (27.2 microseconds/line) =
5.51 lines/pulse
By rounding up (never down) to 6 lines/pulse we now have the vertical sync
pulse width.
To guess at the total number of lines per frame (illuminated lines plus
nonilluminated lines in the border) we assume (from "Videotiming&hellip") that the
total number of lines will be 5&percnt more than the number of viewable lines. So
the total number of lines is
(600 lines) x (1.05) = 630 total lines per frame
So now we must place the pulse in the time between the end of the illuminated
lines and the end of the frame. Since we have 630 total lines, 600
illuminated lines, and 6 lines for the pulse, we have
630 - 600 - 6 = 24 lines left
Some displays don't mind if the pulse begins immediately after the illuminated
lines, but others might want a line or two between the last illuminated line
and the beginning of the sync pulse. Taking the latter course just to be
safe, we add three lines between the last illuminated line and the beginning
of the pulse. The rest of the lines are added after the pulse ends. So the
vertical timing numbers become
600 (600+3) (600+3+6) (600+3+6+21)
or
600 603 609 630
Before we do anything else, we must check that the display can handle 630
lines/frame at 27.2 microseconds/line. We do this by calculating how many
frames per second our configuration will generate, and comparing it to the
display manual's entry for vertical sync rate. For 630 lines/frame at 27.2
micro- seconds/line, we have 630 x 27.2 = 17,136 microseconds/frame. 17,136
microseconds/frame is 0.017136 seconds/frame, or 1/0.017892 frames/second.
1 / (0.017136 seconds/frame) = 58.4 frames/second
If the manual says the vertical sync rate is 58.4 Hz, or 58.4 Hz is in the
range of the display's vertical sync rate, we are fine. If the display cannot
handle this rate, we'll have to change the number of lines per frame by
adjusting all of the timings proportionally.
Now we combine the horizontal and vertical timing numbers together with the
resolution and clock values to produce a test configuration for Xconfig. Our
line becomes
"800x600" 40 800 868 1020 1088 600 603 609 630
Now we have a configuration of XFree86 to try. It may not work if any of our
assumptions were grossly wrong, but in most cases it should at least give us a
stable display. Now it takes a little experimentation to produce something
pleasing.
An actual calculation
My adapter card has a 40 MHz crystal on it so I started with a 40
MHz clock rate. My display's maximum horizontal sync rate is 37
KHz, so the minimum dots per line are 40,000,000/37,000 = 1081.
My display's vertical sync rate is the range from 50 Hz to 90 Hz.
My display's manual says that the largest horizontal sync pulse
is 3.92 microseconds. With 0.025 microseconds per dot, the pulse
is
(3.92 microseconds) / (.025 microseconds/dot) =
156.8 dots
Rounding this up to the nearest number evenly divisible by eight
gives 160 dots.
The manual also says that the time between the last illuminated
dot and the beginning of the sync pulse must be at least 0.67
microseconds. The number of dots in 0.67 microseconds at a 40
MHz clock rate - remember 40 MHz is .025 microseconds/dot - is
D dots = (0.67 microseconds) / (.025 microseconds/dot) =
26.8 dots
Since 26.8 is not evenly divisible by eight, round it up to 32
dots.
My display's manual says the time after the sync pulse should be
3.56 microseconds or more. In dots, 3.56 microseconds is
D dots = (3.56 microseconds) / (.025 microseconds/dot) =
142.4 dots
Round 142.4 up to 144, so that it's evenly divisible by eight.
So now for a horizontal line we have 800 illuminated dots, 32
dots between the illuminated dots and the sync pulse, 152 dots
for the sync pulse, and 144 dots after the sync pulse.
800 + 32 + 160 + 144 = 1136
We now have a line that is 1136 dots long. This is greater than
the 1088 we previously calculated, but remember that 1088 was the
MINIMUM number of dots that could be on a line. So 1136 dots per
line is okay for starters.
The numbers to enter on the Xconfig line so far are
"800x?" 40 800 (800+32) (800+32+160) (800+32+160+144)&hellip
or
"800x?" 40 800 832 992 1136&hellip
A line of 1136 dots at .025 microsecond/dot means that a line
represents 1136 x .025 = 28.4 microseconds.
Since we chose 800 dots/line horizontal resolution, we choose 600
lines/frame as the vertical resolution.
My display's manual says that the vertical sync pulse must be at
least 64 microseconds long. In terms of lines, 64 microseconds
is
(64 microseconds/pulse) / (28.4 microseconds/line) =
2.25 lines/pulse
We round 2.25 up to 3 lines for the vertical sync pulse.
The manual says the time between the last displayed line and the
start of the sync pulse must be at least 318 microseconds, and
the delay after the end of the pulse must be at least 630
microseconds. We calculate how many lines each of these time
periods represents as follows.
(318 microseconds) / (28.4 microseconds/line) =
11.20 lines
(630 microseconds) / (28.4 microseconds/line) =
22.18 lines
We round each of the times up to become 12 lines before the sync
pulse and 23 lines after the pulse. This makes our vertical
timing numbers
600 (600+12) (600+12+3) (600+12+3+23)
or
600 612 615 638
Checking the frame rate to see if it falls within the rate of the
display, we see that 638 lines/frame at 28.4 microseconds/line is
18,119 microseconds/frame, which is 55.19 frames/second. My
display can handle anything from 50 Hz to 90 Hz, so the timing is
all right.
Putting the resolution, clock, horizontal, vertical timing
numbers together on a video mode line in Xconfig results in
"800x600" 40 800 832 992 1136 600 612 615 638
This was the first video mode I tried. It turned out not to be
very satisfactory because there was too much flicker. I tried
other timings both above and below this setting as shown in the
following example. I finally settled on the "784x614" mode as a
compromise between flicker and resolution.
You'll notice that almost all of the clock frequencies are 40
MHz. Through experimentation I found that higher frequencies
were beyond my adapter card's capabilities, and that lower
frequencies didn't provide the resolution I wanted.
Example:
Timings I have tried:
OK, so you've got your X configuration numbers. You put them in Xconfig with
a test mode label. You fire up X, hot-key to the new mode, &hellip and the image
doesn't look right. What do you do? Here's a list of common problems and how
to fix them.
You *move* the image by changing the sync pulse timing. You *scale* it by
changing the frame length (you need to move the sync pulse to keep it in
the same relative position, otherwise scaling will move the image as well).
Here are some more specific recipes:
The horizontal and vertical positions are independent. That is, moving the
image horizontally doesn't affect placement vertically, or vice-versa.
However, the same is not quite true of scaling. While changing the horizontal
size does nothing to the vertical size or vice versa, the total change in both
may be limited. In particular, if your image is too large in both dimensions
you will probably have to go to a higher dot clock to fix it. Since this
raises the usable resolution, it is seldom a problem!
The image is displaced to the left or right
To fix this, move the horizontal sync pulse. That is, increment or
decrement (by a multiple of 8) the middle two numbers of the horizontal timing
section that define the leading and trailing edge of the horizontal sync pulse.
If the image is shifted left (right border too large, you want to move
the image to the right) decrement the numbers. If the image is shifted right
(left border too large, you want it to move left) increment the sync pulse.
The image is displaced up or down
To fix this, move the vertical sync pulse. That is, increment or
decrement the middle two numbers of the vertical timing section that define
the leading and trailing edge of the vertical sync pulse.
If the image is shifted up (lower border too large, you want to move
the image down) decrement the numbers. If the image is shifted down
(top border too large, you want it to move up) increment the numbers.
The image is too wide (too narrow) horizontally
To fix this, increase (decrease) the horizontal frame length. That is,
change the fourth number in the first timing section. To avoid moving the
image, also move the sync pulse (second and third numbers) half as far,
to keep it in the same relative position.
The image is too deep (too shallow) vertically
To fix this, decrease (increase) the vertical frame length. That is,
change the fourth number in the second timing section. To avoid moving the
image, also move the sync pulse (second and third numbers) half as far,
to keep it in the same relative position.
Any distortion that can't be handled by combining these techniques is probably
evidence of something more basically wrong, like a calculation mistake or a
faster dot clock than the monitor can handle.
Finally, remember that increasing either frame length will decrease your
refresh rate, and vice-versa.