Pong Game on an FPGA with VGA Video and a Custom Board
A complete Pong game that runs without a processor on a Spartan-6: VHDL code, 640×480 VGA video and a board I designed in Altium.
Overview
This project is a Pong game I built on an FPGA in 2016. There is no processor or software: the whole game, from VGA video generation to the movement of the ball, runs as digital hardware described in VHDL on a Spartan-6. I also designed the FPGA board in Altium Designer, and the picture appears on an LCD display. The game screen shows the name and address of this website.
How the game works
The game has three screens, and a state machine moves between them:
Start screen: waits for the Start button, with a flashing message.
Play screen: a green ball moves around the screen and bounces off the top wall and the side walls. The player moves a red paddle at the bottom with the left and right buttons to send the ball back.
Game-over screen: if the ball gets past the paddle the game ends, and the Start button begins it again.
The Reset button returns the game to the start screen at any time. The diagram below shows the parts inside the FPGA and the signal path.
VGA video generation
The picture is generated at 640×480 and 60 Hz. The 50 MHz board clock is divided to 25 MHz to make the pixel clock, and two counters, one for pixels and one for lines, produce the sync signals (H-Sync and V-Sync) and give every game part the coordinates of the current pixel. Each part compares those coordinates with its own shape and decides what color the pixel should be, so no frame memory is needed and everything is drawn on the fly. A 3-bit RGB output and the two sync signals go to the display.
Ball and paddle movement
The game updates once per frame, about every 16 ms. The paddle moves 6 pixels per frame and the ball 3 pixels in each direction. When the ball hits the top wall or the side walls, or the paddle, its direction reverses. If the ball falls below the paddle's height, the game goes to the game-over state.
Specifications
FPGA: Xilinx Spartan-6, model XC6SLX9
Code: VHDL, with the Xilinx ISE tools
VGA output at 640×480 and 60 Hz, 3-bit color
Inputs: four buttons (left, right, Start, Reset)
Three screens: start, play, game over
Main clock: 50 MHz
Powered over USB
Hardware design
I designed the board under the FPGA myself. It has these parts:
The XC6SLX9 FPGA in a TQG144 package and a 50 MHz oscillator
An SPI flash memory that holds the configuration, so the FPGA starts by itself after every power-up
An FT2232HL chip for the USB connection: FPGA programming over JTAG and a parallel data channel
Two AMS1117 regulators, one for 3.3 V and one for 1.2 V, powered from the 5 V of USB
Five switches: Reset, left, right, Start and a configuration switch
LEDs for power and for the end of FPGA configuration
An output header for VGA and a power terminal
The pictures below show the game running, the 3D view and the PCB layout, and the schematic.
Result
A complete game with live video that runs as digital hardware without any processor, together with the board that was designed and built for it.
Gallery
BLOG
Related posts
Questions about this project?
If you have questions about this project, or a similar one in mind, I would be glad to hear from you.