Verilog language question

  • Thread starter david90
  • Start date
  • #1
david90
309
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?
 

Answers and Replies

  • #2
chroot
Staff Emeritus
Science Advisor
Gold Member
10,275
40
Create a top-level module that instantiates each of the three modules, and connects them with wires.

- Warren
 
  • #3
david90
309
2
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:
  • #4
chroot
Staff Emeritus
Science Advisor
Gold Member
10,275
40
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
 
  • #5
david90
309
2
My interpretation of ur code sub_a input is wired to sub_b output. Am I right?
 
  • #6
chroot
Staff Emeritus
Science Advisor
Gold Member
10,275
40
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
 
  • #7
david90
309
2
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??
 
  • #8
chroot
Staff Emeritus
Science Advisor
Gold Member
10,275
40
...

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
 
  • #9
david90
309
2
now that i have a one bit ALU, how would I link 4 of them together for a 4bit ALU? same method?
 
  • #10
Guybrush Threepwood
520
1
yep, just be careful not to mix up the carry signals.....
 

Suggested for: Verilog language question

  • Last Post
Replies
12
Views
380
  • Last Post
Replies
13
Views
260
  • Last Post
Replies
2
Views
45
  • Last Post
Replies
19
Views
165
  • Last Post
Replies
6
Views
182
  • Last Post
Replies
5
Views
388
Replies
10
Views
409
Replies
4
Views
206
Replies
2
Views
258
Replies
6
Views
353
Top