calculator using verilog hdl
calculator using verilog hdl
Abstract— A calculator is a device that can be found in daily physically smaller. FPGA designers have to create designs
life. This paper proposed the design of a calculator using Verilog that meet the essential criteria that other designers can
HDL. A series of synthesizable Verilog code was created and understand for performing the chip under worst-case
simulated on Quartus II 15.0. The design of an 8-bit calculator temperature. Besides, the process variation conditions are
can solve mathematical operations such as addition,
reliable, testable and can be proven to meet the specification
subtraction, multiplication, division, square and cube functions,
square root and factorial. This calculator consists of eight-digit and do not exceed the power consumption goals. Therefore,
numbers. In this paper, among the family devices in Altera, the designers write hardware description language (HDL)
Cyclone V was used to perform the simulation process. The code that will be used for synthesis, and the code will be
outputs are shown in the RTL viewer and waveform simulation implemented in the hardware chips. Simulation and
of the calculator design. The implementation of a calculator was operational testing of the outputs using Verilog are vital as
successfully designed using Verilog HDL in terms of digit they help avoid the error, which may cost much in silicon
numbers and the operation of the calculator function. turns and schedule delays [5 - 13]. The Verilog simulation
provides no-cost experiment, and the software tools are cheap
Keywords—Calculator, Verilog, Digital design, Mathematical
of free for testing equipment in FPGA logic [14]. Hardware
operation
Description Language such as Verilog HDL and VHDL was
I. INTRODUCTION used to create systems on chips with schematics. RTL is the
design abstraction that controls the modeling of a
The calculator is an electronic hardware or software synchronous digital circuit in the digital signals between
device that can carry out simple arithmetic operations such as hardware registers in the digital circuit design and performs
addition, subtraction, multiplication and division. A scientific logical operations on the signals. There are lots of research
calculator has some advanced operations such as have been done related to calculator design such as calculator
trigonometry function, hyperbolic function, exponential design with RISC (64 bit) architecture using Verilog and
function and logarithmic function, which could solve FPGA, Translation of Division Algorithm into Verilog HDL,
complicated mathematics problems. The invention of A New ALU Architecture Design using Reversible Logic,
calculators has reduced the required time to explain complex 12-Bit Verilog Calculator with Trigonometry Functions,
figures and common errors when digits are calculated by Simple 8-Bit Calculator Design Bit Slicing Technique and
hand [1, 2]. FPGA Prototyping, Simplified VHDL Coding of Modified
Scientific calculators support even more transistors in the Non-Restoring Square Root Calculator, A New Algorithm
integrated circuits to carry out the performance of advanced for Designing Square Root Calculators based on FPGA with
mathematical calculations. The inputs data to the calculators Pipeline Technology [15 - 21].
are processed in binary form. The integrated circuit will then
convert the decimal numbers into a binary number system, II. OBJECTIVES
which in the base-two system. Integrated circuits use the This research focuses on the design of a Verilog HDL
binary strings of data to control the transistors for the calculator based on FPGA. The improvement of this
performance of mathematical calculations. Once the calculator can be accomplished by adding the function and
mathematical operations are completed, the binary data will the calculator's digit number. The objective of this study is to
be converted back into the base-ten system. The output will design eight digits calculator with several different functions
appear on the display screen [3, 4]. Adder is formed by using Verilog HDL.
combining several logic gates to get a complex circuit.
Different combinations of logic gates in the chips can III. DATA TYPE AND FLOW OF THE DESIGN
perform various mathematical calculations like addition, Figure 1 shows the block diagram of the data type and
subtraction, multiplication and division.
flow of the calculator design. First, the input values were
The digital design developers face challenges to create
given to the design, which is in decimal form and converted
faster designs with more significant numbers of gates and
Authorized licensed use limited to: NATIONAL INSTITUTE OF TECHNOLOGY TIRUCHIRAPALLI. Downloaded on September 24,2024 at 12:19:34 UTC from IEEE Xplore. Restrictions apply.
into binary form for data processing purposes. The calculator
conducts several sequential operations in their binary form,
such as addition, subtraction, multiplication, division, square
& cube function, square root, and factorial feature [16 - 22].
The data were converted from the asynchronous unit to the
synchronous unit in the push-button section. The calculated
output data in binary form are then translated to BCD format
for the functioning at the seven-segment unit. The
mathematical operations' output results are produced by
lighting up the different positions of the 7-segment LEDs to
display the digit. There are nine sets of 7-segment LED
provided for output. Eight of them represented the number
digits of the calculation result. The other one on the most left
side represented the sign of the number.
Authorized licensed use limited to: NATIONAL INSTITUTE OF TECHNOLOGY TIRUCHIRAPALLI. Downloaded on September 24,2024 at 12:19:34 UTC from IEEE Xplore. Restrictions apply.
B. Overflow following state, which is ‘HALT’, where REGA<=0,
Overflow occurs when the size of the number exceeds the REGB<=0, operator<=0, and count < = 0, the overflow
maximum range of bits allowed in the registers. In this paper, occurs. This is the custom where you need to insert the ‘ac’
the inputs must be limited in the range from -99999999 to button. The ‘ac’ is responsible for clarifying the calculator
99999999, otherwise, overflow. The overflow of the design and changing functions. Once again, the program will return
is calculated based on the operation of the decimal mode. The to the ‘DECIMAL’ state.
input values must be larger than -99999999, with the signed
binary form of
0000_0101_1111_0101_1110_0000_1111_1111. When
converted to its 2’s complement, the value is
1111_1010_0000_1010_0001_1111_0000_0001. Hence, it
becomes 4194967297 when its 2’s complement binary value
is converted back into decimal form. On the other hand, the
input values must not exceed 99999999 as this is the
maximum value for an eight-digit calculator.
C. Synchronous circuit
Flip flops are made of a latch with enable input and an
edge detector circuit. The input to the edge detector is a signal
called ‘clock’. A clock signal is a square wave with a fixed
Fig. 3. FSM of a calculator
frequency. A positive edge triggered flip flop was the edge
circuit that generates pulses during rising edges.
n-bit Shift Register is connected serially. The flip flops IV. RESULT AND DISCUSSION
share the same reset and clock signals. The result is a counter Figure 4 shows the RTL viewer of top-level module
where only a single bit has a different value for two design based on the code in the appendix. The top-level
consecutive counts. All the flip flops share the asynchronous module was named with ‘calctop’. The overall modules,
signal ‘reset’, which sets the initial count. n-BIT Register is a ‘calc’, ‘syncro’, ‘syncro10’, ‘bintobcd’, ‘binled’, and ‘ledout’
collection of ‘n’ D-type flip flops, where each flip flop were included in the top-level module. There are 14 inputs
independently stores one bit. The flip flops are connected in pin and 15 outputs pin name in the design. Next, 11 syncro
parallel. They also share the same reset and clock signals. blocks and 1 syncro10 block. Syncro depends on the user
D. Binary to BCD translation which function will they be using, the data will enter the
There is 27 bits width required by register A and 29 bits ‘calc’ module. In contrast, syncro 10 depends on the number
for register B. Since the maximum value of the input in this that the user has key in. All the data will enter the ‘calc’
calculator design is 99999999, the binary result has a bit module. Afterward, calculation main module ‘calc’, where all
width of 27 bits to be translated into BCD form. The data the calculation of addition, subtraction, multiplication,
must be translated into the BCD format to be displayed on the divide, exponential power of 2 and 3, factorial and square root
seven segments LED. There are eight LEDs to display the formula was processed. This module also includes the
computed result and another one to represent the result's sign. process of the register bit width and the overflow of output.
Lastly, the ‘binled’ module which functions to transport the
E. Digit count information from the ‘calc’ module to the output which is
It is important to arrange the position of the digit count in ‘ledout’ to be displayed on seven segments LED, inside
the calculator. The function of “*10” and “+” shifts the output ‘binled’ module has a ‘bintobcd’ module and ‘ledout’
at the 7-segment LED display. Each time data input to the module.
system, the output at the display will move from the very right
side to the left side.
Figure 5 shows the waveform summary in the
Report Timing report. The circuit implemented was on
F. FSM for the calculator the Cyclone V family device. Cyclone V has the highest
Figure 3 illustrates the finite state machine of a calculator. number of total registers. The size of registers indicates
The finite state machine (FSM) summarizes the various the data that the system can be used at any given time.
circumstances of feedback from the anticipated statistics to In this circuit, the timing requirement is specified to
the operation scheme. ‘DECIMAL’ is the initial state, which 20.0ns clock. The amount of time for data to be present
is the alpha of the measure. The 10 keys assignment compute at an input pin until the clock signal clocks at the
as input from this standpoint. Just as count<=count+1, register is asserted at the clock pin, which feeds a
thereupon REGA<=REGA*10+d. When the function ‘ce’ register through its data or activates inputs. The setup
that erases the last figure or operation registered, it is inserted slack value in this circuit is 12.711ns, which is positive
at instant REGA <=0 as count <=0. When the mathematical means it meets the time requirement. The clock delay is
operations are registered, the state will shift. ‘OPE’ is the
4.985ns, represents the time between the launch at the
following state. The out func =~ b+1 at ' OPE ' is (b[28]==1),
pin of the device and the clock inputs of the
otherwise it is out func = b. Then the system moves to the
Authorized licensed use limited to: NATIONAL INSTITUTE OF TECHNOLOGY TIRUCHIRAPALLI. Downloaded on September 24,2024 at 12:19:34 UTC from IEEE Xplore. Restrictions apply.
source/destination flip-flops. The required data showed operation, the second input values can enter Register A.
the time the data would have arrived at the flip-flop The final values enter Register B. It transmits the
destination by data delay takes by 5.758ns for a signal computed data in register B. Register B stored the input
to propagate from source to destination. The diagram number memory for processing purposes on the output.
shows that the data arrives at its destination before the Suppose the user selects the operation, such as the
time required to arrive. Therefore, the timing constraint addition. In that case, the multiplexer switches from 0
is satisfied. to 1, as it implies in a high or active state. Other
operations are subtraction, multiply, divide, square,
cube, square root, and factorial.
Based on Figure 6, two inputs from the ‘decimal’
signal loaded to register A are 96345 and 7812. The
operator selector is ‘add,’ which represented the
addition operation. The computed result is stored at
register B, 104157, and output at the ‘out’ waveform.
This means that when the number 96245 is added with
7812, the output is 104157. All the other operations
have the same method to get the final output.
96345 7812
104157
Fig. 4. RTL view for top-level module ‘calctop’ Figure 7, 8, 9, 10, 11, 12, and 13 show the waveform
simulation results of different function of calculator design
using Verilog HDL in this paper such a subtraction,
multiplication, division square, cube, square root and
factorial respectively.
Authorized licensed use limited to: NATIONAL INSTITUTE OF TECHNOLOGY TIRUCHIRAPALLI. Downloaded on September 24,2024 at 12:19:34 UTC from IEEE Xplore. Restrictions apply.
designing complex digital circuits using Verilog HDL. The
calculator designs can only generate an integer answer and
produce 8-digit output, which means that if the answer
includes decimal numbers, the result lack precision. It is
suggested for future work to get a more precise result;
floating-point includes getting an accurate output. Lastly, it
is recommended to include more mathematical operations to
solve complex mathematical problems, such as logarithmic,
Fig. 9. Waveform simulation of the ‘div’ function exponential, and trigonometric functions.
ACKNOWLEDGMENT
The author would like to thank Universiti Malaysia
Sarawak (UNIMAS) for providing opportunity and facilities
to support this project.
REFERENCES
Fig. 10. Waveform simulation of the ‘sq’ function
[1] “What is calculator? definition and meaning.” [Online]. Available:
http://www.businessdictionary.com/definition/calculator.html.
[Accessed: 20-Nov-2019].
[2] “Evolution of the calculator.” [Online]. Available:
https://cosmosmagazine.com/mathematics/evolution-calculator.
[Accessed: 25-Nov-2019].
[3] “SchoolMart.” [Online]. Avalable:
https://www.schoolmart.com/2017/03/29/the-calculator-a-brief-
history/?v=e71bc9c013d9. [Accessed: 20-Nov-2019].
[4] “The People's Best Friend: The Calculators' Brief History.” [Online].
Fig. 11. Waveform simulation of the ‘cube’ function Available: https://interestingengineering.com/brief-history-
calculators. [Accessed: 20-Nov-2019].
[5] “Casio.” [Online]. Available:
http://www.vintagecalculators.com/html/casio.html. [Accessed: 20-
Nov-2019].
[6] “The History of the Calculator.” [Online]. Available:
https://www.thecalculatorsite.com/articles/units/history-of-the-
calculator.php. [Accessed: 20-Nov-2019].
[7] “Digital Logic Gate Tutorial - Basic Logic Gates.” [Online]. Available:
https://www.electronics-tutorials.ws/logic/logic_1.html. [Accessed:
20-Nov-2019].
[8] “How Does a Calculator Work?” [Online]. Available:
Fig. 12. Waveform simulation of the ‘sqrt’ function https://www.wonderopolis.org/wonder/how-does-a-calculator-work.
[Accessed: 20-Nov-2019].
[9] “Learnabout electronics.” [Online]. Available: http://www.learnabout-
electronics.org/Digital/dig21.php. [Accessed: 20-Nov-2019].
[10] K.Coffman, Real world FPGA design with Verilog. Upper Saddle
River, NJ: Prentice Hall PTR, 2000.
[11] “Register Transfer Level.” [Online]. Available:
https://semiengineering.com/knowledge_centers/eda-
design/definitions/register-transfer-level/. [Accessed: 25-June-2020].
[12] Huang, J. L., & F.Cauley, S. (2009). Chapter 8. In C. K. Koh (Ed.),
Logic and circuit simulation (pp. 449-512).
Fig. 13. Waveform simulation of the ‘factr’ function [13] Hamblen, J. O., & Furman, M. D. (2002). Chapter 3. In Rapid
Prototyping of Digital Systems: A Tutorial Approach (pp. 37-52).
V. CONCLUSION Boston, MA: Springer US.
[14] Mathew, B., Stopyak, M., Wagner, M. (2017) Simple Calculator ECE
The objective of this paper is to design eight digits of 2700-Digital Logic Design Final Project Paper. (2017). Simple
calculator and implement operators using Verilog HDL, were Calculator ECE 2700-Digital Logic Design Final Project Paper.
achieved. The calculator was designed, coded in Verilog [15] Shelke, M. G., Jaunjare, N. V., & Penshanwar, S. K. (2017).
HDL, and simulated using Altera Quartus II. For designers, Calculator design with RISC (64 bit) architecture using VERILOG and
FPGA. Calculator Design with RISC (64 Bit) Architecture Using
Verilog HDL is important to create schematic chip systems VERILOG and FPGA.
that can be implemented into Field Programmable Gate Array [16] Yusmardiah, Y, Darmawaty, M., A, Abdul Karimi, H, Abdul Aziz, A.,
(FPGA). Verilog HDL could describe and define the arbitrary R, & Ahmad, K., S. (2017). Translation of division algorithm into
collection of digital circuits by performing operations in verilog hdl. translation of division algorithm into verilog HDL.
parallel ways that are beneficial in comparison with other [17] Banerjee, A., & Das, D. K. (2016). A new ALU architecture design
languages. Cyclone V is the device chosen from the Altera using reversible logic. 2016 Sixth International Symposium on
Embedded Computing and System Design (ISED). doi:
family device. Due to certain factors such as lack of facilities 10.1109/ised.2016.7977079
and software, the calculator design has many deficiencies in
Authorized licensed use limited to: NATIONAL INSTITUTE OF TECHNOLOGY TIRUCHIRAPALLI. Downloaded on September 24,2024 at 12:19:34 UTC from IEEE Xplore. Restrictions apply.
[18] L., I. E., Q., E. R., Colinares, D. S., Lousie, J. D., & Caldo, R. B. (n.d.). [21] Wang, X., Zhang, Y., Ye, Q., & Yang, S. (2009). A New Algorithm for
12-bit Verilog calculator with trigonometric functions. 12-bit verilog Designing Square Root Calculators Based on FPGA with Pipeline
calculator with trigonometric functions, 3(No.), 43–48. Technology. 2009 Ninth International Conference on Hybrid
[19] Jin, G. S. (n.d.). Simple 8-Bit Calculator Design Bit Slicing Technique Intelligent Systems. doi: 10.1109/his.2009.27
And FPGA Prototyping. [22] C. Yu, “Verilog Hardware Description Language,” 26-Feb-2007.
[20] Sutikno, T., Jidin, A. Z., Jidin, A., & Idris, N. R. (2012). [Online]. Available:
Simplified VHDL Coding of Modified Non-Restoring Square Root http://ece.niu.edu.tw/~chu/download/fpga/verilog.pdf. [Accessed: 7-
Calculator. International Journal of Reconfigurable and Embedded Dec-2019]
Systems (IJRES), 1(1). doi:10.11591/ijres.v1i1.440
Authorized licensed use limited to: NATIONAL INSTITUTE OF TECHNOLOGY TIRUCHIRAPALLI. Downloaded on September 24,2024 at 12:19:34 UTC from IEEE Xplore. Restrictions apply.