Advertisement
Xisepe

traffic light

Jun 1st, 2022
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. `timescale 1ns / 1ps
  2. //////////////////////////////////////////////////////////////////////////////////
  3. // Company:
  4. // Engineer:
  5. //
  6. // Create Date: 12.05.2022 09:34:38
  7. // Design Name:
  8. // Module Name: traffic_light
  9. // Project Name:
  10. // Target Devices:
  11. // Tool Versions:
  12. // Description:
  13. //
  14. // Dependencies:
  15. //
  16. // Revision:
  17. // Revision 0.01 - File Created
  18. // Additional Comments:
  19. //
  20. //////////////////////////////////////////////////////////////////////////////////
  21.  
  22.  
  23. module top(
  24. input clk,
  25. input reset,
  26. input night_mode,
  27. output red_v,
  28. output yellow_v,
  29. output green_v,
  30. output red_h,
  31. output yellow_h,
  32. output green_h
  33. );
  34.  
  35. traffic_light light(.clk(clk), .reset(reset), .night_mode(~night_mode),
  36. .red_h(red_h), .yellow_h(yellow_h), .green_h(green_h),
  37. .red_v(red_v), .yellow_v(yellow_v), .green_v(green_v));
  38.  
  39. endmodule
  40.  
  41. //пока без мерцания
  42. module traffic_light(
  43. input clk,
  44. input reset,
  45. input night_mode,
  46. output logic red_h,
  47. output logic yellow_h,
  48. output logic green_h,
  49. output logic red_v,
  50. output logic yellow_v,
  51. output logic green_v
  52. );
  53. enum logic[2:0] {
  54. RED = 3b'001,
  55. YELLOW_FORWARD = 3b'010,
  56. YELLOW_BACK = 3b'011,
  57. GREEN = 3b'100
  58. } COLOR;
  59.  
  60. integer i;
  61. integer sec;
  62.  
  63. always_ff @(posedge clk) begin
  64. if (!reset) begin
  65. COLOR = RED;
  66. sec <= 0;
  67. i <= 0;
  68. end;
  69.  
  70. i <= i + 1;
  71. if (i == 12000000) begin
  72. i <= 0;
  73. sec <= sec + 1;
  74. end;
  75.  
  76. if (sec == 3) begin
  77. sec <= 0;
  78. case(COLOR)
  79. RED: begin
  80. red_v <= 1;
  81. red_h <= 0;
  82. yellow_v <= 0;
  83. yellow_h <= 0;
  84. green_v <= 0;
  85. green_h <= 1;
  86. COLOR <= YELLOW_FORWARD;
  87. end;
  88.  
  89. YELLOW_FORWARD: begin
  90. red_v <= 0;
  91. red_h <= 0;
  92. yellow_v <= 1;
  93. yellow_h <= 1;
  94. green_v <= 0;
  95. green_h <= 0;
  96. COLOR <= GREEN;
  97. end;
  98.  
  99. GREEN: begin
  100. red_v <= 0;
  101. red_h <= 1;
  102. yellow_v <= 0;
  103. yellow_h <= 0;
  104. green_v <= 1;
  105. green_h <= 0;
  106. COLOR <= YELLOW_BACK;
  107. end;
  108.  
  109. YELLOW_BACK: begin
  110. red_v <= 0;
  111. red_h <= 0;
  112. yellow_v <= 1;
  113. yellow_h <= 1;
  114. green_v <= 0;
  115. green_h <= 0;
  116. COLOR <= RED;
  117. end;
  118.  
  119. endcase
  120.  
  121. end;
  122.  
  123.  
  124. end;
  125.  
  126.  
  127.  
  128.  
  129.  
  130. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement