## Introduction: CPE 133 Final Project Decimal to Binary

Binary Numbers are one of the first things that come to mind when thinking of digital logic. However, Binary Numbers can be a difficult concept for those new to it.

This project will help those who are both new and experienced with binary numbers master converting decimal numbers. Through the creation of a game we will test users on their conversion skill. This game will be executed on a Basys3 Board and programmed in Verilog.

## Step 1: Materials Needed

The Following Materials are needed to make this Decimal to Binary Conversion Game:

• Xilinx Vivado Design Suite Software

• Digilent Basys3 FPGA Board

• USB to Micro USB Cable

## Step 2: Setting Up the LFSR (Linear Feedback Shift Register)

A LFSR (Linear Feedback Shift Register) is a module used to generate “random” numbers.

A LFSR isn't completely random as it generates pseudo-random numbers which is a process of generating numbers that appear random but are not.

A LFSR is a shift register whose input bit is a linear function of its previous state, which means the LFSR will cycle through a finite set numbers. Specifically for this game, the LFSR will only use 8 bits to limit the decimal number it can generate to 255.

Button L (btnL) is used to reset the number on the LFSR.

This LFSR module was not created by the makers of this game. The LFSR module was created by Carleton University Professor, John Knight. The link for his module is included below.

http://www.doe.carleton.ca/~jknight/97.478/97.478_...

## Step 3: Setting Up the Seven Segment Display

A Seven-Segment Display is used on the Basys3 Board and on many other pieces of hardware to display alphanumeric characters.

The Seven-Segment Display module that is used in this game converts a binary number into a decimal number and displays it as a decimal number.

By utilizing the previously discussed LFSR module, a random generated number will be output onto the Seven-Segment Display.

The Seven-Segment Display module was not created by the makers of this game. The Seven-Segment Display module was provided by California Polytechnic State University Professor, Joseph Callenes-Sloan. The pdf for the module is attached below.

## Step 4: Creating the Game Module

Create Game (main) Module.

This module will use the LFSR module to generate a random number and then output it onto the Seven-Segment Display.

The module then uses an always block that resets the random number. This operates on the positive edge of Button R (btnR), which means that it will only operate when Button R has been pressed.

The Second always block operates on the positive edge of the clock (clk). If Button C (btnC) is pressed this will check if the number on the Seven-Segment Display is the same as the input number from the switches (sw). This block will raise a flag (set the flag register (flag) to 1) and change the messageVal wire according to if the user has won or lost.

The Third always block also operates on the positive edge of the clock. If the flag is raised it will set the ssegInputVal to the messageVal wire on the Seven-Segment Display. If the flag is not raised it will continue to output the random number (randomVal).

## Step 5: Playing the Game!

Instructions:

• The user will press Button R to make a new game, or change the number on the Seven-Segment Display.
• The user will flip the first 8 switches up (1) or down (0) to input the represent the binary number.
• Button C will be used to check if the user won or lost.
• If the User won '111' will be displayed on the Seven-Segment Display.
• If the User lost '0' will be displayed on the Seven-Segment Display.
• To start a new game Button R can be pressed at any time.