Chapter 5 Behavioral Model Part1
Chapter 5 Behavioral Model Part1
Binh Tran-Thanh
January 5, 2022
1 / 24
Behavioral Verilog
2 / 24
Types of Blocks
initial
Behavioral block operates ONCE
Starts at time 0 (beginning of operation)
Useful for test benches
Can sometimes provide initialization of memories/FFs
Often better to use ”reset” signal
Inappropriate for combinational logic
Usually cannot be synthesized
always
Behavioral block operates CONTINUOUSLY
Can use a trigger list to control operation; @(a, b, c)
3 / 24
initial vs. always
initial always
reg[7:0] v1, v2, v3, v4; reg[7:0] v1, v2, v3, v4;
initial begin always begin
v1 = 1; v1 = 1;
#2 v2 = v1 + 1; #2 v2 = v1 + 1;
v3 = v2 + 1; v3 = v2 + 1;
#2 v4 = v3 + 1; #2 v4 = v3 + 1;
v1 = v4 + 1; v1 = v4 + 1;
#2 v2 = v1 + 1; #2 v2 = v1 + 1;
v3 = v2 + 1; v3 = v2 + 1;
end end
What values does each block produce?
4 / 24
initial Blocks
`timescale 1ns /1ns
module t_full_adder; all initial blocks
reg [3:0] stim; start at time 0
wire s, c;
// instantiate UUT
full_adder(sum, carry, stim[2], stim[1], stim[0]);
6 / 24
always blocks with trigger lists
7 / 24
Trigger Lists
Uses ”event control operator” @
When net or variable in trigger list changes, always block is triggered
9 / 24
Example: Comparator
endmodule
10 / 24
Solution: Comparator
end
endmodule
11 / 24
Edge Triggering
12 / 24
Example: DFF
13 / 24
DFF with Set Control
14 / 24
Procedural Assignments
15 / 24
Blocking Assignments
”Evaluated” sequentially
Works a lot like software (danger!)
Used for combinational logic
16 / 24
Non-Blocking Assignments
”Updated” simultaneously if no delays given
Used for sequential logic
reg[7:0] A, B, C, D; reg[7:0] A, B, C, D;
19 / 24
Correcting The Example
reg[7:0] A, B, C, D;
reg[7:0] newA, newB, newC, newD;
21 / 24
Shift Register: Blocking
//else begin D = E; C = D; B = C; A = B;
//end// option 2
end
endmodule
E D Q A
Q̄
Rst
clk
rst
Q̄ Q̄ Q̄ Q̄
Rst Rst Rst Rst
clk
rst
23 / 24
Combinational vs. Sequential
Combinational
Not edge-triggered
All ”input s” (RHS nets/variables) are triggers
Does not depend on clock
Sequential
Edge-triggered by clock signal
Only clock (and possibly reset) appear in trigger list
Can include combinational logic that feeds a FF or register
24 / 24