Documente Academic
Documente Profesional
Documente Cultură
Differences:
VHDL was designed to support system level design and
specification.
Verilog HDL was designed primarily for digital hardware
designers developing FPGAs and ASICs.
The differences becomes clear when one analyze the language features.
VHDL
– Provides some high level constructs not available in
Verilog (User defined types, Configurations etc.,)
Verilog
– Provides comprehensive support for low-level digital
design
– Not available in native VHDL
• Range of type definitions and supporting
functions(called packages need to be included)
R56_68
FIVE$
$count Illegal
12six_b Illegal
MODULE-I VLSI SYSTEM DESIGN 20
• Sized numbers.
– <size> ‟<base format> <number>
• Unsized numbers.
– ‟<base format> <number>
• <size> in decimal
• <base format> can be b or B, d or D, o or O and h or
H.
Examples:
32 ‟B z // this is a 32-bit high impedance number
6 ‟h X // this is a 6-bit hex number
12 ‟H 13x // this is a 12-bit hex number
module ex2(y,a,b,c,d);
Module name: ex2
output y;
input a,b,c,d; No. of ports: 5
wire f1,f2;
or o1(f1,a,b)
and a1(f2,c,d);
xor x1(y,f1,f2);
endmodule
MODULE-I VLSI SYSTEM DESIGN 29
• In Verilog nesting of modules is not permitted i.e.,
one module definition cannot contain another
module definition within the module and
endmodule statements.
module counter(q, clk, reset);
output [3:0]q;
input clk, reset;
Module / Primitive
T_FF T_FF
(tff0) (tff1)
Top module
module templates
Module Module
Module ex1 ex2
ex2
Primitive 1 Primitive 2
inout bidirectional
Inputs
Internally, input ports must always be of the type net.
Externally, the inputs can be connected to a variable
which is a reg or a net.
Outputs
Internally, outputs ports can be of the type reg or net.
Externally, outputs must always be connected to a net.
They cannot be connected to a reg.
Inouts
Internally, inout ports must always be of the type net.
Externally, inout ports must always be connected to a
net.
MODULE-I VLSI SYSTEM DESIGN 37
Port Connection Rules
Width matching
It is legal to connect internal and external items of different sizes
when making inter-module port connections. However, a warning
is typically issued that the widths do not match.
Unconnected ports
Verilog allows ports to remain unconnected. For example, certain
output ports might be simply for debugging, and you might not be
interested in connecting them to the external signals. You can let a
port remain unconnected by instantiating a module as shown
below.
• Default Value : z
reg reset;
initial
begin
reset = 1 ‟b1; //initialize reset to 1
#100 reset = 1 ‟b0; /* after 100 times units reset
is de asserted*/
end
• wire [0:15]busB;
busB[9]; // bit # 9 or 7th bit of vector busB from LSB
• reg [31:0]cnt_out;
cnt_out[14:7]; // group of 8 bits of a vector register
cnt_out[7:14]; // is illegal addressing
Divide / binary
Add + binary
Subtract - binary
Modulus % binary
logical or || binary
a1 && a2 is 0 (false)
a1 || a2 is 1 (true)
!a2 is 0 (false)
a=2‟b1x b=2‟b11
a || b // is unknown, evaluates to x.
a >b // evaluates to 0
a <= b // evaluates to 1
b >= c // evaluates to x
Bitwise or | Binary
c = ~a; // c = 3‟b000
c = a & b; // c = 3‟b101
c = a & b; // c = 3‟b111
c = a ^ b; // c = 3‟b010
c = a | d; // c = 3‟b1x1
reduction or | unary
c = |x // c= 0|1|1|0|0 c=1
c = ^x // c=0^1^1^0^0 c=0
Example:
a = 4‟b1011;
y = a >> 2; // y =4‟b0010, 0‟s filled in MSB
y = a << 2; // y = 4‟b1100, 0‟s filled in LSB
a=3‟b101; b=3‟b111;
y = {a,b}; // y = 6‟b101111
y = {a,b,3‟b010}; // y =101111010
a=3‟b101 b =2‟b10
control out
1 I1
0 I2
endmodule
buf bufif0
and not bufif1
nand notif0
or notif1
nor
xor
xnor
• Rise delay: refers to the transition to the „1‟ value from any other value.
• Fall delay: refers to the transition to the „0‟ value from any other value.
• Two delay specification: If specified, they refer to rise and fall times.
or #(rise_del, fall_del) o1 (out, i1, i2);
or #(5, 6) o1 (out, i1, i2);
• Three delay specification: If specified, they refer to rise, fall and turn-
off times.
bufif1 #(rise_del, fall_del, turn_off_del) b1 (out, in, cnt);
bufif1 #(2, 3, 5) b1 (out, in, crtl);
MODULE-I VLSI SYSTEM DESIGN 86
Primitive gate delays allow three values each for the rise, fall and
turn-off delays.
The three values are minimum, typical and maximum, and the
three are separated by colons.
Verilog Test
Bench
• Syntax : $<keyword>
• $monitor
• $strobe
• $write
• $finish
• $stop
`timescale 100 ns / 1 ns
module dummy1;
reg toggle;
//initialize toggle
initial
toggle = 1'b0;
always #5 begin
toggle = ~toggle;
$display("%d , In %m toggle = %b ", $time, toggle);
end
endmodule
module generate_mux
D
(data,select,out); A MUX
OUT
input [0:7] data; T
A
input [0:2]select;
output out;
wire out;
assign out = data[select];
SELECT
endmodule
module generate_mux
a
(a,b,f,s);
input a,b;
b
MUX f
input s;
output f;
wire f; s
assign f = s? a : b;
endmodule
Example:
module and_ex(and_out , a_in, b_in);
input a_in, b_in;
output and_out;
wire and_out;
assign #10 and_out = a_in & b_in;
endmodule
• Any event on the RHS signals which is not lasting for the
amount of inertial delay specified will not have any effect on
the LHS target.
MODULE-I VLSI SYSTEM DESIGN 137
in1
in2
out
10 20 30 60 70 80 85
time
Example:
output and_out;
endmodule
Example:
module and_ex(and_out , a_in, b_in);
input a_in, b_in;
output and_out;
wire #10 and_out;
assign and_out = a_in & b_in;
endmodule
initial initial
begin
xor_out = in1 ^ in2; and_out = a_in & b_in;
end
initial
initial begin
begin clk = 1‟b0;
enable = 1‟b0; reset = 1‟b0;
rst = 1‟b0; initial
#100 rst = 1‟b1; begin
#20 enable = 1‟b1; #100 reset = 1‟b1;
end #20 clk = 1‟b1;
end
end
MODULE-I VLSI SYSTEM DESIGN 146
always statement
• Starts execution at „0‟ simulation time and is active all
through out the entire simulation.
always
always @(posedge reset)
begin
begin
cnt = 1‟b0;
if (reset == 1‟b1)
reset = 1‟b0;
q_out = 1‟b0;
always @(posedge clk)
else
begin
q_out = d_in;
#100 cnt = 1‟b1;
end
#20 enable = 1‟b1;
end
end
MODULE-I VLSI SYSTEM DESIGN 149
always block - Examples
always statement without
always statement with timing control -Example
timing control - Example
module cntr(cnt_out, module clk_gen(clk_out);
clk_in);
input clk_in;
output cnt_out; output clk_out;
reg clk_out;
reg cnt_out;
wire clk_in;
always
always @(posedge clk_in) #5 clk_out = ~clk_out;
cnt_out = cnt_out + 1‟b1;
initial
endmodule clk_out = 1‟b1;
endmodule
MODULE-I VLSI SYSTEM DESIGN 150
Block statements
• Provides a means of grouping two or more procedural
statements together.
• Types of blocks:
– sequential block / begin-end block
– parallel block / fork-join block
• The assignments to the target gets scheduled for the end of the
simulation cycle.
– Normally occurs at the end of the sequential block (begin …..
end)
– Statements subsequent to the instruction under the
consideration are not blocked by the assignment.
• Recommended style for modeling sequential logic
- Can be used to assign several „reg‟ type variables synchronously,
under the control of a common block
Format:
#<delay_value> <target> = RHS expression;
e.g. : #10 c = a + b;
#(2:4:6,3:5:7) or_out = a | b;
e.g. : c = #10 a + b;
• Event or control
e.g.: @ (ena) q = d;
q = @ (negedge clk) d;
Format:
always @ (event1 or event2 or event3)
Format:
wait (condition) <statement>
reg q_out;
wire d_in, ena_in_n;
1. Execute initialization
2. Evaluate expression
3. If the expression evaluates to the true state(1), carry out
statements. Go to step 5.
4. If the expression evaluates to false state (0), exit the loop.
Format:
repeat (a)
begin
statements
end
Format:
while (expression)
begin
statements
end
MODULE-I VLSI SYSTEM DESIGN 190
While loop - Example
Format:
forever
begin
statements;
end
endmodule
Format:
#<delay_value> <target> = RHS expression;
e.g. : #10 c = a + b;
#(2:4:6,3:5:7) or_out = a | b;
e.g. : c = #10 a + b;
• Event or control
e.g.: @ (ena) q = d;
q = @ (negedge clk) d;
Format:
always @ (event1 or event2 or event3)
Format:
wait (condition) <statement>
reg q_out;
wire d_in, ena_in_n;
1. Execute initialization
2. Evaluate expression
3. If the expression evaluates to the true state(1), carry out
statements. Go to step 5.
4. If the expression evaluates to false state (0), exit the loop.
Format:
repeat (a)
begin
statements
end
Format:
while (expression)
begin
statements
end
MODULE-I VLSI SYSTEM DESIGN 224
While loop - Example
Format:
forever
begin
statements;
end
endmodule