基础计数模块对应的实际code如下:
module CNT(
input wire clk,
input wire rst_n,
output reg [2:0] OUT
);
reg [15:0] CNT;
parameter CNT_MAX = 16'd49999;
always @(posedge clk or negedge rst_n)begin
if( rst_n == 1'b0 )begin
CNT <= 16'b0;
OUT <= 3'b0;
end
else if( CNT == CNT_MAX ) begin
CNT <= 16'b0;
OUT <= OUT + 1'b1;
end
else begin
CNT <= CNT + 1'b1;
end
end
endmodule