Verilog: Here, We Will Use The Verilog HDL VHDL Is Another Common HDL
Verilog: Here, We Will Use The Verilog HDL VHDL Is Another Common HDL
1
History
Verilog was developed in 1984 by Philip Moorby.
It become property of Gateway Design Automation, which
was later acquired by Cadence design System.
In 1990 cadence released verilog to public.
Open verilog international (OVI) was formed to control
language specifications.
In 1993 IEEE accepted OVI verilog as standard .
Verilog HDL is an IEEE standard -1364.
2
Verilog Module
Module is the basic building block in Verilog.
Syntax : module module_name (port list);
port declaration
Parameter declaration
Assignments (data flow statement)
Procedural blocks
Instantiation of lower module
Tasks and function
endmodule
3
Verilog Module
A[1:0]
module name ports names
of module 2
7
Module Port List
Multiple ways to declare the ports of a module
8
Module Styles
Modules can be specified different ways
Structural – connect primitives and modules
RTL – use continuous assignments
Behavioral – use initial and always blocks
A single module can use more than one method!
9
Structural
A schematic in text form
Build up a circuit from gates/flip-flops
Gates are primitives (part of the language)
Flip-flops themselves described behaviorally
Structural design
Create module interface
Instantiate the gates in the circuit
Declare the internal wires needed to connect gates
Put the names of the wires in the correct port
locations of the gates
For primitives, outputs always come first
10
Structural Example
module majority (major, V1, V2, V3) ;
output major ;
input V1, V2, V3 ; V1 N1
A0
V2
wire N1, N2, N3;
11
RTL Example
Module is specified by specify dataflow.
The designer is aware to how the data flow
between register
12
Behavioral Example
Used to model behavior of design without concern of
hardware implementation details
endmodule
13
Language Conventions
Case-sensitivity
Verilog is case-sensitive.
Keywords are lower case
No space is allowed inside an indentifier.
Different names must be used for different items within
the same scope
Identifier :
Upper and lower case alphabetical
decimal digits
Underscore
14
Language Conventions
Maximum of 1024 characters in identifier
First character not a digit
Statement terminated by “ ; “
Strings enclosed in double quotes and must be on a
single line
Comments:
All characters after // in a line are treated as a
comment
Multi-line comments begin with /* and end with */
15
Four-Value Logic
A single bit can have one of FOUR 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
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 REALITY
Cannot detect x or z
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 driving signal (tri-state)
17
Resolving 4-Value Logic
A OUT A OUT
B B
A B OUT A B OUT
0 0 0 0 0 0
0 1 1 0 1 0
1 1 1 1 1 1
0 x x 0 x 0
0 z x 0 z 0
1 x 1 1 x x
1 z 1 1 z x
OUT A 0 1 x z
A
OUT 1 0 x x
18
Representing Numbers
Representation: <size>’<base><number>
size => number of BITS (regardless of base used)
base => base the given number is specified in
number => the actual value in the given base
Size : Specified in decimal only and represents number of bits
in number
Can use different bases
Decimal (d or D) – default if no base specified!
Hex (h or H)
Octal (o or O)
Binary (b or B)
Size defaults to at least 32…
You should specify the size explicitly!
Why create 32-bit register if you only need 5 bits?
May cause compilation errors on some compilers 19
Number Examples
Number Decimal Equivalent Actual Binary
4’d3 3 0011
3’hA 10 010
8’o26 22 00010110
5’b111 7 00111
8’b0101_1101 93 01011101
8’bx1101 - xxxx1101
‘o7 7 00000………111(32 bits)
10 10 ????
20
Review Questions
What are some advantages of using HDLs,
instead of schematic capture?
What are some ways in which HDLs differ from
conventional programming languages? How are
they similar?
What are the different styles of Verilog coding?
21