[hdl] add a counter design which is triggered by negative edges

This commit is contained in:
tangxifan 2022-05-09 16:41:21 +08:00
parent 812af4f722
commit 9c7868cfab
2 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,29 @@
///////////////////////////////////////////
// Functionality: Counter triggered at negative edge with asynchronous reset
// Author: Xifan Tang
////////////////////////////////////////
module counter (
clkn,
reset,
result
);
input clkn;
input reset;
output [7:0] result;
reg [7:0] result;
initial begin
result <= 0;
end
always @(negedge clkn or posedge reset)
begin
if (reset)
result = 0;
else
result = result + 1;
end
endmodule

View File

@ -0,0 +1,25 @@
module counter_tb;
reg clk, reset;
wire [7:0] result;
counter DUT(
.clkn(clk),
.reset(reset),
.result(result)
);
initial begin
#0 reset = 1'b1; clk = 1'b0;
#100 reset = 1'b0;
end
always begin
#10 clk = ~clk;
end
initial begin
#5000 $stop;
end
endmodule