I. Blocking vs. Nonblocking Assignments
I. Blocking vs. Nonblocking Assignments
Nonblocking Assignments
Verilog supports two types of assignments within always
blocks, with subtly different behaviors.
Blocking assignment: evaluation and assignment are immediate
always @ (a or b or c)
begin
x = a | b;
y = a ^ b ^ c;
z = b & ~c;
end
@ (a or b or c)
a | b;
a ^ b ^ c;
b & ~c;
Lecture 6, Slide 1
a
b
Blocking:
Evaluation and assignment
are immediate
a = b
b = a
x = a & b
y = x | c
Non-Blocking:
Assignment is postponed until
all r.h.s. evaluations are done
a <= b
b <= a
x <= a & b
y <= x | c
When to use:
Sequential
Circuits
Combinational
Circuits
Lecture 6, Slide 2
in
D Q
q1
D Q
q2
D Q
out
clk
q1
in
D Q
D Q
in
out
q1 q2
D Q
out
clk
clk
D Q
q2
Lecture 6, Slide 4
x = a & b;
y = x | c;
Nonblocking Behavior
(Given) Initial Condition
a changes;
always block triggered
x <= a & b;
y <= x | c;
Assignment completion
abc xy
110
010
010
010
11
11
01
00
abc xy
110
010
010
010
010
11
11
11
11
01
always @ (a or b or c)
begin
x = a & b;
a
y = x | c;
b
end
x
y
Deferred
x<=0
x<=0, y<=1
always @ (a or b or c)
begin
x <= a & b;
y <= x | c;
end
Lecture 6, Slide 5
Lecture 6, Slide 6
0
D
BUTTON
LE
CLK
CLK
D Q
LIGHT
LOAD-ENABLED REGISTER
Lecture 6, Slide 7
Cant guarantee
setup and hold
times will be met!
Clock
II
III
D
Clock
Transition is missed on
first clock cycle, but
caught on next clock
cycle.
Transition is caught on
first clock cycle.
Output is metastable
for an indeterminate
amount of time.
Lecture 6, Slide 8
D Q
Sequential System
Async
Input
Q0
Clock
D
Clock
Q1
Clock
Lecture 6, Slide 9
Handling Metastability
Very unlikely to be
metastable for >1
clock cycle
D Q
D Q D Q
Extremely unlikely to
be metastable for >2
clock cycle
Complicated
Sequential Logic
System
Clock
Lecture 6, Slide 10
inputs
+
Combinational
Logic
present
state
n
Q
+
next
state
CLK
outputs
FlipFlops
Lecture 6, Slide 11
BUTTON=0
LIGHT
= 1
BUTTON=0
BUTTON=1
Logic diagram
Combinational logic
0
1
BUTTON
D Q
LIGHT
CLK
6.111 Fall 2007
Register
Lecture 6, Slide 12
+1
Verilog
count
clk
# 4-bit counter
module counter(clk, count);
input clk;
output [3:0] count;
reg [3:0] count;
always @ (posedge clk) begin
count <= count+1;
end
endmodule
6.111 Fall 2007
Lecture 6, Slide 13
+1
count
0
Verilog
enb
clk
Lecture 6, Slide 14
+1
0
1
0
Verilog
enb
1 4
0
clr
count
clk
Lecture 6, Slide 15
inputs
x0...xn
next
state
S+
Comb.
Logic
Flip- Q
Flops
CLK
Comb.
Logic
outputs
yk = fk(S)
present state S
Mealy FSM:
direct combinational path!
inputs
x0...xn
S+
Comb.
Logic
CLK
FlipFlops
outputs
yk = fk(S, x0...xn)
Comb.
Logic
S
6.111 Fall 2007
Lecture 6, Slide 16
CLK
...output P produces a
single pulse, one clock
period wide.
Lecture 6, Slide 17
unsynchronized
user input
Synchronizer
Edge Detector
D Q
D Q
Level to
Pulse
FSM
CLK
L=0
00
L=1
High input,
Waiting for fall
Edge Detected!
P=1
L=0
11
01
Low input,
Waiting for rise
P=0
L=1
L=1
P=0
L=0
Lecture 6, Slide 18
L=1
L=0
00
P=0
Edge Detected!
P=1
L=0
S0
0
0
0
0
1
1
0
0
1
1
1
1
0
1
0
1
0
1
L=1
11
01
Low input,
Waiting for rise
S1
High input,
Waiting for fall
P=0
L=0
Next
State
Out
S1+ S0+
0
0
0
1
0
1
0
1
0
1
0
1
0
0
1
1
0
0
S1S0 for S1 :
00 01 11 10
L
0 0 0 0 X
1 0 1 1 X
+:
S1S0 for S0
00 01 11 10
L
0 0 0 0 X
1 1 1 1 X
S+
Comb.
Logic
S1+ = LS0
S0 + = L
n
CLK
D Flip- Q
Comb.
Logic
Flops
n
P = S1S0
P
S0
S1
for P:
0 1
0 0 X
1 1 0
Lecture 6, Slide 19
next
state
S+
Comb.
Logic
Flip- Q
Flops
Comb.
Logic
CLK
S1 = LS0
S0 + = L
+
outputs
yk = fk(S)
present state S
P = S1S0
S0 +
CLK
S1 +
S0
Q
D
Q
Q
S1
Lecture 6, Slide 20
S+
Comb.
Logic
Comb.
Logic
D Flip- Q
Flops
CLK
L
P
L=1 | P=1
L=0 | P=0
Clock
Input is low
Input is high
L=0 | P=0
L=1 | P=0
State
Output transitions immediately.
State transitions at the clock edge.
Lecture 6, Slide 21
Input is low
Input is high
L=0 | P=0
L=0 | P=0
L=1 | P=0
Pres.
State
In
S
0
0
1
1
L
0
1
0
1
Next
Out
State
S+
0
1
0
1
P
0
1
0
0
S+
CLK
Lecture 6, Slide 22
Moore/Mealy Trade-Offs
How are they different?
Clock
Clock
State[0]
State
Lecture 6, Slide 23
0
1
BUTTON
D Q
LIGHT
D Q
Q
CLK
Level-to-Pulse
FSM
Light Switch
FSM
Lecture 6, Slide 24