Skip to content
Stephen Julian edited this page Feb 2, 2022 · 43 revisions

Verilog FPGA Pingpong Game Wiki

Introduction

The objective of this project was to design and implement an electronic pingpong game using Verilog and the Basys3 Field Programmable Gate Array (FPGA) kit.

Motivation

According to the project requirements document provided... "this assignment is to enable the student to extend electrical and electronic knowledge for specialist applications in embedded systems."

Verilog FPGA Pingpong Game is published under the MIT License.

Digilent Basys 3 FPGA Board

Requirements

The following specification was provided in the project requirements document:

"It is a game of two players; each player has a push button. Either player can start the game by pressing his/her push button. Eight LEDs represent the position of the ball. The ball movement is indicated by the illumination of the LEDs and the opponent player should press his/her push button only, when the ball is at his end. The ball is considered struck if the player presses the push button while the ball is resident on the last LED at the players end. The ball should be flying until any player violates the rule. Once violation happens, then a player gets the point. Scores of the players should be displayed on seven segments LED. The speed of the ball’s movement should increase as the game progresses."

Methodology

State Machine Diagram

The requirements specification was transcribed into an overall State Machine Diagram as a method for gaining understanding of what work needed to be done.

Pingpong State Machine Diagram

Game Rules

Starting the Game:

  1. Any player can start a game round by pressing his or her button at which point the “ball” is shown as an illuminated LED heading toward the other player's side of the board.
  2. When Player 1 starts the game round by pressing their button the “ball” will first appear as the LED LD04 (W18) illuminated and heading toward Player 2's side of the board.
  3. When Player 2 starts the game round by pressing their button the “ball” will first appear as the LED LD03 (V19) illuminated and heading toward Player 1's side of the board.

Player One's Turn

Supposing Player 2 has started the game round by pressing their button:

  1. The “ball” is revealed starting with LED LD03 (V19) illuminated.
  2. Next the ball moves to the left toward Player 1 meaning LD03 (V19) is dimmed and LED LD04 (W18) is illuminated.
  3. The ball moves to the left again and so LD04 (W18) is dimmed and LED LD05 (U15) is illuminated.
  4. The ball again moves to the left. LD05 (U15) is dimmed and LED LD06 (U14) is illuminated.
  5. The ball moves to the left once more. LD06 (U14) is dimmed and LED LD07 (V14) is illuminated.
  6. At this point Player 1 must quickly press their button before a timer expires. If the button is not pressed within this time frame then Player 2 wins the round and a point is added to their score.
  7. After a round has been won by a player the next round can be started by either player by pressing their button.

Player Two's Turn

If Player 1 presses their button when the “ball” was on the left-most LED:

  1. The ball moves to the right toward Player 2 meaning LD07 (V14) is dimmed and LED LD06 (U14) is illuminated.
  2. Next the ball moves to the right again and so LD06 (U14) is dimmed and LED LD05 (U15) is illuminated.
  3. The ball again moves to the right. LD05 (U15) is dimmed and LED LD04 (W18) is illuminated.
  4. The ball moves to the right again. LD04 (W18) is dimmed and LED LD03 (V19) is illuminated.
  5. The ball moves to the right again. LD03 (V19) is dimmed and LED LD02 (U19) is illuminated.
  6. The ball moves to the right again. LD02 (U19) is dimmed and LED LD01 (E19) is illuminated.
  7. The ball moves to the right once more. LD01 (E19) is dimmed and LED LD00 (U16) is illuminated.
  8. At this point Player 2 must quickly press their button before a timer expires. If the button is not pressed within this time frame then they lose the round and Player 1 scores a point.

Buttons Either player can start the game by pressing his or her button. The game is considered over once a player has won 10 rounds - making them the overall winner of the game. At this point the player score counters both revert back to zero and the next time a player presses their button the first round of an entirely new game will commence.

Game Speed In regards to the requirements specifying that the game speeds up, this has been interpreted as meaning that the game speed increases at the beginning of each new round. This is as opposed to increasing the game speed throughout the duration of each round in the game.

Button Player 1 (Momentary push button) Player 1 is only permitted to press the player one button while LED LD15 is illuminated. Pressing the button at any other time will immediately result in Player 2 winning the round of the game.

Button Player 2 (Momentary push button) Player 2 is only permitted to press the player one button while LED LD0 is illuminated. Pressing the button at any other time will immediately result in Player 1 winning the round of the game.

Wish List

The attachment of a piezoelectric buzzer or speaker to an output interface of the Basys 3 could be valuable both to testing and to improving the game play experience via audio notifications of game events such as ball hitting and game round points awarding.

Shopping List

Starting List

Before starting, read the original Project Report to access more complete documentation than this Wiki otherwise provides.

Testing List

Initial testing was found to have somewhat unpredictable results. The one change that appeared to remedy this was writing the decimal places on the 7-segment display. Previously the decimal place was ignored however it was found that writing a blank output had the result of the FPGA circuit behaving as described by the State Machine diagram.

A system crash in combination with a development process failure appeared to have been the cause of some data loss which delayed the demonstration of the finished project. Changes to the development process were implemented to prevent this from recurring and the project was successfully completed.

Conclusion

This project proved to be a useful exercise for learning how to design, implement and test an FPGA circuit working with an FPGA development board. The project was completed and functioned correctly as per the provided requirement specifications.

Resources

Additional resources about FPGA for further study:

Programming FPGA with ISE - https://www.youtube.com/watch?v=eLOLBYxLXcE

BASYS2 using ISE explanation of the board - https://www.youtube.com/watch?v=6_GxkslqbcU

Fabrication of IC Circuits - How an IC is made - https://www.youtube.com/watch?v=35jWSQXku74

Figures

All photographs, diagrams and screenshots are by the author unless otherwise indicated.

References

This project was originally completed by Stephen Julian in June 2019 as an Assignment for his Embedded Systems paper during study for a Bachelor of Engineering Technology (Electrical) degree.

This GitHub repository delivers on the intention to publish the project work under the MIT Licence.

While this wiki provides a project summary, the complete original documentation is available in Adobe PDF format below:

Julian, Stephen (4/06/2019). Verilog FPGA Pingpong Game - MG7013 Embedded Systems (~3.6 MB PDF, 31 pages)

Appendices

Appendix A: Verilog Files