Professional Documents
Culture Documents
D Tsu Th Tsu Th
20ns 5ns 20ns 5ns
CLK Tw 25ns
Tplh Tphl
Q 25ns 40ns
13ns 25ns
all measurements are made from the clocking event that is,
the rising edge of the clock
CS 150 - Spring 2008 – Lec #6: Moore and Mealy Machines - 2
Cascading Edge-triggered Flip-Flops
Shift register
New value goes into first stage
While previous value of first stage goes into second stage
Consider setup/hold/propagation delays (prop must be > hold)
Q0 Q1
IN D Q D Q OUT
CLK
100
IN
Q0
Q1
CLK
Shift register
New value goes into first stage
While previous value of first stage goes into second stage
Consider setup/hold/propagation delays (prop must be > hold)
Q0 Q1
IN D Q D Q OUT
Clk1
CLK Delay
100
IN
Q0
Q1
CLK
Clk1
CS 150 - Spring 2008 – Lec #6: Moore and Mealy Machines - 4
Cascading Edge-triggered Flip-Flops
(cont’d)
In
Tsu Tsu
4ns 4ns timing constraints
guarantee proper
Q0 operation of
Tp Tp
3ns 3ns cascaded components
Q1
assumes infinitely fast
CLK distribution of the clock
Th Th
2ns 2ns
CS 150 - Spring 2008 – Lec #6: Moore and Mealy Machines - 5
Clock Skew
The problem
Correct behavior assumes next state of all storage elements
determined by all storage elements at the same time
Difficult in high-performance systems because time for clock
to arrive at flip-flop is comparable to delays through logic
(and will soon become greater than logic delay)
Effect of skew on cascaded flip-flops:
100
In
CLK1 is a delayed
Q0 version of CLK0
Q1
CLK0
CLK1
original state: IN = 0, Q0 = 1, Q1 = 1
due to skew, next state becomes: Q0 = 0, Q1 = 0, and not Q0 = 0, Q1 = 1
CS 150 - Spring 2008 – Lec #6: Moore and Mealy Machines - 6
Registers
R S R S R S R S
D Q D Q D Q D Q
CLK
IN D Q D Q D Q D Q
CLK
Holds 4 values
Serial or parallel inputs
Serial or parallel outputs
Permits shift left or right
Shift in new values from left or right
output
clear sets the register contents
and output to 0
left_in right_out
left_out right_in s1 and s0 determine the shift function
clear
s0 clock s0 s1 function
s1 0 0 hold state
0 1 shift right
1 0 shift left
1 1 load new input
input
Nth cell
to N-1th to N+1th
cell Q cell
D
CLK
assign lo = out[3];
assign ro = out[0];
IN D Q D Q D Q D Q
CLK
IN D Q D Q D Q D Q
CLK
D Q D Q D Q D Q
CLK
"1"
=
endmodule
Inputs Outputs
Combinational
Logic
Storage Elements
Clock
CS 150 - Spring 2008 – Lec #6: Moore and Mealy Machines - 27
Finite State Machine Representations
States: determined by possible values in sequential
storage elements
Transitions: change of state
Clock: controls when state can change by controlling
storage elements
001 010 111
In = 1 In = 0
In = 0
100 110
Sequential Logic In = 1
Sequences through a series of states
Based on sequence of values on input signals
Clock period defines elements of sequence
Combination lock
ERR
closed
1
100 110
1 0 1 1
1
0
0 0 1 0
001 011
0
Counters
Proceed thru well-defined state sequence 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, ...
endmodule
CS 150 - Spring 2008 – Lec #6: Moore and Mealy Machines - 32
How Do We Turn a State Diagram into Logic?
Counter
Three 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
D Q D Q D Q
CLK
"1"
C1 0 1 0 1 C1 1 0 0 1 C1 0 0 0 0
C2 C2 C2
CS 150 - Spring 2008 – Lec #6: Moore and Mealy Machines - 36
Implementation (cont'd)
DQ
Q
output Outputs
logic
Inputs
next state Next State
logic
Current State
CS 150 - Spring 2008 – Lec #6: Moore and Mealy Machines - 43
State Machine Model (cont’d)
output Outputs
logic
States: S1, S2, ..., Sk Inputs
next state Next State
Inputs: I1, I2, ..., Im logic
Next State
State
Clock 0 1 2 3 4 5
C: Break in wall
Go forward, turning E: Wall in front or on left
right slightly Turn left
if R, go to A If L or R, stay in E
if not R, stay in C Otherwise, go to B
L+R L’ R
LOST L+R E L A
(F) (TL) (TL, F)
L’ R’ L’ R’ R
R
L’ R’
B C
R’
(TR, F) (TR, F)
R’
L’ R’ L’ R’ R
R
L’ R’
state L R next state outputs B C
LOST 0 0 LOST F (TR, F) (TR, F) R’
LOST – 1 E/G F R’
LOST 1 – E/G F
A 0 0 B TL, F
A 0 1 A TL, F
A 1 – E/G TL, F
B – 0 C TR, F
B – 1 A TR, F
... ... ... ... ...
CS 150 - Spring 2008 – Lec #6: Moore and Mealy Machines - 50
Synthesis
output F
TR
logic
TL
L next state Next State
R logic
X+ Y+ Z+
Current State
X Y Z
L’ R’
L+R L’ R
000 L+R 001 L 010
(F) (TL) (TL, F)
101
L’ R’ R
R
L’ R’
011 100
110 (TR, F) (TR, F) R’
R’
111
Ant is in deep trouble
if it gets in this state
CS 150 - Spring 2008 – Lec #6: Moore and Mealy Machines - 55
State Minimization
Fewer states may mean fewer state variables
High-level synthesis may generate many redundant states
Two state are equivalent if they are impossible to distinguish
from the outputs of the FSM, i. e., for any input sequence the
outputs are the same
L+R L’ R
LOST L+R E L A
(F) (TL) (TL, F)
L’ R’ L’ R’ R
R
L’ R’
B C
R’
(TR, F) (TR, F)
R’
L+R L’ R
LOST L+R E L A
(F) (TL) (TL, F)
L’ R’ L’ R’ R
R
L’ R’
B C
R’
(TR, F) (TR, F)
R’
L+R L’ R
LOST L+R E L A
(F) (TL) (TL, F)
L’ R’ L’ R’ R
R
L’ R’
B C
R’
(TR, F) (TR, F)
R’
L+R L’ R
LOST L+R E L A
(F) (TL) (TL, F)
L’ R’ L’ R’ R
L’ R’
B/C
R’
(TR, F)