Professional Documents
Culture Documents
111 Lecture 6
Today: 1.Blocking vs. non-blocking assignments 2.Single clock synchronous circuits 3.Finite State Machines
Lecture 6, Slide 1
a b
a b c
x y
Blocking: Evaluation and assignment are immediate Non-Blocking: Assignment is postponed until all r.h.s. evaluations are done When to use:
( only in always blocks! )
a = b b = a a <= b b <= a
Sequential Circuits
D Q
D Q
D Q
Will nonblocking and blocking assignments both produce the desired result?
module nonblocking(in, clk, out); input in, clk; output out; reg q1, q2, out; always @ (posedge clk) begin q1 <= in; q2 <= q1; out <= q2; end endmodule
6.111 Fall 2005
module blocking(in, clk, out); input in, clk; output out; reg q1, q2, out; always @ (posedge clk) begin q1 = in; q2 = q1; out = q2; end endmodule
Lecture 6, Slide 3
q1 in clk D Q D Q
q2 D Q out clk in D Q
q1 q2
out
Blocking assignments do not reflect the intrinsic behavior of multi-stage sequential logic
x = a & b; y = x | c;
x y
Nonblocking Behavior
(Given) Initial Condition a changes; always block triggered
Deferred
Nonblocking assignments do not reflect the intrinsic behavior of multi-stage combinational logic While nonblocking assignments can be hacked to simulate correctly (expand the sensitivity list), its not elegant
module onoff(button,light); input button; output light; reg light; always @ (posedge button) begin light <= ~light; end BUTTON endmodule
6.111 Fall 2005
D Q Q
LIGHT
Lecture 6, Slide 6
BUTTON CLK
SINGLE GLOBAL CLOCK
6.111 Fall 2005
LE CLK
D Q
LIGHT
LOAD-ENABLED REGISTER
Lecture 6, Slide 8
Clock
II
III
?
Idea: ensure that external signals directly feed exactly one flip-flop
Clocked Synchronous System Async Input D Q Q0
Sequential System D Q
Clock D Q Q1
Clock
Clock
This prevents the possibility of I and II occurring in different places in the circuit, but what about metastability?
Lecture 6, Slide 10
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, a pair of synchronization registers is sufficient
Lecture 6, Slide 11
Combinational Logic
Q
CLK
6.111 Fall 2005
FlipFlops
Lecture 6, Slide 12
Logic diagram
Combinatorial logic
0 1
BUTTON CLK
6.111 Fall 2005
D Q
LIGHT
Register
Lecture 6, Slide 13
inputs
x0...xn
Flip- Q Flops
n
Comb. Logic
outputs yk = fk(S)
present state S
Mealy FSM:
direct combinational path!
inputs
x0...xn
Comb. Logic
S+
n CLK
FlipFlops
S
6.111 Fall 2005 Lecture 6, Slide 17
Lecture 6, Slide 18
D Q
D Q
L=1 00 01
Edge Detected!
L=1 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?)
Lecture 6, Slide 19
Curren In t State S1 0 0 0 0 1 1 S0 0 0 1 1 1 1 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
P=0
P=1
L=0
P=0 L=0
0 0 0 0 X 1 0 1 1 X
+:
S+ Comb. Logic
n CLK D Flip- Q
S1S0 for S0 00 01 11 10 L
Flops
n
Comb. Logic
P S0 S1
for P:
0 0 0 0 X 1 1 1 1 X
+ + = LS S S1 0 1 = LS 0 + += S L S0 = L 0
P S0 P= =S S1 1S 0
0 1 0 0 X 1 1 0
Lecture 6, Slide 21
Flip- Q Flops
Comb. Logic
outputs yk = fk(S)
present state S
+ + = LS S S1 0 1 = LS 0 + + S = L S0 = L 0
P S0 P= =S S1 1S 0
Q Q
S0
S1+
Q Q
S1
Lecture 6, Slide 23
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 asserted.
6.111 Fall 2005
Lecture 6, Slide 24
Pres. State
In L 0 1 0 1
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 singlecycle assertion of outputs during state transitions
6.111 Fall 2005 Lecture 6, Slide 26
Moore/Mealy Trade-Offs
How are they different?
Moore: outputs = f( state ) only Mealy outputs = f( state and input ) Mealy outputs generally occur one cycle earlier than a Moore: Moore: delayed assertion of P
L P Clock State[0]
Minimum Delay
inputs + present state
Combinational Logic
Combinational Logic
Tlogic Tcq
Q FlipFlops D
Tcd,logic Tcd,reg
Q FlipFlops D
CLK
Tsu
Thold
CLK
Summary
Assignments in always blocks:
blocking (=) for combinational logic non-blocking (<=) for sequential logic
Combinational Logic
Q
6.111 Fall 2005
FlipFlops
D
Lecture 6, Slide 29