feat: ✨ counter with enable
This commit is contained in:
parent
c6bdc199f3
commit
5ebded9372
2 changed files with 37 additions and 0 deletions
14
02-counter_with_enable/counter_with_enable.v
Normal file
14
02-counter_with_enable/counter_with_enable.v
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
module counter_with_enable(out, enable, clk, reset);
|
||||||
|
parameter WIDTH = 8;
|
||||||
|
input enable, clk, reset;
|
||||||
|
output[WIDTH-1:0] out;
|
||||||
|
reg[WIDTH-1:0] out;
|
||||||
|
|
||||||
|
always @(posedge clk)begin
|
||||||
|
if (reset) begin
|
||||||
|
out <= 8'b0;
|
||||||
|
end else if(enable) begin
|
||||||
|
out <= out + 1;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
endmodule
|
23
02-counter_with_enable/counter_with_enable_tb.v
Normal file
23
02-counter_with_enable/counter_with_enable_tb.v
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
module counter_with_enable_tb;
|
||||||
|
parameter WIDTH = 8;
|
||||||
|
reg reset = 0;
|
||||||
|
reg enable = 0;
|
||||||
|
initial begin
|
||||||
|
#17 reset = 1;
|
||||||
|
#11 enable = 1;
|
||||||
|
#17 reset = 0;
|
||||||
|
#11 enable = 1;
|
||||||
|
#17 reset = 1;
|
||||||
|
#17 $stop;
|
||||||
|
end
|
||||||
|
|
||||||
|
reg clk = 0;
|
||||||
|
always begin
|
||||||
|
#1 clk = 0;
|
||||||
|
#1 clk = 1;
|
||||||
|
end
|
||||||
|
wire[WIDTH-1:0] output_wire;
|
||||||
|
counter_with_enable c1(output_wire, enable, clk, reset);
|
||||||
|
initial
|
||||||
|
$monitor("Time = %t, Value = %h (%0d)", $time, output_wire, output_wire);
|
||||||
|
endmodule
|
Loading…
Add table
Add a link
Reference in a new issue