Professional Documents
Culture Documents
Acknowledgements:
Materials in this lecture are courtesy of the following sources and are used with permission.
Rex Min
J. Rabaey, A. Chandrakasan, B. Nikolic. Digital Integrated Circuits: A Design Perspective. Prentice Hall/Pearson, 2003.
Clock
II
III
?
Courtesy of Nathan Ickes. Used with permission. L6: 6.111 Spring 2006
Sequential System D Q
Clock D Q Q1
Clock
Courtesy of Nathan Ickes. Used with permission.
Clock
This prevents the possibility of I and II occurring in different places in the circuit, but what about metastability?
Handling Metastability
Preventing metastability turns out to be an impossible problem High gain of digital devices makes it likely that metastable conditions will resolve themselves quickly Solution to metastability: allow time for signals to stabilize Likely to be metastable right after sampling Very unlikely to be metastable for >1 clock cycle Extremely unlikely to be metastable for >2 clock cycle
D Q
D Q D Q
Clock
Depends on many design parameters(clock speed, device speeds, ) In 6.111, one or maybe two synchronization registers is sufficient
Introductory Digital Systems Laboratory 4
Finite State Machines (FSMs) are a useful abstraction for sequential circuits with centralized states of operation At each clock edge, combinational logic computes outputs and next state as a function of inputs and present state
Combinational Logic
n D
Q
CLK
FlipFlops
Flip- Q Flops
Comb. Logic
outputs yk = fk(S)
present state S
Mealy FSM:
direct combinational path!
inputs
x0...xn
Comb. Logic
S+
n CLK
FlipFlops
S
L6: 6.111 Spring 2006 Introductory Digital Systems Laboratory 6
A level-to-pulse converter produces a single-cycle pulse each time its input goes high. In other words, its a synchronous risingedge detector. Sample uses:
Buttons
and switches pressed by humans for arbitrary periods of time Single-cycle enable signals for counters
D Q
D Q
L=1 00
L=1 01
Edge Detected!
11
High input, Waiting for fall
L=0
L=1
P=0
if L=0 at the clock edge, then stay in state 00.
P=0
This is the output that results from this state. (Moore or Mealy?)
Transition diagram is readily converted to a state transition table (just a truth table)
L=1 L=0 L=1
Current State S1 0 0 0 0 1 1 S0 0 0 1 1 1 1
In L 0 1 0 1 0 1
Out
P 0 0 1 1 0 0
00
Low input, Waiting for rise
01
Edge Detected!
11
High input, Waiting for fall
L=1
P=0
P=1
L=0
P=0 L=0
L Comb. Logic
S+
n CLK D Flip- Q
S0+:
Flops
n
Comb. Logic
P S0 S1 0 1
for P:
0 0 1 1 X 0
+ + = LS S S1 1 = LS0 0 + + S = L S0 0 = L
P S0 P= =S S1 1S0
inputs
x0...xn
Flip- Q Flops
Comb. Logic
outputs yk = fk(S)
Q Q
S0
S1+
Q Q
S1
10
S+ Comb. Logic
n CLK D Flip- Q
Comb. Logic
n
Flops S
Since outputs are determined by state and inputs, Mealy FSMs may need fewer states than Moore FSM implementations
1. When L=1 and S=0, this output is asserted immediately and until the state transition occurs (or L changes).
L P
1 2
Clock
0
Input is low L=0 | P=0
1
Input is high
State
Output transitions immediately. State transitions at the clock edge.
L=1 | P=0
2. After the transition to S=1 and as long as L remains at 1, this output is 0.
11
In L 0 1 0 1
Next State S+ 0 1 0 1
Out
P 0 1 0 0
0
Input is low L=0 | P=0 L=0 | P=0
1
Input is high L=1 | P=0
S 0 0 1 1
Q Q
FSMs state simply remembers the previous value of L Circuit benefits from the Mealy FSMs implicit single-cycle assertion of outputs during state transitions
Introductory Digital Systems Laboratory 12
Moore/Mealy Trade-Offs
13
Timing requirements for FSM are identical to any generic sequential system with feedback
Minimum Clock Period
Combinational Logic
Minimum Delay
Combinational Logic
Tlogic Tcq
Q FlipFlops D
Tlogic,cd Tcq,cd
Q FlipFlops D
Tsu
CLK
Thold
CLK
Lab assistants demand a new soda machine for the 6.111 lab. You design the FSM controller. All selections are $0.30. The machine makes change. (Dimes and nickels only.) Inputs: limit 1 per clock
Q - quarter inserted D - dime inserted N - nickel inserted
30
30
COINS ONLY
25
15
...
...
got35c
got40c
got45c
got50c
16
A Moore Vender
Heres a first cut at the state transition diagram.
idle
N=1 D=1
got5c
N=1
D=1
got10c
N=1
Q=1
D=1
got15c
N=1 Q=1
D=1
got20c
N=1 Q=1
D=1
got25c
N=1 Q=1
* *
Q=1
D=1
got30c
DC=1
got35c
DC=1
chg35
* * * *
DN=1
got40c
DC=1
chg40
DD=1
*
chg45b
DN=1
got45c
DC=1
chg45
DD=1
got50c
DC=1
chg50
DD=1
chg50b
DD=1
17
State Reduction
Duplicate Duplicate states states have: have:
idle
N=1 D=1
idle
N=1 D=1
The The same same outputs, outputs, and and The The same same transitions transitions
got5c
N=1
got5c
N=1
There There are are two two duplicates duplicates in in our our original original diagram. diagram.
Q=1
D=1
got10c
N=1
Q=1
D=1
got10c
N=1
D=1
got15c
N=1 Q=1
D=1
got15c
N=1 Q=1
D=1
got20c
N=1 Q=1 Q=1
D=1
got20c
N=1
D=1
Q=1 Q=1 Q=1
got25c
N=1
D=1
got25c
N=1
D=1
got30c
DC=1
D=1
got30c
DC=1
*
chg35
DN=1
Q=1
got35c
DC=1
* * * *
got40c
DC=1
chg40
DD=1
*
chg45b
DN=1
got35c
DC=1
rtn5
* * * *
DN=1
got40c
DC=1
rtn10
DD=1
* *
got45c
DC=1
chg45
DD=1
got45c
DC=1
rtn15
DD=1
got50c
DC=1
chg50
DD=1
chg50b
DD=1
got50c
DC=1
rtn20
DD=1
18
Comb. Logic
n CLK
D State Q
Register
n
Comb. Logic
State register
(sequential always block)
19
(Q) next = GOT_25c; (D) next = GOT_10c; if (N) next = GOT_5c; next = IDLE; (Q) next = GOT_30c; (D) next = GOT_15c; if (N) next = GOT_10c; next = GOT_5c; (Q) next = GOT_35c; (D) next = GOT_20c; if (N) next = GOT_15c; next = GOT_10c; (Q) next = GOT_40c; (D) next = GOT_25c; if (N) next = GOT_20c; next = GOT_15c; (Q) next = GOT_45c; (D) next = GOT_30c; if (N) next = GOT_25c; next = GOT_20c;
20
State Output
idle
got5c got15c
got20c got45c
rtn15 rtn5
idle
10
21
next = GOT_25c; next = GOT_10c; next = GOT_5c; IDLE; next = GOT_30c; next = GOT_15c; next = GOT_10c; GOT_5c; next = GOT_35c; next = GOT_20c; next = GOT_15c; GOT_10c; next = GOT_40c; next = GOT_25c; next = GOT_20c; GOT_15c; next = GOT_45c; next = GOT_30c; next = GOT_25c; GOT_20c; next = GOT_50c; next = GOT_35c; next = GOT_30c; GOT_25c;
RETURN_20c: begin DD = end RETURN_15c: begin DD = end RETURN_10c: begin DD = end RETURN_5c: begin DN = end
FSM state bits may not transition at precisely the same time Combinational logic for outputs may contain hazards Result: your FSM outputs may glitch!
during this state transition...
got10c
D=1
0010 0110
0 1 0
glitch
got20c
0100
assign DC = (state == GOT_30c || state == GOT_35c || state == GOT_40c || state == GOT_45c || state == GOT_50c);
If the soda dispenser is glitch-sensitive, your customers can get a 20-cent soda!
23
D Output Q
Registers
CLK
inputs
D CLK
State Q Registers
n
present state S
reg DC,DN,DD; // Sequential always block for state assignment always @ (posedge clk or negedge reset) begin if (!reset) state <= IDLE; else if (clk) state <= next; DC <= (next next next DN <= (next DD <= (next next end == == == == == == GOT_30c || next == GOT_35c || GOT_40c || next == GOT_45c || GOT_50c); RETURN_5c); RETURN_20c || next == RETURN_15c || RETURN_10c);
Move output generation into the sequential always block Calculate outputs based on next state
24
got5c
N=1 Q=1
A Mealy machine can eliminate states devoted solely to holding an output value.
D=1
got10c
N=1
D=1
got15c
N=1 Q=1
*
idle D=1 N=1 got5c N=1 D=1 Q=1
D=1
got20c
N=1 Q=1 Q=1
D=1
got25c
N=1
* | DN=1
* | DD=1
Q=1 | DC=1
D=1
got30c
DC=1
got35c
DC=1
Q=1
rtn5
DN=1
got10c N=1
Q=1 | DC=1
rtn5
* * * *
got40c
DC=1
rtn10
DD=1
* *
Q=1 | DC=1
rtn10
* | DD=1
got45c
DC=1
rtn15
DD=1
got50c
DC=1
rtn20
DD=1
rtn15
* | DD=1
25
// Sequential always block for state assignment always @ (posedge clk or negedge reset) if (!reset) state <= IDLE; else state <= next;
26
if (Q) begin DC = 1; next = IDLE; end else if (D) next = GOT_15c; else if (N) next = GOT_10c; else next = GOT_5c; begin 1; next = RETURN_5c; next = GOT_20c; next = GOT_15c; GOT_10c; begin 1; next = RETURN_10c; next = GOT_25c; next = GOT_20c; GOT_15c;
GOT_10c:
RETURN_20c:
RETURN_15c:
GOT_15c:
RETURN_10c:
RETURN_5c:
1; next = RETURN_10c;
1; next = RETURN_5c;
1; next = IDLE;
1; next = IDLE;
GOT_20c:
if (Q) begin DC = 1; next = RETURN_15c; end else if (D) begin DC = 1; next = IDLE; end else if (N) next = GOT_25c; else next = GOT_20c;
27
State Output
idle
got5c got15c
got20c rtn15
rtn5
idle
10
50%
Vin
Vout CL
V out tpHL tpLH
90%
V DD
V DD
tf
50% 10% tr t
R on
(a) Low-to-high
(b) High-to-low
review
V out CL R on V out CL
vin
vout C
tp = ln (2) = 0.69 RC
L6: 6.111 Spring 2006 Introductory Digital Systems Laboratory 29
Combinational Logic
Wire delay
D Q
ClkD
T>
In CLK
R1 D Q tCLK1
Combinational Logic
R3 D Q tCLK3
CLK2 1
TCLK
delay
2
+ th
In
R1 D Q tCLK1
Combinational Logic
R3 D Q tCLK3
delay
CLK
CLK2
In
REGS
Combinational Logic
t logic t logic, cd
Summary
A standard template can be used for coding FSMs Register outputs of combinational logic for critical control signals Clock skew and jitter are important considerations
33