Here ways you can do this:
- Add an ID input port
When this port is tied to a constant, at power-up the device can detect its ID. Technically you could do dynamic ID with this, but usually you just connect the port to a constant value. This is the most flexible option, especially if you want your end product to be used as a configurable component.module A ( /* your_ports */, input [1:0] ID ); /* ... code ... */ endmodule module top; A inst0 ( .ID(2'd0), .* ); A inst1 ( .ID(2'd1), .* ); A inst2 ( .ID(2'd2), .* ); A inst3 ( .ID(2'd3), .* ); endmodule
- Create an ID parameter
Simulate to the ID input port except that the value is hard coded and the instance knows the ID value at compile time, before simulation or device power-up. Unique parameter values generate unique modules. If the ID is 0, it will be physically different than an ID with 1.module A #(parameter ID) ( /* your_ports */ ); /* ... code ... */ endmodule module top; A #( .ID(0) ) inst0 ( .* ); A #( .ID(1) ) inst1 ( .* ); A #( .ID(2) ) inst2 ( .* ); A #( .ID(3) ) inst3 ( .* ); endmodule