Introduction: Nexys3 LED Timer Game

This is a tutorial for how to make the timer game. The timer game is inspired by the arcade light game , the game where a light moves along a string of lights and you try to stop it on the red light to win a prize. This game is different in that when you press the button at the right time, your score goes up and the speed gets faster. This is a fun game because it is easy to play (simply press the button), it is entertaining with its increasing levels of difficulty, and it is competitive because of its high score system. Disclaimer : this game can be addictive to certain people.

Here is a cheesy video demo of the game.

https://www.youtube.com/watch?v=iSYPododrN0

Step 1: Required Materials

1) Nexys FPGA board. In our example we use the Nexys 3 Board. [You can do the same with the Nexys 2 board, with simple modifications to the VHDL.]

2) LEDs (9 red and 1 yellow). [** Different colors may be used. A different number of LEDs may be used, but the VHDL provided in this guide is for 10 LEDs.]

3) Jumper Wires (Male-Male). 22 required.

4) Breadboard(s). A breadboard with connections is ideal.

5) Computer and software (Xilinx software and adept ).

These are jumper wires and LEDs. Notice how one led is different from the rest.

Step 2: Picture of Nexys 3 Board

This is the Nexys 3 Board required

Step 3: Button Picture

Make sure these buttons exist on your board.

Step 4: Game Specifications

The game requires a certain functionality. Here are the basic requirements.

1) A light moves along a line of LEDs.

2) Pressing the primary button will stop the LED.

3) If it landed on the right one, you go to the next level. If it did not land on the right one, you lose.

4) The primary button acts as an "okay" button. It is the starts the game and starts each level.

5) The seven segment display can show score, light's speed, "lose", "play", or high score. More details in next section.

The next section covers how this written in VHDL.

Step 5: Finite State Machine Specifications

Here we have the basic outline for the finite state machine that runs the game.

VHD and UCF files are available on this step.

To play game as we wrote it, load TimerGameMain.BIT . For editable VHD, use TimerGameMain.VHD , TimerGameMain.UCF , LoseWordDec.VHD , PlayWordDec.VHD , and sseg_Dec.VHD .

Basic Description on next step. Credits on final page.


1) Game uses a finite state machine. Four states are required

a) Ready State : Score, LED speed, and other variables are given initial values.

i) Score and next_score are set to 0, LED_speed and next_LED_speed are set to the level one speed, and Light location is set to first LED.

ii) By default the word "PLAY" is displayed on the seven segment display. A secondary button allows you to display High Score on the seven segment display.

iii) When the primary button is pressed, the game transitions to Play State.

b) Play State : The light moves from LED to LED at a set speed.

i) Score is set to next_score. LED_speed is set to next_LED_speed

ii) The light moves at the level speed.

iii) The current score is displayed on the seven segment display. Pressing the secondary button allows you to display the Light's speed.

iv) When the primary button is pressed, the game transitions to Check State.

c) Check State : It is checked if the light is stopped at the correct LED.

i) The light stops moving. The game detects if the light is on the right LED.

ii) Next_score is increased. Next_LED_speed is increased.

iii) The current score is displayed on the seven segment display. Pressing the secondary button allows you to display the Light's speed.

iv) When the primary button is pressed, the state will change depending on the light location.

-If the light is on the right LED, the game transitions to Play State.

-If the light is on the wrong LED, the game transitions to Lose State.

d) Lose State : A lose screen is displayed and high score is managed.

i) Current Score and High Score are compared.

-if Current Score is higher, High score is set to current score.

-If not, nothing happens.

ii) By default, the word "LOSE" is displayed on the seven segment display. A secondary button allows you to display High Score on the seven segment display.

iii) When the primary button is pressed, the game transitions to Ready State.

2) This is just an outline. For more details on how the game functions, you may read the vhd provided. Comments are written to guide you through each step.

The next section covers the description of each file.

Step 6: VHD Description

