misc.txt 670 B

12345678910111213141516171819202122232425262728293031323334353637
  1. `timescale 1ns / 1ps
  2. /**
  3. * counter: a generic clearable up-counter
  4. */
  5. module counter
  6. #(parameter WIDTH=64)
  7. (
  8. input clk,
  9. input ce,
  10. input arst_n,
  11. output reg [WIDTH-1:0] q
  12. );
  13. // some child
  14. clock_buffer #(WIDTH) buffer_inst (
  15. .clk(clk),
  16. .ce(ce),
  17. .reset(arst_n)
  18. );
  19. // Simple gated up-counter with async clear
  20. always @(posedge clk or negedge arst_n) begin
  21. if (arst_n == 1'b0) begin
  22. q <= {WIDTH {1'b0}};
  23. end
  24. else begin
  25. q <= q;
  26. if (ce == 1'b1) begin
  27. q <= q + 1;
  28. end
  29. end
  30. end
  31. endmodule