Professional Documents
Culture Documents
Finite State Machines: Primitive Sequential Elements Combinational Logic
Finite State Machines: Primitive Sequential Elements Combinational Logic
Sequential circuits
primitive sequential elements
combinational logic
Models for representing sequential circuits
finite-state machines (Moore and Mealy)
Basic sequential circuits revisited
shift registers
counters
Design procedure
state diagrams
state transition table
next state functions
Hardware description languages
Inputs Outputs
Combinational
Logic
Storage Elements
Clock
In =00
In
1 =1 In = X
001
001 010
010 111
111
In 1= 1 In
0 =0
In 0= 0 In = X
100
100 110
110
In1= 1
5 states
8 other transitions between states
6 conditioned by input
1 self-transition (on 0 from 001 to 001)
2 independent of input
1 reset transition (from all states) to state 100
0
1
001 010 111
1 0
0
100 110
reset 1
Counters
proceed through well-defined sequence of states in response to enable
Many types of counters: binary, BCD, Gray-code
3-bit up-counter: 000, 001, 010, 011, 100, 101, 110, 111, 000, ...
3-bit down-counter: 111, 110, 101, 100, 011, 010, 001, 000, 111, ...
100 110
001 011
1
100 110
1 0 1 1
1
0
0 0 1 0
001 011
0
Counter
3 flip-flops to hold state
logic to compute next state
clock signal controls when flip-flop memory can change
wait long enough for combinational logic to compute new value
don't wait too long as that is low performance
OUT1 OUT2 OUT3
D Q D Q D Q
CLK
000 100
Implementation
N3 C3 N2 C3 N1 C3
0 0 1 1 0 1 1 0 1 1 1 1
C1 0 1 0 1 C1 1 0 0 1 C1 0 0 0 0
In C1 C2 C3 N1 N2 N3
0 0 0 0 0 0 0 1
100 110
0 0 0 1 0 0 0
0 0 1 0 0 0 1 1 0 1 1
1
0 0 1 1 0 0 1
0 1 0 0 0 1 0 0 000 1 010 101 0 111 1
0 1 0 1 0 1 0 0
0 0 1 0
0 1 1 0 0 1 1
0 1 1 1 0 1 1 001 011
0
1 0 0 0 1 0 0
1 0 0 1 1 0 0 N1 <= In
1 0 1 0 1 0 1
N2 <= C1
1 0 1 1 1 0 1
1 1 0 0 1 1 0 N3 <= C2 OUT1 OUT2 OUT3
1 1 0 1 1 1 0
1 1 1 0 1 1 1 D Q D Q D Q
1 1 1 1 1 1 1 IN
CLK
Autumn 2006 CSE370 - VII - Finite State Machines 13
Complex counter
repeats 5 states in sequence
not a binary number representation
Step 1: derive the state transition diagram
count sequence: 000, 010, 011, 101, 110
Step 2: derive the state transition table from the state transition diagram
note the don't care conditions that arise from the unused state codes
Autumn 2006 CSE370 - VII - Finite State Machines 14
More complex counter example (cont’d)
C+ C B+ C A+ C
0 0 0 X 1 1 0 X 0 1 0 X
A X 1 X 1 A X 0 X 1 A X 1 X 0
B B B
C+ <= A
B+ <= B’ + A’C’
A+ <= BC’
A 1 1 1 1 A 1 0 0 1 A 0 1 0 0
B B B
Start-up states
at power-up, counter may be in an unused or invalid state
designer must guarantee that it (eventually) enters a valid state
Self-starting solution
design counter so that invalid states eventually transition to a valid state
may limit exploitation of don't cares
implementation
111 on previous slide 001
001 111
000 110
000 110
100
100
010 101
010 101
011
011
Activity
00 11
01 10
Activity (cont’d)
S1
0 0 1 1 N1 = C’S1
0 0 1 1 + CDS0’S1’ + CDS0S1
D + CD’S0S1’ + CD’S0’S1
C 1 0 1 0 = C’S1
S1 S0 C D N1 N0 + C(D’(S1 ⊕ S0) + D(S1 ≡ S0))
0 1 0 1
0 0 0 0 0 0 = C’S1 + C (D ⊕ (S1 ⊕ S0))
0 0 0 1 0 0 S0
S1
0 0 1 0 0 1
0 0 1 1 1 1 0 1 1 0 N0 = CS0’ + C’S0
0 1 0 0 0 1 0 1 1 0
0 1 0 1 0 1 D
0 1 1 0 1 0 C 1 0 0 1
0 1 1 1 0 0 1 0 0 1
1 0 0 0 1 0 S0
1 0 0 1 1 0
1 0 1 0 1 1
1 0 1 1 0 1
1 1 0 0 1 1
1 1 0 1 1 1
1 1 1 0 0 0
1 1 1 1 1 0
RESET
R R R R R
LED LED LED LED LED LED LED
(6) (5) (4) (3) (2) (1) (0)
L L L L L
endmodule
Autumn 2006 CSE370 - VII - Finite State Machines 22
Counter/shift-register model
next state
Inputs Next State
logic
Current State
Outputs
output Outputs
logic
Inputs
next state Next State
logic
Current State
Current State
Next State
State
Clock 0 1 2 3 4 5
Autumn 2006 CSE370 - VII - Finite State Machines 25
state feedback
combinational
logic for reg
next state
state feedback
Synchronous Mealy
logic for
inputs outputs
outputs
combinational
logic for reg
next state
state feedback
Autumn 2006 CSE370 - VII - Finite State Machines 27
1/0
output Outputs
logic
Inputs
next state
logic
Current State
N
Vending Open
Coin Machine Release
Sensor FSM Mechanism
D
Clock
two dimes
S1 S2
draw state diagram:
inputs: N, D, reset
output: open chute
assumptions:
assume N and D asserted
for one cycle
each state has a self loop
for N = D = 0 (no coin)
two dimes
S1 S2
draw state diagram:
inputs: N, D, reset N D N D
Reset
S0
N D
S1 S2
N D N D
S4 S5 S6
S3
[open] [open] [open]
N D
S7 S8
[open] [open]
D1 = Q1 + D + Q0 N
D0 = Q0’ N + Q0 N’ + Q1 N + Q1 D
OPEN = Q1 Q0
One-hot encoding
0¢
N’ D’ 0¢ N’ D’/0
[0]
N N/0
D 5¢ D/0
N’ D’ 5¢ N’ D’/0
[0]
N N/0
10¢
D N’ D’ D/1 10¢ N’ D’/0
[0]
N+D N+D/1
15¢
Reset’ 15¢ Reset’/1
[1]
Reset/0 Reset/0
present state inputs next state output
Q1 Q0 D N D1 D0 open
0¢ N’ D’/0 0 0 0 0 0 0 0
0 1 0 1 0
N/0
1 0 1 0 0
1 1 – – –
D/0 0 1 0 0 0 1 0
5¢ N’ D’/0
0 1 1 0 0
1 0 1 1 1
N/0 1 1 – – –
1 0 0 0 1 0 0
D/1 10¢ N’ D’/0 0 1 1 1 1
1 0 1 1 1
N+D/1 1 1 – – –
1 1 – – 1 1 1
15¢ Reset’/1
Q1
Open
0 0 1 0 D0 = Q0’N + Q0N’ + Q1N + Q1D
0 0 1 1
N D1 = Q1 + D + Q0N
X X 1 X
D OPEN = Q1Q0 + Q1N + Q1D + Q0D
0 1 1 1
Seq
N
Q1
DQ
Seq
D
Open
DQ
Com
Reset
Q0
DQ
Seq
N
Q1
DQ
Seq
D
OPEN Open
DQ
Seq
Reset
A
out
D Q
B
clock
Q
A
D Q out
B
D Q
clock
Q
A
D Q
B
D Q
Q
clock
out
A
D Q D Q
Q Q
B
D Q D Q
Q Q
clock
Moore Mealy
zero
[0] 0/0
zero
1 0 [0]
0 one1 0/0 1/0
[0]
one1
0 1 [0]
1 1/1
two1s
[1]
state assignment
Moore machine
(easy to change,
module reduce (clk, reset, in, out); if in one place)
input clk, reset, in;
output out;