MillisCounter.v 603 B

1234567891011121314151617181920212223242526272829303132
  1. // 32 bit millisecond counter starting from reset
  2. module MillisCounter(
  3. input clk,
  4. input reset,
  5. output reg [31:0] millis = 32'd0
  6. );
  7. reg [15:0] delayCounter = 16'd0; // counter for timing 1 ms
  8. always @(posedge clk)
  9. begin
  10. if (reset)
  11. begin
  12. millis <= 32'd0;
  13. delayCounter <= 16'd0;
  14. end
  15. else
  16. begin
  17. if (delayCounter == 16'd49999)
  18. begin
  19. delayCounter <= 16'd0;
  20. millis <= millis + 1'b1;
  21. end
  22. else
  23. begin
  24. delayCounter <= delayCounter + 1'b1;
  25. end
  26. end
  27. end
  28. endmodule