Advertisement
Guest User

Untitled

a guest
May 14th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module fsm_zad1
  2. (
  3.     input w,clk,aclr,
  4.     output reg z,
  5.      output reg [8:0] y
  6. );
  7.     //Zdefiniowanie stanów//
  8. localparam [8:0]    
  9.    A = 9'b000000001,  
  10.    B = 9'b000000010,
  11.    C = 9'b000000100,
  12.    D = 9'b000001000,
  13.    E = 9'b000010000,
  14.    F = 9'b000100000,
  15.    G = 9'b001000000,
  16.    H = 9'b010000000,
  17.    I = 9'b100000000;
  18.  
  19. reg [8:0] current = A, next;
  20. always @(*)
  21. begin
  22. y = current;
  23.  
  24.   case (current)
  25.     A:  if (!w) next = B;   else next = F;
  26.     B:  if (!w) next = C;   else next = F;
  27.     C:  if (!w) next = D;   else next = F;
  28.     D:  if (!w) next = E;   else next = F;
  29.     E:  if (!w) next = E;   else next = F;
  30.     F:  if (!w) next = B;   else next = G;
  31.     G:  if (!w) next = B;   else next = H;
  32.     H:  if (!w) next = B;   else next = I;
  33.     I:  if (!w) next = B;   else next = I;
  34.     default:    next = 9'bxxxxxxxxx;
  35.   endcase
  36.  
  37. end
  38.  always @(*)
  39.    begin
  40.     case (current)
  41.     A: z = 1'b0;
  42.     B: z = 1'b0;
  43.     C: z = 1'b0;
  44.     D: z = 1'b0;
  45.     E: z = 1'b1;
  46.     F: z = 1'b0;
  47.      G: z = 1'b0;
  48.      H: z = 1'b0;
  49.      I: z = 1'b1;
  50.     endcase
  51. end
  52.  
  53. always @(posedge clk,posedge aclr)
  54.    if (aclr)     
  55.         current <= A;
  56.     else
  57.      begin
  58.        
  59.         current <= next;
  60.        
  61.      end
  62.        
  63. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement