From 0de3f55e7122e1103291ce34882b64734967e3a4 Mon Sep 17 00:00:00 2001 From: xingchen <1098756313@qq.com> Date: Fri, 25 Sep 2026 11:57:23 +0800 Subject: [PATCH] feat: add rtl/timeout_counter.v --- rtl/timeout_counter.v | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 rtl/timeout_counter.v diff --git a/rtl/timeout_counter.v b/rtl/timeout_counter.v new file mode 100644 index 0000000..c3a08fa --- /dev/null +++ b/rtl/timeout_counter.v @@ -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