Unit - 5 (FSMS)
Unit - 5 (FSMS)
Unit - 5 (FSMS)
circuits
Mealy and Moore
Sequential circuits
State diagram
State table
General Sequential circuit
State Encoding
❑ Common FSM encoding options:
▪ One-hot code
▪ Binary code
▪ Gray code
▪ Random code
One-hot encoding
An important feature of the one-hot state assignment is that it often leads
to simpler output expressions than do assignments with the minimal
number of state variables. Simpler output expressions may lead to a faster
circuit.
A 0101 Sequence Detector (overlapping)
Design an FSM to detect the pattern 0101 in the input
sequence x
A 0101 Sequence Detector (Cont.)
A 0101 Sequence Detector - Mealy
module melay_fsm(din, reset, clk, y);
input din; input clk; S2: if (din == 1'b1)
input reset; begin nst = S0; y=1'b0; end
output reg y; else
begin nst = S3; y=1'b0; end
reg [1:0] cst, nst; S3: if (din == 1'b0)
parameter S0 = 2'b00, S1 = 2'b01, S2 = begin nst = S1; y=1'b0; end
2'b10, S3 = 2'b11; //all state else
always @(cst or din) begin nst = S2; y=1'b1; end
default: nst = S0;
begin
endcase
case (cst)
end
S0: if (din == 1'b1)
always@(posedge clk)
begin nst = S0; y=1'b0; end
begin
else
if (reset) cst <= S0;
begin nst = S1; y=1'b0; end
else cst <= nst;
S1: if (din == 1'b0)
end
begin nst = S1; y=1'b0; end
endmodule
else
begin nst = S2; y=1'b0; end
State diagram – Moore (0101)
(non-overlapping)
S 0 S 1 S 0 S 1 S
0 1 2 3 4
0 0 0 0 1
1
0
1
A 0101 Sequence Detector -Moore
module moore_fsm(din, reset, clk, y); S2: begin y=1'b0;
input din; input clk; if (din == 1'b1) nst = S0;
input reset; else nst = S3; end
output reg y; S3: begin y=1'b0;
reg [2:0] cst, nst; if (din == 1'b0) nst = S1;
parameter S0 = 3'b000, S1 = 3'b001, else nst = S4; end
S2 = 3'b010, S3 = 3'b011, S4=3’b100; S4: begin y=1'b1;
//all state if (din == 1'b0) nst = S1;
always @(cst or din) else nst = S0; end
begin default: nst = S0;
case (cst) endcase
S0: begin y=1'b0 ; end
if (din == 1'b1) nst = S0; always@(posedge clk)
else nst = S1; end begin
S1: begin y=1'b0; if (reset) cst <= S0;
if (din == 1'b0) nst = S1; else cst <= nst;
else nst = S2; end end
State diagram – Moore (0101)
(overlapping)
1
S 1 S 0 S 1 S
0 1 2 3
0 0 0 1
0
1
A 0101 Sequence Detector -Moore
module moore_fsm(din, reset, clk, y); S2: begin y=1'b0;
input din; input clk; if (din == 1'b1) nst = S3;
input reset; else nst = S0; end
output reg y; S3: begin y=1'b1;
reg [1:0] cst, nst; if (din == 1'b0) nst = S2;
parameter S0 = 2'b00, S1 = 2'b01, else nst = S0; end
S2 = 2'b10, S3 = 2'b11;
//all state default: nst = S0;
always @(cst or din) endcase
begin end
case (cst) always@(posedge clk)
S0: begin y=1'b0 ; begin
if (din == 1'b1) nst = S1; if (reset) cst <= S0;
else nst = S0; end else cst <= nst;
S1: begin y=1'b0; end
if (din == 1'b0) nst = S2; endmodule
else nst = S0; end
Serial adder
Our task is to design a circuit that will perform serial addition, dealing with a
pair of bits in one clock cycle.
In the next clock cycle, bits a1 and b1 are added, including a possible carry
from the bit-position 0, and so on.
We can derive a suitable state diagram by splitting both G and H into two
states.
Instead of G, we will use G0 and G1 to denote the fact that the carry is 0
and that the sum is either 0 or 1, respectively.