Guest User

Untitled

a guest
Nov 23rd, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module traffic (
  2.     clock,
  3.     red_a, green_a, yellow_a,
  4.     red_b, green_b, yellow_b
  5. );
  6.  
  7.     input clock;
  8.     output red_a, green_a, yellow_a, red_b, green_b, yellow_b;
  9.  
  10.     reg o_red_a = 0;
  11.     reg o_green_a = 1;
  12.     reg o_yellow_a = 0;
  13.     reg o_red_b = 1;
  14.     reg o_green_b = 0;
  15.     reg o_yellow_b  = 0;
  16.  
  17.     reg [7:0] counter = 0;
  18.  
  19.     always @(posedge clock) begin
  20.         counter = counter + 1;
  21.        
  22.         if (counter == 20) begin
  23.             o_green_a = !o_green_a;
  24.             o_yellow_a = !o_yellow_a;
  25.         end else if (counter == 40) begin
  26.             o_red_b = !o_red_b;
  27.             o_green_b = !o_green_b;
  28.             o_red_a = !o_red_a;
  29.             o_yellow_a = !o_yellow_a;
  30.         end else if (counter == 60) begin
  31.             o_green_a = !o_green_a;
  32.             o_yellow_a = !o_yellow_a;          
  33.         end else if (counter == 80) begin
  34.             o_red_b = !o_red_b;
  35.             o_green_b = !o_green_b;
  36.             o_red_a = !o_red_a;
  37.             o_yellow_a = !o_yellow_a;
  38.         end
  39.        
  40.         if (counter == 81) begin
  41.             counter = 0;
  42.         end
  43.     end
  44.  
  45.     assign green_a = o_green_a;
  46.     assign yellow_a = o_yellow_a;
  47.     assign red_a = o_red_a;
  48.     assign green_b = o_green_b;
  49.     assign yellow_b = o_yellow_b;
  50.     assign red_b = o_red_b;
  51. endmodule
Add Comment
Please, Sign In to add comment