Verilog Quickstart, practical guide to simulation & synthesis in verilog (3rd ed ) - Pdf 12


VERILOG
®
QUICKSTART
A Practical Guide to Simulation
and Synthesis in Verilog
Third Edition
THE KLUWER INTERNATIONAL SERIES
IN ENGINEERING AND COMPUTER SCIENCE
VERILOG
®
QUICKSTART
A Practical Guide to Simulation
and Synthesis in Verilog
Third Edition
James M. Lee
Intrinsix Corp.
KLUWER ACADEMIC PUBLISHERS
NEW YORK, BOSTON, DORDRECHT, LONDON, MOSCOW
eBook ISBN: 0-306-47680-0
Print ISBN: 0-7923-7672-2
©2002 Kluwer Academic Publishers
New York, Boston, Dordrecht, London, Moscow
Print ©2002 Kluwer Academic Publishers
All rights reserved
No part of this eBook may be reproduced or transmitted in any form or by any means, electronic
mechanical, recording, or otherwise, without written consent from the Publisher
Created in the United States of America
Visit Kluwer Online at:
and Kluwer's eBookstore at:
Dordrecht

Escaped Identifiers
White Space
Comments
Numbers
Text Macros
Modules
Semicolons
Value Set
Strengths
Numbers, Values, and Unknowns
9
10
11
12
12
13
14
14
15
15
16
vi
Verilog Quickstart
3 STRUCTURAL MODELING
19
Primitives
Ports
Ports in Primitives
Ports in Modules
Instances

34
35
36
39
46
5 SYSTEM TASKS FOR DISPLAYING RESULTS
47
What is a System Task?
$display and Its Relatives
Other Commands to Print Results
Writing to Files
Advanced File IO Functions
Setting the Default Radix
Special Characters
The Current Simulation Time
Suppressing Spaces in Your Output
Periodic Printouts
When to Printout Results
A Final System Task
Exercise 3 Printing Out Results from Wires Buried in the Hierarchy
47
47
49
51
53
53
54
55
56
58

66
67
68
68
69
69
70
70
7
PROCEDURAL ASSIGNMENTS
73
Procedural Assignments, Ports and Regs
Best Practices with Procedural Assignments
Procedural Assignment for Combinatorial Logic
Procedural Assignment for Sequential Logic
Philosophy of Intra-Assignment Delays for Sequential Assignments
Conventions Moving Forward
77
78
78
78
79
80
8 OPERATORS
81
Binary Operators
Unary Operators
Reduction Operators
Ternary Operator
Equality Operators

103
viii
Verilog Quickstart
Summary of Procedural Timing
106
10 PROCEDURAL FLOW CONTROL
109
The if Statement
The case Statement
Loops
The forever Loop
The repeat Loop
The while Loop
The for Loop
Exercise 4 Using Expressions and case
109
110
114
114
115
116
117
118
11 TASKS AND FUNCTIONS
125
Tasks
Automatic Tasks
Common Uses for Tasks
Functions
Functions and Integers

The Gritty Details
Sequential UDPS
UDP Instances
The Final Details
Exercise 6 Using UDPs
152
152
152
153
154
157
157
158
14 PARAMETERIZED MODULES
161
ix
N-Bit Mux
N-Bit Adder
N By M Mux
N By M Ram
Using Parameterized Modules
Parameter Passing by Name
Parameter Passing by Order
Parameter Passing by Named List
Values of Parameters in Module Instances
162
162
163
164
165

Modeling Asynchronous Circuits
Modeling a One-Shot
Modeling Asynchronous Systems
Special-Purpose Models
Two-Dimensional Arrays
Z-Detectors
Multiplier Examples
A Proven, Successful Approach to Modeling
187
188
189
192
193
193
193
196
198
198
199
205
205
206
207
217
17 MODELING STYLE TRADE-OFFS
219
Forces That Influence Modeling Style
Evolution of a Model
Modeling Style and Synthesis
Is It Synthesizable?

Test Benches with No Test Vectors
Using A Script To Run Test Cases
Modeling Bist
The Surround and Capture Method
233
234
235
235
235
235
236
236
237
238
238
239
241
246
249
251
254
254
255
257
19 MODEL ORGAINZATION
263
File Organization
Declaration Organization
ANSI Style ports
Testcase Organization

