How Can I Connect Multiple Modules in Verilog?

  • Thread starter Thread starter david90
  • Start date Start date
  • Tags Tags
    Language
Click For Summary
To connect multiple modules in Verilog, create a top-level module that instantiates each module and connects them using the "wire" keyword. The top-level module serves as a fourth module that links the outputs of the lower modules to their inputs. For example, one module's output can be wired to another's input, facilitating communication between them. When integrating outputs from multiple modules into an AND gate, declare wires for each output and connect them to the AND gate instance. The same method applies when linking multiple ALUs, ensuring careful management of carry signals.
david90
Messages
311
Reaction score
2
Say I have 3 modules and I want them to connect them together (make them work together. Ie, output of one module would go into another etc.), how would I do this in verilog?
 
Engineering news on Phys.org
Create a top-level module that instantiates each of the three modules, and connects them with wires.

- Warren
 
instantiates ?[?] [b(] U mean create a 4th module that connects the 3 modules together with wire? Can u elaborate on the "wire" part?
 
Last edited:
Yes, make a top level module which creates instances of the three lower modules.

The "wire" keyword, surprisingly, makes wires.

Here's a simple example with two modules, sub_a and sub_b, and a toplevel module which connects their inputs and outputs.

module sub_a ( in, out );

input in;
output out;

...

endmodule

module sub_b ( in, out );

input in;
output out;

...

endmodule

module toplevel;

wire one;
wire two;

sub_a sub_a_instance ( .in(one), .out(two) );

sub_b sub_b_instance ( .in(two), .out(one) );

endmodule
 
My interpretation of ur code sub_a input is wired to sub_b output. Am I right?
 
Yup, it just wires the inputs of each to outputs of the other. Of course the names are not exactly well-chosen. I just wanted to demonstrate the concept.

- Warren
 
Thanks you've cleared it up alot. I have another problem. I'm trying to write a code for a chip that has 3 modules and the output of those three modules are connected to an AND gate. How do I go about doing that??
 
...

wire sub_1_output;
wire sub_2_output;
wire sub_3_output;

wire and_output;

and and_gate (and_output, sub_1_output, sub_2_output, sub_3_output);

...

- Warren
 
now that i have a one bit ALU, how would I link 4 of them together for a 4bit ALU? same method?
 
  • #10
yep, just be careful not to mix up the carry signals...
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
2K
Replies
8
Views
2K
  • · Replies 15 ·
Replies
15
Views
5K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 9 ·
Replies
9
Views
5K
Replies
37
Views
6K
Replies
2
Views
7K
Replies
5
Views
2K
  • · Replies 28 ·
Replies
28
Views
5K
  • · Replies 4 ·
Replies
4
Views
3K