Lecture02 Basic Review Upload
Lecture02 Basic Review Upload
1
2
Primitives
No declarations - can only be instantiated
Output port appears before input ports
Optionally specify: instance name and/or delay (discuss
delay later)
3
Review
4
5
module adder4 (sum, carry, inA, inB);
output [3:0] sum;
output carry;
input [3:0] inA, inB;
6
Example: Combinational Gray code
7
Example: Combinational Gray code
8
Example: Combinational Gray code
9
Example: Combinational Gray code
X=…., Y=…., Z=…, K=… ?
10
Example: Combinational Gray code
X=…., Y=…., Z=…, K=… ?
11
Example: Combinational Gray code
X=…., Y=…., Z=…, K=… ?
12
Example: Combinational Gray code
X=…., Y=…., Z=…, K=… ?
13
Example: Combinational Gray code
X=…., Y=…., Z=…, K=… ?
14
Example: Combinational Gray code
X=A
Y
X Y Z K
HW!
15
Four-Value Logic
A single bit can have one of FOUR possible values
0 Numeric 0, logical FALSE
1 Numeric 1, logical TRUE
x Unknown or ambiguous value
z No value (high impedence)
Why x?
Could be a conflict, could be lack of initialization
Why z?
Nothing driving the signal
Tri-states
16
Four-Value Logic
A single bit can have one of FOUR possible values
0 Numeric 0, logical FALSE
1 Numeric 1, logical TRUE
x Unknown or ambiguous value
z No value (high impedence)
Why x?
Could be a conflict, could be lack of initialization
Why z?
Nothing driving the signal
Tri-states
17
Four-Value Logic
A single bit can have one of FOUR possible values
0 Numeric 0, logical FALSE
1 Numeric 1, logical TRUE
x Unknown or ambiguous value
z No value (high impedence)
Why x?
Could be a conflict, could be lack of initialization
Why z?
Nothing driving the signal
Tri-states
18
The x and z Values
IN SIMULATION
Can detect x or z using special comparison operators
x is useful to see:
Uninitialized signals
Conflicting drivers to a wire
Undefined behavior
IN REAL HARDWARE (i.e. in synthesis) ?
19
The x and z Values
IN SIMULATION
Can detect x or z using special comparison operators
x is useful to see:
Uninitialized signals
Conflicting drivers to a wire
Undefined behavior
IN REAL HARDWARE (i.e. in synthesis)
Cannot detect x or z as logical values
No actual ‘x’ – electrically just isn’t 0, 1, or z
Except for some uninitialized signals, x is bad!
Multiple strong conflicting drivers => short circuit
Weak signals => circuit can’t operate, unexpected results
z means nothing is driving a net (tri-state)
20
Resolving 4-Value Logic (Boolean Algebra)
S
A A A T OUT
OUT OUT
B B B
Z’s often appear in simulation when you forget to connect an input port of a module 21
Resolving 4-Value Logic (Boolean Algebra)
S
A A A T OUT
OUT OUT
B B B
Z’s often appear in simulation when you forget to connect an input port of a module 22
Hierarchy
Build up a module from smaller pieces
Primitives and other modules
Can mix/match Verilog coding models (structural, etc.)
Design: typically top-down
Verification: typically bottom-up
Add_half Add_half or
Add_half
xor and
24
Add_half Module
Add_half
xor and
25
Add_full Module
Add_full
Add_half Add_half or
26
Add_full Module
Add_full
Add_half Add_half or
27
Top module
module topadd (c_out, sum, a, b, c_in);
output sum, c_out;
input a, b, c_in;
assign a = 1, b = 0, c_in = 1;
Add_full AD(c_out, sum, a, b, c_in) ;
initial begin
$monitor($time, ,"a=%b, b=%b, c_in=%b, c_out=%b, sum=%b", a, b, c_in, c_out, sum);
end
endmodule
module Add_full(c_out, sum, a, b, c_in) ;
output sum, c_out;
input a, b, c_in;
wire w1, w2, w3;
Add_half AH1(.sum(w1), .c_out(w2), .a(a), .b(b));
Add_half AH2(.sum(sum), .c_out(w3), .a(c_in), .b(w1));
or carry_bit(c_out, w2, w3);
endmodule
module Add_half(c_out, sum, a, b);
output sum, c_out;
input a, b;
xor sum_bit(sum, a, b);
and carry_bit(c_out, a, b);
endmodule 28