Signed Integer to Binary Timed Instructional Tool

Introduction: Signed Integer to Binary Timed Instructional Tool

This instructional tool will help improve your skills of converting signed integers to binary in two's complement. The way it works is first you flip the last switch on the left to generate your random number which appears on the seven-segment display on the Basys 3 board. The timer begins to count down starting at ten seconds. The user then has to input the integer into 6-bit binary using 6 switches on the right side of the board. Once the timer has reached zero, the seven-segment display on the left side of the breadboard will display PASS or FAIL depending on if you entered the correct number. You may use the second to last switch on the left side of the breadboard to restart or you may try figuring out the correct switches for the binary number because the display will show PASS even after the timer is done. This is so the user can figure out what was the correct number and improve their skills.

This tutorial will teach you how to build and program an integer to binary game using a Basys 3 board, wires and headers, seven-segment displays, and a breadboard. The program is written using Xilinx Vivado. This instructable will guide you through the process of making the tool.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Materials Used

For this project, we used the following material listed below:

-Basys 3 Board

-Wires and header pins

-Seven-Segment Displays


-Soldering kit

Step 2: Diagrams

The black box diagram is shown in the picture. We can see the 2 main components and the checker. The outputs of the main module go out to the anodes and cathodes of the displays. The inputs are the switches on the Basys 3 board. There is are switches for the reset , to generate a random number and six other switches for the user input. The timer, random number, and the checker are each displayed on a seven-segment display.

Step 3: Code and Description of Subparts

mainMod => This file calls the two main subparts and also generates the pseudo-random number. It does this by running the system clock at its max speed then once the user uses the switch, it grabs whatever value the clock was on and assigns it as the random number the user has to input. The two components/subparts it consists of are the mainBinToSignedInt subpart and the other is the mainTimer subpart. The mainModule also includes the code for the PASS and FAIL. The pass and fail is determined by comparing the bits of the random binary number to the switches on the basys 3 board. The result is then displayed on one of the external seven-segment displays on the breadboard.

-mainBinToSignedInt => This module is responsible for taking in the generated random number and displaying it onto the seven-segment display on the basys board. The random number passes through the doubleDabble, TwosComplement and the bToI(Binary to Integer). The clock divider is used to determine the speed at which the clock will run. The output are then mapped to the number cathode and the number anode in the mainModule.

-doubleDabble => This subpart takes in the random number generated in the mainMod and the result is the integer of the random binary number. It takes in an 8-bit binary number and since the random number generated is only 6-bits, we add two 0's in front of it before passing it into the doubleDabble. If the binary number has the value 28, then the doubleDabble splits it into its ones, tens, and hundreds place. We only use the ten's and one's place so we don't care about the hundred's place. This is necessary in order to be able to display an integer number on the display from the generated 6-bit binary number.

-TwosComp => It turns a 6-bit binary number to its negative in twos complement. The way we went about this one is by using a pattern described in the course textbook. Using the pattern we were able to easily convert positive binary numbers to their negative values. The pattern is starting from the right, you go through the 6-bit number until you reach a 1. That first 1 remains unchanged but then the rest of the bits are toggled. For example, if you have the following 6-bit number, 010100, starting from the right, bit(2) is a 1 so you leave that and toggle the rest of the bits so the result would be 101100.

-clockDivider => The Clock Divider determines the speed of the clock. This is needed to be able to display onto the seven-segment displays and to run process because it updates on the rising edge of the clock. We set the divider to 60 hertz so the anodes on the seven segments get refreshed at just the right speed to be unnoticeable to the human eye and so the digits don't appear to be blinking or displaying incorrectly.

-bToI => This module is for the seven segments themselves. It tells us which segments to turn on in order to display the number we want. We made it be able to display numbers 1-9 and also made two to turn the negative sign on and off for the signed integer numbers.

-mainTimer => The main timer is responsible to setting up the countdown clock on the other external display on the breadboard. It gets mapped to the system timer on the main module. The outputs are mapped to the timer anodes and cathodes. The code in the main timer works by subtracting the number in the one's place by one then once it reaches zero, it subtracts one from the tens place and it keeps iterating until the digits in the ten's and one's place both reach zero. It then triggers the timer done and in the main module it runs the checker. The mainTimer is composed of a clock divider(description above) and a binToDec.

-binToDec => This converts a binary number to its decimal equivalent and assigns it to an 8-bit bus that gets used in the main timer module.

Step 4: Setting Up the Hardware

We used the a diagram from the Basys 3 reference manual to figure out how to set up the Pmod connectors on the board. We were just using two external seven segment displays. From class, we knew that each digit has a common anode and there are 7 segments(8 including the decimal point). We just needed 7 wires for the cathodes of the first display and 8 wires for the second display due to the decimal point. We also used4 wires for the anodes of each display. In total we used 23 wires because of the decimal point on the timer display. It was just a matter to figuring out which pins on the seven-segments turned on which segment which is shown in the diagram. The cathodes on the diagram are labeled A-G and the anodes are labeled D1-D4. For the sake of organizing the wires and make setting it up easier, we labeled the wires according to which cathodes and anodes they were for and also soldered the ends to headers so we wouldn't have stray wires getting disconnected and messing up our project.

Step 5: Video

The first 20 seconds shows the first example of a PASS situation in which the user correctly input the binary number before the time runs out. Once the countdown timer reaches zero, the seven-segment display on the right shows "PASS". In the second half of the video, we show what happens if you don't correctly input the number displayed on the Basys 3 board when the timer reaches zero. As you can see from the video, the seven-segment display on the left shows "FAIL". Those are the two possible scenarios in this demo.

Step 6: Sources and References

Basys 3 reference manual which can be found by clicking here.

Digital McLogic Design pdf can be found here.

Be the First to Share


    • Backyard Contest

      Backyard Contest
    • Silly Hats Speed Challenge

      Silly Hats Speed Challenge
    • Finish It Already Speed Challenge

      Finish It Already Speed Challenge