1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
`timescale 1ns / 100ps module timer ( input clock, input count, input count_clear, output reg [15:0] tim ); always @ (posedge clock) begin if (count_clear) tim <= 0; else if (count) tim <= tim + 16'b1; end endmodule