feat: add rtl/timeout_counter.v

This commit is contained in:
2026-09-25 11:57:23 +08:00
parent dc4f037849
commit 0de3f55e71

14
rtl/timeout_counter.v Normal file
View File

@@ -0,0 +1,14 @@
module timeout_counter #(
parameter WIDTH = 16,
parameter LIMIT = 1000
) (
input wire clk, input wire rst_n, input wire clear,
output reg timeout, output reg [WIDTH-1:0] count
);
always @(posedge clk or negedge rst_n) begin
if (!rst_n) begin count <= 0; timeout <= 0; end
else if (clear) begin count <= 0; timeout <= 0; end
else if (count >= LIMIT) begin count <= LIMIT; timeout <= 1; end
else begin count <= count + 1'b1; timeout <= 0; end
end
endmodule