You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.6 KiB

2 years ago
  1. `timescale 1ns/1ns
  2. module led_test
  3. (
  4. sys_clk, // system clock 50Mhz on board
  5. rst_n, // reset ,low active
  6. led // LED,use for control the LED signal on board
  7. );
  8. input sys_clk;
  9. input rst_n;
  10. output [3:0] led;
  11. //define the time counter
  12. reg [31:0] timer;
  13. reg [3:0] led;
  14. always @(posedge sys_clk or negedge rst_n)
  15. begin
  16. if (~rst_n)
  17. timer <= 32'd0; // when the reset signal valid,time counter clearing
  18. else if (timer == 32'd199_9999_9) //4 seconds count(50M*4-1=199999999)
  19. timer <= 32'd0; //count done,clearing the time counter
  20. else
  21. timer <= timer + 1'b1; //timer counter = timer counter + 1
  22. end
  23. always @(posedge sys_clk or negedge rst_n)
  24. begin
  25. if (~rst_n)
  26. led <= 4'b0000; //when the reset signal active
  27. else if (timer == 32'd49_999_9) //time counter count to 1st sec,LED1 Extinguish
  28. led <= 4'b0001;
  29. else if (timer == 32'd99_999_9) //time counter count to 2nd sec,LED2 Extinguish
  30. begin
  31. led <= 4'b0010;
  32. end
  33. else if (timer == 32'd149_999_9) //time counter count to 3nd sec,LED3 Extinguish
  34. led <= 4'b0100;
  35. else if (timer == 32'd199_999_9) //time counter count to 4nd sec,LED4 Extinguish
  36. led <= 4'b1000;
  37. end
  38. endmodule