By: Jonathan Flores and Colton Petiprin
This project is a simple and easy to make game that is programmed using a Baysis 3 Artix-7 FPGA Board. The game play of this game has a single LED on that moves back and forth on a line of 5. The objective is to press a button at exactly the moment the middle LED turns on to increment your score. We used a different color LED to make this objective clear. Pressing the button too early or too late triggers a loss and your score will reset to zero. To recreate this project yourself, some previous experience with digital design and VHDL coding would be highly recommended.
All of the files we used are attached and can be downloaded for your own use. This tutorial is structured in reference to these files and modules.
Step 1: Layout
Our top level layout and design of this project consisted of 5 modules and written using VHDL structural modeling. Two of these modules our our original design. Our top level inputs are two std_logic ports: one for the baysis boards clock, and one for the button input. Out outputs are a 5 bit std_logic_vector corresponding to the LED's, an 8 bit std_logic_vector for the boards seven segment cathodes, and finally a 4 bit std_logic_vector for the boards seven segment anodes. These ports are set in our constraints file and is available for reference.
Step 2: Position State Machine Module
In this module, we coded a state machine that’s main goal was to signal what LED’s to turn on based off what state it was in and would output a signal when the middle led was turned on. The state machine was composed of 8 states. Starting from state one at the left-most LED to state 5 at the right-most LED and then going back the other direction until state 8 at the second from the left LED When the LED was on at the middle state (State 3 or state 7) it would output a ‘1’ to a different module that would take that information to determine whether or not you scored a point. (If button pressed while the output is ‘1’ meaning middle state; then you got a point)
Step 3: Game Logic Module
This module was basically the intermediate stage between the position state machine and the seven seg decoder. It would take the output from the position state machine as input (boardSIn = ‘1’ whenever the middle LED was lit up and ‘0’ otherwise) and then, based on button press, decide whether to increase score or reset score to zero. If boardSIn (board state in) was ‘1’ and the button was pressed, the score was increased, if button pressed at any time when boardSin = ‘0’ then it would reset score to zero. When we made this code, VHDL automatically created a score registery so that the score would be kept (remembered) and then changed accordingly.
Step 4: Other Modules
The next three components are not our design and all credit goes to the original authors. We made minor modifications mostly to adjust timing.
The SSEG_DEC module was provided by our professor. This module takes in an 8 bit vector as a number and decodes it to display on the FPGA boards seven segment display. In addition due to the design of the FGPA board, any time a digit is displayed, it displays on all enabled segments. This is a problem when you want to display multi digit numbers. This modules gets around this by cycling through different digits in different locations faster than a human can perceive. This fixes the problem mentioned.
The clock divider module is a simple one that takes in a clock signal and slows down the frequency as its output allowing for a clock cycle slower than the boards default. This is required so that the LED blinks at a reasonable speed.
The final module handles a problem called button bouncing. This occurs when a button is pressed as there is a slight high and low dip before the signal stabilizes, in addition the button when pressed for however many milliseconds, is read as a continuous stream of high. These problems are necessary to solve for this project to work as timing is crucial and with ought fixing them, the score would not increment correctly.
The debounce module handles this by holding the buttons signal for a few microseconds and checking if the signal changes during that time. The module will only output a single instance of high instead of a continuous signal which solves our problems almost entirely. All credit for this module goes to the author of this article: https://www.nandland.com/goboard/debounce-switch-p...
For further explanation we recommend checking out the article.
Step 5: Files
Step 6: Working Project
Hopefully by now your game is up and running. Thanks for checking out our project!