Reputation: 303
I want to implement HA (half Adder), and I have a problem. When I click simulate, it displays this warning:
Warning: Instantiation depth of '/TM_HA/HA/HA/HA .....This might indicate a recursive instantiation.
I don't know what's going on.
HA.v
`timescale 1ns/1ns
module HA(a,b,c,sum,cout);
input a,b,c;
output sum,cout;
wire e1,e2,e3;
xor(e1,a,b);
and(e2,a,b);
and(e3,e1,c);
xor(sum,e1,c);
or(cout,e3,e2);
endmodule
TM_HA.v
`timescale 1ns/1ns
module TM_HA;
reg A,B,Cin;
wire Sum,Cout;
TM_HA HA(.a(A), .b(B), .c(Cin), .sum(Sum), .cout(Cout));
parameter t = 200;
initial
begin
#(2*t)
A = 1'b0;
B = 1'b0;
Cin = 1'b0;
#t
A = 1'b0;
B = 1'b0;
Cin = 1'b1;
....
#t
$stop;
end
endmodule
Upvotes: 2
Views: 1547
Reputation: 1181
As mentioned in the warning ModelSim is giving you: you are performing a recursive instantiation. Lets have a look at the first couple of lines of your TM_HA
module:
module TM_HA;
reg A,B,Cin;
wire Sum,Cout;
TM_HA HA(.a(A), .b(B), .c(Cin), .sum(Sum), .cout(Cout));
Within the module TM_HA
, you are creating an instance called HA
of the parent module TM_HA
. This is a recursive call, since that instance will again create another instance of TM_HA
.
To actually instantiate your HA
module, you should do (something like) this:
HA HA_inst (.a(A), .b(B), .c(Cin), .sum(Sum), .cout(Cout));
Upvotes: 2
Reputation: 14007
As you warning says, you have a recursive instantiation. This line
TM_HA HA(.a(A), .b(B), .c(Cin), .sum(Sum), .cout(Cout));
inside module TM_HA
means
instantiate module
TM_HA
and give it the instance nameHA
.
As that line is inside module TM_HA
, you are instantiating module TM_HA
inside itself - a recursive instantiation. At some point, between zero and infinity levels of hierarchy, you simulator gives up.
Upvotes: 0