This section describes what each of the files contains. Important if you want to add modifications to the game.

TimerGameMain.vhd contains the main program. It includes the functionality described in the previous step.

TimerGameMain.ucf contains the pin assignments for the main program. It assigns the input and output signals to their corresponding hardware components.

TimerGameMain.bit is the program file that gives the Nexys3 Board the required functionality.

sseg_dec.vhd is a decoder that receives an 8 bit binary number input and a clock signal and outputs anode and cathode values. These anode and cathode values are sent to the seven segment display, displaying the decimal number corresponding to the 8 bit binary number. There is also a clock divider program (clkdiv2) which takes in a clock signal and tick rate value and outputs a slower clock signal. This is what allows the game to speed up as levels progress. (sseg_dec.vhd written by Professor Bryan Mealy of Cal Poly San Luis Obispo. clkdiv2 subprogram written by students Eric Chen and Luke McBee of Cal Poly San Luis Obispo).

LoseWordDec.vhd is a pseudo decoder. It receives a clock signal and outputs anode and cathode values. These anode and cathode values are sent to the seven segment display, displaying the word "LOSE".

PlayWordDec.vhd is a pseudo decoder. It receives a clock signal and outputs anode and cathode values. These anode and cathode values are sent to the seven segment display, displaying the word "PLAY".

The next sections cover hardware wiring.

Step 7: Hardware Setup

Here we have how to set up the hardware for the game.

1) The output LED signals are assigned to the Nexys 3 Pmod connectors by using vhdl (ucf file included)(the black boxes with 2x6 female connectors).

2) Jumper Wires connect the Pmod outputs to the positive lead of the corresponding LEDs using a breadboard. (See diagram for clarification).

3) Jumper Wires connect the negative leads of the LEDs to a common node. A jumper wire connects this node to a pmod ground port, effectively grounding all the negative leads of the LEDs. (See diagram for clarification).

4) The primary button ( button1) input signal is assigned to button C4 on the Nexys 3 board (this the left button, the 9 o' clock button, the board has labeling as well). The secondary button ( button2) input signal is assigned to button D9 (this is the right button, the 3 o'clock button). (See diagram for clarification).

5) TIP : Use colored jumper wires for visual appeal and making hardware troubleshooting easier. It is much easier to see where each wire goes by using the color pattern. (See diagram for clarification).

This is a circuit diagram of all the connections required. For clarification on the correct Pmod Bank sockets, see "Pmod Bank Diagram".

Step 8: BreadBoard Picture

This is the breadboard with Wires and LEDs properly connected. The Pattern helps with seeing where each wire goes. See previous picture for clarification on connections.

Step 9: Nexys to Pmod

Here you can see the wires are being connected to the Pmod Banks. For future reference, the Pmod banks from top to bottom are A, B, C, D.

Step 10: Pmod Bank Picture

To connect the wires, simply push the male lead into the female connector.

Step 11: Pmod Diagram Picture

Here is the diagram to clarify Pmod connections. Any ground may be used, but we chose to use the one in Pmod Bank A. Note : G = Ground. Note : Pmod bank D is off to the left of the picture, but is not being used.

Step 12: Button Picture

The button circled in RED (on the left) is button 1, or button C4; this button is the primary game button that causes state transitions. The button circled in BLUE is button2, or button D9; this button is the secondary game button that displays high score in lose and ready.

Step 13: Have Fun!

Now, upload the bit file to the board, and play the game!

Step 14: Credits

Instructable written by Cal Poly San Luis Obispo students Eric Chen and Luke McBee, made for CPE 133 Final Project at Cal Poly San Luis Obispo.

sseg_dec.vhd written by Professor Bryan Mealy of Cal Poly San Luis Obispo. (slight modifications by Eric Chen and Luke McBee).

TimerGameMain.vhd , LoseWordDec.vhd, PlayWordDec.vhd written by Eric Chen and Luke McBee.

Game Inspiration is Moving Light Arcade Game.