Week 5 - Verilog Description of Combinational Logic
Week 5 - Verilog Description of Combinational Logic
- Introduction
1
Verilog
2
Example: Verilog for Thermostat
wire fanOn ;
assign fanOn = (currentTemp > presetTemp) ;
endmodule
3
Module declaration I/O list
4
Example: Days in Month Function
7
Verilog design style – for synthesizable modules
9
Reminder: 4-bit Prime Number Function
0XX1
ba a a
dc 00 01 11 10 001X d 0XX1
b
00
0 1 1 1
001X
c
f
01
0 1 1 0
c
X011
X011
0 1 0 0
11
X101
d
0 0 1 0
10
X101
a
b
d
dcba b
c
0xx1 f
001x
x101
x011
10
Using case
11
Using casex
13
Using structural description
14
Which is a better description?
• Using case
• Using casex
• Using assign
• Using structural description
15
Result of synthesizing description using case
in[3] n3 U5
U3
in[2] 0XX1
n4
U4 X101
X01X X011
X10X n2
isprime
U1
in[1] n1
U2
001X
16
Synthesis Reports
**************************************** ****************************************
Report : area Report : timing
Design : prime -path full
Version: 2003.06 -delay max
Date : Sat Oct 4 11:38:08 2003 -max_paths 1
**************************************** Design : prime
Version: 2003.06
Library(s) Used: Date : Sat Oct 4 11:38:08 2003
****************************************
XXXXX
Operating Conditions:
Number of ports: 5 Wire Load Model Mode: enclosed
Number of nets: 9
Number of cells: 5 Startpoint: in[2] (input port)
Number of references: 4 Endpoint: isprime (output port)
Path Group: (none)
Combinational area: 7.000000 Path Type: max
Noncombinational area: 0.000000
Net Interconnect area: undefined (Wire load has zero Des/Clust/Port Wire Load Model Library
net area) ------------------------------------------------
prime 2K_5LM XXXXX
Total cell area: 7.000000
Total area: undefined Point Incr Path
--------------------------------------------------------
---
input external delay 0.000 0.000
r
in[2] (in) 0.000 0.000
r
U4/Y (EX210) 0.191 0.191
f
U5/Y (BF051) 0.116 0.307
r
U1/Y (BF052) 0.168 0.475
f
isprime (out) 0.000 0.475
f
data arrival time 0.475
--------------------------------------------------------
---
(Path is unconstrained)
Summary
• The Verilog casex statement is like the case statement, but it allows
our cases to allow x's (don't cares) in some of the bits.
18
Verilog Description of Combinational Logic
- Testbench
19
Using case for 4-bit Prime Number Function
20
Test bench
module test_prime ;
reg [3:0] in ;
wire isprime ;
// instantiate module to test
prime p0(in, isprime) ;
initial begin
in = 0 ;
repeat (16) begin
#100
$display("in = %2d isprime = %1b",in,isprime) ;
in = in+1 ;
end
end
endmodule
21
Test benches use a very different style of Verilog
• Initial statements
• $display
• Repeat and other looping constructs
• #delay
22
Testing Result
# in = 0 isprime = 0
# in = 1 isprime = 1
# in = 2 isprime = 1
# in = 3 isprime = 1
# in = 4 isprime = 0
# in = 5 isprime = 1
# in = 6 isprime = 0
# in = 7 isprime = 1
# in = 8 isprime = 0
# in = 9 isprime = 0
# in = 10 isprime = 0
# in = 11 isprime = 1
# in = 12 isprime = 0
# in = 13 isprime = 1
# in = 14 isprime = 0
# in = 15 isprime = 0
23
Wave output
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
24
Using casex
initial begin
in = 0 ;
check = 0 ;
repeat (16) begin
#100
if (isprime0 !== isprime1) check = 1 ;
in = in+1 ;
end
if (check != 1) $display(“PASS”) ; else $display(“FAIL”) ;
end
endmodule
Summary
• The Verilog casex statement is like the case statement, but it allows
our cases to allow x's (don't cares) in some of the bits.
27