Friday, November 19, 2010

Understanding the basic requirements to display video on a CRT TV

The basic thing that attracted me towards ARM was the idea of creating a Game Console for NTSC TV. I previously made a game console for VGA monitor using AVR. But now the desire to make it better, to get greater resolution video, good quality audio and also huge number of sprite support made me start working with ARM. The basic reason for choosing LPC1768 over hundreds of microcontrollers available in the market was that this controller seems appropriate for video graphics generation purpose. The basic architecture of it is such that it makes our job simple.

Before getting into the core work of the game console we need to know as to how to interface a TV with a microcontroller. What all signals does the TV except? and what are the specifications of those signals and all. So here we are discussing all the things that are required to interface a TV with LPC1768 and to display a white line (horizontal or vertical).

TV consists of a total of around 525 horizontal lines (scanlines). It uses interlaced scanning. In interlaced scanning the horizontal lines are divide into even and odd lines. So scanlines 1,3,5... come under odd field and 2,4,6,... come under even field. In interlaced scanning, TV writes either to all even lines or all odd lines in one frame. But writes the complementary lines in the next frame. So effectively we require two frames to display a complete picture in interlaced scanning. You will understand interlaced scanning better by having a look at the animation below (Click the image to see the animation).


Fake progressive scanning: Here we write the image in only even field or odd field but not in both. So effectively the frame rate got doubled!! The slight disadvantage with this method is that there will be a one scanline gap (i.e. black line) between two used scanlines. But there is no need to worry about this disadvantage. Those black lines interleaving the scanlines of the image wont be visible from the watchable distance. If you need to know as to how to use interlaced or fake progressive scanning refer link [2] after reading this tutorial.

TV needs Synchronization pulses to synchronize the light beam of the TV to the correct position, Luminance setting the intensity of the display and Chrominance which decides the color and also its relative amplitude to the color burst (will discuss what a color burst is in a while) signal will decide the color saturation.

In a TV the video is split into scanlines which nothing but one horizontal line on it. And each of these scanlines will be 63.5uS in length. Each scanline except the vertical sync lines consists of two parts, one is the synchronization part and another one is the rendering part. The synchronization part consists of a horizontal sync and the color burst signal which is the reference carrier of the chrominance signal. In the rendering part both luma and chroma signals will be given to the TV.

To display the video correctly TV needs two syncs. One is horizontal sync and another is vertical sync. A horizontal sync is nothing but a low level pulse for 4.3uS in the 63.5uS scanline. Whenever an horizontal sync is given the beam of the TV gets focused to the left edge of the TV but the vertical position of the beam cannot be determined if the vertical sync is not provided. And a vertical sync is nothing but one or two scanlines of  invert horizontal sync i.e scnalines being high for a period of (63.5uS - 4.3uS) = 59.2uS. According to the specifications in total of eight scanlines with different duty cycle wavefroms compose one vertical sync [2]. But only one scanline of inverted horizontal sync pulse gets the job done (This doesnot work if you are planning to do interlaced scanning. But it works for fake progressive scanning). If you are a person who likes to sticks to the specs you can go with the eight scanlines V-sync only. When vertical sync is given the light beam of the TV gets focused to the top of the TV. So a H-sync following a V-sync will move the beam to the top-left of the TV from where we start giving the video signals.

Now we can easily give the luminance (signal with amplitude ranging from 0.3v to 1v to get black to different shades of white) and get Black and White video. But we need color video. So we need to give color burst after the horizontal sync pulse. This signal will act as a carrier phase reference for the chroma signal. This carrier frequency will be different for different standards. For NTSC it is 3.57954545 MHz, whereas for PAL and NTSC 4.43 it is 4.433618 MHz. Both the horizontal sync pulse and the color burst is in together called as blanking period. The following image shows a typical scanline.


Now the most important thing is to add color to the video. In TV the color produced will depend on the phase difference between the chroma waveform and the color burst. So to get different colors waveforms of color carrier frequency with different phases need to be sent. The saturation of the color depends upon the relative amplitude of the chroma signal w.r.t the color burst signal. The colors generated for different phase differences is shown in the below image.




We can generate H-sync and V-sync pulses using PWM while the color burst and chroma is sent via SPI and luma is put out on GPIO. The detailed explanation of implementation will be written shortly.

For further information on basic working of TV go to
1. http://zone.ni.com/devzone/cda/tut/p/id/3020
2. http://www.retroleum.co.uk/electronics-articles/pal-tv-timing-and-voltages/
3. http://www.batsocks.co.uk/readme/art_SerialVideo_5.htm
4. http://graffiti.virgin.net/ljmayes.mal/var/tvsync.htm

No comments: