Generating a Color NTSC signal with an FPGA

With every project I do, professional electronics engineers earn more and more of my respect. In my eyes, these folks are true geniuses. When I think about the shoulders of the giants I’ve stood on just to get to the amateurish level of electronics understanding that I’m at, I’m also completely awed by some of the things that the professionals and advanced hobbyists are doing. As I grow, I’m also beginning to realize why many designs are as complex as they are. In my simple frame of mind I’ve often thought, “well, why can’t you just do this? It’d be so much simpler that way!” There’s a huge difference between just getting things to work and making them work well. Electronics is part art, and part science. That’s why I love it.

That said, I’m a proponent of getting things to work, and then improving upon them. In my computer science classes, one of my college professors once said, “first make it work, then make it fancy.”

For this project, I set out to build an FPGA version of an old 8-bit computer system. Of course, before I even started I got distracted! I said to myself, “self, this replica I’m building has to have composite video, just like the original system.” Oh brother. Why couldn’t I have just been content with VGA? (For those who aren’t aware, a VGA signal is relatively easy to implement in an FPGA; I won’t go into the details, but you can read more about it here.)

NTSC stands for “National Television Standards Committee”, and it’s also the format that we use here in the United States for sending pictures to a TV. PAL is the European format; it’s very similar, but again I won’t go into detail.

Creating a color NTSC signal has proved to be much more difficult than a VGA signal. However, generating a black and white composite signal was very easy, once I figured out what it was supposed to look like. Searching the web, I found about 700 descriptions of the timing information for an NTSC signal; all of them were different.

What I found was that to get all the accurate details on the NTSC signal, you should probably go buy a book– because no one seems to know the correct signal details anymore. Or maybe someone does, but you can’t tell, because everyone does the timing or positioning of the horizontal synchronization a little differently. Some sites might say “62us” instead of “63.5us”, some might put the vertical and horizontal pulses at the beginning or end of a field, etc; some put the “front porch” at the end of the signal, etc… Truthfully, I think the timing of the signal itself is very forgiving on most TVs. At least it has been on my TV so far!

I tried to glean as much as I could from as many web sites I could find, and do my best to piece all of the information together by using what they had in common.

I will say that I believe that this is probably the most accurate description of the signals that I could find. I think these are “official” images from the Television Standards Committee but they are a little difficult to understand. Probably the best general resource I have found was Rickard Gunee’s web site. His description is very clear, but I still think that some of the stuff I read there may have lumped together some information on the PAL and NTSC formats. Still, it’s very evident that Gunee knows what he’s doing. The main difference between his project and mine, though, is that he is generating an NTSC signal with software, and I wanted to generate one with hardware (well, an FPGA to be exact).

NTSC Basics

I will attempt to describe the parts of an NTSC signal as I understand them. This is what works for me, but it may not be a 100% accurate description of the signal. If you need accuracy, I would suggest finding a book on the subject rather than trying to glean the information from the Internet.

There are two parts to a full screen of video: the vertical sync pulses, and the video. Both of these parts are further divided into what I would call “scan lines”. In total, there are 525 scan lines, and each one lasts 63.5us.

The picture below shows a correct NTSC video scan line, captured from a Sylvania VCR/DVD with my brand new PC oscilloscope. This is pretty much what I believe to be a “textbook” scan line signal. As you can see, there are 4 distinct parts to the scan line: A front porch, a horizontal sync pulse, a back porch, and the video signal. I would not consider the “color burst” to be a distinct part of the waveform, because with a black and white signal it’s not needed.
A Correct NTSC Signal

Here is a breakdown of the signal from the NTSC-TV web site. I think this is the official NTSC web site (but it has ads on it, so I’m not really sure.)

sync-wf[1].gif

Signal Overview

As mentioned, there are 525 total lines in an NTSC composite signal, but not all of them describe the picture. Many are used for vertical synchronization, and some are used for other information, such as closed captioning. A single television frame is “interlaced” into two separate frames: first the odd lines in the picture are drawn (line 1,3,5… etc), then the even lines are filled in (2,4,6,8…).

