FPGA Pong Game
PROBLEM ANAYLSIS:
​
In this lab, we will be learning how to draw various color patterns on a computer monitor by asserting red/green/blue signals through the VGA port on the FPGA. With these techniques we will then have to create a VHDL code that will implement a virtual version of ping pong. This includes designing the color and lengths of the borders, paddles, and game ball. The most challenging obstacle that we will encounter on this project will be getting the ball to constantly move diagonally in different directions and bounce off the walls and paddles.
VHDL MODELING:
​
In order to create the Pong game we need to create the ball, paddles, borders, and logic to describe how to game works. In order to accomplish these tasks we created two processes, one for drawing the game and the other one for game mechanics. In order to make the coding easier, we chose values for our borders to exploit vertical and horizontal symmetry. We created constants to help us define paddles, borders, and ball dimensions. Finally we created shared temporary variables that will allow us to move the ball and paddles.
​
The first process defines how we created the game board. We used an if else-if statement to draw the borders. Next we had to draw the paddles where we used a nested if statement to draw the paddle. We used a temporary variable when drawing the vertical dimensions in order to be able to move the paddles up and down. We used a nested if statement to draw the ball with two temporary variables that will allow us to move the ball any direction we need.
​
The second process defines the mechanics of the game. It has a sensitivity list of Key buttons, the slow clock and switch 0 The Key buttons will move the paddles, the slow clock helps move the ball and paddles and switch 0 resets the game. We have a nested if structure. We have a if statement that checks if switch 0 is on and if it is then reset the games. If the switch is off then proceed with the game mechanics. We made code to move the paddles up and down based on which key is pressed. Next we created 3 case statements. Two of the case statements is used to keep track of the players score and send the score to the seven segment display. The third case statement is the finite statement machine of the game. We used five states, the first four deals with what direction the ball is moving and the fifth stops the game once a player wins. Inside each state we used a if else-if statement to detect if the ball hit a border, paddle or nothing and then go to the appropriate next state.
VERIFICATION AND RESULTS:
​
After many hours of thinking of possible ways to design our layout and how we wanted our game to operate, our results came to a nice finish and it can be seen below in Figure 1. We wanted to give it a beach theme which explains why we chose the shown colors. From the starting position, it looks like everything is on point, but we now had to verify that our game operates how we want it. After playing a few rounds we concluded that everything was indeed perfect. The ball bounced in different directions when hitting the paddle or vertical borders, it stayed within the appropriate bounds, and restarted in the original position once it went into either player’s goal. The paddles moved in both vertical directions and also stayed within their limits (Figure 2).
Figure 1: Final layout of pong game on FPGA.
Figure 2: Playing a round of the pong game.
CONCLUSION AND DISCUSSION:
​
In this lab, we learned how to draw color patterns on a monitor with a pixel resolution of 1280x1024 and a 60 Hz frame refresh rate. We then used those skills to create a two player game of pong. The game consists of player one controlling the left paddle and player two controlling the right paddle with the intention of trying to get the ball to enter the side border of the opponent in order to receive a game point. Creating the color and layout of the game was pretty straight forward but getting the ball to bounce around was the most difficult challenge we faced. This was because we needed the ball to also to take the top borders and the moving paddles into consideration rather than just moving at a constant diagonal direction. But after a lot of testing and thought, we were able to finally implement a perfect game of pong. This project required us to use all the concepts that we learned throughout the semester. Overall, this was an exciting project and we were able to learn how all these skills come together.