Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. `timescale 1ns/1ps
  2. module myfsm (input clk, reset, in, output reg out);
  3.   parameter S0 = 0;
  4.   parameter S1 = 1;
  5.   parameter S2 = 2;
  6.   parameter S3 = 3;
  7.   reg [1:0] state, next_state;
  8.   // new state assignment
  9.   always @(posedge clk)
  10.     if (reset) state <= #1 S0;
  11.     else state <= #1 next_state;
  12.   // output assignment
  13.   always @(in or state)
  14.     out <= #1 (state [1] & state [0]);
  15.   // next state computation
  16.   always @(in or state)
  17.     case (state)
  18.       S0: if (in) next_state <= #1 S1;
  19.         else next_state <= #1 S0;
  20.       S1:  if (in) next_state <= #1 S2;
  21.         else next_state <= #1 S0;
  22.       S2: if (in) next_state <= #1 S3;
  23.         else next_state <= #1 S0;
  24.       S3: if (in) next_state <= #1 S3;
  25.         else next_state <= #1 S0;
  26.      endcase
  27. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement