Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

What will happen if I declare wire and port with same name in verilog

Status
Not open for further replies.

mail4idle2

Full Member level 4
Joined
Oct 20, 2012
Messages
200
Helped
20
Reputation
40
Reaction score
19
Trophy points
1,298
Activity points
2,173
What will happen if I declare wire and port with same name in verilog ?
Please refer to below example for question (clk1 is declared as port and wire )

module test (
clk1,
rstn1,
out1 );

input clk1;
input rstn1;
output out1;

wire clk1;

counter U0_counter (
.clk1 (clk1),
.rstn1 (rstn1),
.out1 (out1) );

endmodule




module counter (
clk1,
rstn1,
out1
);

input clk1;
input rstn1;
output out1;

reg [4:0] counter;

always @ (posedge clk1 or negedge rstn1)
begin
if(~rstn1)
begin
counter <= 5'd30;
end
else
begin
if (counter == 5'd0)
begin
counter <= 5'd30;
end
else
begin
counter <= counter - 2'd2;
end

end
end

assign out1 = counter[0];

endmodule
 

dave_59

Advanced Member level 3
Joined
Dec 15, 2011
Messages
815
Helped
361
Reputation
726
Reaction score
354
Trophy points
1,353
Location
Fremont, CA, USA
Activity points
6,457
Verilog implicitly connects a port to a signal with the same name. If you don't declare the signal, Verilog implicitly creates a wire for you with the same name as the port, as is the case with rstn1 and out1.

I highly recommend using the Verilog-2001 way of declaring ports and signals together so that each name only appears once.

Code:
module test (
 input wire clk1,
 input rstn1,
 output out1
);

 counter U0_counter (
                           .clk1 (clk1),
                           .rstn1 (rstn1),
                           .out1 (out1) );
endmodule
wire is still the default kind of signal, so it is not needed here, or you can put wire on the other ports to make everything explicit.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top