Missing Initialization
Overly Complex Code
Unintended Storage
Timing Errors
Negative Setup Time
Zero-Delay Races
Tool Specific Pragmas
274
274
275
275
276
276
277
277
277
278
278
279
21 DEBUGGING A DESIGN
281
Overview of Functional Debugging
Where Are the Errors?
Universal Techniques
Printing Out Messages
“I am here.”
Values
The Log File
Using Waveforms
Interactive Debugging

309
311
312
22 CODE COVERAGE
315
Code Coverage and Test Plans
Code Coverage and Fifos
Code Coverage and State Machines
Code Coverage and Modeling Style
316
319
322
322
xii
Verilog Quickstart
Appedix A GATE-LEVEL DETAILS
325
Primitive Descriptions
Logic Gates
AND
NAND
OR
NOR
XOR
XNOR
Buffers
BUF
NOT
BUFIF0
BUFIF1

330
331
332
332
333
333
334
335
336
337
337
338
338
338
339
340
340
341
342
INDEX
343
LIST OF FIGURES
Figure 1-1 Design Abstraction Hierarchy
Figure 1-2 Gate-Level Model Mux Schematic
Figure 2-1 Number Format
Figure 2-2 The Mux Example
Figure 2-3 Three-State Buffer
Figure 2-4 Two Three-State Buffers
Figure 3-1 AND Gate Primitives
Figure 3-2 Gate-Level Model Mux Schematic

Figure 18-6 Logic Surrounded by BIST
Figure 18-7 Surround and Capture Method
Figure A-1 AND Gate
Figure A-2 NAND Gate
4
7
12
14
16
16
21
22
23
24
25
26
29
29
30
30
56
71
99
120
121
121
121
124
144
159

Figure A-13 Pulldown
Figure A-14 Pullup
Figure A-15 NMOS or RNMOS Transistor
Figure A-16 PMOS or RPMOS Transistor
Figure A-17 CMOS or RCMOS transistor
327
327
328
328
329
329
330
330
331
332
332
333
334
335
336
LIST OF EXAMPLES
5
7
11
11
11
11
12
13
13

57
58
59
Example 1 -1 Abstract Model of a Phone
Example 1 -2 Verilog for Gate-Level Mux
Example 2-1 Simple Hello Module
Example 2-2 Hello Module without White Space
Example 2-3 Hello Module with Extra White Space
Example 2-4 Illegal Use of White Space
Example 2-5 Comments
Example2-6 Numbers
Example 2-7 Specifying a Text Macro
Example 2-8 Using a Text Macro
Example 2-9 Gate-Level Mux Verilog Code
Example 3-1 Verilog Code for the 2-Input and 4-Input AND Gates
Example 3-2 Verilog for Gate-level Mux
Example 3-3 Hierarchical 2-Bit Mux
Example 3-4 Hierarchical 4-Bit Mux
Example 3-5 Hierarchical Names
Example 3-6 Mux Connected by Name
Example 3-7 Hello Verilog
Example 3-8 Adder Test Module
Example4-1 An initial Block
Example 4-2 An always Block
Example 4-3 Three initial Statements
Example 4-4 Three initial Statements with Delay
Example 4-5 Simple begin-end Block
Example 4-6 begin-end Block with Delay
Example 4-7 Multiple begin-end Blocks
Example 4-8 fork-join Blocks

Example 6-7 Memory and Reg Declarations
Example 6-8 Selecting Bits in Registers and Words in Memories
Example 6-9 Reg Declaration with Initialization
Example 6-10 Declaring Integers and Reals
Example 6-11 Declaring Variables of Type time
Example 6-12 Parameters
Example 6-13 Events
Example 6-14 Strings
Example 6-15 Multi-Dimensional Arrays of nets
Example 6-16 Multi-Dimensional Arrays of Regs
Example 6-17 Accessing Multi-Dimensional Arrays
Example 6-18 Output as a Reg
Example 7-1 Simple Procedural Assignments
Example 7-2 Procedural Assignments with fork-join
Example 7-3 fork-join with Intra-assignment Delays
Example 7-4 fork-join with Multiple Delays
Example7-5 fork-join with Simplified Delays
Example 7-6 Effect of Intra-assignment Delays on Time Flow
Example 7-7 Nonblocking Assignments
Example 7-8 Combinatorial Procedural Assignments
Example 7-9 Sequential Procedural Assignment
Example 8-1 Using Operators
Example 8-2 Distinguishing between Bit-wise and Logical Operators
Example 8-3 Using Reduction Operators
Example 8-4 Ternary Operator
Example 8-5 Using the Ternary Operator for a Three-State Buffer
Example 8-6 Module To Test an Operator
Example 8-7 Concatenations
Example 8-8 Bit-wise and Logical operations
Example 8-9 Operators and Strings

