一、 counter.v
module counter
(
input wire sclk,
input wire rst_n,
output wire [9:0] cnt
);
reg [9:0] cnt_r = 0;
always@(posedge sclk or negedge rst_n)
if(rst_n == 1'b0)
cnt_r <= 10'd0;
else
cnt_r <= cnt_r +1'b1;
assign cnt = cnt_r;
endmodule
*/
endmodule
二、 counter_test.v
`timescale 1ns/100ps
module counter_test();
reg sclk;
reg rst_n;
wire [9:0] cnt;
initial
begin
sclk <= 1'b0;
rst_n <= 1'b1;
#100
rst_n <= 1'b0;
#100
rst_n <= 1'b1;
end
always #10 sclk = ~sclk;
counter counter_inst
(
.sclk(sclk),
.rst_n(rst_n),
.cnt(cnt)
);
endmodule