// modulo n counter implementation with localparam
module mod_n_counter_10bit
  // parameters to pass at instantiation 
# (parameter N = 10)
(
  // module inputs
  input CLK,
  input RST,
  input EN,
  // module outputs
  output reg [9:0] Q,
  output TC
);

localparam TERMINAL_COUNT = N-1;

always @(posedge CLK or posedge RST) begin
  if (RST) begin
    Q <= 10'd0;
  end else if (EN) begin
    if (Q == TERMINAL_COUNT) begin
      Q <= 10'd0;
    end else begin
      Q<= Q + 10'd1;
    end
  end else begin
    Q <= Q;
  end
end

assign TC = (Q == TERMINAL_COUNT);

endmodule