11 Two More Example Calculations

Contents of this section

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...") that the total number of lines will be 5% 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)...

or

"800x?" 40 800 832 992 1136...

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:

     # the following line works but is right of center
     "752x564"  40  752  784  944 1088  564 567 569 611
     #        44.5  752 792  976 1240  564 567 570 600
     #
     # this line fixes the problem with the previous line
     #"752x564" 40  752  816  976 1088  564 567 569 611
     #
     # trying to increase the vertical display size, it works
     #"752x614" 40  752  816  976 1088  614 617 619 661
     #
     # trying to increase the horiz. display size, it works
     #"784x564" 40  784  816  976 1088  564 567 569 611
     #
     # the following works but is to the right of center
     #"784x614" 40  784  816  976 1088  614 617 619 661
     #
     # the following corrects the uncentered problem of the previous one
     "784x614"  40  784  848 1008 1088  614 617 619 661
     #
     # trying to increase the display size
     # the following works, the display is slightly off center to the left
     #"800x614" 40  800  864 1024 1088  614 617 619 661
     #
     # the following corrects the problem of the previous entry
     "800x614"  40  800  864 1024 1104  614 617 619 661
     #
     # increase the display size, it works
     "816x614"  40  816  880 1040 1120  614 617 619 661
     #
     # increase the display size, it works
     "800x620"  40  800  864 1024 1104  620 623 625 661
     #
     # increase the display size, it works
     "816x620"  40  816  880 1040 1120  620 623 625 661
     #
     # increase the display size, it works
     "832x630"  40  832  896 1056 1136  630 633 635 661
     #
     # change the display size, it works but flickers badly
     "848x618"  40  848  912 1072 1152  618 621 623 661

Next Chapter, Previous Chapter

Table of contents of this chapter, General table of contents

Top of the document, Beginning of this Chapter