Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
68
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: 14.04.2018 18:58:29
  7. // Design Name:
  8. // Module Name: FSM
  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 FSM(input L, R, clk, rst, output reg [5:0] LIGHTS);
  24.  
  25. localparam S0=0, S1=1, S2=2, S3=3, S4=4, S5=5, S6=6;
  26. reg [2:0] state_p, // Current state
  27. state_n; // Next state
  28. parameter IDLE = 6'b000000, // Output-coded state assignment
  29.           L3 = 6'b111000, // and tail-light patterns
  30.           L2 = 6'b011000,
  31.           L1 = 6'b001000,
  32.           R1 = 6'b000100,
  33.           R2 = 6'b000110,
  34.           R3 = 6'b000111;
  35.          
  36. clk_div clk_div(clk, rst, clk_en);
  37.  
  38. always @(clk_en) begin
  39.  if (rst) begin
  40.  state_p <= S0; // Initial state
  41.  end else begin
  42.  state_p <= state_n;
  43.  end
  44. end
  45.  
  46. always@(*) begin
  47.  // state_n <= state_p;
  48.  case (state_p)
  49.  
  50.  S0: begin
  51.     TL <= 3'b000;
  52.     TR <= 3'b000;
  53.    
  54.     if (L == 1) begin
  55.     state_n <= S1;
  56.     end
  57.    
  58.     else if (R == 1) begin
  59.     state_n <= S4;
  60.     end
  61.    
  62.     end
  63.    
  64.  S1: begin  
  65.     TL <= 3'b001;
  66.     state_n <= S2;
  67.     end
  68.    
  69.  S2: begin
  70.     TL <= 3'b011;
  71.     state_n <= S3;
  72.     end
  73.    
  74.  S3: begin
  75.     TL <= 3'b111;
  76.     state_n <= S0;
  77.     end
  78.    
  79.  S4: begin
  80.     TR <= 3'b100;
  81.     state_n <= S5;
  82.     end
  83.    
  84.  S5: begin
  85.     TR <= 3'b110;
  86.     state_n <= S6;
  87.     end
  88.    
  89.  S6: begin
  90.     TR <= 3'b111;
  91.     state_n <= S0;
  92.     end
  93.    
  94.  default: begin
  95.     TL <= 3'b000;
  96.     TR <= 3'b000;
  97.     end
  98.  
  99.  endcase
  100. end
  101.  
  102. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement