Professional Documents
Culture Documents
09 Verilog Tutorial 2
09 Verilog Tutorial 2
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; 1. Evaluate a | b, assign result to x
y = a ^ b ^ c; 2. Evaluate a^b^c, assign result to y
z = b & ~c; 3. Evaluate b&(~c), assign result to z
end
• Nonblocking assignment: all assignments deferred until all
right-hand sides have been evaluated (end of simulation
timestep)
always @ (a or b or c)
begin
x <= a | b; 1. Evaluate a | b but defer assignment of x
y <= a ^ b ^ c; 2. Evaluate a^b^c but defer assignment of y
z <= b & ~c; 3. Evaluate b&(~c) but defer assignment of z
end 4. Assign x, y, and z with their new values
a a x
b
b c y
Blocking: a = b x = a & b
Evaluation and assignment
are immediate b = a y = x | c
Non-Blocking: a <= b x <= a & b
Assignment is postponed until
all r.h.s. evaluations are done b <= a y <= x | c
When to use: Sequential Combinational
( only in always blocks! ) Circuits Circuits
Flip-Flop Based q1 q2
in D Q D Q D Q out
Digital Delay
Line
clk
q1 q2 q1 q2
in D Q D Q D Q out in D Q out
clk clk
D
Clock
Transition is missed on Transition is caught on Output is metastable
first clock cycle, but first clock cycle. for an indeterminate
caught on next clock amount of time.
cycle.
Q: Which cases are problematic?
6.111 Fall 2007 Lecture 6, Slide 8
Asynchronous Inputs in Sequential Systems
Q1
D Q
Clock
Clock
Complicated
D Q D Q D Q Sequential Logic
System
Clock
n n
Q Flip- D
Flops
CLK
BUTTON=1
LIGHT LIGHT
BUTTON=0 BUTTON=0
= 0 = 1
BUTTON=1
• Logic diagram
Combinational logic
1
D Q LIGHT
BUTTON
CLK
4 4
+1 count
• Verilog clk
# 4-bit counter
module counter(clk, count);
input clk;
output [3:0] count;
reg [3:0] count;
4 4
+1 1 count
0 1 4 4
+1 1 count
0
0
present state S
• Mealy FSM:
direct combinational path!
outputs
yk = fk(S, x0...xn)
inputs S+ Comb.
Comb. D Flip- Q
x0...xn n Logic
Logic Flops
CLK
n
Level to
L Pulse P
Converter
...output P produces a
Whenever input L goes
single pulse, one clock
from low to high...
CLK period wide.
unsynchronized Level to
user input
D Q D Q L Pulse P
FSM
CLK
00 01 11
L=0 Low input, High input,
Waiting for rise
Edge Detected!
Waiting for fall
L=1
P=0 P=1 P=0
L=0
L=0
“if L=0 at the clock edge, This is the output that results from
then stay in state 00.” this state. (Moore or Mealy?)
present state S
S1 = LS0
+
P = S1S0
S0 + = L
D Q
S1 + S1
Q
S+ Comb.
Comb. D Flip- Q
n Logic
Logic Flops
CLK
n
S
CLK Q
S
L L
P P
Clock Clock
State[0] State
1
D Q LIGHT
BUTTON D Q
CLK