FSM 1
FSM 1
Models of synchronous sequential systems Two common models of synchronous sequential systems
Moore machines Mealy machines
Moore Machine
Mealy Machine
10
Inputs
Combinational circuit
Current State
State Memory
Clock
11
Mealy Model
inputs Next-state Logic F clock input excitation State Memory current state Output Logic G
outputs
clock signal
Copyright 2000 by Prentice Hall, Inc. Digital Design Principles and Practices, 3/e
12
Moore Model
inputs Next-state Logic F clock input excitation State Memory current state Output Logic G outputs
clock signal
Copyright 2000 by Prentice Hall, Inc. Digital Design Principles and Practices, 3/e
13
Analysis - Goals
Characterize as Mealy or Moore machine Determine next state equations, i.e., find the function F next state = F (current state, inputs) Determine output equations Meally: outputs = G (current state, inputs), or Moore: outputs = G (current state) Express as machine behavior State table, or State diagram Formulate English description of machine behavior
14
A sequential circuit with two JK flip-flops State or memory: Q1Q0 One input: X; One output: Z
15
Present State Q1 Q0 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1
Inputs X 0 1 0 1 0 1 0 1
Next State Q1 Q0
Outputs Z
16
Output Equations
From the diagram, you can see that Z = Q1Q0X Mealy model circuit !!!
Present State Q1 Q0 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1
Inputs X 0 1 0 1 0 1 0 1
Next State Q1 Q0
Outputs Z 0 0 0 0 0 0 0 1
17
J1 = X Q0 K1 = X + Q0 J0 = X + Q1 K0 = X
18
Excitation equations:
Excitation equations:
Excitation equations:
Present State Q1 Q0 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1
Inputs X 0 1 0 1 0 1 0 1
Next State Q1 Q0 0 0
Outputs Z 0 0 0 0 0 0 0 1
22
Present State Q1 Q0 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1
Inputs X 0 1 0 1 0 1 0 1
Next State Q1 Q0 0 0
Outputs Z 0 0 0 0 0 0 0 1
23
24
25
Present State Q1 Q0 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1
Inputs X 0 1 0 1 0 1 0 1
J1 0 0 1 0 0 0 1 0
Flip-flop Inputs K1 J0 0 1 1 1 0 1 1 1 0 1 0 1 1 1 1 1
K0 1 0 1 0 1 0 1 0
26
J1 0 0 1 0 0 0 1 0
K0 1 0 1 0 1 0 1 0
27
J1 0 0 1 0 0 0 1 0
K0 1 0 1 0 1 0 1 0
28
A different look
Present State Inputs Next State Outputs Q1 Q0 X Q1 Q0 Z 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 0 0 1 0 1 0 0 0 0 1 0 1 1 1 0 1 0 0 0 0 0 0 0 1
Output Z X= 0 0 0 0 0 X= 1 0 0 0 1
29
excitation Q0
MAX
Q0 Q0 D1
D CLK Q Q
Q1
Q1 Q1
current state
Copyright 2000 by Prentice Hall, Inc. Digital Design Principles and Practices, 3/e
32
Excitation Equations
Next-state Logic F State Memory Output Logic G output input EN EN EN D0
D CLK Q Q
excitation Q0
MAX
Q0 Q0 D1
D CLK Q Q
Q1
Q1 Q1
current state
Copyright 2000 by Prentice Hall, Inc. Digital Design Principles and Practices, 3/e
D0 = EN Q0 + EN Q0 D1 = EN Q1 + EN Q1Q0 + EN Q1 Q0
33
excitation Q0
MAX
Q0 Q0 D1
D CLK Q Q
Q1
Q1 Q1
current state
Copyright 2000 by Prentice Hall, Inc. Digital Design Principles and Practices, 3/e
35
State Name A B C D
0 1 0 1
1 1
EN = 0 A EN = 1
(MAX = 0) (MAX = 0)
EN = 1
(MAX = 1)
EN = 1
(MAX = 0)
D EN = 0
(MAX = 0)
Copyright 2000 by Prentice Hall, Inc. Digital Design Principles and Practices, 3/e
EN = 1
(MAX = 0)
C EN = 0
(MAX = 0)
Present State Q1 Q0 A B C D
Input EN= 0 A B C D
Moore Circuit
Next-state Logic F State Memory Output Logic G output MAXS input EN EN EN D0
D CLK Q Q
excitation
X
Q0
Q0 Q0 D1
D CLK Q Q
Q1
Q1 Q1
current state
Copyright 2000 by Prentice Hall, Inc. Digital Design Principles and Practices, 3/e
38
excitation
X
Q0
Q0 Q0 D1
D CLK Q Q
Q1
Q1 Q1
current state
Copyright 2000 by Prentice Hall, Inc. Digital Design Principles and Practices, 3/e
40
EN = 0 EN = 1 B
MAXS=0
EN = 1
EN = 1
D
MAXS=1
EN = 1
C
MAXS=0
EN = 0
EN = 0
Copyright 2000 by Prentice Hall, Inc. Digital Design Principles and Practices, 3/e
Present State Q1 Q0 0 0 1 1 0 1 0 1 0 0 1 1
Output MAXS 0 0 0 1
41
State Transitions
CLOCK EN Q1 Q0 MAX MAXS STATE A A B C C C D D D A A
Copyright 2000 by Prentice Hall, Inc. Digital Design Principles and Practices, 3/e
MAX : Output of the Mealy circuit MAXS : Output of the Moore circuit
42
43
44
Sequence Detector
A circuit that detects the occurrence of a particular pattern on its input is referred to as a sequence detector.
Design a circuit that examine a string of 0s and 1s applied to the input X and for any input sequence ending in 101 will produce an output Z=1 coincident with the last 1. The circuit does not reset when a 1 output occur. We assume that the input X can only change between clock pulses
45
X = Z = (time:
0 0 0
0 0 1
1 0 2
1 0 3
0 0 4
1 1 5
1 0 6
0 0 7
0 0 8
1 0 9
0 0 10
1 1 11
0 0 12
1 1 13
0 0 14
46
0 0 15)
47
48
49
Z X =1 0 0 1
50
DA = X.B
DB = X
AB 00 0 0 0 01 0 0 11 X X
A 10 0 1
Z = X.A
C1
s(t+1)
next state
State Register
s(t)
present state
C2
z(t)
clock
52
X = Z = (time:
0 0 0
0 0 1
1 0 2
1 0 3
0 0 4
1 1 5
1 0 6
0 0 7
0 0 8
1 0 9
0 0 10
1 1 11
0 0 12
1 1 13
0 0 14
0 0 15)
53
54
56
State Table
Prese nt state S0 S1 S2 S3
A+ B + AB 00 01 11 10 X=0 00 11 00 11 X=1 01 01 10 01 Z 0 0 0 1
57
59
Another Example
60
There is one output, Z, which is 1 when the desired pattern is found Our example will detect the bit pattern 1001: Inputs: Outputs: 11100110100 100110 00000100000 100100
A sequential circuit is required because the circuit has to remember the inputs from previous clock cycles, in order to determine whether or not a match was found
61
This is usually the most difficult step. Once you have the state table, the rest of the design procedure is the same for all sequential circuits
62
A
State A B C D
1/0
0/0
C
Meaning
0/0
None of the desired pattern (1001) has been input yet. Weve already seen the first bit (1) of the desired pattern. Weve already seen the first two bits (10) of the desired pattern. Weve already seen the first three bits (100) of the desired pattern.
63
1/0
0/0
C 1/1
0/0
State A B C D
Meaning None of the desired pattern (1001) has been input yet. Weve already seen the first bit (1) of the desired pattern. Weve already seen the first two bits (10) of the desired pattern. Weve already seen the first three bits (100) of the desired pattern.
64
1/0 A 0/0
State A B C D
1/0
0/0
None of the desired pattern (1001) has been input yet. Weve already seen the first bit (1) of the desired pattern. Weve already seen the first two bits (10) of the desired pattern. Weve already seen the first three bits (100) of the desired pattern.
65
0/0
1/0
0/0 1/0
C 1/1
0/0
Output 0 0 0 0 0 0 0 1
66
Present State A A B B C C D D
Input 0 1 0 1 0 1 0 1
Next State A B C B D B A B
Output 0 0 0 0 0 0 0 1
Input X 0 1 0 1 0 1 0 1
Output Z 0 0 0 0 0 0 0 1
67
Present State Q1 Q0 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1
Input X 0 1 0 1 0 1 0 1
Next State Q1 Q0 0 0 1 0 1 0 0 0 0 1 0 1 1 1 0 1
Output Z 0 0 0 0 0 0 0 1
68
JK excitation table
An excitation table shows what flip-flop inputs are required in order to make a desired state change
Q(t) 0 0 1 1 Q(t+1) 0 1 0 1 J 0 1 x x K x x 1 0 Operation No change/reset Set/complement Reset/complement No change/set
This is the same information thats given in the characteristic table, but presented backwards
J 0 0 1 1 K 0 1 0 1 Q(t+1) Q(t) 0 1 Q(t) Operation No change Reset Set Complement
69
Use the JK excitation table on the right to find the correct values for each flip-flops inputs, based on its present and next states
Q(t) 0 0 1 1
Q(t+1) 0 1 0 1
J 0 1 x x
K x x 1 0
Present State Q1 Q0 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1
Input X 0 1 0 1 0 1 0 1
Next State Q1 Q0 0 0 1 0 1 0 0 0 0 1 0 1 1 1 0 1
Output Z 0 0 0 0 0 0 0 1
70
Input X 0 1 0 1 0 1 0 1
Output Z 0 0 0 0 0 0 0 1
71
FF input equations
Present State Q1 Q0 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 Input X 0 1 0 1 0 1 0 1 Next State Q1 Q0 0 0 1 0 1 0 0 0 0 1 0 1 1 1 0 1 Flip flop inputs J1 K1 J0 K0 0 0 1 0 x x x x x x x x 0 1 1 1 0 1 x x 1 1 x x x x 1 0 x x 1 0 Output Z 0 0 0 0 0 0 0 1
J1 00 X 0 1 0 0
Q1 Q0 01 1 0 11 x x 10 x x X
K1 00 0 1 x x
Q1 Q0 01 x x 11 1 1 10 0 1
J1 = X Q0
K1 = X + Q0
72
FF input equations
Present State Q1 Q0 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 Input X 0 1 0 1 0 1 0 1 Next State Q1 Q0 0 0 1 0 1 0 0 0 0 1 0 1 1 1 0 1 Flip flop inputs J1 K1 J0 K0 0 0 1 0 x x x x x x x x 0 1 1 1 0 1 x x 1 1 x x x x 1 0 x x 1 0 Output Z 0 0 0 0 0 0 0 1
J0 00 X 0 1 0 1
Q1 Q0 01 x x 11 x x 10 1 1 X
K0 00 0 1 x x
Q1 Q0 01 1 0 K0 = X 11 1 0 10 x x
J 0 = X + Q1
73
Output equation
Present State Q1 Q0 0 0 0 0 1 1 1 1 0 0 1 1 0 0 1 1 Input X 0 1 0 1 0 1 0 1 Next State Q1 Q0 0 0 1 0 1 0 0 0 0 1 0 1 1 1 0 1 Flip flop inputs J1 K1 J0 K0 0 0 1 0 x x x x x x x x 0 1 1 1 0 1 x x 1 1 x x x x 1 0 x x 1 0 Output Z 0 0 0 0 0 0 0 1
Z 00 X 0 1
Q1 Q0 01 11 1 Z = X Q1 Q0
74
10
J1 = X Q0 K1 = X + Q0 J0 = X + Q1 K0 = X Z = Q1Q0X
75
There is one output, Z, which is 1 when the desired pattern is found Our example will detect the bit pattern 1001: Inputs: Outputs: 11100110100 100110 00000100000 100100
A sequential circuit is required because the circuit has to remember the inputs from previous clock cycles, in order to determine whether or not a match was found
76
B/0
0 1
C/0
0 0
D/0
E/1
0
Present State A A B B C C D D E E Input 0 1 0 1 0 1 0 1 0 1 Next State A B C B D B A E C B Output 0 0 0 0 0 0 0 0 1 1
77
Comparison of Mealy and Moore Mealy machines have less states FSM states (n) outputs are on transitions (n ) rather than
2
Moore machines are safer to use outputs change at clock edge (always one cycle later) in Mealy machines, input change can cause output change as soon as logic is done a big problem when two machines are interconnected asynchronous feedback may occur if one isnt careful Mealy machines react faster to inputs react in same cycle don't need to wait for clock outputs may be considerably shorter than the clock cycle in Moore machines, more logic may be necessary to decode state into outputs there may be more gate delays after clock edge
79
80
81
State Reduction
82
State Optimization
Equivalent States:
Two states are equivalent if, for each member of the set of inputs,
they give exactly the same output and send the circuit either to the same state or to an equivalent state.
If two states are equivalent, one can be eliminated without effecting the behavior of the FSM.
83
Combine the equivalent states into a new renamed state. Repeat until no more states are combined.
84
State Table
85
86
89
State Table
Prese nt State a b c d e f g h Next State X=0 d f e a c f b c 1 c h d e a b h g Present Output X=0 0 0 1 0 1 1 0 1 91
92
a|b
iff
d| f
and
c|h
b{c
a|d
iff
a|d iff
and
a|g
b|d
94
95
97
98
Output is a function of the state registers. The simplest Moore machine can use only one process
nand
D type FF
not
99
signal C: std_logic; -- global, can be seen by -- different processes begin D <= not C; -- F2 = combination logic process(CLK) begin if (CLKvent and CLK =1) then C <= A nand C; --F1 = combination end if; end process; end moore1_arch;
100
-- sequential logic
101
-- combinational logic
-- sequential logic
State Representation
General State machine Design steps
Step 1. Identify the states Step 2. Connect the states with certain conditions.
Comparison of Mealy and Moore Mealy machines have less states FSM states (n) outputs are on transitions (n ) rather than
2
Moore machines are safer to use outputs change at clock edge (always one cycle later) in Mealy machines, input change can cause output change as soon as logic is done a big problem when two machines are interconnected asynchronous feedback may occur if one isnt careful Mealy machines react faster to inputs react in same cycle don't need to wait for clock outputs may be considerably shorter than the clock cycle in Moore machines, more logic may be necessary to decode state into outputs there may be more gate delays after clock edge
104
std_logic;
105
THEN state <= S2; <= S0; THEN state <= S1; <= S0;
WHEN S2
=>
106
LIBRARY ieee; USE ieee.std_logic_1164.ALL; USE ieee.std_logic_unsigned.ALL; USE ieee.numeric_std.ALL; ENTITY SM_11 IS PORT ( clock, reset, X: IN Y : OUT std_logic); END SM_11;
std_logic;
107
IF X = 1 THEN nstate<= S1; Y <= 1; ELSE Y <= 0 END IF; IF X = 1 THEN nstate<= S0; Y <= 1; ELSE nstate <= S0; Y <= 0; END IF;
WHEN S1
=>
hold
POS clear=1' track=0'
sample
extend
clear='0' track='1'
clear=1' track=1'
110
111
113
FSM
115
116
117
118
120
121
122
123
125
126
State Assignment
127
State Assignments
After the number of states in a state table has been reduced, the next step in realizing the transition table is to assign flipflop states (i.e. binary values) to correspond to the states in the state table. The cost of the logic required to realize a sequential circuit is strongly dependent on the way this state assignment is made.
128
State Assignments
Given a sequential circuit with three states and two flipflops (A and B), there are 4 3 2 = 24 possible state assignments for the three states.
129
Equivalent Circuits
130
131
132
State Assignments
When realizing a three-state sequential circuit with symmetrical flip-flops (i.e. JK or SR), it is only necessary to try three different states to be assured of a minimum cost realization. Similarly, only three different assignments must be tried for four states.
133
State Assignments
134
1. 2. 3.
States which have the same next state for a given input should be given adjacent assignments. States which are the next states of the same state should be given adjacent assignments. States which have the same output for a given input should be given adjacent assignments.
136
137
138
139
140
141
142
143
Reference
"Fundamentals of Logic Design", 5th Edition, Charles H. Roth, Jr Chapters 13,14,15,17,18,19,20
145