0% found this document useful (0 votes)
835 views6 pages

Binary Calculator

This document summarizes a student project to build an 8-bit simple calculator using a microcontroller board. The calculator takes in two 8-bit numbers via a 4x4 keypad, performs one of four basic math operations based on the operation key pressed, and displays the result on a 7-segment display. The project implements addition, subtraction, multiplication, and division circuits. It uses a finite state machine with 4 states to control the flow of operations and displays. Testing showed the calculator worked as expected, with the limitation that subtraction of larger numbers would show an unsigned result.

Uploaded by

MS Rahil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
835 views6 pages

Binary Calculator

This document summarizes a student project to build an 8-bit simple calculator using a microcontroller board. The calculator takes in two 8-bit numbers via a 4x4 keypad, performs one of four basic math operations based on the operation key pressed, and displays the result on a 7-segment display. The project implements addition, subtraction, multiplication, and division circuits. It uses a finite state machine with 4 states to control the flow of operations and displays. Testing showed the calculator worked as expected, with the limitation that subtraction of larger numbers would show an unsigned result.

Uploaded by

MS Rahil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Simple Calculator

ECE 2700 - Digital Logic Design Final Project Paper

List of Authors (Benley Mathew, Matthew Stopyak, Matthew Wagner)


Electrical and Computer Engineering Department
School of Engineering and Computer Science
Oakland University, Rochester, MI
e-mails: [email protected], [email protected],
[email protected]

ABSTRACT
This project demonstrates how users can use two eight-bit unsigned integer
numbers for the four main operations of math, which are addition, subtraction,
multiplication and division. While this concept sounds simple in nature the actual task of
implementing this is complex and can be confusing. The actual math of it was easy to
understand and implement, while the input and output mapping and control was more
challenging. We came to the conclusion that an 8 bit calculator is not very useful but
after the heavy lifting, implementing the calculator states and I/O integration, it could
easily be expanded to accomplish larger more useful tasks.
I. INTRODUCTION decided, the next step was to figure out
For this project, a simple how many input values that will be used.
calculator was created. The motivation To avoid complex calculations, two
of this project was that the main math numbers would be enough. These
operations were created in the labs of values would then be converted from
this course. Other main components BCD numbers into Binary.
were a BCD to Binary converter and a
seven segment display. Some other
components also include registers to
store the data values of the two
numbers. What we learned from this
project is to clear variables in the
sensitivity of the process. Another thing
that we had to learn on our own was
how to converter BCD to Binary and
Binary to BCD. This method is called
Double-Dabble, where you convert
numbers from Binary to BCD and vise
Figure 1: 4x4 Keypad Schematic [2]
versa. We also learned how to
troubleshoot error messages from our
After the numbers go through the
project. This project can be used for any
operations, the results will be converted
person who needs to use a calculator
back from Binary to BCD and will be
for simple math, such as elementary
outputted onto a seven segment display.
school students who are just starting to
For division, if the number has a
learn basic mathematics.
remainder, the remainder will be shown
on segments 3 and 4 of the
II. METHODOLOGY
seven-segment display. Additionally, for
the seven-segment display to work with
A. Inputs and Outputs
the multiple digits, we had to create a
The first parts of this project is
multiplexer that would select each digit
the input and output values. The input
one at a time and display the correct
values’ range is determined by the
value.
number of bits this calculator is built for.
Since the decision of this calculator is
For a static system the human
eight-bit unsigned integer numbers, the
can not discern rates above 30Hz so we
range for the inputs is from 0 to 255
arbitrarily selected a value of 40kHz for
binary. Furthermore, since we are using
this scan cycle related to the operation
a 4x4 Keypad, it is further limited to the
of the seven segment display.
range, 0 to 99. Once the range was
The four mathematical operations
that were programmed were addition,
subtraction, multiplication and division.

The addition operation was


created from a lab from the course and
was modified to accommodate eight bit
Figure 2: Seven Segment Display [1] unsigned numbers.

Additionally, leds 15 through 12 The subtraction operation was


