|
|
|
XFree86 configuration: the theoryCopyright © 1998 Greg LeheyMost people know Microsoft's ``Windows'' series of ``Operating Systems''. From a UNIX point of view, they're not really operating systems at all: their main function is display management. UNIX systems use a separate software package for display management, usually the X window system, often called simply X. Some people call it X windows, but the X Consortium, who are responsible for X, frown on this term. To quote the documentation: The X Consortium requests that the following names be used when referring to this software:
X Window System X Version 11 X Window System, Version 11 X11
``X Window System'' is a trademark of X Consortium, Inc.
X is the most popular display manager, at least partially because it is free. As a result, nearly every UNIX-like free operating system supplies an implementation of X. On the Intel platforms, the best-known implementation is called XFree86 XFree86 goes back to a display board driver written by Thomas Röll and Mark Snitily, called X386. This driver was originally free, but Thomas Röll subsequently developed it into a commercial product and created a company, XInside, to market it. At about the same time, the XFree86 project was created to maintain the old X386 server. At Thomas Rölls request, they changed the name of the server to XFree86. That wasn't the only name change: it's a sign of the times that XInside was frequently mistaken for a purveyor of pornography, so they changed their name to Xi Graphics. By comparison with Microsoft's combined operating environments, the combination of UNIX and X offers much more flexibility. Unfortunately, the flexibility comes with a price: it can be difficult to set up X to run the way you want it. This article is the first of a series aimed to help you get the most out of X. I have previously published most of the material in my book The Complete FreeBSD, but the material isn't specific to any particular operating system, and Linux Journal published an early version of this article a while back. Setting up your XF86Config file normally takes a few minutes, but sometimes you can run into problems which make grown men cry. In this article, we'll look at the technical background:
I mean the last point seriously: conventional wisdom says that you can't damage
hardware with a programming mistake, but in this case, you can, and people do it
from time to time. When you've read the section on how monitors work, you'll
understand, but please don't start tuning until you understand the dangers
involved.
There are at least two ways to create pictures on a cathode ray tube: one is
derived from oscilloscopes, where each individual character is scanned by the
electron beam, rather like writing in the sand with your finger. Some early
terminals used this technology, but it has been obsolete for at least 20 years.
TVs and monitors display the picture by scanning lines across the screen. Like
in a book, the first line starts at the top left of the screen and goes to the
top right. Each successive line starts slightly below the previous line. This
continues until the screen is full. Like in a book, the lines don't have to be
full: the picture is formed by altering the intensity of the electron beam as it
scans the lines.
To perform this scan, the TV has two deflection units: one scans from left
to right, and the other scans, much more slowly, from top to bottom. Not
surprisingly, these units are called the horizontal and vertical
deflection units. You may also encounter the terms line and frame
deflection.
The tube can only move the electron beam at a finite speed. When the electron
beam reaches the right hand side of the screen, it needs to be deflected back
again. This part of the scan is called the horizontal flyback, and it is
not used for displaying picture data. The actual time that the hardware
requires for the flyback depends on the monitor, but it is in the order of 5% to
10% of the total line scan time. Similarly, when the vertical deflection
reaches the bottom of the screen, it performs a vertical flyback, which is
also not used for display purposes.
As if that wasn't enough, the video amplifier, the part of the TV which alters
the intensity of the spot as it travels across the screen, needs time to ensure
that the flyback is invisible, so there are brief pauses between the end of the
line and the start of the sync pulse, and again between the end of the sync
pulse and the beginning of the data. This process is called blanking, and
the delays are called the front porch (before the sync pulse) and the
back porch (after the sync pulse).
Scan line and register values
That, in a nutshell, is how horizontal deflection works. Vertical deflection works in almost the same way, just slower, with one minor exception. This basic display mechanism was developed for TVs in the 1930s, at a time when terms like high-tech (or even electronics) hadn't even been invented, and even today we're stuck with the low data rates that they decided upon in those days. Depending on the country, TVs display only 25 or 30 frames (pages of display) per second. This caused an unpleasant flicker in the display. This flicker was avoided with a trick called interlacing: instead of displaying the frame in one vertical scan, the odd and even lines are displayed in two alternating half frames, which increases the apparent frame frequency to 50 or 60 Hz. How monitors differ from TVsSo how do we apply this to computer displays? Let's look at the US standard NTSC systemthe international PAL and SECAM systems are almost identical except for the number of lines and a minor difference in the vertical frequency. NTSC specifies 525 lines, but that includes the vertical flyback time, and in fact only about 480 lines are visible. The aspect ratio of a normal TV is 4:3, in other words the screen is one-third wider than it is high, so if we want square pixels, we need to have one-third more pixels per line. This means that we can display 640 pixels per line on 480 lines. Do these values look familiar? Now you know why.This resolution is normally abbreviated to ``640x480''. PAL and SECAM have lower vertical frequencies, which allows a nominal 625 lines, of which about 580 are displayed. Either way, these values have two huge disadvantages: first, the resolution is barely acceptable for modern graphics displays, and secondly they are interlaced displays. Older PC display hardware, such as the CGA and some EGA modes, was capable of generating these signal frequencies, but VGAs can no longer do it. The first problem is interlace: it works reasonably for TVs, but it's a pain for computer displaysthere's still more flicker than a real 50 Hz or 60 Hz display. Modern display boards can still run in interlace mode, but don't even think about doing so unless you're forced tothe resultant picture looks out of focus and is very tiring to read. The second problem is the resolution: nowadays, 1024x768 is a normal enough resolution, but I'm writing this on a display with 1280x1024, and many modern boards display 1600x1200. On the other hand, even 60 Hz refresh rate is barely adequate: read any marketing literature and you'll discover that 72 Hz is the point at which flicker suddenly disappears. To get high-resolution, high refresh rate displays, you need some very high internal frequencieswe'll see how high further down. How to fry your monitorRemember that a monitor is just a glorified TV? Well, one of the design constraints of real TVs is that they have only a single horizontal frequency and only a single vertical frequency. This simplifies the hardware design considerably: the horizontal deflection uses a tuned circuit to create both the deflection frequency and the high voltage required to run the tube. This circuit is comprised of a transformer (the line transformer) and a condenser. Run a line transformer even fractionally off its intended frequency and it will run much less efficiently and use more current, which gets converted to heat. If you run a conventional monitor off spec for any length of time, it will burn out the line transformer.You don't have to roll your own X configuration to burn out the monitor: ten years ago, the standard display boards were CGAs (Color Graphics Adapters) and HDAs (Hercules Display Adapters) and they had different line frequencies and thus required different monitors. Unfortunately, they both used the same data connector. If you connected an HDA (18.43 kHz line frequency) to a CGA monitor (15.75 kHz, the NTSC line frequency), you could expect smoke signals within a few minutes.
Modern PC monitors no longer use line transformers, and there are few of them
which can't handle at least a range of line frequencies, but this doesn't mean
you can't damage themyou'll just burn out something else, frequently the
power supply. In addition, just because the monitor displays correctly doesn't
mean that it is running in spec. I have a rather elderly Eizo 9500 (called
Nanao in the US) which has three frequency ranges: (exactly) 31.5 kHz, 48 to 50
kHz, or 64 to 78 kHz. In fact, it will display at any frequency between 48 and
78 kHz, but if it were run at 57 kHz for any length of time, I would be in for a
hefty repair bill. The moral of the story:
Never run your monitor out of spec. If your display is screwed up, there's a
good chance that the frequencies are out, so turn off the monitor.
monitors aren't the only thing that you can burn out, of course. If you try hard, you can also burn out chips on some display boards by running them at frequencies which are out of spec. In practice, though, this doesn't happen nearly as often. Another difference between TVs and monitors is the kind of signal they take. A real TV includes a receiver, of course, so you have an antenna connection, but modern TVs also have connections for inputs from VCRs, which are usually an audio signal and a video signal. The video signal consists of five important parts: the red signal, the green signal, the blue signal, and the horizontal and vertical sync pulses. This kind of signal is called composite video. By contrast, most modern monitors separate these signals onto individual signal lines, and older boards, such as the EGA, even used several lines per colour. Unfortunately, there is no complete agreement about how these signals should work: the polarity of the sync pulses varies from one board to the next, and some boards cheat and supply the sync pulses on the green signal line. This is mainly of historical interest, but occasionally you'll come across a real bargain 20" monitor which only has 3 signal connections, and you may not be able to get it to workthis could be one of the reasons. The CRT controllerThe display controller, usually called a CRT (Cathode Ray Tube) controller, is the part of the display board which creates the signals we've just been talking about. Early display controllers were designed to produce signals that were compatible with TVs: they had to produce a signal with sync pulses, front and back porches, and picture data in between. Modern display controllers can do a lot more, but the principles remain the same.The first part of the display controller creates the framework we're looking for: the horizontal and vertical sync pulses, blanking and picture information, which is represented as a series of points or dots. To count, we need a pulse source, which also determines the duration of individual dots, so it is normally called a dot clock. For reasons lost in history, CRT controllers start counting at the top left of the display, and not at the vertical sync pulse, which is the real beginning of the display. To define a line to the horizontal deflection, we need to set four CRTC registers to tell it.
In addition, the Start Horizontal Blanking and End Horizontal Blanking registers (SHB and EHB) define when the video signals are turned off and on. The server sets these registers automatically, so we don't need to look at them in more detail. The control of the vertical deflection is similar. In this case, the registers are Vertical Display End (VDE), Start Vertical Retrace (SVR), End Vertical Retrace (EVR), Vertical Total (VT), Start Vertical Blanking (SVB), and End Vertical Blanking (EVB). The values in these registers are counted in lines.
VGA hardware evolved out of older 8 bit character-based display hardware, which
counted lines in characters, not dot clocks. As a result, all of these
registers are 8 bits wide. This is adequate for character displays, but it's a
problem when counting dots: the maximum value you can set in any of these
registers is 255. The designers of the VGA resorted to a number of nasty
kludges to get around this problem: the horizontal registers count in groups of
8 dot clocks, so they can represent up to 2048 dot clocks. The vertical
registers overflow into an overflow register. Even so, the standard VGA can't
count beyond 1024 lines. Super VGAs vary in how they handle this problem, but
typically they add additional overflow bits. To give you an idea of how clean
the VGA design is, on a standard VGA, the real Vertical Total (total number of
lines on the display) is defined as the value of the VT register + 256 if bit 0
of the overflow register is set + 512 if bit 5 of the overflow register is set.
Modeline "640x480a" 28 640 680 728 776 480 480 482 494
These eleven values are required. In addition, you may specify modifiers at the
end of the line. The values are:
This is pretty dry stuff. To make it easier to understand, let's look at how we
would set a typical VGA display with 640x480 pixels. Sure, you can find values
for this setup in any release of XFree86, but that doesn't mean that they're the
optimum for your system. We want a non-flicker display, which we'll
take to mean a vertical frequency of at least 72 Hz, and of course we don't want
interlace. Our multiscan monitor can handle any horizontal frequency between 15
and 40 kHz: since we want the least flicker, we'll aim for 40 kHz.
First, we need to create our lines. They contain 640 pixels, two porches and a
sync pulse. The only value we really know for sure is the number of pixels.
How long should the porches and the sync pulses be? If you have a good monitor
with good documentation, it should tell you, but most monitor manufacturers
don't seem to believe in good documentation. When they do document the values,
they vary significantly from monitor to monitor, and even from mode to mode:
they're not as critical as they look. For example, here are some typical values
from my NEC 5D handbook:
Horizontal sync pulse: 1 to 4 µs, front porch 0.18 to 2.1 µs, back porch
1.25 to 3.56 µs.
As we'll see, the proof of these timing parameters is in the display. If the
display looks good, the parameters are OK. I don't know of any way to damage
the monitor purely by modifying these parameters, but there are other good
reasons to stick to this range. As a rule of thumb, if you set each of the
three values to 2 µs to start with, you won't go too far wrong.
Alternatively, you could start with the NTSC standard values: the standard
specifies that the horizontal sync pulse lasts for 4.2 to 5.1 µs, the front
porch must be at least 1.27 µs. NTSC doesn't define the length of the back
porchinstead it defines the total line blanking, which lasts for 8.06 to 10.3
µs. For our purposes, we can consider the back porch to be the length of the
total blanking minus the lengths of the front porch and the sync pulse. If you
take values somewhere in the middle of the ranges, you get a front porch of 1.4
µs, a sync pulse of 4.5 µs, and total blanking 9 µs, which implies a
back porch of 9 - 1.4 - 4.5 = 3.1 µs.
For our example, let's stick to 2 µs per value. We have a horizontal
frequency of 40 kHz, or 25 µs per line. After taking off our 6 µs for
flyback control, we have only 19 µs left for the display data. In order to
get 640 pixels in this time, we need one pixel every 19 / 640 µs, or about 30
ns. This corresponds to a frequency of 33.6 MHz. This is our desired dot
clock.
The next question is: do we have a dot clock of this frequency? Maybe. This
should be in your display board documentation, but I'll take a bet that it's
not. Never mind, the XFree86 server is clever enough to figure this out for
itself. When you start the server, it will either print out a list of allowable
dot clocks or a maximum dot clock if the board has a freely programmable dot
clock. At the moment, let's assume that you do have a dot clock of 33 MHz.
If you don't have a suitable clock, you'll have to take the next lower clock
frequency that you do have: you can't go any higher, since this example assumes
the highest possible horizontal frequency.
You now need to calculate four register values to define the horizontal lines:
At this point, our vestigial mode line looks like:
Modeline "640x480" 28 640 704 768 832
Next, we need another four values to define the vertical scan. Again, of the
four values we need, we only know the number of lines. How many lines do we use
for the porches and the vertical sync? We've seen that NTSC uses about 45 lines
for the three combined, but modern monitors can get by with much less. Again
referring to the Multisync manual, we get a front porch of betwwen 0.014 and 1.2
ms, a sync pulse of between 0.06 and 0.113 ms, and a back porch of between 0.54
and 1.88 ms. But how many lines is that?
To figure that out, we need to know our real horizontal frequency. We
were aiming at 40 kHz, but we made a couple of tradeoffs along the way. The
real horizontal frequency is the dot clock divided by the horizontal total, in
this case 33 MHz / 832, which gives us 39.66 kHznot too bad. At that
frequency, a line lasts 1/39660 seconds, or just over 25 µs, so our front
porch can range between 1/2 and 48 lines, our sync pulse between 2 and 5 lines,
and the back porch between 10 and 75 lines. Do these timings make any sense?
No, they don'tthey're just values which the monitor can accept.
To get the highest refresh rate, we can go for the lowest value in each case.
It's difficult to specify a value of 1/2, so we'll take a single line front
porch. We'll take two lines of sync pulse and 10 lines of back porch. This
gives us:
Modeline "640x480" 28 640 704 768 832 480 481 483 493
Now we can calculate our vertical frequency, which is the horizontal frequency
divided by the Vertical Total, or 39.66 / 493 kHz, which is 80.4 Hzthat's
not bad either. By comparison, if you use the standard entry in
XF86config, you will get a horizontal frequency of 31.5 kHz and a vertical
frequency of only 60 Hz.
If you know the technical details of your monitor and display board, it really
is that simple. This method doesn't require much thought, and it creates
results which work.
|
||