E
e.hanrahan27
Hi I am very new to digital design and am using Verilog to code some modules.
The following is the module code for a Counter I designed using Verilog.
//
module counter (clk,rst,q);
input clk,rst;
output [2:0] q;
reg [2:0] q;
always @ (posedge clk)
begin
if (rst==0)
q <= 0;
else
q <= q+1;
end
endmodule
//
In the testbench I set (rst = 0) for the first 10ns and then (rst = 1) for the rest. The following is the testbench code.
module countertest;
reg clk, rst;
wire q;
counter c1(clk,rst,q);
//
always
begin
#5 clk = ~clk;
end
initial
begin
clk = 0;
rst = 0;
#10 rst =1;
end
endmodule
//
my question is this - what does the command (q <= q + 1) do in this example. The simulation shows that it will start to cause the q output to cycle between low and high every 10ns. I want to know why this is?
The following is the module code for a Counter I designed using Verilog.
//
module counter (clk,rst,q);
input clk,rst;
output [2:0] q;
reg [2:0] q;
always @ (posedge clk)
begin
if (rst==0)
q <= 0;
else
q <= q+1;
end
endmodule
//
In the testbench I set (rst = 0) for the first 10ns and then (rst = 1) for the rest. The following is the testbench code.
module countertest;
reg clk, rst;
wire q;
counter c1(clk,rst,q);
//
always
begin
#5 clk = ~clk;
end
initial
begin
clk = 0;
rst = 0;
#10 rst =1;
end
endmodule
//
my question is this - what does the command (q <= q + 1) do in this example. The simulation shows that it will start to cause the q output to cycle between low and high every 10ns. I want to know why this is?