Introduction: FPGA Memory Game on Basys 3 Board

This is a bare-bones, simple instructable on how to create a memory game inspired by Simon on an FPGA, specifically the Basys 3 using Vivado.

How the game works: The game starts with a single LED being shown for about a second. The user has to press the corresponding button to proceed to the next level. As the game goes on, more buttons are needed to be pressed. If the user fails to press the corresponding button to the specific light pattern, it is game over.

Here is how we make it.

Supplies

  • Xilinx Vivado


  • Basys 3 Board


  • 4 LEDs (preferably different colors)


  • 1 Small Breadboard


  • 4 Resistors (Under 1k Ohms is OK)


  • Minimum 5 Connecting Wires

Step 1: Identifying Pieces of the Whole

We are going to need certain key components in our code in order to get this game running. These may include:

  • A counter (to time how long events in the program happen)
  • An LSFR (to pseudo-randomly generate patterns in the game)
  • A multiplexor (this allows for binary to be converted to LED display)
  • A decoder (This takes the pseudo-randomly generated patterns and compares them to user inputs to match.)
  • FSM
  • Wait
  • Display
  • Player Input
  • Game over

Step 2: FSM

There will be 4 states

WAIT - The initial state of the FSM, the system waits until enable is activated. Values are reset in this state and are ready for the next display state

DISPLAY - Displays random combinations based on the LSFR. Each pattern display increments the variable "count" so that the right amount of patterns are displayed.

PLAYER_INPUT - Input to take player inputs after the last display. This is stored as variable "player_led". If this matches the pattern given during the DISPLAY state, the 'count' is incremented again, and the machine enters DISPLAY again. If "player_led" is different than the pattern given during the DISPLAY state, case GAME_OVER is started

GAME_OVER - When the combination is wrong all 4 LEDs will flash twice before beginning a new game. The variables are all reset to zero again and the machine enters case WAIT. To anticipate starting of a new game.

Step 3: Map Buttons to Inputs and LEDs to Outputs

For each button, it needs to be mapped to the board. I used BTNL, BTNR, BTNU, and BTND to give my input. These buttons use W19, T17, T18, and U17 respectively to call these inputs in the constraint file.

Each LED output is assigned to a PMOD port. These ports give 3.3V signals when called to during DISPLAY state and GAME_OVER state. I will show how to connect these PMOD outputs to LEDs and a breadboard in the next step.

Step 4: Wiring/breadboarding

I have included this visual diagram of how the LEDs should be wired. It is a basic way to do so. Each color wire on the left represents a different output of the Basys 3 board. Using the Basys 3 board, I personally used the PMOD output ports to give signals of 3.3V to each of the LEDs. Whichever way you give the output signals, you need to plug each of these colored wires into what port you assigned the outputs. Make sure that your ground wire is connected. There is a GND port near the PMOD ports.

Step 5: Video Demonstration Link

https://youtube.com/shorts/9fYIGJEH9xM?feature=share

or

https://www.youtube.com/shorts/9fYIGJEH9xM

This video shows how the game functions, and what the state looks like at the end. The button sounds that you hear are the player inputs given by me to match the light display. At the end, I input the wrong combination so that the Game Over state is triggered.


Thank you for looking at my Instructable on how to create a memory game like Simon on FPGA!






HDL for this project: https://drive.google.com/drive/folders/1fFZ0TTUuXvqM7yBJTzR_16F9JK2CUHAz?usp=drive_link