VHDL Game: LED - Button Push Game Instructable

by yellowspear in Circuits > Linux

8668 Views, 6 Favorites, 0 Comments

VHDL Game: LED - Button Push Game Instructable

pic.jpg

Welcome! This is an instructable to create a simple VHDL game using LEDs and buttons that we called PushPace. Before we continue, here is the background and inspiration behind the game.

Background If you grew up in the 90’s, we’re pretty sure you played with the classic Simon Electronic Game. In the 90’s there weren’t any PlayStation 4s or X-Box 1s around at the time, so we had to find other ways to pass the time when we were bored. Originally invented by Ralph Baer in 1978, the Simon Electronic Game is considered the first video game system.

The Simon game is a game of memory, to put it short. The game has four different color buttons; these buttons are red, blue, yellow and green. When the game begins, these buttons will light up in a random pattern. Your job is to recreate that pattern in the same order by pressing the buttons corresponding to the lights that were lit up. The game gets more challenging as time goes on as the pattern gets longer and your time to react gets shorter. If at any point you press the wrong button, the game is over.

Please note, due to time constraints, our group was only able to recreate the Simon game up to a certain point. More specifically, our project lacks the full sequence characteristic of the original Simon game. Where as the original Simon game will display lights in an increasing sequence each turn, our game only displays a single LED per turn. The user must still press the button corresponding to the LED that was lit up, but the following turn will once again only display one light and instead of two lights. As a result, the game in this instructable is most similar to the “Whac-a-mole” created by Kazuo Yamada in 1975. However, the spirit for most of the building portion of this game was to recreate Simon. In addition, isn’t Whac-a-Mole basically a Simon game with only one button at a time? The classic game Whac a mole is a real test of hand-eye coordination and swiftness.

As students at Cal Poly, San Luis Obispo, one of our courses required that we make an electronic game for a final project. In the end, our game most represents Whac-a-Mole created in 1975. If you are a digital design enthusiast and a fan of video games, we recommend that you yourself build the Simon game as it is a very fun and learning experience. On top of that, you’re paying honor to a historical device that holds historical impact on the future of the video game industry. This instructable shares the experiences we had recreating this game, as well as helps you recreate it on your own so that you can also benefit from this experience.

Below we’ve listed step by step instructions of how to create PushPace (our version of the Whac-a-Mole) on a Nexys 2 board; we hope your find our instructions helpful and that you enjoy recreating this game.

Materials

IMG_2271.jpg

For this project, you will need

4 small LED's

1 Digilent Spartan 3E Nexys 2 Board

and download ISE Design Suite 14.5 from Xilinx

Breadboard (Highly Optional) (( for style))

These materials are all you need to recreate our game PushPace.

Overview and Breakdown of VHDL Modules

The VHDL behind this game can be split into two different states: display state and wait state. The idea behind the display state is to take a signal and output one hot LED for a certain amount of time. Easy enough right? For this procedure we are going to need a LFSR, counter, and multiplexer (MUX). At the bottom of this page is an explanation of each component and attached is the vhd file for each.

In addition, the wait state is even simpler! The wait state must be able to take a value from the LFSR and compare it to the button that is pushed by the user. Thus, the wait state is a decoder that will send signal when the appropriate button is pushed to the respective LED.

Below is a list of the components and their function for the game.

LFSR ( Linear Feedback Shift Register) - A block which will "randomly" generate a number every clock cycle. Instead of having a predefined set of moves, the LFSR is an excellent way to keep the pattern psuedo-random. The number that the LFSR outputs corresponds to the LED lit up.

Counter - The counter's purpose is to count for a certain amount of time and relay a signal when done. Although it sounds simple, this is the brain of the whole game. The counter controls how long the LED is lit up and how long the player has to push the corresponding button. The counter is extremely important because it is connected to the display and wait state.

Multiplexer (for the display state) - This module in the display state must be able save the given number from the LFSR and display that number on the LEDs as long as the counter is going. When the counter is done, the mux will not display anything on the LEDs.

Decoder ( for the wait state) - This module is the simplest out of them all! The decoder's function is to receive a number from the LFSR and check if the correct button is pushed by the user. If the button and number match, then a redo signal is outputted. This enables the game to cycle again and show a new LED.

