Module - 3 Gate Level Modeling and Data Flow Modeling: Objectives
Module - 3 Gate Level Modeling and Data Flow Modeling: Objectives
MODULE -3
GATE LEVEL MODELING AND DATA FLOW MODELING
3.1 : Objectives
Identify logic gate primitives provided in Verilog.
Understand instantiation of gates, gate symbols, and truth tables for and/or and buf/not type gates.
Understand how to construct a Verilog description from the logic diagram of the circuit.
Describe rise, fall, and turn-off delays in the gate-level design and Explain min, max, and typ delays
in the gate-level design
Describe the continuous assignment (assign) statement, restrictions on the assign statement, and the
implicit continuous assignment statement.
Explain assignment delay, implicit assignment delay, and net declaration delay for continuous
assignment statements and Define expressions, operators, and operands.
Use dataflow constructs to model practical digital circuits in Verilog
A logic circuit can be designed by use of logic gates. Verilog supports basic logic gates as predefined
primitives. These primitives are instantiated like modules except that they are predefined in Verilog and do not
need a module definition. All logic circuits can be designed by using basic gates. There are two classes of basic
gates: and/or gates and buf/not gates.
And/or gates have one scalar output and multiple scalar inputs. The first terminal in the list of gate terminals is
an output and the other terminals are inputs. The output of a gate is evaluated as soon as one of the inputs
changes. The and/or gates available in Verilog are: and, or, xor, nand, nor, xnor.
The corresponding logic symbols for these gates are shown in Figure 3-1. Consider the gates with two inputs.
The output terminal is denoted by out. Input terminals are denoted by i1 and i2.
These gates are instantiated to build logic circuits in Verilog. Examples of gate instantiations are shown
below. In Example 3-1, for all instances, OUT is connected to the output out, and IN1 and IN2 are
connected to the two inputs i1 and i2 of the gate primitives. Note that the instance name does not need to be
specified for primitives. This lets the designer instantiate hundreds of gates without giving them a name.
More than two inputs can be specified in a gate instantiation. Gates with more than two inputs are
Dept.of ECE, SJBIT Page 1
instantiated by simply adding more input ports in the gate instantiation. Verilog automatically instantiates
the appropriate gate.
The truth tables for these gates define how outputs for the gates are computed from the inputs. Truth tables are
defined assuming two inputs. The truth tables for these gates are shown in Table 3-1. Outputs of gates with
more than two inputs are computed by applying the truth table iteratively.
Table 3-1. Truth Tables for And/Or
Buf/not gates have one scalar input and one or more scalar outputs. The last terminal in the port list is connected
to the input. Other terminals are connected to the outputs. We will discuss gates that have one input and one
output. Two basic buf/not gate primitives are provided in Verilog
buf not
The symbols for these logic gates are shown in Figure 3-2.
Figure 3-2. Buf/not Gates
These gates are instantiated in Verilog as shown Example 3-2. Notice that these gates can have multiple
outputs but exactly one input, which is the last terminal in the port list.
Truth tables for gates with one input and one output are shown in Table 3-2.
Bufif/notif
Gates with an additional control signal on buf and not gates are also available.
bufif1 notif1
bufif0 notif0
These gates propagate only if their control signal is asserted. They propagate z if their control signal is
deasserted. Symbols for bufif/notif are shown in Figure 3-3.
The truth tables for these gates are shown in Table 3-3
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. To simplify specification of such instances, Verilog HDL
allows an array of primitive instances to be defined. Example3-4 shows an example of an array of instances.
3.1.4 Examples
Having understood the various types of gates available in Verilog, consider the real examples that illustrates
design of gate-level digital circuits.
Gate-level multiplexer
Consider the design of 4-to-1 multiplexer with 2 select signals. Multiplexers serve a useful purpose in logic
design. They can connect two or more sources to a single destination. They can also be used to implement
Boolean functions. We will assume for this example that signals s1 and s0 do not get the value x or z. The I/O
diagram and the truth table for the multiplexer are shown in Figure 3-4. The I/O diagram will be useful in
setting up the port list for the multiplexer.
Implement the logic for the multiplexer using basic logic gates. The logic diagram for the multiplexer is shown
in Figure 3-5.
output out;
// Gate instantiations
This multiplexer can be tested with the stimulus shown in Example 3-6. The stimulus checks that each
combination of select signals connects the appropriate input to the output. The signal OUTPUT is displayed
one time unit after it changes. System task $monitor could also be used to display the signals when they
change values.
module stimulus;
// to inputs
wire OUTPUT;
initial
begin
// choose IN0
S1 = 0; S0 = 0;
// choose IN1
S1 = 0; S0 = 1;
// choose IN2
S1 = 1; S0 = 0;
// choose IN3
S1 = 1; S0 = 1;
end
endmodule
The output of the simulation is shown below. Each combination of the select signals is tested.
S1 = 0, S0 = 0, OUTPUT = 1
S1 = 0, S0 = 1, OUTPUT = 0
S1 = 1, S0 = 0, OUTPUT = 1
S1 = 1, S0 = 1, OUTPUT = 0
Consider the design of a 4-bit full adder whose port list was defined in, List of Ports. We use primitive
logic gates, and we apply stimulus to the 4-bit full adder to check functionality. For the sake of simplicity,
we will implement a ripple carry adder. The basic building block is a 1-bit full adder. The mathematical
equations for a 1-bit full adder are shown below.
sum = (a b cin)
cout = (a b) + cin (a b)
The logic diagram for a 1-bit full adder is shown in Figure 3-6.
Figure 3-6. 1-bit Full Adder
This logic diagram for the 1-bit full adder is converted to a Verilog description, shown in Example 3-7.
input a, b, c_in;
// Internal nets
endmodule
A 4-bit ripple carry full adder can be constructed from four 1-bit full adders, as shown in Figure 3-7. Notice that
fa0, fa1, fa2, and fa3 are instances of the module fulladd (1-bit full adder).
Figure 3-7. 4-bit Ripple Carry Full Adder
This structure can be translated to Verilog as shown in Example 3-8. Note that the port names used in a 1-bit
full adder and a 4-bit full adder are the same but they represent different elements. The element sum in a 1-bit
adder is a scalar quantity and the element sum in the 4-bit full adder is a 4-bit vector quantity. Verilog keeps
names local to a module.
Names are not visible outside the module unless hierarchical name referencing is used. Also note that instance
names must be specified when defined modules are instantiated, but when instantiating Verilog primitives, the
instance names are optional.
Example 3-8 Verilog Description for 4-bit Ripple Carry Full Adder
output c_out;
input[3:0] a, b;
input c_in;
// Internal nets
endmodule
Finally, the design must be checked by applying stimulus, as shown in Example 3-9. The module stimulus
stimulates the 4-bit full adder by applying a few input combinations and monitors the results.
module stimulus;
// Set up variables
reg [3:0] A, B;
reg C_IN;
wire C_OUT;
initial
begin
$monitor($time," A= %b, B=%b, C_IN= %b, --- C_OUT= %b, SUM= %b\n",
end
// Stimulate inputs
initial
begin
#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
Until now, circuits are described without any delays (i.e., zero delay). In real circuits, logic gates have delays
associated with them. Gate delays allow the Verilog user to specify delays through the logic circuits. Pin-to-pin
delays can also be specified in Verilog.
There are three types of delays from the inputs to the output of a primitive gate.
Rise delay
The rise delay is associated with a gate output transition to a 1 from another value.
Fall delay
The fall delay is associated with a gate output transition to a 0 from another value.
Turn-off delay
The turn-off delay is associated with a gate output transition to the high impedance value (z) from another
value. If the value changes to x, the minimum of the three delays is considered.
Three types of delay specifications are allowed. 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. If all three delays are specified, they refer to rise, fall, and turn-off delay values. If
no delays are specified, the default value is zero. Examples of delay specification are shown in Example 3-10.
Verilog provides an additional level of control for each type of delay mentioned above. For each type of delay?
rise, fall, and turn-off?three values, min, typ, and max, can be specified. Any one value can be chosen at the
start of the simulation. Min/typ/max values are used to model devices whose delays vary within a minimum and
maximum range because of the IC fabrication process variations.
Min value
The min value is the minimum delay value that the designer expects the gate to have.
Typ val
The typ value is the typical delay value that the designer expects the gate to have.
Max value
The max value is the maximum delay value that the designer expects the gate to have. Min, typ, or max values
can be chosen at Verilog run time. Method of choosing a min/typ/max value may vary for different simulators
or operating systems. (For Verilog- XL , the values are chosen by specifying options +maxdelays, +typdelays,
and +mindelays at run time. If no option is specified, the typical delay value is the default).
This allows the designers the flexibility of building three delay values for each transition into their design. The
designer can experiment with delay values without modifying the design.
Examples of min, typ, and max value specification for Verilog-XL are shown in Example3-11.
// One delay
// if +mindelays, delay= 4
// if +typdelays, delay= 5
// if +maxdelays, delay= 6
// Two delays
// Three delays
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.
Let us consider a simple example to illustrate the use of gate delays to model timing in the logic circuits. A
simple module called D implements the following logic equations:
out = (a b) + c
The gate-level implementation is shown in Module D (Figure 3-8). The module contains two gates with delays
of 5 and 4 time units.
output out;
input a,b,c;
// Internal nets
wire e;
endmodule
module stimulus;
// Declare variables
reg A, B, C;
wire OUT;
initial
begin
#20 $finish;
end
endmodule
The waveforms from the simulation are shown in Figure 3-9 to illustrate the effect of specifying delays on
gates. The waveforms are not drawn to scale. However, simulation time at each transition is specified below the
transition.
2. At time 10, after A, B, and C all transition to 1, OUT transitions to 1 after a delay of 4 time units and E
changes value to 1 after 5 time units.
3. At time 20, B and C transition to 0. E changes value to 0 after 5 time units, and OUT transitions to 0, 4 time
units after E changes.
It is a useful exercise to understand how the timing for each transition in the above waveform corresponds to
the gate delays shown in Module D.
3.4 Dataflow Modeling
For small circuits, the gate-level modeling approach works very well because the number of gates is limited and
the designer can instantiate and connects every gate individually. Also, gate-level modeling is very intuitive to a
designer with a basic knowledge of digital logic design. However, in complex designs the number of gates is
very large. Thus, designers can design more effectively if they concentrate on implementing the function at a
level of abstraction higher than gate level. Dataflow modeling provides a powerful way to implement a design.
Verilog allows a circuit to be designed in terms of the data flow between registers and how a design processes
data rather than instantiation of individual gates.
A continuous assignment is the most basic statement in dataflow modeling, used to drive a value onto a net. This
assignment replaces gates in the description of the circuit and describes the circuit at a higher level of abstraction.
The assignment statement starts with the keyword assign. The syntax of an assign statement is as follows.
The default value for drive strength is strong1 and strong0. The delay value is also optional and can be used to
specify delay on the assign statement. This is like specifying delays for gates. Continuous assignments have the
following characteristics:
1. The left hand side of an assignment must always be a scalar or vector net or a concatenation of scalar and vector
nets. It cannot be a scalar or vector register.
2. Continuous assignments are always active. The assignment expression is evaluated as soon as one of the right-
hand-side operands changes and the value is assigned to the left-hand-side net.
3. The operands on the right-hand side can be registers or nets or function calls. Registers or nets can be scalars or
vectors.
4. Delay values can be specified for assignments in terms of time units. Delay values are used to control the time
when a net is assigned the evaluated value. This feature is similar to specifying delays for gates. It is very useful in
modeling timing behavior in real circuits.
Examples of continuous assignments are shown below. Operators such as &, ^, |, {, } and + used in the examples, At
this point, concentrate on how the assign statements are specified.
Instead of declaring a net and then writing a continuous assignment on the net, Verilog provides a shortcut by which
a continuous assignment can be placed on a net when it is declared. There can be only one implicit declaration
assignment per net because a net is declared only once.
In the example below, an implicit continuous assignment is contrasted with a regular continuous assignment.
wire out;
If a signal name is used to the left of the continuous assignment, an implicit net declaration will be inferred for that
signal name. If the net is connected to a module port, the width of the inferred net is equal to the width of the module
port.
// Continuous assign. out is a net.
assign out = i1 & i2; //Note that out was not declared as a wire
3.5 Delays
Delay values control the time between the change in a right-hand-side operand and when the new value is assigned
to the left-hand side. Three ways of specifying delays in continuous assignment statements are regular assignment
delay, implicit continuous assignment delay, and net declaration delay.
The first method is to assign a delay value in a continuous assignment statement. The delay value is specified after
the keyword assign. Any change in values of in1 or in2 will result in a delay of 10 time units before re-computation
of the expression in1 & in2, and the result will be assigned to out. If in1 or in2 changes value again before 10 time
units when the result propagates to out, the values of in1 and in2 at the time of re-computation are considered. This
property is called inertial delay. An input pulse that is shorter than the delay of the assignment statement does not
propagate to the output.
1. When signals in1 and in2 go high at time 20, out goes to a high 10 time units later (time = 30).
3. However, in1 changes to high at 80, but it goes down to low before 10 time units have elapsed.
4. Hence, at the time of re-computation, 10 units after time 80, in1 is 0. Thus, out gets the value 0. A pulse of width
less than the specified assignment delay is no propagated to the output.
An equivalent method is to use an implicit continuous assignment to specify both a delay and an assignment on the
net.
//same as
wire out;
The declaration above has the same effect as defining a wire out and declaring a continuous assignment on out.
A delay can be specified on a net when it is declared without putting a continuous assignment on the net. If a delay is
specified on a net out, then any value change applied to the net out is delayed accordingly. Net declaration delays
can also be used in gate-level modeling.
//Net Delays
wire # 10 out;
wire out;
Dataflow modeling describes the design in terms of expressions instead of primitive gates. Expressions, operators,
and operands form the basis of dataflow modeling.
Expressions are constructs that combine operators and operands to produce a result.
a ^ b
addr1[20:17] + addr2[20:17]
in1 | in2
Operands can be any one of the data types defined, Data Types. Some constructs will take only certain types of
operands. Operands can be constants, integers, real numbers, nets, registers, times, bit-select (one bit of vector net or
a vector register), part-select (selected bits of the vector net or register vector), and memories or function calls
real a, b, c;
reg ret_value;
Operators
Operators act on the operands to produce desired results. Verilog provides various types of operators. Operator
Types d1 && d2 // && is an operator on operands d1 and d2.
Operator Types
Verilog provides many different operator types. Operators can be arithmetic, logical, relational, equality, bitwise,
reduction, shift, concatenation, or conditional. Some of these operators are similar to the operators used in the C
programming language. Each operator type is denoted by a symbol. Table shows the complete listing of operator
symbols classified by category.
.
Table 3-4 Operator Types and Symbols
Examples
A design can be represented in terms of gates, data flow, or a behavioral description. Consider the 4-to-1 multiplexer
and 4-bit full adder described earlier. Previously, these designs were directly translated from the logic diagram into a
gate-level Verilog description. Here, we describe the same designs in terms of data flow. We also discuss two
additional examples: a 4-bit full adder using carry look ahead and a 4-bit counter using negative edge-triggered D-
flip-flops.
4-to-1 Multiplexer
Gate-level modeling of a 4-to-1 multiplexer, Example. The logic diagram for the multiplexer is given in Figure 3.4
and the gate-level Verilog description is shown in Example. We describe the multiplexer, using dataflow statements.
Compare it with the gate-level description. We show two methods to model the multiplexer by using dataflow
statements.
We can use assignment statements instead of gates to model the logic equations of the multiplexer. Notice that
everything is same as the gate-level Verilog description except that computation of out is done by specifying one
logic equation by using operators instead of individual gate instantiations. I/O ports remain the same. This important
so that the interface with the environment does not change. Only the internals of the module change.
output out;
endmodule
output out;
endmodule
In the simulation of the multiplexer, the gate-level module can be substituted with the dataflow multiplexer modules
described above. The stimulus module will not change. The simulation results will be identical. By encapsulating
functionality inside a module, we can replace the gate-level module with a dataflow module without affecting the
other modules in the simulation. This is a very powerful feature of Verilog.
The 4-bit full adder in, Examples, was designed by using gates; the logic diagram is shown in Figure 3.7. In this
section, we write the dataflow description for the 4-bit adder. In gates, we had to first describe a 1-bit full adder.
Then we built a 4-bit full ripple carry adder. We again illustrate two methods to describe a 4-bit full adder by means
of dataflow statements.
output c_out;
input[3:0] a, b;
input c_in;
endmodule
If we substitute the gate-level 4-bit full adder with the dataflow 4-bit full adder, the rest of the modules will not
change. The simulation results will be identical.
Method 2: full adder with carry lookahead
In ripple carry adders, the carry must propagate through the gate levels before the sum is available at the output
terminals. An n-bit ripple carry adder will have 2n gate levels. The propagation time can be a limiting factor on the
speed of the circuit. One of the most popular methods to reduce delay is to use a carry lookahead mechanism. Logic
equations for implementing the carry lookahead mechanism can be found in any logic design book. The propagation
delay is reduced to four gate levels, irrespective of the number of bits in the adder. The Verilog description for a
carry lookahead adder. This module can be substituted in place of the full adder modules described before without
changing any other component of the simulation. The simulation results will be unchanged.
output c_out;
input c_in;
// Internal wires
p1 = a[1] ^ b[1],
p2 = a[2] ^ b[2],
p3 = a[3] ^ b[3];
c3 = g2 | (p2 & g1) | (p2 & p1 & g0) | (p2 & p1 & p0 & c_in),
c4 = g3 | (p3 & g2) | (p3 & p2 & g1) | (p3 & p2 & p1 & g0) |
// Compute Sum
sum[1] = p1 ^ c1,
sum[2] = p2 ^ c2,
sum[3] = p3 ^ c3;
endmodule
Ripple Counter
Consider the design of a 4-bit ripple counter by using negative edge-triggered flipflops. This example was discussed
at a very abstract level, Hierarchical Modeling Concepts. We design it using Verilog dataflow statements and test it
with a stimulus module. The diagrams for the 4-bit ripple carry counter modules are show the counter being built
with four T-flipflops.
.
Figure 3.12 T-flipflop is built with one D-flipflop and an inverter gate
Figure 3.13 shows the D-flipflop constructed from basic logic gates.
Given the above diagrams, we write the corresponding Verilog, using dataflow statements in a top-down fashion.
First we design the module counter. The code is shown in. The code contains instantiation of four T_FF modules.
// Ripple counter
module counter(Q , clock, clear);
// I/O ports
output [3:0] Q;
endmodule
// cycle.
// I/O ports
output q;
endmodule
// Edge-triggered D flipflop
output q,qbar;
// Internal variables
// Output latch
endmodule
module stimulus;
wire [3:0] Q;
initial
initial
begin
CLEAR = 1'b1;
initial
begin
CLOCK = 1'b0;
end
initial
begin
#400 $finish;
end
endmodule
The output of the simulation is shown below. Note that the clear signal resets the count
to zero.
3.6: Outcomes
After completion of the module the students are able to:
Identify logic gate primitives provided in Verilog and Understand instantiation of gates, gate
symbols, and truth tables for and/or and buf/not type gates.
Understand how to construct a Verilog description from the logic diagram of the circuit.
Describe rise, fall, and turn-off delays in the gate-level design and Explain min, max, and typ delays
in the gate-level design
Describe the continuous assignment (assign) statement, restrictions on the assign statement, and the
implicit continuous assignment statement.
Explain assignment delay, implicit assignment delay, and net declaration delay for continuous
assignment statements and Define expressions, operators, and operands.
Use dataflow constructs to model practical digital circuits in Verilog
1. Write the truth table of all the basic gates. Input values consisting of ‘0’, ‘1’, ‘x’, ‘z’.
2. What are the primitive gates supported by Verilog HDL? Write the Verilog HDL statements to
instantiate all the primitive gates.
3. Use gate level description of Verilog HDL to design 4 to 1 multiplexer. Write truth table, top-level
block, logic expression and logic diagram. Also write the stimulus block for the same.
4. Explain the different types of buffers and not gates with the help of truth table, logic symbol, logic
expression
5. Use gate level description of Verilog HDL to describe the 4-bit ripple carry counter. Also write a
stimulus block for 4-bit ripple carry adder.
6. How to model the delays of a logic gate using Verilog HDL? Give examples. Also explain the
different delays associated with digital circuits.
7. Write gate level description to implement function y = a.b + c, with 5 and 4 time units of gate delay for
AND and OR gate respectively. Also write the stimulus block and simulation waveform.
8. With syntax describe the continuous assignment statement.
9. Show how different delays associated with logic circuit are modelled using dataflow description.
10. Explain different operators supported by Verilog HDL.
11. What is an expression associated with dataflow description? What are the different types of operands
in an expression?
12. Discuss the precedence of operators.
13. Use dataflow description style of Verilog HDL to design 4:1 multiplexer with and without using
conditional operator.
14. Use dataflow description style of Verilog HDL to design 4-bitadder
using i. Ripple carry logic.
ii. Carry look ahead logic.
15. Use dataflow description style, gate level description of Verilog HDL to design 4-bit ripple carry
counter. Also write the stimulus block to verify the same.