I want to share my experience trying to make an Arduino produce a B/W composite video signal. (That's the yellow RCA-plug one uses for, let's say, Nintendos)
The difficulties in producing this signal on a platform like the Arduino (I am using the Uno with a mounted ATMega328 µ-chip) arise from the fact that the PAL signal (Yes, PAL! Take that SECAM and NTSC!) expects synchronization-pulses at certain intervals. But the Arduino of course is limited to changes at specific time instants.
While browsing for the signal and timing specifications I found a lot of great sites covering the same topic:
- TVOut Library on Google Code:
First there is this gorgeous library that already comes with built-in PAL/NTSC support and methods for printing text and basic forms. Awesome but the PAL version did not work on my Teevo. Also I do want to build my own! - Craft by Linus Akesson:
Great project on an ATMega88! I took a deep look into the source code (done in assembler!), but it uses a five-wire approach, namely RGB and two sync signals. So not really what I was looking for. Make sure to check out some of his other projects, too! - Lucid Science has a cover-up on a similar (color) project using an ATMega644. But it uses the VGA cable, so no composite signal either.
- Javier Valcarce has a compact how-to on PAL video signals on Arduino. I really like the basicness (is that even a word?) of it. Just what I need. But sadly, neither of my two TVs produces an image using this sketch.
Afterwards I checked out several pages trying to gather information about the PAL signal specifications. Sadly, no one seemed to agree on what it is supposed to be like. Luckily, after some frustrating days of browsing I had the good idea to ask the right question. Who regulates PAL TV?
That is how I came to the ITU-R's page for broadcasting service (television) [BT]. And specifically I looked at the document for Conventional Analogue Television Systemsa (Rec. ITU-R BT.470-6).
Before it is time to take a look at that document to see how exactly the composite signal needs to be composed, I want to take the time to talk about the basic principle of analog video. If you are familiar with it, you can skip on ahead.
Personally, I like the image found here to be the most discriptive:
Firstly, notice the name PAL TV interlace. The word interlaced says that the picture is composed of two fields, shown on the schematic, too. These two fields are joined together like the teeth of two combs when displayed. Field1 starts with the first line of the final image and contains all the odd lines. Field2 has all the even lines. This displaymode is a fragment from the past: on an old cathode ray display a beam would move behind the screen to illuminate the phosphorous material on the inner side of the screen. But by the time it reached down low, the upper rows would have stopped glowing. That is why the picture was split into two, thus faster, passes, the known fields.Next, take a look at the right side. It says 40ms and 25Hz. Now you might be thinking "25Hz is kinda' low!" and you would be right. But remember that there are two fields displayed at this rate. And the second field is temporarily advanced. A fancy way of saying that it has moved one instant further in time. That is how motion can be displayed at 50Hz on PAL and it looks decent, I would say.
Now the other information on the left tells us that the signal consists of as many as 625 lines. No more, no less. And at the bottom it reads 64µs. That is the time of a single line.
But the real information shown in this schematic is the composition of the whole frame. We said before, that each frame, of the 25 per second, is split into two fields. Now the picture also tells us that the first field start only after 5 lines that are made up of vertical synchronization pulses, named long sync and short sync here. The red color inside the sync periods also tell us that the long syncs spend most of their time at sync level (figures!) and the rest at black level. With the short syncs it is quite the opposite.
Then Field 1 begins. The magenta and light green bars indicate the horizontal (or line) synchronization pulse that every line begins with. The white part of the field is the actual picture data contained.
(I did not dig into the duration of pulses etc. because we will be using the official numbers we are about to discover in the ITU-R document)
Back to the ITU-R Recommendation BT.470-6 document:
First thing we are checking out here is the figure Levels in the composite signal and details of line-synchronizing signals. This can be found all over the web but all we need is right here in this document. Take a look at the label O_{H}. This is the time instant at which a new line begins.
First thing to come in a new line is the level 3: Synchronization level for the duration of d. Followed by level 1: Blanking level for b - d µicroseconds. Now do not forget about the blanking level right before O_{H} called front porch! It actually is also located after the data part and takes c µs.
Let us look up the values in the table after the figure: b = 10.5µs and d = 4.7µs and c = 1.5µs.
To sum things up: Every line starts with 4.7µs at sync level followed by 5.8µs at blanking level followed by the data part that has the remaining 52µs of the 64µs time-slot available. The line is concluded by the front porch at blanking level for 1.5µs.
(You may have noticed the thick bubble with the vertical bars. It is used for color-generation and we can safely ignore it.)
Now that we know how to generate the regular data lines let us look into the vertical synchronization:
The figure Details of equalizing and synchronizing pulses contains what we need. The H/2 says that either pulse takes up half of the line duration in total. That is 32µs.
The left half of this signal is the equalization pulse. It is made up of 2.35µs at sync level and 29.65µs at blanking level.
The right one is the synchronization pulse consisting of sync level for 27.3µs and blanking level for 4.7µs.
Finally, we need to know how the equalize- and synchronize-pulses are to be arranged to form the vertical- or field-synchronization. Therefor we take a look at Details of field-synchronizing waveforms:
Again, the beginning of a new field is indicated by O_{H}. The main thing to take note of here is that a new field starts with five equalization pulses directly followed by five consecutive synchronization-pulses. Each one of these pulses lasts half a line so we are now (5+5)/2 = 5 lines into the first field.But obviously after the sync pulses the data does not start right away. there is a number of blank lines containing only the horizontal synchronization pulse and nothing more. How much of them are there exactly? Let us look up the value of j, the so called field-blanking interval. It is 25 lines + 12µs long. And because j starts five pulses AND a k, which is not shown in the diagramme but in the table and takes 1-5µs, it ends at (25lines+12µs) - (2.5lines+[1to5]µs) = 22.5 lines and 7-11µs. In other words, image data begins 39 to 43µs into line #23.
Field 2 begins where you would expect it to: halfway into line 625/2 = 312.5 -> 313 and then follows the same rules.
I think that is enough information to digest for one session. We have learned how an analog composite signal should be generated. Also we now know how the specific synchronization pulses are timed and when the actual data needs to be written.
The next session will get into things and explain how to hook up the Arduino to a television and also how the code for such a venture could look like.




No comments:
Post a Comment