Create the Display State

InstructablesPic2.png

The display state functions to take a number from the LSFR and light a corresponding LED for a certain amount of time. This is done using a LSFR, counter, and mux. Above, is the block diagram for the display state. In addition, the vhd files corresponding to the LSFR, counter, and mux are attached to this page. Below is a brief summary on how the display state works.

Before we continue to how the display state functions, it is important to note who created and owns the code. Our Professor Andrew Danowitz created the LSFR and counter modules. Ownership is completely his and needs his permission to be copied or reproduced. As students, we created the mux module, named "lights" in the vhd files.

When enable is high, the counter is ready to begin and the flip flops are ready to hold a number from the LSFR. (Remember, the LSFR is constantly changing its number at the clock frequency.) Then, when enable goes low, the counter begins and the flip flops hold the number for as long as the counter continues to count up. In addition, the held number is passed to a mux which then displays it over the LEDs. Meanwhile, the counter is counting up to a number ( specified to be .5 seconds in the module). When the counter has finished counting, the mux gives the LED all low inputs. The output of the counter is a signal which is the enable for the wait state.

The display state works to display an LED for a given amount of time. For a challenge, you can try to incorporate the Nexys 2 board speakers and have it play a respective tone for a unique LED.

Creating the Wait State

InstructablesPic3.png

The wait state's function is to receive the number from the flips flops and check if the corresponding button is pushed by the player. Above is the block diagram of this state and attached are the vhd files. This is a one module state created by us.

Furthermore, in the wait state, if the number and button match, a redo signal is sent back up to the display state to begin the playing cycle over again. The wait state is enabled as long as the counter is high ("counting"). The player loses when the counter is low and the player has not pushed the correct button.

Connecting the Modules ( Display and Wait From Previous 2 Slides)

You are almost done! All you need to do now is connect the two modules are you game will be complete. After looking at both block diagrams, it should be easy to determine which signals match up and we have clarified below.

Output of D FF's => Number into Check Module

Output of Counter => Enable into Check Module

Output of Check Module => get's OR'd with the Enable from input. Then feeds into the inputs of the counter and D FF's.

Ports and Connecting LEDs

ProjectPicture.jpg

As part of a requirement for our project (maybe you can find a different way), it was expected of us to use off-board devices on our Nexys2 board. For this task, we decided to use four separate LEDs to match the lights on the original Simon Electronic game; we used a red, green, blue, and yellow LED. If you decide to do it this way as well, it is not complicated. Basically, the Nexys2 provides you with four Pmod connecters that function like typical bread board.

The four LEDs correspond to the four outputs from the ‘Display’ module mentioned earlier. For this part, we connected up the positive lead of the LED to JA1 of Pmod JA, remembering that one lead of the LED goes to the Pmod connector (JA1) while the other lead must go to the ground connection on the Pmod. The other LED's are connected in the same fashion using the other 3 corresponding Pmods.

You can use a breadboard here if desired to make it cleaner and pretty.

Complete!

As a review of our whole project, let's explain the game we've just created. Toggling the ENABLE switch to on, then back to off starts the whole game. Upon toggling the ENABLE switch as such, we have turned on a single LED light for the player and it is now up to that person to press the corresponding button of the light that turned on. If the correct button is pressed within the allotted time frame, then a new "random" light is lit up and again the player must press the correct corresponding button within the time frame. If the player does not press the correct button within the allotted time frame, then the game is over and the ENABLE switch must be toggled again to play once again. Keep in mind though, that the original goal was to make the full version of the Simon Electronic game. However, as mentioned earlier, due to the allotted time frame we had to complete this project, we weren't able to insert the whole increasing sequence aspect of the Simon game. As a result, our version of the Simon game ended up being more like a 'Whack-a-Mole' game. It'll be up to you to finish the increasing sequence aspect if you recreate the Simon game (hint: try a FIFO).

You are now done and created a game using VHDL! We hope you enjoyed making this game and that our instructions were helpful to you. As a reminder, making this game was a big accomplishment considering that the Simon game was basically the first video game system. A lot of us, including myself, go into digital design in the hopes of one day working on interesting projects in the future (i.e. designing video games, working for Apple etc.). By recreating this game, you're following in the steps of history of how all of this revolutionary technology came about.