<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>Black Magic and Sync Pulses</TITLE>
</HEAD>
<BODY BGCOLOR="#efefef" TEXT="black" LINK="blue" VLINK="#551A8B" ALINK="red">

<A HREF="VideoModes.html"><EM>XFree86 Video Timings HOWTO</EM></A>
 <b>:</b> <EM>Black Magic and Sync Pulses</EM><BR>
<b>Previous:</b> <A HREF="VideoModes8.html"><EM>Computing Frame Sizes</EM></A><BR>
<b>Next:</b> <A HREF="VideoModes10.html"><EM>Putting it All Together</EM></A>


<HR NOSHADE>
  <H2><A NAME="13"></A>9. Black Magic and Sync Pulses<A NAME="magic"></A></H2>

<p>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. </p>
<p>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. </p>
<p>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). </p>

<H3><A NAME="14"></A>9.1. Horizontal Sync:</H3>

<p>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 &lt; HFL by definition.  For concreteness, let's assume both start
at the same instant as shown below: 
<hr>
<pre>
  |___ __ __ __ __ __ __ __ __ __ __ __ __
  |_ _ _ _ _ _ _ _ _ _ _ _                |
  |_______________________|_______________|_____ 
  0                       ^               ^     unit: ticks
                          |   ^       ^   |
                          HR  |       |  HFL
                          |   |&lt;-----&gt;|   |
                          |&lt;-&gt;|  HSP  |&lt;-&gt;|
                          HGT1         HGT2
</pre>
<hr>
</p>
<p>Now, we would like to place a sync pulse of length HSP as shown above, ie,
between the end of clock ticks for display data and the end of clock ticks for
the entire frame.  Why so?  because if we can achieve this, then your screen
image won't shift to the right or to the left.  It will be where it supposed to
be on the screen, covering squarely the monitor's viewable area. </p>
<p>Furthermore, we want about 30 ticks of "guard time" on either side of the sync
pulse.  This is represented by HGT1 and HGT2.  In a typical configuration HGT1
!= HGT2, but if you're building a configuration from scratch, you want to start
your experimentation with them equal (that is, with the sync pulse centered). </p>
<p>The symptom of a misplaced sync pulse is that the image is displaced on the
screen, with one border excessively wide and the other side of the image
wrapped around the screen edge, producing a white edge line and a band of
"ghost image" on that side.  A way-out-of-place vertical sync pulse can
actually cause the image to roll like a TV with a mis-adjusted vertical hold
(in fact, it's the same phenomenon at work). </p>
<p>If you're lucky, your monitor's sync pulse widths will be documented on its
specification page.  If not, here's where the real black magic starts... </p>
<p>You'll have to do a little trial and error for this part.  But most of the
time, we can safely assume that a sync pulse is about 3.5 to 4.0 microsecond
in length. </p>
<p>For concreteness again, let's take HSP to be 3.8 microseconds (which btw, is not
a bad value to start with when experimenting). </p>
<p>Now, using the 65Mhz clock timing above, we know HSP is equivalent to 247 clock
ticks (= 65 * 10**6 * 3.8 * 10^-6) [recall M=10^6, micro=10^-6] </p>
<p>Some makers like to quote their horizontal framing parameters as timings rather
than dot widths.  You may see the following terms:
<dl>
<dt><b>active time (HAT)</b><dd><p>Corresponds to HR, but in milliseconds.  HAT * DCF = HR.</p>
<dt><b>blanking time (HBT)</b><dd><p>Corresponds to (HFL - HR), but in milliseconds.  HBT * DCF = (HFL -
HR).</p>
<dt><b>front porch (HFP)</b><dd><p>This is just HGT1.</p>
<dt><b>sync time</b><dd><p>This is just HSP.</p>
<dt><b>back porch (HBP)</b><dd><p>This is just HGT2.</p>
</dl>
</p>

<H3><A NAME="15"></A>9.2. Vertical Sync:</H3>