75
76
76
77
78
79
83
84
85
85
86
89
90
91
93
94
94
95
95
98
98
99
100
xvii
100
100
101
102
102
103

Example 9-15 Using wait To Detect an Unknown
Example 9-16 Using always To Detect an Unknown
Example10-1 Simple if
Example10-2 if with else
Example10-3 Nested if with else
Example 10-4 The case Statement
Example10-5 case Matching x and
z
Example10-6 Using casez
Example10-7 Counter Using case
Example 10-8 Counter Using if
Example 10-9 Oscillator Using always
Example 10-10 Oscillator Using forever
Example 10-11 Repeating “Hello Verilog”
Example10-12 Using repeat in a State Machine
Example 10-13 A while Loop
Example 10-14 A Simple for loop
Example 10-15 A for Loop with Expressions Not Referencing the Same Variable
118
122
126
127
128
128
129
130
131
132
133
134

Example 12-9 Mux with PC A
Example 12-10 Proper Synthesizable Flip-Flop
Example 12-11 inout Port Connected to a Reg
Example 12-12 Reg with Controllable Connection to inout Port
Example 12-13 Named Blocks
Example 12-14 The disable Statement
Example 12-15 disable Used To Model Reset
Example 12-16 Controlling When a Simulation Finishes
Example 13-1 Optimistic Mux UDP
Example 13-2 Pessimistic Mux UDP
Example 13-3 One-Line UDP
Example 13-4 Level-Sensitive D Latch
Example 13-5 Edge-Sensitive D Flip-Flop
Example 13-6 Flip Flop Using Explicit Edge Definitions
Example 13-7 initial Block in a UDP
Example 14-1 parameter Statements
Example 14-2 n-Bit Wide 4-to-1 Mux
Example 14-3 Parameterized Width Adder
Example 14-4 Mux with Parameterized Width and Number of Inputs
Example 14-5 Parameterized RAM
Example 14-6 The defparam Statement
Example 14-7 Using Parameterized Modules
Example 14-8 Parameter Passing by Order
Example 14-9 Parameter Passing by Named List
Example 15-1 Style 1 Moore State Machine
Example 15-2 Style 1 Mealy State Machine
Example 15-3 Style 2 Moore Machine
Example 15-4 Style 2 Mealy Machine
Example 15-5 Style 3 Mealy Machine
Example 15-6 Style 4 Moore Machine

162
162
163
163
164
165
165
166
167
173
174
174
175
176
177
178
182
183
183
185
188
188
189
189
189
190
191
xix
Example 16-8 The 8-Bit Adder Using always
Example 16-9 Simplified 8-Bit Adder Using always

Example 17-12 Improved Barrel Shifter
Example 17-13 Blocking vs Non Blocking Assignments
Example 18-1 Basic Sequential Cycle Test Bench
Example 18-2 Adder Test Module Repeated
Example 18-3 Using Verilog To Calculate Responses
Example 18-4 Simplifying the Test Bench with a task
Example 18-5 Using a Second Module To Check the Results
Example 18-6 Generating x's for Miscompare
Example 18-7 Printer Abstraction
Example 18-8 Printer Test Bench with Guessed Timing
Example 18-9 Response-Driven Printer Test Bench
Example 18-10 Test Bench for a RAM
Example 18-11 Memory Declaration
191
192
192
193
194
194
194
195
196
198
199
200
202
204
206
206
207

