// Simple counter module `timescale 1ns/1ps module counter #(parameter WIDTH = 8, parameter int DEPTH = 16) ( input wire clk, input wire rst_n, // async reset output logic [WIDTH-1:0] count, output logic overflow ); // internal signals logic [WIDTH-1:0] next_count; wire enable; assign next_count = count + 1'b1; assign overflow = (count == {WIDTH{1'b1}}) && enable; always_ff @(posedge clk or negedge rst_n) begin if (!rst_n) begin count <= '0; end else if (enable) count <= next_count; else count <= count; end always_comb begin case (count[1:0]) 2'b00: dbg = 4'd0; 2'b01, 2'b10: dbg = 4'd1; default: dbg = 4'd2; endcase end submod #(.W(WIDTH), .D(DEPTH)) u_sub (.clk(clk), .rst_n(rst_n), .data_out(data), .unused()); endmodule : counter