<p>Going back to the picture above, how do we place the 247 clock ticks as shown
in the picture? </p>
<p>Using our example, HR is 944 and HFL is 1176.  The difference between the two
is 1176 - 944=232 &lt; 247!  Obviously we have to do some adjustment here.  What
can we do? </p>
<p>The first thing is to raise 1176 to 1184, and lower 944 to 936.  Now the
difference = 1184-936= 248. Hmm, closer. </p>
<p>Next, instead using 3.8, we use 3.5 for calculating HSP; then, we have
65*3.5=227.  Looks better.  But 248 is not much higher than 227.  It's normally
necessary to have 30 or so clock ticks between HR and the start of SP, and the
same for the end of SP and HFL.  AND they have to be multiple of eight!  Are we
stuck? </p>
<p>No.  Let's do this, 936 % 8 = 0, (936 + 32) % 8 = 0 too.  But 936 + 32 = 968,
968 + 227 = 1195, 1195 + 32 = 1227.  Hmm.. this looks not too bad.  But it's
not a multiple of 8, so let's round it up to 1232. </p>
<p>But now we have potential trouble, the sync pulse is no longer placed right in
the middle between h and H any more.  Happily, using our calculator we find
1232 - 32 = 1200 is also a multiple of 8 and (1232 - 32) - 968 = 232
corresponding using a sync pulse of 3.57 micro second long, still
reasonable. </p>
<p>In addition, 936/1232 ~ 0.76 or 76%, still not far from 80%, so it should be
all right. </p>
<p>Furthermore, using the current horizontal frame length, we basically ask our
monitor to sync at 52.7khz (= 65Mhz/1232) which is within its capability.  No
problems. </p>
<p>Using rules of thumb we mentioned before, 936*75%=702, This is our new vertical
resolution.  702 * 1.05 = 737, our new vertical frame length. </p>
<p>Screen refresh rate = 65Mhz/(737*1232)=71.6 Hz.  This is still excellent. </p>
<p>Figuring the vertical sync pulse layout is similar: 
<hr>
<pre>
   |___ __ __ __ __ __ __ __ __ __ __ __ __
   |_ _ _ _ _ _ _ _ _ _ _ _                |
   |_______________________|_______________|_____ 
   0                      VR              VFL     unit: ticks
                           ^   ^       ^
                           |   |       |
                           |&lt;-&gt;|&lt;-----&gt;|
                            VGT    VSP
</pre>
<hr>
</p>
<p>We start the sync pulse just past the end of the vertical display data ticks.
VGT is the vertical guard time required for the sync pulse.  Most monitors are
comfortable with a VGT of 0 (no guard time) and we'll use that in this
example.  A few need two or three ticks of guard time, and it usually doesn't
hurt to add that. </p>
<p>Returning to the example: since by the definition of frame length, a vertical
tick is the time for tracing a complete HORIZONTAL frame, therefore in our
example, it is 1232/65Mhz=18.95us. </p>
<p>Experience shows that a vertical sync pulse should be in the range of 50us and
300us.  As an example let's use 150us, which translates into 8 vertical clock
ticks (150us/18.95us~8). </p>
<p>Some makers like to quote their vertical framing parameters as timings rather
than dot widths.  You may see the following terms:</p>
<p>
<dl>
<dt><b>active time (VAT)</b><dd><p>Corresponds to VR, but in milliseconds.  VAT * VSF = VR.</p>
<dt><b>blanking time (VBT)</b><dd><p>Corresponds to (VFL - VR), but in milliseconds.  VBT * VSF = (VFL - VR).</p>
<dt><b>front porch (VFP)</b><dd><p>This is just VGT.</p>
<dt><b>sync time</b><dd><p>This is just VSP.</p>
<dt><b>back porch (VBP)</b><dd><p>This is like a second guard time after the vertical sync pulse.  It
is often zero.</p>
</dl>
</p>

 <HR NOSHADE>
<A HREF="VideoModes.html"><EM>XFree86 Video Timings HOWTO</EM></A>
 <b>:</b> <EM>Black Magic and Sync Pulses</EM><BR>
<b>Previous:</b> <A HREF="VideoModes8.html"><EM>Computing Frame Sizes</EM></A><BR>
<b>Next:</b> <A HREF="VideoModes10.html"><EM>Putting it All Together</EM></A>



</BODY>
</HTML>
