LEDvisualizer.v 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Visualizes activity using a LED
  2. // Works by setting a minimum amount of cycles that the LED has to stay on before turning off
  3. module LEDvisualizer
  4. #(parameter MIN_CLK = 10000)
  5. (
  6. input clk,
  7. input reset,
  8. input activity,
  9. output LED
  10. );
  11. localparam s_idle = 0;
  12. localparam s_busy = 1;
  13. reg [31:0] counterValue = 32'd0; // 32 bits for timerValue
  14. reg [1:0] state = s_idle; // state of module
  15. assign LED = !(state == s_busy); // inverted because led is active low
  16. always @(posedge clk)
  17. begin
  18. if (reset)
  19. begin
  20. counterValue <= 32'd0;
  21. state <= s_idle;
  22. end
  23. else
  24. begin
  25. case (state)
  26. s_idle:
  27. begin
  28. if (activity)
  29. begin
  30. counterValue <= MIN_CLK;
  31. state <= s_busy;
  32. end
  33. end
  34. s_busy:
  35. begin
  36. if (activity)
  37. begin
  38. counterValue <= MIN_CLK;
  39. end
  40. else
  41. begin
  42. if (counterValue == 32'd0)
  43. begin
  44. state <= s_idle;
  45. end
  46. else
  47. begin
  48. counterValue <= counterValue - 1'b1;
  49. end
  50. end
  51. end
  52. endcase
  53. end
  54. end
  55. endmodule