Module 3 Chapter 1
Module 3 Chapter 1
Gate-Level Modeling
Sujay S N
Asst. Prof.
Dept. of ECE
Dr. AIT, Bangalore
Learning Objectives
2
Gate Types
• There are two classes of basic gates: and/or gates and buf/not
gates.
And/Or Gates
• The first terminal in the list of gate terminals is an output and
the other terminals are inputs
• The and/or gates available in Verilog are shown below.
3
•These gates are instantiated to build logic circuits in Verilog
•More than two inputs can be specified in a gate instantiation.
•Gates with more than two inputs are instantiated by simply
adding more input ports in the gate instantiation.
•Verilog automatically instantiates the appropriate gate.
4
Gate Instantiation of And/Or Gates
5
Buf/Not Gates
Two basic buf/not gate primitives are provided in Verilog.
buf not
7
Gate Instantiations of Bufif/Notif Gates
8
Array of Instances
•There are many situations when repetitive instances are
required.
•These instances differ from each other only by the index of the
vector to which they are connected.
4-to-1 Multiplexer
10
Logic Diagram for Multiplexer
11
// Module 4-to-1 multiplexer. Port list is taken exactly from the I/O
diagram.
module mux4_to_1 (out, i0, i1, i2, i3, s1, s0);
// Port declarations from the I/O diagram
output out;
input i0, i1, i2, i3;
input s1, s0;
// Internal wire declarations
wire s1n, s0n;
wire y0, y1, y2, y3;
// Gate instantiations
// Create s1n and s0n signals.
not n1(s1n, s1);
not n2(s0n, s0);
13
// choose IN0
S1 = 0; S0 = 0;
#1 $display("S1 = %b, S0 = %b, OUTPUT = %b \n", S1, S0, OUTPUT);
// choose IN1
S1 = 0; S0 = 1;
#1 $display("S1 = %b, S0 = %b, OUTPUT = %b \n", S1, S0, OUTPUT);
// choose IN2
S1 = 1; S0 = 0;
#1 $display("S1 = %b, S0 = %b, OUTPUT = %b \n", S1, S0, OUTPUT);
// choose IN3
S1 = 1; S0 = 1;
#1 $display("S1 = %b, S0 = %b, OUTPUT = %b \n", S1, S0, OUTPUT);
end
endmodule
14
The output of the simulation is shown below
S1 = 0, S0 = 0, OUTPUT = 1
S1 = 0, S0 = 1, OUTPUT = 0
S1 = 1, S0 = 0, OUTPUT = 1
S1 = 1, S0 = 1, OUTPUT = 0
15
4-bit Ripple Carry Full Adder
16
OR
17
// Define a 1-bit full adder
module fulladd(sum, c_out, a, b, c_in);
// Internal nets
wire s1, c1, c2;
endmodule
18
// Define a 4-bit full adder
module fulladd4(sum, c_out, a, b, c_in);
// Internal nets
wire c1, c2, c3;
endmodule
19
Stimulus for 4-bit Ripple Carry Full Adder
// Define the stimulus (top level module)
module stimulus;
// Set up variables
reg [3:0] A, B;
reg C_IN;
wire [3:0] SUM;
wire C_OUT;
// Stimulate inputs
20
initial
begin
A = 4'd0; B = 4'd0; C_IN = 1'b0;
#5 A = 4'd3; B = 4'd4;
#5 A = 4'd2; B = 4'd5;
#5 A = 4'd9; B = 4'd9;
#5 A = 4'd10; B = 4'd15;
end
endmodule
21
Gate Delays
22
If the value changes to x, the minimum of the three delays is
considered.
If only one delay is specified, this value is used for all transitions.
If two delays are specified, they refer to the rise and fall delay
values. The turn-off delay is the minimum of the two delays.
23
If all three delays are specified, they refer to rise, fall, and
turn-off delay values.
24
Min/Typ/Max Values
For each type of delay rise, fall, and turn-off, three values
min, typ and max, can be specified.
The min value is the minimum delay value that the designer
expects the gate to have.
The typ value is the typical delay value that the designer expects
the gate to have.
The max value is the maximum delay value that the designer
expects the gate to have.
25
Min, typ, or max values can be chosen at Verilog run time.
This allows the designers the flexibility of building three delay values
for each transition into their design.
26
Example : Min, Max, and Typical Delay Values
// One delay
// if +mindelays, delay= 4
// if +typdelays, delay= 5
// if +maxdelays, delay= 6
and #(4:5:6) a1(out, i1, i2);
// Two delays
// if +mindelays, rise= 3, fall= 5, turn-off = min(3,5)
// if +typdelays, rise= 4, fall= 6, turn-off = min(4,6)
// if +maxdelays, rise= 5, fall= 7, turn-off = min(5,7)
and #(3:4:5, 5:6:7) a2(out, i1, i2);
// Three delays
// if +mindelays, rise= 2 fall= 3 turn-off = 4
// if +typdelays, rise= 3 fall= 4 turn-off = 5
// if +maxdelays, rise= 4 fall= 5 turn-off = 6
and #(2:3:4, 3:4:5, 4:5:6) a3(out, i1,i2);
27
Examples of invoking the Verilog-XL simulator with the command-
line options are shown below.
Assume that the module with delays is declared in the file test.v.
28
Delay Example
29
30
31
32
https://veriloghdl15ec53.blogspot.com/
33