Back in 2011 I put together an implementation of Pong that uses an Arduino Pro, a couple of resistors, a couple of potentiometers, and two sweet cans from M&S. I called it the Cansole: video game console in a can. Just a silly weekend project.
Recently, someone asked to try it out and I retrieved it only to find that my TV doesn't have composite video inputs, only HDMI. The Cansole creates a black and white 128x96 PAL composite video image in software using a project called TVout. So, I ordered a composite to HDMI converter and while waiting for it to arrive decided to refresh my memory about how the video circuit (which is two resistors!) works.
In the image above you can just make out that the video signal is provided from two digital pins on the Arduino fed into two resistors that connect to the RCA connector for composite video. Here's the schematic of the whole thing:
The video signal is created on pins 7 and 9 which are connected to two resistors (470 ohm and 1k ohm) which connect to the pin of the RCA connector for the composite output. To understand how that works it's worth delving quickly into composite video.
Here's a look at two lines in a PAL composite video signal. There are three parts: line sync (telling the TV that a new line is starting), colour information (which we won't have since TVout only does black and white), and brightness information (we'll be using just black and white with no in between).
Composite video uses a signal that varies between 0V and 1V. Since we only need line sync (which is 0V), black (which is roughly 0.3V) and white (which is 1V), the Arduino needs to generate three different voltages. It does this using different settings of pins 7 and 9. Each pin can either be 5V or 0V.
Here's what the different combinations give on the pin of RCA connector when it is disconnected from the TV.
Pin 7 (470 ohm) Pin 9 (1k ohm) Voltage
5V 5V 5V
5V 0V 3.4V
0V 5V 1.6V
0V 0V 0V
The case where pins 7 and 9 are both 5V or 0V are boring: the pin of the RCA connector will be 5V or 0V. But the other two cases are more interesting. These are calculated be seeing that the two resistors form a
voltage divider and the standard voltage divider formula can be used.
Forget for a minute that these are not the values that we want for composite video (we'll get to that in a minute, but remember I said that this was when the RCA connector was disconnected). To make it a little clearer to see, here's a diagram just showing that the two resistors form a voltage divider with pins 7 and 9 determining which side is 5V and which is 0V.
Let's take a look at the waveform being generated by the Cansole by hooking it up to an oscilloscope. Here I've captured four line syncs. The first one is followed by no information at all (the line is entirely black), the second one has a bunch of brightness information (which you can see is either black or white).
The oscilloscope is telling us two things. Firstly, the time between line syncs is 64 microseconds giving a line sync frequency of 15.6kHz (the actual composite signal is 15.625kHz for PAL). Secondly, the peak to peak voltage is 5.16V (which seems to confirm the range of voltages) from the table above.
So, the signal looks like composite with the wrong voltages. How come?
Well, that's because it's disconnected. When it's connected the input impedance of the TV comes into play (and the impedance of the cable connecting the two, but I am going to ignore that). For standard composite the input impedance is 75 ohm. If you were to measure the composite input of a TV you should find 75 ohms. Here I measured the input to the
composite to HDMI converter I'm using.
So, effectively there's a 75 ohm resistor across the video input when connected. The circuit would now look something like this.
So, when a pin is at 0V (and the other at 5V) the input impedance of 75 ohm is in parallel with that pin's resistor.
Imagine that pin 7 is 0V and pin 9 is 5V. So the 75 ohm resistor and the 470 ohm resistor will be in parallel. That's effectively a
resistance of roughly 65 ohms. So, the voltage divider that was 1k ohm and 470 ohm is now 1k ohm and 65 ohms. That means a very different output voltage will be created. Using a voltage divider calculator that says that the voltage will be 0.3V (perfect for black!).
When pin 7 is 5V and pin 9 is 0V the situation is reversed. The 75 ohm resistor is in parallel with the 1k ohm resistor which gives an effective resistance of roughly 70 ohms. And again using a voltage divider calculator we find that the composite voltage will be 0.7V (which could be grey).
Now what happens if both pins 7 and 9 are 5V? Now there's yet another voltage divider created. The 1k ohm and 470 ohm resistor are now in parallel with an effective resistance of 320 ohms. That resistance forms a voltage divider with the 75 ohm input impedance. Hence the video voltage will be 0.95V (very close to the 1V needed for pure white).
Pin 7 (470 ohm) Pin 9 (1k ohm) Voltage
5V 5V 0.95V
5V 0V 0.7
0V 5V 0.3V
0V 0V 0V
So just with two resistors and two output pins its possible to create the voltages necessary.
As a final test let's try this under load. Here's the oscilloscope trace with the Cansole connected to the composite to HDMI converter.
The peak to peak voltage is now close to the 1V needed for composite. Each horizontal line represents 200mV so you can see the line sync being about 300mV below the black line (recall that line sync is 0V and black is 0.3V) and the peak of white is about 700mV above black (which would be white at 1V).
Ok, enough analyzing, let's play Pong in a can.
Shout out to the designers and makers of the little Chinese composite to HDMI adapter I bought. Their little gadget coped very well with my messy PAL composite signal!
No comments:
Post a Comment