Laboratory No. 9:: Simple Calculator (Final Lab)
Laboratory No. 9:: Simple Calculator (Final Lab)
Laboratory No. 9:: Simple Calculator (Final Lab)
9:
Simple Calculator (Final Lab)
A. Purpose
Students will combine the sub-modules that were created in the previous lab exercises to complete the
SIMPLE CALC module. They will also use a Verilog generate statement to choose between the two versions of
the COMP module. Students will develop a test bench that thoroughly verifies the structural module. They
will also modify the ROM contents to hold the specific values that you will use in the verification process.
Finally, they will implement the logic, targeting the Spartan-3 FPGA, and examine the contents of the report
files.
The schematic for the calculator is shown in Figure 4 below. Students will write the RTL description for
the top-level module SIMPLE CALC.
B. Equipment
There is a minimal amount of equipment to be used in this lab. The few requirements are listed below:
• Xilinx ISE Navigator Software (v10.0.1)
• Spartan 3E Developer Board
• Computer capable of running the software mentioned
C. Procedure
2
II. SCHEMATIC DIAGRAMS
This section consists of block diagrams which are useful for the laboratory procedure as well as simulation
results.
FIG. 1: Overall block diagram of the calculator project showing the relationship of all of the components.
3
FIG. 3: Detailed RTL view for the simple calculator with all modules.
4
III. EXPERIMENT DATA
This section will consist of the code blocks that created the counter block as seen in Figure 4.
‘ d e f i n e SYNTH 1
generate
i f ( ‘SYNTH )
//COMP RTL U4 (COMP EN, EXPECTED, ALU OUT, CLK, RESULT) ;
COMP RTL U4 ( . COMP EN(COMP EN) , . EXPECTED(EXP OUT) , . ALU OUT(ALU OUT) , . CLK(CLK) , . RESULT(RESULT) ) ;
else
//COMP BEH U5 (COMP EN, EXPECTED, ALU OUT, CLK, RESULT) ;
COMP BEH U5 ( . COMP EN(COMP EN) , . EXPECTED(EXP OUT) , . ALU OUT(ALU OUT) , . CLK(CLK) , . RESULT(RESULT) ) ;
endgenerate
endmodule
This is the text fixture for the simple calculator called (SIMPLE CALC TB.v).
‘timescale 1 ns / 1 ps
// I n p u t s
reg CLK ;
reg RESET ;
// O u t p u t s
wire RESULT ;
i n i t i a l begin
// I n i t i a l i z e Inputs
CLK = 0 ;
RESET = 0 ;
#1 RESET = 1 ;
#1 RESET = 0 ;
end
always
#50 CLK = ˜CLK ;
endmodule
This is the pin out information for the hardware simple calculator called Full.ucf.
#PACE : Start of Constraints generated by PACE
#T h i s ucf file has all the s w i t c h e s and LEDs t h a t might be used i n CompE 2 2 4
5
#M o d i f y this file with your net names and comment o u t or delete the lines not n e e d e d .
#Main S w i t c h e s
#NET ”SW3” LOC = ”N17” ;
#NET ”SW2” LOC = ”H18” ;
#NET ”SW1” LOC = ” L14 ” ;
#NET ”SW0” LOC = ” L13 ” ;
#E x t r a S w i t c h e s
#NET ”SW7” LOC = ”A6” ;
#NET ”SW6” LOC = ”B6” ;
#NET ”SW5” LOC = ”E7” ;
#NET ”SW4” LOC = ”F7” ;
#Main LED’ s
NET ”RESULT” LOC = ”F9” ;
#NET ”LED6” LOC = ”E9” ;
#NET ”LED5” LOC = ”D11” ;
#NET ”LED4” LOC = ” C11 ” ;
#NET ”LED3” LOC = ” F11 ” ;
#NET ”LED2” LOC = ” E11 ” ;
#NET ”LED1” LOC = ” E12 ” ;
#NET ”LED0” LOC = ” F12 ” ;
#E x t r a LED’ s
#NET ”LED11” LOC = ”B4” ;
#NET ”LED10” LOC = ”A4” ;
#NET ”LED9” LOC = ”D5” ;
#NET ”LED8” LOC = ”C5” ;
#P u s h b u t t o n S w i t c h e s
#NET ” BTN North ” LOC = ”V4” | PULLDOWN ;
NET ”RESET” LOC = ”H13” | PULLDOWN ; # East
NET ”CLK” LOC = ”K17” | PULLDOWN ; #S o u t h
#NET ”BTN West” LOC = ”D18” | PULLDOWN ;
#D e b o u n c e r C9 50MHz
#NET ”CLK” LOC = ”C9” ;
This is the map report for the simple calculator called Map Report.txt.
R e l e a s e 1 0 . 1 . 0 2 Map K. 3 7 ( n t )
X i l i n x Mapping R e p o r t F i l e f o r Design ’ SIMPLE CALC ’
Design Information
−−−−−−−−−−−−−−−−−−
Command L i n e : map − i s e C : / CompE340/ Lab09 / Lab09 . i s e − i n t s t y l e i s e −p
x c 3 s 5 0 0 e −f g 3 2 0 −4 −cm a r e a −p r o f f −k 4 −c 1 0 0 −o SIMPLE CALC map . ncd
SIMPLE CALC . ngd SIMPLE CALC . p c f
Target Device : xc3s500e
Target Package : f g 3 2 0
Target Speed : −4
Mapper V e r s i o n : s p a r t a n 3 e −− $ R e v i s i o n : 1 . 4 6 . 1 2 . 2 $
Mapped Date : Wed J u l 15 2 0 : 2 0 : 5 6 2 0 0 9
D e s i g n Summary
−−−−−−−−−−−−−−
Number o f e r r o r s : 0
Number o f w a r n i n g s : 1
Logic U t i l i z a t i o n :
Number o f S l i c e F l i p F l o p s : 20 o u t o f 9 ,312 1%
Number o f 4 input LUTs : 40 o u t o f 9 ,312 1%
Logic D i s t r i b u t i o n :
Number o f o c c u p i e d S l i c e s : 23 o u t o f 4 ,656 1%
Number o f S l i c e s c o n t a i n i n g o n l y r e l a t e d l o g i c : 23 out o f 23 100%
Number o f S l i c e s c o n t a i n i n g u n r e l a t e d l o g i c : 0 out o f 23 0%
∗ S e e NOTES b e l o w f o r an e x p l a n a t i o n o f t h e e f f e c t s o f unrelated logic .
T o t a l Number o f 4 input LUTs : 40 o u t o f 9 ,312 1%
Number o f bonded IOBs : 3 out o f 232 1%
Number o f BUFGMUXs: 1 out o f 24 4%
6
B. Individual Modules
This is alu.v.
‘timescale 1 ns / 1 ps
module ALU(
input [ 3 : 0 ] A,
input [ 3 : 0 ] B,
input C IN ,
input [ 3 : 0 ] OP CODE,
input CLK,
input EN,
output reg [3:0] Y
);
i f (EN)
begin
c a s e (OP CODE) // S p e c i f y o u t p u t s for each address .
4 ’ b0000 :
Y = A + C IN ;
4 ’ b0001 :
Y = A + B + C IN ;
4 ’ b0010 :
Y = A + ( ˜B) + C IN ;
4 ’ b0011 :
Y = A − 1 + C IN ;
4 ’ b0100 :
Y = A & B;
4 ’ b0101 :
Y = A | B;
4 ’ b0110 :
Y = A ˆ B;
4 ’ b0111 :
Y = ˜A ;
4 ’ b1000 :
Y = 0;
default :
Y = 0;
endcase
end
endmodule
output reg [ 1 6 : 1 3 ] A IN ,
output reg [ 1 2 : 9 ] B IN ,
output reg C IN ,
output reg [ 7 : 4 ] OP CODE,
output reg [ 3 : 0 ] EXP,
localparam [ 4 : 0 ]
S0 INIT = 5 ’ b00001 ,
S1 FETCH = 5 ’ b00010 ,
S2 ALU = 5 ’ b00100 ,
S3 COMP = 5 ’ b01000 ,
S4 DONE = 5 ’ b10000 ; // Explicite make sure condition to stay in state
A IN = DATA FRAME [ 1 6 : 1 3 ] ;
B IN = DATA FRAME [ 1 2 : 9 ] ;
7
C IN = DATA FRAME [ 8 ] ;
OP CODE = DATA FRAME [ 7 : 4 ] ;
EXP = DATA FRAME [ 3 : 0 ] ;
c a s e (CURR STATE)
S0 INIT :
begin
ALU EN = 1 ’ b0 ;
MEM EN = 1 ’ b0 ;
COMP EN = 1 ’ b0 ;
NEXT STATE = S 0 I N I T ;
end
endcase
end
endmodule
//OUTPUTS
output reg RESULT // 1− b i t − r e s u l t of comparison
);
i f ( ! RESULT)
$ d i s p l a y ( ” At t i m e %t , EXP = %b , ACT = %b , RESULT = %b ” , $ t i m e , EXPECTED, ALU OUT, RESULT) ;
end
endmodule
8
module COMP RTL(
//INPUTS
input wire COMP EN, // 1− b i t − e n a b l e w i r e f r o m FSM
input wire [ 3 : 0 ] EXPECTED, // 4− b i t − e x p e c t e d o u t p u t , l o a d e d f r o m ROM
input wire [ 3 : 0 ] ALU OUT, // 4− b i t − a c t u a l o u t p u t f r o m ALU
input wire CLK , // 1− b i t − c l o c k i n p u t
//OUTPUTS
output reg RESULT // 1− b i t − r e s u l t of comparison
);
endmodule
This is mem.v.
‘ t i m e s c a l e 1 ns / 1 ps
‘ i n c l u d e ”MY HEADER . t x t ”
// Output
output reg [ ‘WIDTH− 1 : 0 ] DATA FRAME ;
endmodule
This is MY HEADER.txt.
‘ d e f i n e WIDTH 17
‘ d e f i n e ADDR 3
9
IV. DISCUSSION & CONCLUSION
The purpose of this lab was to bring together all of the modules from the previous labs together and create
a simple calculator. This calculator is pre-programmed with the aritmetic and logicical operations with an
expected output which the user give. The actual results are compared and if the calculator worked properly,
the output is a high 1. Students now know how to design, build, test, and synthesis a circuit by using verilog
HDL language.
Personally, I was happy to have worked on this final project with my partner, Tim Price. Together, we
were able to quickly bring all of the modules together, hook them up, simulate, and synthesis the project
to the Spartan 3E board. We had some stumbling blocks along the way, but nothing too sever. The one
module which was giving us most hassle was the CNTRL FSM module. There were all sorts of strange things
it was doing, and we had to modify it a bit from our original one that we did in the previous lab. One in
particular that I can remember was the RST pin being set to a high asserted reset. When we changed it to
be a low asserted, most everything started to work properly.
There were some questions posed in the lab handout that I would like to address here in the conclusion:
• Using the Map Report, answer the following about your design:
– Number of registers?
∗ 20
– Number of 4-input LUTs?
∗ 40
– Number of I/O blocks?
∗ 3
– Number of global clocks?
∗ 1
Other conclusions that I can make is that the overall experience writing in verilog was much nicer and
actually a lot of fun, which is something I didn’t get with Circuit Maker and Cadence OrCAD. This was just
a simple calculator and it demonstrated quite a bit of verilog capability. There’s still a lot to learn about
verilog and it will be exciting to continue learning it to build custom circuits into FPGAs.
10