The odd and even parts of the NTSC signal are called “fields”, and so there are 2 “fields” in one full picture on the screen. At the beginning of each odd and even field, there are “vertical sync” pulses, which tell the TV that either (1) a new frame is coming, or (2) the odd lines have already been drawn, and now the even lines are coming.

Here’s an overview from SXlist.com:

 So, to recap: 

 Field 0 contains 262.5 lines, as follows.

    * 3 lines: 6 pre-eq pulses
    * 3 lines: 6 vertical sync pulses
    * 3 lines: 6 post-eq pulses
    * 253 lines: normal scan lines (many of these are invisible and some are reserved for closed-caption data, cable tv scrambler data, etc... but so far as sync is concerned, these lines are all "normal" scan lines)
    * .5 lines: the last line of the field quits right in the middle! 

Field 1 contains 252.5 lines, as follows.

    * 3 lines: 6 pre-eq pulses
    * 3 lines: 6 vertical sync pulses
    * 3.5 lines: 7 post-eq pulses
    * 253 lines: normal scan lines

Note that black and white signals are identical to color signals, but there is additional information overlaid on top of the signal for color. This was done to stay compatible with the original black and white televisions.

Front Porch

The front porch is a “flat” pulse that lasts 1.5us, and stays constant at 0.3V. 0.3V is significant because it is the black level for the picture.

Horizontal Sync

The horizontal sync, or “Sync Tip” lasts 4.7us at a constant 0.0V.

Back Porch

The back porch is 4.7us at a constant 0.3V for a black and white picture. However, if it’s a color signal, then there is a “color burst” in the back porch, for about 2.5us, which is a 3.579545 MHz signal (about 8 or 9 cycles).

Video Data

The video data is 52.6 us worth of luminance (brightness) information. From left to right, this describes the picture on one single line out of the 525 in a television picture.

The higher the voltage, the brighter the pixel; it’s very simple. For black and white signals this is extremely easy to do: the luminance information goes from a minimum 0.3V (black) to a maximum of 1.0V (white). However, when there is color involved it gets much more complex. I don’t thoroughly understand it (for a good description, try Howto generate color video signals in software), but the basic idea is that by shifting the phase of the 3.579545 signal relative to the color burst, you define the color. Then, the average voltage of the signal at any given point describes the brightness.

One thing that you might have noticed is that there’s no real horizontal “resolution” to this picture. This differs greatly from a VGA signal, which has a rigidly defined number of pixels going horizontally. The horizontal resolution of a TV will depend on how quickly the signal changes. I’m not sure what the highest possible resolution on a TV is, but it’s probably limited by the 3.6 MHz color signal and by the parameters of the television circuitry itself.

Rather than trying to generate this signal directly, I “cheated” and used an AD725 chip from Analog Devices. This chip takes in RGB analog signals, a 14.318180 MHz clock, and synchronization pulses, and generates an NTSC signal for you. You still have to understand the timing of the signal, but the chip puts everything together for you.

Vertical Sync Pulses

This is the part that I found a little hard to find information for; especially about the timing of the pulses.

The vertical sync pulses are a combination of alternating black (0.3V) and 0.0V signals.

There are 2 types of vertical sync pulses, called “equalizing pulses”, and “serration pulses”. The timing of the pulses themselves is shown in the first picture below, and the second picture shows the relationship of the vertical sync pulses to the entire picture’s worth of data. If you stare at the bottom part of the first picture for a while, you will begin to make sense out of it. It’s a color coded picture of how the vertical sync pulses line up from the bottom of one field to the top of the next field, if you were to stack each scan line on top of the next.

Sync Pulses

Raster Scan Synchronization Waveforms

(images taken from here)

More information to come soon

Hardware

The hardware I used to implement this was a Spartan-3E Starter Kit from Xilinx, an Analog Devices AD725 chip, and a 14.318180 MHz oscillator built with a crystal and a Texas Instruments CD74HC04ME4 CMOS High Speed Inverter.

However, you should be able to implement it using any FPGA with free I/O pins; or for that matter, any microcontroller that can generate the correct timing should work.

The AD725 and the Importance of the Right Crystal

The AD725 is a chip that takes analog RGB signals and converts them to composite or S-Video signals. It’s a great chip. Using it, I was able to re-use the code I had generated to create a black and white video signal, and quickly change a few things in order to make it work with color. As I’ve mentioned, the timing of the parts of the scan line are the same; it’s just the addition of the color data that is the difference.

