Introduction: Decimal to Binary Conversion Game

“There are only 10 types of people in the world: Those who understand binary and those who don’t.”

This fun and educational game tests your ability to convert decimal numbers to binary numbers. It is also a great way to challenge your friends in a friendly competition.

The game begins with a random decimal number displayed on a seven-segment display. The player then uses eight switches to input their answer to the conversion in binary. As the player changes the switches, the external 8x8 LED Matrix will shine red LED’s meaning that their answer is currently incorrect. Once the player’s answer is correct, only the green LEDs on the Nexys2 board will be on. To get a new random number, push the far left button on the Nexys2 board.

In this Instructable, we are going to make a decimal to binary conversion game using a Nexys2 FPGA board. This game was made by Mairead Blaes and Edwin Wong. We made it for our CPE 133 Final Project at Cal Poly, San Luis Obispo.

Step 1: Hardware

Hardware used for this project:

  • Nexys 2 FPGA Board
  • PMOD connectors
  • 8x8 LED Matrix
  • Resistors
  • Wires
  • Daisy Chain Wire
  • 2 breadboards

Note: There are variations in which you can implement the external game outcome display.

Step 2: Software

To download the free Xilinx ISE Webpack, go to www.xilinx.com and create a free user account. A quick and easy step-by-step process for downloading the Xilinx ISE Webpack can be access from the following link here.

To download the free Adept program, click on the following link here. The Adept software allows you to download your design or bit file onto your Nexys2 development board. For those of you who are running Windows, download the ‘System’ version. For those of you who are running Linux, download the suitable Runtime and Utilities downloads (32 or 64 bit) and make sure to download the SDK as well.

A very simple tutorial on how to use the Adept software can be found here.

Step 3: External Display: Understanding the LED Matrix

The LED matrix we used has both red and green LED's, but we just used the red LED's.The datasheet for the LED matrix can be found here. The datasheet did not include a schematic for which pin was a row or column. Use the images above to determine the rows from the columns.

Step 4: External Display: Pinning and Wiring the Breadboard

Now that you understand the LED matrix, put it on the breadboard. Use wires to pin every row and every red LED column. You will need a resistor for every column or LED in the matrix. From the LED matrix datasheet, we calculated that you would need 47 ohm resistors. Put these resistors on the breadboard and wire them to the columns of the LED matrix. Use the diagram above as a reference. The blue wires represent the rows and the red wires represent the columns. Once you are done with this step, you should have 16 wires each with its other end not connected to anything. These wires will connect to the Pmod connectors described in the next step.

Step 5: External Display: Pinning the Connectors

Next, we used daisy chain wire to connect the row and column wires on the breadboard to the connectors. The first image above shows where each wire should go on each connector. It also shows where the connectors attach to the Pmods on the Nexys2 board.

By this step, you should have your external display completed. Use the second image as a reference of what your external display should look like.

Step 6: Understanding the High Level Black Box Diagram

The diagram above is the high level black box diagram for the game. Here is a list of inputs and outputs with descriptions of what they are.

Inputs:

  • switches: Each of the eight switches are used by the player to input their answer.
  • en: The en is a button and when pushed, it will give a new random number.
  • clk: The clock signal from the Nexys 2 board, which has a frequency of 50MHz.
  • reset_btn: When pressed in conjunction with the enable button, then random number value will reset.

Outputs:

  • anodes: These control how many 7 segment displays are in use.
  • segments: These display binary numbers in decimal form.
  • row: The row output represents the rows of the LED matrix.
  • column: The column output represents the columns of the LED matrix.
  • LEDs: These are the LED's on the Nexys 2 board.

Step 7: Understanding Game Block Diagram

The first diagram shows all the inputs and outputs in which the game is tied together in one module. The second diagram shows the modules within the Random_Num_Display.

Step 8: VHDL Modules Descriptions

Linear_FB_Register (Random Number Generator) Module

This module is what generates a random number. At the rising edge of clock, the output 8 bit number will be “00001111” or 15 in decimal if the reset is ‘1’. The rest of the time a random number will be generated continuously.


D_FF (D flip-flop) Module

This module is a D flip-flop. Its input gets the output of the random number generator. At the rising edge of clock, if the enable (button) is ‘1’ then the input is latched and therefore the output of the flip-flop.


sseg_dec (Seven-segment Display Decoder) Module

This module was written by Bryan Mealy of California Polytechnic State University on December 16, 2010. It is a four digit seven-segment display driver. It takes in the 8 bit number output from the D flip-flop and converts it to a decimal number. The decimal number is then displayed on the seven-segment display on the Nexys2 board.

clk_div1 (Clock Divider) Module

This module was written by Bryan Mealy of California Polytechnic State University on December 27, 2010. It takes in the clock frequency and divides it into a slower frequency. This slower frequency is used as the clock for the random number generator and the D flip-flop.


COMP_8bit (8 Bit Comparator) Module

This module compares the player binary number input to the random number that is displayed on the seven-segment display. If both numbers are the same then the output is that they are equal. If the numbers are not equal then the output is that they are either less than or greater than.

Game_State Module

This module is a finite state machine, see diagram above. Its two states are win and lose. If the output from the Comparator is equal and not less than and greater than, then the game is in state win. If the output is less than or greater than and not equal, then the game is in state lose.


LED_Matrix_Display (Game Outcome) Module

This module displays whether the player’s answer is correct or incorrect. If the game state is win then the player is correct and the 8 green LEDs on the Nexys2 board will be on. If the state is lose then the play is incorrect and the red LEDs of the external LED matrix will be on.

Step 9: Download the Zip File

Below is a zip file containing the VHDL files for all the modules. Download and unzip this file. Next, create a project file in ISE Design Suite. Add all these modules to the project. Make sure that Whole_Game module is assigned as the top module.

Step 10: Pinning the Inputs and Outputs

The image above states where on the Nexys2 board each input and output is mapped to. Please note that the LEDs output is only pinned to four LED's. This is because Pmod D, the Pmod used for the rows in the LED matrix, has pin assignments which are shared with LD0, LD1, LD2, and LD3. For more information, refer to page 15 of the Digilent Nexys2 Board Reference Manual here.

Step 11: Implementing the VHDL on the Board

By this step, you should have the external display wired properly and the VHDL files loaded and tied together in one module. In the ISE Design Suite, make sure you have Whole_Game selected as the top module and generate a bit file. Next, plug in the Nexys2 board and open the Adept program. Now you can select the bit file you just made and run the game on your board.

Step 12: Enjoy Playing!

Step 13: Build Off of Our Game

Here are a few ideas you can add to our game:

  • a timer where the player has a certain amount of time to input their answer
  • a scoreboard
  • have the level of difficulty increase as the player gets the answers correct
  • make it a two player game, which players take turns and their scores are displayed

There are so many different things you can do with this game!