Example 18-12 Reversed Memory Declaration
Example 18-13 Memory File adder8.vec
Example 18-14 Adder Test Bench Reading from a File
Example 18-15 PROM Data File prom.dat
Example 18-16 Simple PROM
Example 18-17 Test Bench with No Vectors
Example 18-18 LFSR
Example 18-19 Testing the ALU with a LFSR and MISR
Example 18-20 ALU Modified Capture of Inputs and Outputs
Example 18-21 ALU Test Bench Repeated
Example 19-1 File List of 8 bit Adder adder.vc or adder.f
Example 19-2 Using the file list
Example 19-3 Counter Using `include
Example 19-4 Timing.vh
Example 19-5 System.vh
Example 19-6 Counter with commented ports
Example 19-7 Counter with commented ports
Example 19-8 System Test Bench
Example 19-9 Current_test.v
Example 19-10 Conditional Test
Example 19-11 Adder with two or three inputs
Example 20-1 Missing Initialization
Example 20-2 Negative Setup Time
Example 20-3 Corrected Register
Example 21-1 Initial Block to Create VCD Wave File
Example 21-2 Initial Block to Create SHM Wave File
Example 21-3 Interactive Verilog Module
Example 21-4 Single-Stepping
Example 21-5 always Loop Module
Example 21-6 my.key Command File

268
269
269
276
278
278
285
285
287
289
293
301
304
316
317
318
319
320
323
323
324
338
340
341
LIST OF TABLES
Table 2-1 Radix Specifiers
Table 2-2 Numbers and Their Values
Table 3-1 Verilog Primitives
Table 4-1 Procedural Timing keywords
Table 5-1 Format Specifiers

Table 13-4 Complete List of UDP Table Symbols
Table 15-1 State Machine Styles
Table 15-2 Sequential State Encoding
Table 15-3 Mapping State Code To Simplify Outputs
Table 15-4 Gray State Encoding
Table 15-5 States Compared with Outputs
Table 15-6 Outputs as State Code
13
17
20
46
49
51
54
54
62
82
82
82
83
84
86
86
87
87
87
88
88
88
88

Table A-3 Logic Table for or Primitive
Table A-4 Logic Table for nor Primitive
Table A-5 Logic Table for xor Primitive
Table A-6 Logic Table for xnor Primitive
Table A-7 Logic Table for buf Primitive
Table A-8 Logic Table for not Primitive
Table
A-9
Logic Table
for
bufif0
Primitive
Table A-10 Logic Table
for
bufif1
Primitive
Table A-11 Logic Table for notif0 Primitive
Table A-12 Logic Table for notif1 Primitive
Table A-13 Logic Table for nmos Primitive
Table A-14 Logic Table for rnmos Primitive
Table A-15 Logic Table for pmos Primitive
Table A-16 Logic Table for rpmos Primitive
Table A-17 Logic Table for cmos Primitive
Table A-18 Logic Table for rcmos Primitive
Table A-19 Delay and Precision Units
Table A-20 Strengths
Table A-21 Switch Strength Reduction
181
284
294

generally follows the outline of the Verilog class that I teach at the University of
California, Santa Cruz, Extension.
The Verilog language has been updated with the IEEE standardization in 1995, and
now the update to the standard in 2001. In learning Verilog, it is important to
current with the standards, however it should be noted that the Verilog language
itself has changed little compared to the tools, workstations and techniques used by
designers today vs. 1985. This third edition of Verilog Quickstart has been updated
to reflect the current best practices in use today.
This book does not take a “cookie-cutter” approach to learning Verilog, nor is it a
completely theoretical book. Instead, it describes some of the formal Verilog syntax
and definitions, and shows practical uses. Once we cover most of the constructs of
the language, the book examines how style affects the constructs you choose while
2
Verilog Quickstart
modeling your design. This text is not intended as a complete and exhaustive
reference on Verilog. For a comprehensive Verilog reference, I suggest one of the
reference manuals from IEEE, Open Verilog International (OVI) or your tool
vendor.
This book does not cover 100% of t he Verilog language; it focuses on the 90% of
Verilog that is used 90% of the time by designers who want to speed up their design
cycle by verifying their designs in simulation and rapidly producing them through
synthesis.
What is Verilog? In 1985, Automated Integrated Design Systems (renamed
Gateway Design Automation in 1986) introduced a product named Verilog. It was
the first logic simulator to seamlessly incorporate both a higher-level language and
gate-level simulation. Before Verilog, there were many gate-level simulators and
several higher-level language simulators, but there was no way to make them work
together easily. About the same time, Gateway added the -XL algorithm to its
product, creating Verilog-XL. It was the addition of this algorithm that put Verilog
on the


Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status