Friday, October 15, 2021

Moore state Machine of 101 verilog program

The Moore state machine is a finite state machine whose output values depend on the current state.

The Moore state machine output will have the n+1 states for n inputs. For example, if the input has 3 states then it will produce 4 output states.

THE MOORE STATE MACHINE OF 11:

The Moore state machine for 101. It has four states S0, S1, S2, S3. The output will be '1' when it enters state S3 and the outputs of the remaining state are '0'.




PROGRAM:

// The inputs and outputs are declared here

module moore_sequence_101(input CLK,RST,DIN, output reg DOUT);
  
  parameter [1:0]S0 = 2'b00;
  parameter [1:0]S1 = 2'b01;
  parameter [1:0]S2 = 2'b10;
  parameter [1:0]S3 = 2'b11;
  
  reg [1:0] PS;
  reg [1:0] NS;

 // Moore state machine is designed using asynchronous
  
  always @(posedge CLK or negedge RST)
  begin
    if(RST)
      PS <= S0;
    else
      PS <= NS;
  end
  
  always @(PS,DIN)
  begin
    case(PS)
      
// For the state S0

      S0:if(DIN)
          begin
            NS = S1;
            DOUT = 1'b0;
          end
       else
         begin
            NS = S0;
            DOUT = 1'b0;
         end
      
// For the state S1

      S1:if(DIN)
          begin
            NS = S1;
            DOUT = 1'b0;
          end
        else
         begin
            NS = S2;
            DOUT = 1'b0;
         end
        
// For the state S2

      S2:if(DIN)
          begin
            NS = S3;
            DOUT = 1'b0;
          end
         else
           begin
             NS = S0;
            DOUT = 1'b0;
           end
        
// For the state S3

      S3:if(DIN)
          begin
            NS = S1;
            DOUT = 1'b1;
          end
        else
          begin
            NS = S2;
            DOUT = 1'b1;
          end
    
    endcase
  end
endmodule


OUTPUT WAVEFORM:

The output values are tested by forcing the input manually.

when the CLK input is high, rst is low, and based on din the output will be high. When the rst pin is high the output will be zero.

The input is given as 0,0,1,0,1,1,0.






No comments:

Post a Comment

Arrays in Verilog

ARRAYS : An array is a collection of similar types of variables and is accessed using the same name plus one or more indexes.     An array c...