Guest User

Untitled

a guest
Jul 18th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. `timescale 1ns / 1ps
  2. //////////////////////////////////////////////////////////////////////////////////
  3. // Company:
  4. // Engineer:
  5. //
  6. // Create Date:    08:57:32 03/27/2012
  7. // Design Name:
  8. // Module Name:    thunderbolt
  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. module thunderbolt(
  22.     input left,
  23.     input right,
  24.     input reset,
  25.     input clk,
  26.     output reg [5:0] lights
  27.     );
  28.  
  29. parameter lights_off = 2'b00;
  30. parameter light_1 =    2'b01;
  31. parameter light_2 =    2'b10;
  32. parameter light_3 =    2'b11;
  33.  
  34. reg [1:0] state_left, next_left_state, state_right, next_right_state;
  35.  
  36. initial
  37.         begin
  38.                 state_left = lights_off;
  39.                 state_right = lights_off;
  40.                 next_left_state = lights_off;
  41.                 next_right_state = lights_off;
  42.         end
  43.  
  44. wire clk_en;
  45.  
  46. clk_div clock(.clk(clk), .reset(reset), .clk_en(clk_en));
  47.  
  48. always @(posedge clk_en, posedge reset)
  49.         begin
  50.                 if (reset == 1)
  51.                         begin
  52.                                 state_left <= lights_off;
  53.                                 state_right <= lights_off;
  54.                         end
  55.                 else
  56.                         begin
  57.                                 state_left <= next_left_state;
  58.                                 state_right <= next_right_state;
  59.                         end
  60.         end
  61.  
  62.  
  63. always @(posedge clk_en)
  64.         begin
  65.                 if (left == 1 && state_left == lights_off)
  66.                         next_left_state <= light_1;
  67.  
  68.                 case (state_left)
  69.                         light_1: next_left_state <= light_2;
  70.                         light_2: next_left_state <= light_3;
  71.                         default: next_left_state <= lights_off;
  72.                 endcase
  73.  
  74.                 if (right == 1 && state_right == lights_off)
  75.                         next_right_state <= light_1;
  76.  
  77.                 case (state_right)
  78.                         light_1: next_right_state <= light_2;
  79.                         light_2: next_right_state <= light_3;
  80.                         default: next_right_state <= lights_off;
  81.                 endcase
  82.         end
  83.  
  84. //output
  85. always @(*)
  86.         begin
  87.                 case(state_left)
  88.                         light_1:   lights[5:3] <= 3'b001;
  89.                         light_2:   lights[5:3] <= 3'b011;
  90.                         light_3:   lights[5:3] <= 3'b111;
  91.                         default: lights[5:3] <= 3'b000;
  92.                 endcase
  93.  
  94.                 case(state_right)
  95.                         light_1:   lights[2:0] <= 3'b100;
  96.                         light_2:   lights[2:0] <= 3'b110;
  97.                         light_3:   lights[2:0] <= 3'b111;
  98.                         default: lights[2:0] <= 3'b000;
  99.                 endcase
  100.         end
  101. endmodule
Add Comment
Please, Sign In to add comment