Instantiate module in verilog

OP #7611280
Rate this post
• ▲ useful
▼ not useful

Hi guys i have 2 module. Fisrt module is generating clock signal

module ClockGenerator( output reg clk );

// Define clock period parameters parameter CLK_PERIOD = 10; // Define the clock period in simulation time units

// Initialize clock initial begin clk = 1'b0; // Start with the clock low end

// Toggle the clock signal at every half of the period always #((CLK_PERIOD/2)) clk = ~clk;

endmodule

Secound module is counter to 16 then reset to 0 when it reach 16

module CounterAndReset( output reg [3:0] count, input wire clk, input wire reset );

// Define the maximum count value parameter MAX_COUNT = 4'b1111;

// Initialize count always @(posedge clk or posedge reset) begin if (reset) begin count <= 4'b0000; // Reset count to 0 end else begin if (count == MAX_COUNT) begin count <= 4'b0000; // Reset count to 0 when it reaches MAX_COUNT end else begin count <= count + 1; // Increment count end end end

endmodule

I want to ask is how to combine these to module together. Thanks all

#7611400
Rate this post
• ▲ useful
▼ not useful

Thiều Quang A. wrote:

I want to ask is how to combine these to module together.

I would use a top level module (top.v) and there you can instantiate both sub modules.

Untested example:

1
module top;
2

3
  reg main_clk;
4
  reg main_reset = 0;
5
  wire [3:0] main_count;
6

7
  ClockGenerator inst_1 (
8
    .clk(main_clk)
9
  );
10

11
  CounterAndReset inst_2 (
12
    .clk(main_clk),
13
    .reset(main_reset),
14
    .count(main_count)
15
  );
16
 
17
endmodule

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [vhdl]VHDL-Code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.