Introduction: Pong Game

Picture of Pong Game


Basys3 FPGA Board

VGA cable


The purpose of this instructable is to develop a Pong game that will be displayed on a monitor. The project will use VHDL to program and uses a Basys3 FPGA to carry out the code and transfers the image using a VGA interface. This tutorial is intended for people who have a bit of prior knowledge of VHDL. The tutorial will be divided into 6 different sections: Overview, Process, Score Handler, Image Generation, Pong Game, and VGA.

Step 1: Overview

Picture of Overview

The Image above is the overall schematic design of the project.

Objective of Game:

The game consists of a display with a sliding paddle that can be controlled by the user, and a fixed wall that acts as the upper bound. When the user presses the start button, which is the up button, the ball will begin bounce up, and will bounce off the wall and attempt to hit the paddle. If the ball hits the paddle, it bounces up again and continues to bounce until it misses the paddle. The game is over when the ball fails to hit the paddle. The user will be able to use the left and right pushbuttons to determine the movement of the paddle. In order to reset the game, the user must push the center button. The time of the run will be recorded on a 7 segment display. There are five levels, and every ten seconds the level increases, until you hit level 5 where it stays till the user loses. The levels are determined by the speed of the ball; this means that every ten seconds, the speed of the ball increases, thus increasing the difficulty of the game.

System Architecture:

The diagram below is the basic overall top-level block diagram for the system. The system has four inputs: Button R, Button L, Start, and Reset, and a Clock. It has a horizontal and vertical sync outputs, RBG(which refers to the color of the pixel at a certain location), and Score(which acts as a bus to the 7-Segment display).The up button will be used as the start button, and the left and right pushbuttons will be used to move the paddle in their respective directions. The 7-Segment Display will be used to record the score, which is the number of seconds that the user has been playing without losing the game. The number will be displayed as a decimal number.

Circuit Architecture: We will build our gizmo using one FSM that contains a smaller FSM, the sub-FSM will control the difficulty of the game whereas the main FSM will control the overall flow of the game. Our gizmo will also use at least three clock dividers, one for the score (time), one for the refresh rate of the of the display and one that is hooked up to the output of a DeMux so that we can control how fast the game will proceed with increasing amounts of difficulty. The game will move much faster the longer you play. We will have the control input of the DeMux be present state of the sub-FSM so that we can control how fast the game will go by how long that you play it. We will be using a few counters, one to refresh the display and one to count up the score as you continue to play. This project has two main modules and an array of submodules that will manipulate the input data. The two main submodules are the VGA Driver, as well as the button logic module. The VGA Driver will consist of programmable memory, a clock divider, and the logic that will manipulate the output for color. The button logic module will also consist of a clock divider, and a programmable memory, as well as a binary to decimal converter for the 7-Segment Display with its respective clock divider.

Step 2: Image Process

For the Image Process section of the project, we will be determining the movement of the ball and the paddle. The program has ports that include the left, right, top and center pushbuttons, the present state, a clock, the X and Y positions of the ball, the left and right edge of the paddle and a fail. The present state is used to determine the enable signal. The code goes over the multiple cases that the ball can move, and has set conditions to determine the path of the ball. The next process block determines the direction that the paddle move based on which button is pressed by the user. The code for this part of the project is attached with detailed comments describing what each section does.

Step 3: Score Handler

Picture of Score Handler

This section consists of files that relate to displaying the score in seconds on the 7 Segment Display on the Basys3 Board. It includes a clock divider that is used to count the seconds, a score counter counts the seconds that the user is playing, the segment driver take the score and converts it to anodes and cathodes to be displayed on the screen and also determines the position that the number will be displayed and lastly, the segment handler converts the binary digits to decimal digits to be displayed on the screen. The score handler puts together all the pieces and maps the signals. The code for all five files is attached below.

Clock Divider:

The clock divider has inputs Clk(clock), CEN(enable in), and Div(divider) and output Clk_out. If the enable signal is on, then the clock will count on the rising edge.

Score Counter

Thescore counter has inputs Clk(Clock) and RST(Reset) and outputs Clk_Out and Q which essentially acts as the score output.

Segment Driver

The segment driver has inputs D1, D10, D100, D1000, and Clock. The numbers after "D" refer to the decimal place on the 7 segment display. The outputs are the anodes and the digit. The clock counts and assigns the numbers and it's position. For example, a "9" will be displayed in the ones place with "0"s in the thousands, hundreds and tens place. When it switches to "10", the number will now have a "1" in the tens place and "0"s in the thousands, hundreds and ones place.

Segment Handler

The segment handler has digit as its input and cathodes as its output. It essentially the binary numbers to the cathode display to output decimal numbers on the screen.

Score Handler

The Score Handler consists of the previous four entities and puts it's all together and maps the signals. It also enables and disables the counter based on the present state.

Step 4: Image Generation

The image generation consists of four components: Animation, Fail Counter, Refresh Image and Start Counter. These files refer how to generate the images on the display monitor.


The Animation file has inputs Clk(Clock Signal), CEN(count enable), RST(Reset Signal), B_X(X position of the ball), B_Y(Y position of the Ball), P_L(left paddle position),and P_R(right paddle position). The outputs are WA(the address we are writing the color to), and WD(the color being written at the determined address). The file has Play_Counter that is a counter which will be used as a control input for the MUX, an encoder that can output the correct colors at the right places, and lastly a multiplexer that displays the correct color based on the position of the paddle and ball.

Refresh Image

The Refresh Image file is used to refresh the image as the position of the ball and paddle change. The file includes the components from the Animation, Start Counter and Fail Counter files. It maps the signals from each component and uses state logic to determine the signals and output addresses.

Start Counter

The Start Counter uses inputs Clk, RS, and CEN and outputs WA and WD. It uses a counter and conversion to determine the control input for the MUX. The Multiplexer then uses the input to determine correct color addresses and sends this data to the VGA driver. This is used to display "Pong" when the user starts the game.

Fail Counter

The fail counter is used to display "Game Over" when the user loses the game. It has a Clk, RST, and CEN signal. It uses a counter and a conversion formula to determine the control input for the MUX. The Multiplexer then uses the input to determine correct color addresses and sends this data to the VGA driver.

Step 5: Pong Game

Picture of Pong Game

This section of the project includes the Pong Master, Finite State Machine(FSM), Timer, and Start Debounce files.


The timer has inputs Clk(Clock) and PS(Present State) and Timer and Clk_out as outputs. The timer is used to change the speed of the game about every five seconds.

Flow FSM

The Flow FSM has inputs Clk, Fail, Timer, Bttn_S(Start Button) and Buttn_RST(Reset Button) and output Pres_S(Present State Output). The FSM uses the timer to update the Present State to the Next State and keeps updating the Next State until the game reaches level 5 where it stays until the game is over.

Start Debounce

The Start Debounce is the starting bounce of the ball. It has inputs S_in and Clk, and output S_out.

Pong Master
This file uses all the previous components and makes it so that all the components are instantaneous. It is the master file that puts together all the previous components that we have built together.

Step 6: VGA Driver

The VGA(Visual Graphics Array) Driver is a piece of software used to accept commands or data that is sent to the display screen. The driver was given to us by our professor. Use the driver and a VGA cord to connect the Basys3 board to the monitor.

You should now be ready to make your own Pong Game using VHDL!


DIY Hacks and How Tos (author)2017-12-03

Fun project. Great Basys tutorial.

About This Instructable




More by ShivaniG16:Pong Game
Add instructable to: