# DIY Pong - Part 1 of 4 - Getting Started

Remember the old TV Pong game? This is one of the early video games where you played a simulated version of ping-pong on a video screen.

Screen shot

Video Game Demo

We built this on a breadboard for the fun of it when I was in grad school. Why would I want to do this again? Because it is doable, educational and fun.
Doing this on a microcontroller with a video screen is easy. How difficult would it be to replicate with common digital ICs on a breadboard? Well, not that difficult as it turns out. I will show you how.

What do we need? The objects on the screen are simple enough. All we need are two paddles and a ball.
Let's get hacking.

Video Basics
Firstly, we need a video screen. An old video monitor that accepts a composite video signal or a VGA monitor will do.
Next, we need to learn how to generate the video signal. This consists of three signals:
1. Horizontal sync
2. Vertical sync
3. Video content
Let's learn what the horizontal and vertical sync signals look like.

You may want to go to this link and read up about Video Basics. This is a very useful tutorial on video formats (thanks to bertus for sharing this link).

NTSC vs PAL
There are different video formats depending on your country and what screen you have. Which country do you live in? Check this link to find out if you need to design for NTSC or PAL. I will be using NTSC in this demonstration. For a different format all you need to do is to modify the numbers given below to suit your situation.

Old fashioned VGA monitor (640 X 480) expects the following (all numbers are approximations):
Horizontal scan frequency = 31.5kHz
Horizontal sync pulse width = 3.8μs
Vertical scan frequency = 60Hz
Vertical sync pulse = 64μs

NTSC format
Number of lines = 525 lines
Horizontal scan frequency = 15.75kHz
Frame frequency = 30Hz

PAL format
Number of lines = 625 lines
Horizontal scan frequency = 15.625kHz
Frame frequency = 25Hz

You need to pay attention to these numbers because your hardware design needs to confirm with a specific format that your display device can accept. Fortunately, video monitors are very tolerant and the horizontal and vertical scan frequencies do not have to be exact.
Here is a graphic of how the signals might appear:

The horizontal scan lines displayed on analog TV screens are interlaced. That is, half the total number of lines are displayed on one vertical scan. The second half are displayed on the next vertical scan with the lines being positioned in between the lines of the first scan, i.e. interlaced. Because the entire frame is displayed at 30Hz (NTSC) or 25Hz (PAL), non-interlaced TV would present an annoying flicker. Interlacing the fields at 60Hz or 50Hz helps to reduce flicker.

For our simple DIY Pong project, we will ignore interlacing and display a complete frame at 60Hz. In order to do this we need to generate 525/2 = 262.5 horizontal scan lines every 16.667 ms. As mentioned before, video monitors are very accommodating. We will bend the rules somewhat and design for the following:

Number of horizontal lines = 260
Vertical scan frequency = 60Hz
Horizontal scan frequency = 260 x 60 = 15600Hz

If you are designing for PAL, choose something like:
Number of horizontal lines = 320
Vertical scan frequency = 50Hz
Horizontal scan frequency = 320 x 50 = 16000Hz

TV Composite Signal
Here is a sample of where the video information sits on top of a horizontal line scan.

Sync Generator
At the heart of any video system is the Sync Generator circuit.

We will set the 555-timer circuit to generate a fixed 4μs low pulse at a frequency of about 15600Hz. A trim pot is used to adjust this Horizontal scan frequency. A 12-stage ripple counter is used to count 260 cycles. This number has been selected because it is a simple matter to detect when the 256 + 4 count occurs. Two bits from the 12-stage counter are ANDed and the output used to reset the counter. For setup, we monitor the vertical sync on an oscilloscope which has been set to trigger on AC line frequency. Then we adjust the 555-timer frequency until the vertical sync matches AC line frequency (60Hz for NTSC).

Sync Generator Circuit

Composite Output Circuit

The HSYNC and VSYNC digital signals are combined in an XOR gate and then fed to the base of NPN transistor Q1. This is a simple emitter follower circuit with a 50Ω load resistor.

The Video input signal which will be described next is also added to the base of Q1

Here is a photo of the monitor with what we have so far. The intensity has been adjusted high so that you can see the scan lines. When the intensity is reduced the background will be black.

Component List at this stage:

TLC555 - timer
CD4040 - 12-stage counter
CD4538 - Dual mono-stable multivibrator
74HC08 - Quad 2-input AND gate
74HC86 - Quad 2-input XOR gate
2N3904 - NPN transistor

The blue trimpot adjusts the horizontal scan frequency.
The large shiny pot adjusts the position of our experimental paddle or ball.

The two paddles (or bats) are identical. The paddle is dead simple and is described in the next blog to come.

The Ball
(to come in future blog)
Finally, we come to the tricky part, the ping-pong ball itself. In order to simulate the motion of the ball as it bounces about the screen we will make use of two triangular wave generators, one for the horizontal motion and the second for the vertical motion.
The horizontal rebound of the ball will be affected by the players' paddles as well as by the walls of the play area.
The vertical rebound of the ball is affected by the walls only. Hence this is the easier of the two. Let us tackle this one first.

Vertical Movement
(to come in future blog)

Horizontal Movement
(to come in future blog)

Embellishments
The only items left to complete the full TV Pong game is the score-board and the sound effects.
The sound effect is dead easy to implement. As for the score-board. Well, I think that's enough for one DIY project. Don't you think?

Edit: I failed to initially consider four additional embellishments:
1. How to apply "english"? That is how to make the ball rebound off the paddle at a different angle?
2. How to make the ball rebound at a different speed?
3. How to make the ball begin a new serve from the middle of the screen?
4. How to change the direction of the serve depending on who won the previous point?
Those are way too much for me at this point. Any takers out there in AAC Land?

Happy Hacking!

Project started 2017.01.13
Project completed 2017.01.23

DIY Pong - Part 2 of 4 - The Paddles
DIY Pong - Part 3 of 4 - The Ball
DIY Pong - Part 4 of 4 - The Play

Author
MrChips
Views
4,886