Professional Documents
Culture Documents
Language - VERILOG
For
Verilog
Verilog
Verilog-95
Verilog
SystemVerilog
System
is a collection
of modules.
Everything you write
in Verilog must be
inside a module
Exception: compiler
directives
in1
in2
my_module
out1
out2
f
inN
outM
7
Hierarchical Design
Module
Verilog Lexical
Conventions
Verilog
is:
Case sensitive
Based on the C programming language
White
space characters:
separator: ,
Statement terminator: ;
Comments
//
[end of line]
/* Multiple line
comment
*/
/* Nesting /* comments */ DO NOT work */
10
Constants
Binary
Binary
bbor
orBB
Octal
Octal
ooor
orOO
Decimal
Decimal
ddor
orDD
Hexadecimal
Hexadecimal
hhor
orHH
Consecutive
Consecutivechars
chars
0-f,
0-f,x,x,zz
Binary
Other bases
12
extension
MS bit = x or z
extend this
4b x1 = 4b xxx1
MS bit = 0 or 1
zero extension
4b 1x = 4b 001x
When
15 = <size>d 15
13
Verilog Identifiers
Identifiers
myidentifier
m_y_identifier
3my_identifier
$my_identifier
_myidentifier$
\module*
Case sensitivity
myid Myid
14
Verilog Keywords
Keywords
15
Verilog-2001
module mylogic (
input W, X,
output Y,
output reg [7:0] Z
);
...
endmodule
16
Nets/Signals
17
Verilog Representation
Models
Structural
Design Model
Algorithmic
FSM
Behavioral /
Data Flow
How it works
RTL
C
Gate
Structural
Layout
Physical
How it is
connected
How it is
implemented
19
E0
E1
ck, ...
Internal states
E2
E3
Status information
Clock and other external inputs...
20
DIN
DOUT
COMBINATIONAL
LOGIC
REGISTERS
CLOCK
21
A
B
SUM
COUT
22
module V2to4dec (
input I0, I1, EN,
output Y0, Y1, Y2, Y3
);
23
U1
U2
U3
U4
U5
U6
(NOTI0, I0);
(NOTI1, I1);
(Y0, NOTI0, NOTI1,
(Y1,
I0, NOTI1,
(Y2, NOTI0,
I1,
(Y3,
I0,
I1,
endmodule
24
inputs
inputs
outputs
: 8'b00000000;
25
Behavioral Model
Normally
Verilog Procedure
always @ (sensitivity list)
begin
local variable declarations
procedural statements
...
procedural statements
end
sequence of sequential
statements.
Activated when any signal
in the sensitivity list
changes.
Primarily a simulation
concept, but can be
synthesized
27
Procedural Statements
blocking/non-blocking
assignment
if-else
case
for
loop
while loop
repeat loop
infinite loop
disable
etc.
28
// enable inputs
// select inputs
// decoded outputs
G2A = ~ G2A_L;
G2B = ~ G2B_L;
case (A)
3'b000:
3'b001:
3'b010:
3'b011:
3'b100:
3'b101:
3'b110:
3'b111:
endcase
Y
Y
Y
Y
Y
Y
Y
Y
=
=
=
=
=
=
=
=
// invert inputs
// invert inputs
8'b10000000;
8'b01000000;
8'b00100000;
8'b00010000;
8'b00001000;
8'b00000100;
8'b00000010;
8'b00000001;
// invert outputs
29
always @*
begin
integer i;
Y = 8'b00000000;
if (G1 & G2 & G3)
for (i=0; i<=7; i=i+1)
if (i==A) Y[i] = 1'b1;
end
input
inputs
outputs
outputs
EI = ~EI_L;
// invert input
I = ~I_L;
// invert inputs
EO = 1'b1; GS = 1'b0; A = 3'b000;
if (EI==1'b0)
EO = 1'b0;
else
begin : Loop
Observe the use of
for (j=7;j>=0;j=j-1)
if (I[j]) begin
disable statement
GS = 1'b1; EO = 1'b0; A = j;
disable Loop;
exit execution of a
end
end
named group (Loop)
EO_L = ~EO;
GS_L = ~GS;
A_L = ~A;
end
endmodule
to
of
statements
// invert output
// invert output
// invert outputs
31
Example
x
1
x
3
x
2
x
4
32
Structural Model
module
endmodule
33
Behavioral Model
module
h);
input x1, x2, x3, x4;
output f, g, h;
endmodule
34
Homework #1 : adder
35
Structural Model
module
endmodule
36
Behavioral Model
module Fulladder (
input A,B,Cin
output S,Cout
);
assign {Cout,S} = A + B + Cin;
endmodule
37
Hierarchical Design
39
Module Instantiation
module FULLADDER (
input A, B, CARRY_IN,
output SUM, CARRY);
(1/2)
A module is instanced
as a module item of
another module.
Signals are linked by
port order connection:
lists signal connections
in the same order as
the port list in the
module definition.
Unconnected ports are
designated by two
commas with no signal
listed.
40
Module Instantiation
A
(2/2)
41
Module Instantiation:
Port Name Connection
module FULLADDER (
input A, B, CARRY_IN,
output SUM, CARRY);
wire W_SUM, W_CARRY1, W_CARRY2;
Port
name
connection:
(.port_name(signa
l),
.port_name(signal
), ...);
or module3 (CARRY,
W_CARRY2, W_CARRY1);
endmodule
module HALFADDER (
...
endmodule
Port
Copyright 2008 Acehub
Vista Sdn. Bhd.
names can
be listed in any
order,
42
Port Assignments
module
reg or net
input
net
ports
module
reg or net
output
net
ports
module
net
inout
net
ports
Copyright 2008 Acehub
Vista Sdn. Bhd.
43
Primitive Instances
Gate Type
Terminal Order
Examples
and
or
xor
nand
nor
xnor
(1_output, 1-or-more_inputs)
buf
not
(1-or-more_outputs, 1_input)
bufif0
bufif1
notif0
notif1
(1_output, 1_input,
1_control)
user-definedprimitives
(1_output, 1-or-more_inputs)
C
A
44
Primitive Instances:
Half Adder Example
module HALFADDER (
input A, B,
output SUM, CARRY);
xor (SUM, A, B);
and (CARRY, A, B);
endmodule
Copyright 2008 Acehub
Vista Sdn. Bhd.
45
Quiz # 1
1) Write the Verilog code for a 1 bit
comparator using
a) Structural Model
b) Behavioral Model
2) Using the 1 bit comparator,
write a Verilog code for a 4 bit
comparator using both models as
above.
47