Folks, please learn from my mistakes if you decide to do this yourself. Go out and get a 14.318180 MHz crystal and a high speed CMOS inverter. Do not try to generate your own clock with an FPGA (unless your clock is a multiple of this exact frequency), and don’t try to generate a 14.318180 signal with a programmable oscillator. It doesn’t work. You will just generate a black and white signal and end up frustrating yourself. Use a schematic like the one on page 13 of the AD725 datasheet; it just works.

The frequency of the color subcarrier is 3.579545 MHz, and it needs to be very close to this frequency in order to generate color. The AD725 datasheet says: “Most monitors can tolerate a subcarrier frequency that deviates several hundred Hz from the nominal standard without any degradation in picture quality.” (p. 11) But believe me, there is a degradation in signal quality if you deviate from this range. If your frequency is not close to exact, the TV will just take an average of what you’ve given it and display it in black and white.

Photos

Resultant display
The resultant display

My signal
My NTSC signal. Ugly, but it works! There is a lot of noise in the display, most likely because I’m implementing the luminance information using PWM. My thought is that this probably does not work well because (1) it interferes with the color information because it’s a high frequency signal, and (2) it causes a lot of noise in the circuit. I believe that a better way to do this would be to create an ADC converter using a resistor ladder, as described on Rickard Gunee’s page; but this worked for a “quick-and-dirty” implementation. I marked here where I think that each color bar is in the signal. You can see here how the average voltage of the signal corresponds to the brightness of the signal.

Formula on Gunee’s page for calculating luminance:

NTSC: Y=0.299R+0.587G+0.114B, where Y is the luminance of the signal.

A more detailed picture of my signal

The circuit
The current circuit

Notes

One thing that I’ve just noticed, which will be useful in generating a more accurate signal, is that the front porch and back porch parts of the signal are actually lower than black level. According to Gunee’s page, true black is 0.3V, so the horizontal and vertical sync pulses must actually be lower than 0.3V (in the diagram above, it is called “blacker-than-black”).

Apparently composite signals are measured in “IRE Units”, after the Institute of Radio Engineers. From this Wikipedia article, it appears that there is no set amplitude for an NTSC signal. Therefore, looking at the diagram above of the NTSC signal, it seems that using 1.0V as white, the “blacker than black” signal should be 0.285V, and the “black” signal should be 0.339V (if black level is at 7.5 IRE).

This image below from Wikimedia further illustrates this.

Composite_Video[1].svg

References

Disclaimer

If you break anything from doing this, it’s not my fault! Don’t attempt any of this stuff unless you’re reasonably sure you know what you’re doing!

  • Kyle

    Back in the old days, the color burst was phase shifted with some really complex equipment and nasty devices called ‘delay lines’ which were about as accurate as a drunk man playing darts. NTSC used to be considered as meaning “Never The Same Color” due to subcarrier phase drift.

    The sync pulses were also overly complex, requiring racks of equipment with over a hundred vacuum tubes just to generate the equalization pulses. It’s been theorized that the equalization pulses are not required for proper synchronizing, at least during the development of the short-lived 405 line CBS field sequential color system. It *DOES* work without EQ pulses in most cases, especially when faux progressive scan is used, such as the timing methods implemented in the old 8 bit game consoles.

    I used to think it may have just been some wicked engineer who thought it would be a nasty joke to require massive amounts of electronics just to prefix “6-6-6” to every video field, but after noticing ‘flag-waving’ and ‘top bending’ after removing the EQ pulses, there may be more to it than just biasing a finicky regenerative oscillator. Too bad we don’t have the old notebooks from when the standard was developed to find out the rationale behind some of these oddities!

    • Steve

      Hi Kyle,

      I’m so far removed from this project now that I had to re-read what I wrote just to have a clue as to what you were saying! I wrote this back in 2009 and had to give up my electronics tinkering since then because I have 4 kids.

      It’s still fascinating to me that a signal so complex actually works *at all*, that they made it work with vaccuum tubes, and that engineers were able to retrofit a black and white signal to one with color based on phase shifting.