[hdl] add a counter design which is triggered by negative edges
This commit is contained in:
parent
812af4f722
commit
9c7868cfab
|
@ -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
|
|
@ -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
|
Loading…
Reference in New Issue