were programmed to display the state of based of the addition, the “addsub” input
the calculator. This helped immensely is set to a one enabling the subtraction
when troubleshooting and debugging function of this circuit.
the systems.Led 0 is the “carry out” of
the adder/subtractor circuit and led 1 is The multiplication operation was
the “overflow” from this same circuit. also created from a lab from the course
Blue led 17 is programmed to come on and was modified to accommodate eight
whenever a button is pressed on the bit unsigned numbers.
4x4 keypad.
Figure 3: State Diagram of the
B. Operations Calculator
The division operation was will move back to State 1 awaiting its
created from a lab from the course and first numeric entry.
was modified to accommodate eight bit
unsigned numbers with an LED system III. EXPERIMENTAL SETUP
to display the remainder.
For this project, we have a
All of these operations will be keypad that is used to input the two
connected to the operational keys on values, an operation, and an equal sign.
the keypad. The operations will be The model of the keypad is the
executed to the two inputs once the PmodKYPD. We also used the NEXYS
equal key is pressed. 4 DDR Board that was purchased for
the class and the Vivado Program used
To control the flow of data in the lab. We defined the operations for
through the calculator, we implemented the calculator on the keypad as the
a four position finite state machine. This following; ‘A’ is addition, ‘B’ is
subtraction, ‘C’ is multiplication, ‘D’ is
State 1 is the initialize state in division, ‘E’ is equals, and ‘F’ is clear.
which the calculator is waiting for its first For the NEXYS Board, the reset button
input value. Upon receiving the first will reset the program if pressed and the
numeric value, the calculator moves to seven-segment display to present the
State 2. In State 2, the calculator is answer to the user. The Vivado Program
collecting the first numeric entry for the is used for our coding for the the
seven-segment display. Once an calculator. The expected results will be
operation button is pressed, the that it calculates the answers to what
calculator moves to State 3, and the first the user asks of it. Example, 1 + 1 = 2.
numeric value is locked into its register.
In State 3, the calculator is collecting the For the Vivado Board, these are the
second numeric entry and displaying things we used on the board.
this data on the seven-segment display.
Once the “equals” button is pressed the 1. Reset button just resets the
calculator moves to State 4 and locks program
the second numeric entry into its 2. LED 15: State 1
register. In State 4, the calculator 3. LED 14: State 2
displays the value of the selected 4. LED 13: State 3
function that has been performed on the 5. LED 12: State 4
numeric inputs. This value will remain 6. LED 11: Enable Register A
until either the “Clear” or “Reset” buttons 7. LED 10: Enable Register B
are pressed. At this point the calculator 8. LED 9: Enable Register E
9. LED 17 (Blue): Key Press
10. LED 0: Carry Out Link to calculator demo:
11. LED 1: Overflow https://photos.app.goo.gl/EvsWD4Uwr1
12. Seven-Segment: oxDwWv5
a. Digit 8: “=” sign
b. Digit 5 and 6: Number In all case the results were as
Display expected. However, do to the unsigned
c. Digit 4: “r” for remainder nature of our subtraction the results of
d. Digit 3: remainder value the arithmetic, when Data B is greater
than Data A, were not representative of
IV. RESULTS the true nature of the operation because
the result value is unsigned. As a future
Table 1: Calculator Project Test improvement the calculator should be
Results converted to using 2’s complement
Operation Data Data Solution binary arithmetic.
A B
V. CONCLUSIONS
12 36 48
Addition (+) Some issues we faced included
3 27 30
the integration of the keypad, including
99 99 98 signed numbers in our project.
carryout
The decoding and button
48 12 36 debouncing of the keypad were
Subtraction 98 8 90 extremely difficult to decode due to the
(-) nature of the 4x4 wiring. It was
54 52 2 especially difficult to determine when the
same button was pressed in successive
3 6 18
order. For each column scan if that
Multiplication 20 4 80 particular row did not have a button
(*)
depressed, then it would have have an
9 9 81 intermediate value set to high. If all
29 10 2 r9 column read were high, then no button
was pressed.
Division (/) 48 12 4
The second sticking point when
56 5 11 r1
integrating the components of this
calculator was the shift nature of the
BCD output. For each button press, four
bits had to be shifted into the four least
significant bits of the appropriate language, the problems you will
register. Initially we were trying to use a encounter with your code will intensify.
“button event” function to accomplish This was a good learning experience for
this task but it wasn’t working. After beginners and we are walking away with
some research and reading about VHDL some valuable lessons.
and Vivado, it seems the “event
function” is specifically reserved for REFERENCES
clock functions which are synchronous
in nature. We were attempting to use [1] Nexys 4 DDR Reference Manual.
this in an asynchronous manner. This (n.d.). Retrieved from
makes sense since VHDL is a hardware https://reference.digilentinc.com/referen
descriptive language. We then ce/programmable-logic/nexys-4-ddr/refe
developed a definite “button press state” rence-manual
and any change latched a synchronous [2] Pmod KYPD. (n.d.). Retrieved
clock would mean that a button was from
pressed. The register would then shift in https://reference.digilentinc.com/referen
four bits of data. ce/pmod/pmodkypd/start

Potential improvements
1. Using 2’s complement binary
arithmetic
2. Drop the leading zeroes on the
display
3. Institute an “all clear” and clear
function
4. Expand the arithmetic capabilities
to handle a greater number of
bits.
5. Rework the FSM and integration
of coding so it is easier to read
6. Replace the seven segment
display with LCD display for
greater functionality

Overall, this project was much


harder than anticipated. VHDL may look
like a coding language but it is not.
When you forget that it is hardware
descriptive and treat it is a coding

You might also like