Professional Documents
Culture Documents
Verilog assumes the value of Q must be maintained if Clk is 0 and therefore synthesizes a latch
Verilog Example e og a p e
x3 x1 x2 Q D Q g
D Clock
Q Q
x3
Q Q
x1 x2 Clock
Q Q
Blocking Assignments oc g ss g e s
The order of statements inside an always block can affect the synthesized design
All previous examples use blocking assignments
Verilog evaluates the assignments in an always block in the order in which they are written
D
treated as Q2 = D since Q1 = D
Q Q
Q2
Non-Blocking Assignments o oc g ss g e s
What if you wanted a cascaded design for the previous example?
The assignment to Q2 should be from the previous Q1 Need both assignments to occur in parallel on the same clock edge
The LHS of a non-blocking assignment is updated after all g RHS values for all assignments have been evaluated
D Clock
Q Q
Q1
Q Q
Q2
non-blocking assignment
Non-Blocking Example o oc g a p e
x3
Q Q
x1 x2 Clock
Q Q
Use non-blocking assignments when designing sequential logic (including for latches) Do not mix blocking and non blocking assignments non-blocking in the same always block
Use separate always blocks for this, if needed
Q3 D Q Q
Q2 D Q Q
Q1 D Q Q
Q0 D Q Q
Parallel input
Clock
Use separate always blocks when you need both types Repeating earlier rules
Use blocking assignments for combinational logic Use non-blocking assignments for sequential logic, and latches
This style separates blocking and non-blocking non blocking assignments into separate always blocks