Ciro Santilli OurBigBook.com  Sponsor 中国独裁统治 China Dictatorship 新疆改造中心、六四事件、法轮功、郝海东、709大抓捕、2015巴拿马文件 邓家贵、低端人口、西藏骚乱
verilog/counter.v
/* https://cirosantilli.com/verilog */
module counter #(
    parameter BITS = 1
) (
    /* All the input ports should be wires. */
    input wire clock,
    input wire reset,
    input wire enable,
    output reg [BITS-1:0] out
);
    /* Do this on every positive edge. */
    always @ (posedge clock) begin
        if (reset == 1'b1) begin
            out <= {BITS{1'b0}};
        end
        else if (enable == 1) begin
            out <= out + 1;
        end
    end
endmodule