Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

help me please. multi bit adder(behavioral and bit by bit logical) verilog testbench

Status
Not open for further replies.

agobgocgo

Newbie level 3
Newbie level 3
Joined
May 1, 2013
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,325
This is my first time using VHDL but I can't understand how can I make the testbench for these.. please let me know testbench for these.


module adder1(a,b,cin,cout,s);
parameter n=8;
input [n-1:0] a,b;
input cin;
output [n-1:0] s;
output cout;

assign {cout,s}=a+b+cin;
endmodule



module adder2(a,b,cin,cout,s);
parameter n=8;
input [n-1:0] a,b;
input cin;
output [n-1:0] s;
output cout;

wire [n-1:0] p= a^b;
wire [n-1:0] g= a&b;
wire [n:0] c={g|(p&c[n-1:0]), cin};
assign s=p^c[n-1:0];
assign cout =c[n];
endmodule
 

module test;
parameter n = 8;
reg [n-1:0]a,b,cin;
wire [n-1:0] sum1,sum2;
wire cout1,cout2;

adder1 #(n) inst1(a,b,cin,cout1,sum1);

adder2 #(n) inst1(a,b,cin,cout2,sum2);
initial
begin
a= ; // give different values of a and b in this way
b= ;
#100
a = ;
b= ;
#200(time delay)
.
.
.

end
endmodule

- - - Updated - - -

refer http://www.asic-world.com/verilog/art_testbench_writing2.html
 

Test bench rule : ALL STATES HAVE TO BE VERIFIED. If you have n inputs so all the 2to the power n inputs have to analysed. for writing test bench you can see any text book on VHDL
 

Thank you... but I made testbench like this but I got no data... What is wrong?


module test;
parameter n = 8;
reg [n-1:0]a,b,cin;
wire [n-1:0] sum1,sum2;
wire cout1,cout2;

adder1 #(n) inst1(a,b,cin,cout1,sum1);

adder2 #(n) inst2(a,b,cin,cout2,sum2);

initial
begin
a= 8'b11111111;
b= 8'b10001101;

#100

a= 8'b11111111;
b= 8'b11101101;

#100

a= 8'b11111111;
b= 8'b10011101;

#100

a= 8'b11110101;
b= 8'b10001101;

#100

a= 8'b11100110;
b= 8'b10100101;


end
endmodule
 

Not that I would know what the problem is without you specifying what the problem is ... :p It does exactly what it does, so there is no problem.

Other than that, you forgot to initialize cin, so you are bound to get unknowns. As in big fat red X's in your testbench result.

Hint for next question: 1) post a screenshot of the testbench results. 2) define the correct result you are looking for. Usually " it doesn't work!" translates to "it works just fine, just not how I expect". So it's useful to actually state what you expect it to be and the result you're getting differs...

Short version: Add a "cin = 0;" to your initial block.

Also, please use code tags. :) See:
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top