Tuesday, April 19, 2011

NTSC demystified - B&W Video and Sync - Part 1

NTSC progressive scanning mode and simpler sync methods are not well documented and this issue is addressed here. Producing video signals by going to lowest hardware level is fun and satisfying. With the number of very capable digital controllers available to hobbyists today, it has become possible to generate analog video signals entirely in software. With the techniques and sync patterns presented here, generating "software video" becomes a much easier task.

NTSC has been around for a very long time, but there seems to be a lack of clarity in many of the common techniques used by digital hardware in generating the video signal. I have attempted to collect as much information as possible about the techniques and cheats used by various game consoles and suggested in other papers. One Sync Signal that is the most easiest to produce and has wide compatibility is presented and some of the less mentioned nuances about sync signals and fake progressive scan are explained.

The TV draws a picture by drawing a horizontal lines (of the picture to be drawn) sequentially from top to bottom. Furthermore, it draws each horizontal line from the left to the right. After drawing one horizontal line, it traces back to the left end of the screen and proceeds drawing the next line. After all the horizontal lines have been drawn, it goes back to the top of the screen and begins writing the next picture[3].

To give information about the picture to the TV, one has to provide sync signals to tell the TV when to start drawing the next line (H-Sync) and when to start drawing the next frame (V-Sync). This process is best understood pictorially and is very well shown by Rickard Gunee [1]. For the sake of continuity, one example is given here.


Now, we see that the voltage level for black is 0.3 V, Sync is 0 V and the brightest point is 1 V. Also, we see that just after the sync has ended (the front porch), the signal level is maintained at the black level. In fact, the TV takes this up as the black level and not 0.3 V, although the TV expects it to be 0.3 V. What this means for us is shown in the following figure.


This feature wherein the TV calibrates itself to the black level of the incoming signal is often referred to as "Auto Black". The point is that if you're producing this signal, it's a good idea to try to keep black as close to 0.3 V as possible but there is absolutely no need to be concerned if it turns out to be 0.25 V or 0.33 V. The reason this feature was added was to combat uncertain and sometimes varying attenuation as broadcast signals travel a significant distance.

The TV typically works in the interlaced scanning mode. This means that odd scanlines are written from the top of the screen to the bottom and then, after vertical retrace, even scanlines follow. So, one frame consisted of 2 fields. This was done to keep bandwidth in check while the apparent frame rate was high enough that the viewers didn't complain of flicker. However, it is rather difficult to produce interlace NTSC signals if using a digital controller to generate signals via software. Here, the rarely documented "fake-progressive" mode is used[11]. The idea is that only even fields are written. We force the TV to write the even field lines and after one field is complete, instead of telling the TV to start writing odd field lines, we force it back to writing the even field again.Yes, there are black, unwritten, odd field lines in between "picture" even field lines. Consequently, the frame rate is doubled to nearly 60Hz and we need no longer distinguish between field and frame. This technique is by no means new, it has been used in NES, SNES, Apple II, Atari 2600, and most other old consoles.

Old NTSC papers will say that during V-Sync, half scanlines are sent to inform the TV to retrace back to the top. Serration, pre-equalization, and post-equalization pulses are in fact not necessary for the modern TV. And when I say modern, I mean TV's made during and after the 80's. We can get away with very simple V-Sync signal by having a look at how the TV distinguishes H-Sync from V-Sync[8].

The TV first separates the Sync from the rest of the signal using a thresholding circuit and then inverts the sync signal. This inverted signal is integrated. When it crosses a certain threshold, the sync pulse(held low for 4.7uS) is detected a h-sync. If the integral crosses a second threshold (sync pulse is held low for a lot longer than 4.7uS) , it is detected as a V-Sync pulse. The reason the sync signal is integrated is to reduce the effect of noise which would otherwise cause the TV to incorrectly sync. This very simple and rather crude method of detecting V-sync inside the TV means that we need not bother with precise sync signals. The following Sync pattern is quite easy to generate using PWM or otherwise and will serve our purpose very well. If we look closely at the circuits (inside the TV) presented in [8], it is clear the this sync pattern will force the TV into "fake-progressive" mode.


I've tested this sync pattern on many TV's and the picture is rock stable. Others[9,10] have suggested similar methods but if one is using PWM, the above sync pattern is the easiest to produce. Surprisingly, however, the fact that this "alternate" sync pattern forces the TV into "fake-progressive" mode is simply not mentioned in most papers. As can be seen in [8], half scanlines are needed to enter interlace mode. So, the added advantage of not using half scanlines with 262 full scanlines per frame is that there is absolutely no chance of accidentally entering the interlaced mode which results in severe flicker.

References

1. PIC PONG by Rickard Gunee
2. Text on TV by Batsocks
3. Video Basics - Maxim
4. PAL TV Timings and Voltages - Retroleum
5. AVR Video Generator with Mega163 - by Bruce Land
6. PAL and NTSC timing information - ePanorama
7. NTSC V-Sync Confusion - AVRFreaks Forum post
8. Scanning, Timing, Sync Recovery, Numbers
9. "TV Paint", Embedded Systems Design Laboratory EE281, Handout 7 - Stanford University
10. Video Generation with Mega644, EE476 - Cornell university
11. Video Primer - Uzebox

4 comments:

  1. All this info was very helpful to me. Thank you very much for putting it all together.

    ReplyDelete
  2. The power of the system can be realized with the reports that can be generated to help teachers keep their library relevant and monitor book usage. https://www.scscan.cc/

    ReplyDelete
  3. Thanks for this! It's such a pain to find timings for the progressive mode despite it being so common. Every so often I decide to implement a cycle-counting bit-banging composite out on some microcontroller for a silly project and need to find the information again. I'll be making a copy of this for my own reference before it disappears like so many other useful NTSC resources!

    ReplyDelete