Verilog - Introduction
Verilog - Introduction
-D
,C
TS
Verilog HDL
AC
Introduction
©
AC
verification.
• Verilog is invented as “Simulation Language”.
-D
• Designed by Phil Moorby and Prabhu Goel.
• 1989 Cadence Design System acquired Gateway Design
,C
Automation.
• 1990 Verilog became open language.
TS
• Verilog became “IEEE Standard 1364” in 1995.
• The revision of the language is done in 2001 and 2005.
AC
• The Verilog IEEE 1364-2001 is in use.
©
AC
work like it works in “C”]
• Verilog simulator has to manage less data compare to
-D
VHDL simulator.
• Verilog can be used to model a digital system as
,C
algorithmic, RTL, gate and switch level.
• Verilog can’t be used for system level modeling.
TS
• Advanced simulation features like TEXTIO, PLI simpler.
• User can’t define anything.
AC
• There is no concept of package.
©
AC
• The basic rule are as follows,
-D
– May contain letters (a-z, A-Z), digit (0-9), _ and $.
,C
– Must start with letters or underscore.
TS
– Are case sensitive.
AC
– Other printable ASCII character may be used in an
escaped identifier.
©
AC
• Syntax
Number_of_bits’radix value
-D
• Radix specifier
,C
– ‘b or ‘B : Binary
– ‘d or ‘D : Decimal
TS
– ‘o or ‘O : Octal
– ‘h or ‘H : Hexadecimal
AC
• Signed Numbers
– (s/S) before radix-specifier will be interpreted as 2C.
©
AC
• 3’b011 // is a 3-bit binary number
• 5’O473 // is a 5-bit octal number
-D
• 8’d -6 // is an illegal syntax
,C
• -8’d6 // defines the 2’s complement of 6, (8-bit)
• 4’shf //denotes the 4-bit number “1111”, to be
TS
//interpreted as 2C number or “-1”. This is
//equivalent to -4’h1
AC
• -4’sd15 //equivalent to –(-4’d1), “0001”
• 11’h0z3 //0000zzzz0011
• 32’h12ab_f001
©
AC
• Module declaration:
-D
module <module_name>(<name_of_ports>);
,C
//definition of ports;
//definition of data objects;
TS
//behavioral or RTL code;
endmodule //no semicolon
AC
©
AC
• All the declaration used within a model must be declared
-D
locally within the module.
,C
• Functional composition is a description of structure
using primitives, data-flow assignment and sequential
constructs. TS
AC
• A module can be instantiated inside another module as
component.
©
AC
– input: ports defined as input are input ports
-D
– output: these ports can be read back internally.
,C
– inout: bi-directional ports defined as inout ports. Inout
ports can never be updated in procedural assignment
statement. TS
AC
©
AC
• The default net type is plain wire with no special property.
• Ex:
– wire, tri : default net type, plain wire
-D
– supply0, supply1 : power and ground rails
– wor,trior : multiple drivers that are Wire-ORed
,C
– wand, triand : multiple drivers that are Wire-ANDed
– trireg : nets with capacitive storage
– tri1, tri0 TS : pull up or down when not driven
AC
©
AC
• ex:
-D
– wand w; // A scalar net of type “wand”.
,C
– tri [15:0] busa; // a 16-bit three-state bus;
TS
– wire [0:31] w1,w2; // Two 32 bit wires with msb= bit 0
AC
– wire #5 addr_sel; //a scalar wire with delay
AC
• Assignments to reg’s is done in procedural block.
-D
in the testbench.
,C
• Verilog language offers four type of register data type:
– integer : signed 32 bit integer variable.
TS
– real : Signed double precision floating-point variable
– reg : Unsigned storage of varying bit width
AC
– time : Unsigned 64 bit integer variable
Hardware.
AC
• Can be used as substitute for a constant or literal.
-D
• Can be changed on instance by instance basis.
,C
• ex:
parameter cycle = 20;
TS
parameter prop_del = 3;
parameter setup = cycle/2 – prop_del;
AC
parameter file = “../src/data_input.txt”;
©
AC
– An input or inout port must be a net.
-D
,C
– A signal assigned a value in a procedural block must
be a register data type.
TS
AC
©
AC
• assign [drive_strength] [delay] list_of_assignments;
-D
• LHS is any net type.
• Automatically get evaluated when any of the operands
,C
change.
• Can not occur in sequential block.
TS
• Can make explicit or implicit continuous assignment.
– Ex:
AC
wire ab;
assign ab = a & b; //explicit
wire in_ = ~in; //implicit
©
AC
output [7:0] o1,o2;
output [31:0] SUM;
output eq,AND,OR,even,odd,one,COUT;
-D
input a,b,CIN;
input [7:0] in;
input [31:0] A,B;
,C
wire [7:0] #3 o2;//no assignments yet, but a delay
TS
tri AND = a&b,OR=a|b; //two assignments
wire #5 eq = (a ==b); //implicit, with delay
wire (weak1,strong0) [7:0] #(3,5,2) o1 = in; // strength and delays
AC
assign o2[7:4]=in[3:0],o2[3:0]=in[7:4];//part-select
tri #5 even = ^in, odd = ~^in;// delay, two assignments
wire one = 1'b1;//constant assignment
©
AC
• Organized as follows
– Logic Gates : and, or, xor, xnor, nand, nor
-D
– Buffers : buf, not, pullup, pulldown, etc.
– Transistor : nmos, pmos, cmos etc.
,C
• First port in built in primitive is output.
TS
• The same primitive can be used for more number of
AC
inputs.
AC
-D
module mux(OUT, A, B, SEL);
,C
output OUT;
input A,B,SEL;
TS
not I1 (sel_n, SEL);
and I2 (sel_a, A, SEL);
AC
endmodule
AC
not I1 (sel_n, SEL);
-D
and I2 (sel_a, A, SEL);
and I3 (sel_b, sel_n, B);
,C
or I4 (OUT, sel_a, sel_b);
endmodule
TS
AC
©
AC
[terminal,.. ];
-D
• Ex : notif1 #3 n1 (inv_out, in1, cntr);
,C
• Rise, fall and turnoff delay
• notif1 #(3, 4, 5) n1 (inv_out, in1, cntr);
TS
• minimum, typical, maximum delay
AC
• notif1 #(3:4:5, 8:10:12, 15:16:17) n1 (inv_out, in1, cntr);
©
AC
• Assignment of ports is done by
-D
– Positional mapping
– Naming mapping
,C
• Syntax
.port_name (net_to_be_connected)
TS
AC
©
AC
output [1:0] OUT;
-D
input [1:0] A,B;
input SEL;
,C
mux hi (OUT[1], A[1], B[1], SEL);
TS
mux lo (OUT[0], A[0], B[0], SEL);
AC
endmodule
©
AC
input [1:0] A,B,
input SEL);
-D
mux hi (.OUT(OUT[1]), .A(A[1]), .B(B[1]), .SEL(SEL));
,C
mux lo (.OUT(OUT[0]), .A(A[0]), .B(B[0]), .SEL(SEL));
TS
endmodule
AC
©
AC
module mux2(output [1:0] OUT,
input [1:0] A,B,
-D
input SEL);
,C
mux m1[1:0] (.OUT(OUT), .A(A), .B(B), .SEL(SEL));
endmodule
TS
AC
©
• Write the code for single bit full adder and extend it up to
AC
4 bit using the idea of component instantiation.
-D
• Write the program for D latch using gate primitive.
,C
TS
AC
©
AC
• Equality operators
-D
== (Logical equality), === (case equality), <=, >=, <, >
,C
• Logical operator
!(not), &&(and), ||(or)
TS
• Logical bitwise operator OR Unary Reduction operators
AC
|, &, ^, ~, ~^
©
AC
Right),<<<(Signed Shift Left)
-D
• Concatenation
{ } // e.g.: B[1:0] = {B1, B0};
,C
• Conditional operator
TS
<condition>? <true>:<false>
AC
©
AC
...
-D
a = -1; //1111
,C
b = 8; //1000
c = 8; //00001000
c = c + a;
TS
//00010111
b = b + a; //0111
AC
©
AC
a = 8’b00000011;
-D
b = 8’b00000100;
c = 8’b00011000;
,C
d = 8’b11100000;
y = {a[1:0], b[2], c[4:3], d[7:5]};
TS
• You can concatenate an unlimited number of operands,
AC
separating with comma.
AC
• The bitwise negation operator (~) inverts each bit of the
-D
operands.
,C
• !4’b0100 //0
• !4’b0000 //1
• !4’b00z0 //x
TS
• !4’bx000 //x
AC
• ~4’b01zx //10xx
©
AC
• They operates across all bits of a vector.
-D
• Ex
&4’b1110 //0
,C
&4’b1111 //1
|4’b0000 //0
TS
|4’b1000 //1
AC
^4’b1110 //1
©
^~4’b1110 //0
AC
• Ex
4’b01zx & 4’b0000 //0000
-D
4’b01zx & 4’b1100 //0100
,C
4’b01zx | 4’b1111 //1111
4’b01zx | 4’b0011 //0111
TS
4’b01zx ^ 4’b1111 //10xx
AC
4’b01zx ^~ 4’b0000 //10xx
©
AC
• Ex
-D
8’b00011000 << 2 //01100000
,C
8’b00011000 >> 2 //00000110
8’b00011000 << -2
TS //00000000
AC
8’b00011000 << 1’bx //xxxxxxxx
©
AC
== 0 1 Z X
0 1 0 X X
1 0 1 X X
-D
Z X X X X
,C
X X X X X
TS
• Case equality operator
=== 0 1 Z X
AC
0 1 0 0 0
1 0 1 0 0
©
Z 0 0 1 0
X 0 0 0 1
AC
input in1, in2,sel;
output op;
-D
assign op = sel ? in1 : in2 ;
,C
endmodule
TS
AC
©
AC
Concatenation & replication { } {{ }}
Unary ! ~ & ^ ^~
-D
Arithmetic * / %
,C
+ -
Logical Shift << >>
Relational
TS < <= > >=
Equality == != === !==
AC
Conditional ?:
AC
• Design 8:3 priority encoder
-D
,C
TS
AC
©