Seca1605 Programming in Hdl
Seca1605 Programming in Hdl
UNIT - I
PROGRAMMING IN HDL – SECA1605
1
I. CONCEPTS IN VHDL
INTRODUCTION TO VHDL
VHDL is an acronym for VHSIC Hardware Description Language (VHSIC is an acronym for Very
High Speed Integrated Circuits). It is a hardware description language that can be used to model a
digital system at many levels of abstraction ranging from the algorithmic level to the gate level. The
complexity of the digital system being modeled could vary from that of a simple gate to a complete
digital electronic system, or anything in between. The digital system can also be described
hierarchically. Timing can also be explicitly modeled in the same description.
The VHDL language can be regarded as an integrated amalgamation of the following languages:
sequential language
Concurrent language
net-list language
timing specifications
Waveform generation language.
Therefore, the language has constructs that enable you to express the concurrent or sequential
behavior of a digital system with or without timing. It also allows you to model the system as an
interconnection of components. Test waveforms can also be generated using the same constructs.
All the above constructs may be combined to provide a comprehensive description of the system in
a single model.
The language not only defines the syntax but also defines very clear simulation semantics for each
language construct. Therefore, models written in this language can be verified using a VHDL
simulator. It is a strongly typed language and is often verbose to write. It inherits many of its
features, especially the sequential language part, from the Ada programming language. Because
VHDL provides an extensive range of modeling capabilities, it is often difficult to understand.
Fortunately, it is possible to quickly assimilate a core subset of the language that is both easy and
simple to understand without learning the more complex features. This subset is usually sufficient to
model most applications. The complete language, however, has sufficient power to capture the
descriptions of the most complex chips to a complete electronic system.
2
Digital system design process :-
Requirements
Logic Simulation
Logic Design Verification
Fault Simulation
Digital Systems have conquered the whole world. Every appliances or equipment’s we see today are
digital. This is because of the very small element called Transistor invented by John Bardeen,
Walter Brattain & William Shockley in 1947 at Bell Labs. This tiny and Powerful transistor changed
the future of Electronics. Therefore it is our responsibility to study the analysis and design of this
digital system as an electronic student. In this chapter we will study the Basic Digital IC Design
Flow and then we will study what are the tools available for digital design and synthesis. Later we
are going to study a special hardware description language (VHDL) which is used to describe the
digital systems.
3
Behavioral Design:
Hardware Description Languages (HDLs) are used to model the design idea (block diagram). Circuit
details and electrical components are not specified. Instead, the behavior of each block at the highest
level of abstraction is modeled. Simulations are then run to see if the blocks do indeed function as
expected and the whole system performs as a whole. Behavioral descriptions are important as they
corroborate the integrity of the design idea. Here we don’t have any architectural or hardware
details.
Logic Design:
Logic Design is the next phase in the design process and involves the use of primitive gates and flip-
flops for the implementation of data registers, busses, logic units, and their controlling hardware.
The result of this design stage is a net list of gates and flip-flops. Components used and their
interconnections are specified in this net list.
Physical Design:
This stage transforms the net list into transistor list or layout. This involves the replacement of gates
and flip-flops with their transistor equivalents or library cells.
Manufacturing:
The final step is manufacturing, which uses the transistor list or layout specification to burn fuses of
FPGA or to generate masks for Integrated circuit (IC).
Basic Terminology
VHDL is a hardware description language that can be used to model a digital system. The digital
system can be as simple as a logic gate or as complex as a complete electronic system. A hardware
4
abstraction of this digital system is called an entity in this text. An entity X, when used in another
entity Y, becomes a component for the entity Y. Therefore, a component is also an entity, depending
on the level at which you are trying to model.
To describe an entity, VHDL provides five different types of primary constructs, called design units.
They are
1. Entity declaration
2. Architecture body
3. Configuration declaration
4. Package declaration
5. Package body
Entity Declaration
The entity' declaration specifies the name of the entity being modeled and lists the set of interface
ports. Ports are signals through which the entity communicates with the other models in its external
environment.
5
The following is another example of an entity declaration for a 2-to-4 decoder circuit
entity DECODER2x4 is
port(A, B, ENABLE: in SIT: Z: out BIT_VECTOR(0 to 3)); end DECODER2x4;
Architecture Body
The internal details of an entity are specified by an architecture body using any of the following
modeling styles:
1. As a set of interconnected components (structural modeling)
2. As a set of concurrent assignment statements (dataflow modeling)
3. As a set of sequential assignment statements (behavioral modeling)
4. Any combination of the above three (Mixed modeling)
6
Configuration Declaration
A configuration declaration is used to select one of the possibly many architecture bodies that an
entity may have, and to bind components, used to represent structure in that architecture body, to
entities represented by an entity-architecture pair or by a configuration, that reside in a design
library. Consider the following configuration declaration for the HALF_ADDER entity.
library CMOS_LIB, MY_LIB;
configuration HA_BINDING of HALF_ADDER is for HA-STRUCTURE
for X1:XOR2
use entity CMOS_LIB.XOR_GATE(DATAFLOW);
end for;
for A1:AND2
use configuration MY_LIB.AND_CONFIG;
end for;
end for; end HA_BINDING;
Package Declaration
A package declaration is used to store a set of common declarations like components, types,
procedures, and functions. These declarations can then be imported into other design units using a
context clause. Here is an example of a package declaration.
package EXAMPLE_PACK is
type SUMMER is (MAY, JUN, JUL, AUG, SEP); component D_FLIP_FLOP
port (D, CK: in BIT; Q, QBAR: out BIT); end component;
constant PIN2PIN_DELAY: TIME := 125 ns; function INT2BIT_VEC (INT_VALUE: INTEGER)
return BIT_VECTOR;
end EXAMPLE_PACK;
Package Body
A package body is primarily used to store the definitions of functions and procedures that were
declared in the corresponding package declaration, and also the complete constant declarations for
any deferred constants that appear in the package declaration. Therefore, a package body is always
associated with a package declaration; furthermore, a package declaration can have at most one
package body associated with it. Contrast this with an architecture body and an entity declaration
7
where multiple architecture bodies may be associated with a single entity declaration. A package
body may contain other declarations as well.
Here is the package body for the package EXAMPLE_PACK declared in the previous section.
package body EXAMPLE_PACK is
function INT2BIT_VEC (INT_VALUE: INTEGER) return
BIT_VECTOR is
begin
end INT2BIT_VEC;
end EXAMPLE_PACK;
Identifiers
- Identifiers are used to name items in a VHDL model.
Basic identifier: composed of a sequence of one or more characters, A basic identifier may contain
only capital ‘A’ - ’Z’ , ‘a’ - ’z’, ‘0’ - ’9’, underscore character ‘_’
first character must be a letter, last character must NOT be an underscore
Two underscores cannot occur concurrently
case insensitive: COUNT, count, Count, counT are all the same
Keywords can not be used as basic identifiers
Comments
Its non executable or readable parameter for understanding purpose.
The comments to be proceeded by two consecutive hyphens(--)
Example
entity half_adder is
port (a, b: in std_logic; sum, carry: out std_logic);
end half_adder; -- end of entity with entity name
architecture HA-DF of half_adder is
begin
sum <= a xor b; -- a xor with b, result assigned to sum
carry <= a and b; -- a and with b, result assigned to carry
end HA_DF; -- end of architecture with architecture name
Data Objects
– hold a value of a specified type
constant: holds a single value of a specified type and cannot be changed throughout the simulation
constant declaration:
constant RESULT: BIT:=1;
constant FALL_TIME: TIME:=10ns
variable: holds a single value of a specified type but can be changed throughout the simulation
variable ABAR:BIT;
variable STATUS:BIT_VECTOR(3 downto 0);
signal: holds a list of values including current value and a list of possible future values
typically used to model wires and flip-flops
signal DATA_BUS:BIT_VECTOR(0 to 31)
9
file: same as with any computer file, contains data
Data Types
– Is a name which is associated with a set of values and a set of operations.
Major Data Types:
Scalar Type
Composite Type
Access Type
File Type
There can also be user-defined types and subtypes A subtype is a type with a (possibly) added
constraint
syntax: subtype subtype_name is base_type range range_constraint;
example: subtype DIGITS is integer range 0 to 9;
Scalar types
Enumeration – defines a type that has a set of user-defined values
type std_logic is (‘U’, ‘X’, ‘0’, ‘1’, ‘Z’, ‘W’, ‘L’, ‘H’,’-’);
‘u’ unspecified, ‘x’ unknown, ‘0’ strong zero, ‘1’ strong one
‘z’ high impedance, ‘w’ weak unknown, ‘l’ weak zero, ‘h’ weak one, ‘-’ don’t care
Physical – represent measurement of some physical quantity like time, voltage, or current
Composite Types
– a collection of values
Array Types – collection of values all belonging to a single type
10
BIT_VECTOR and STRING are pre-defined one-dimensional array types
type DATA_BYTE is array (0 to 7) of BIT;
type MEMORY is array (0 to 127) of DATA_BYTE;
Record Types – collection of values that may belong to different types
type MODULE is
record
SUM : BIT_VECTOR(0 to 7);
COUT : BIT;
end record;
Access Type
Values belonging to an access type are pointers to a allocated object of some other type.
Example :
type PTR is access MODULE;
File Type
Objects of file type represent files in the host environment.
Syntax :
type file_type_name is file of type_name;
Data Operators
VHDL will support different types of operations. The following are the types of operators available
in VHDL
1. Assignment operator
2. Logical Operator
3. Relational Operator
4. Shift operator
5. Arithmetic operator
5.1 Addition Operator
5.2 Multiplication Operator
5.3 Miscellaneous operator
11
Assignment Operator
This operator is used to assign values to signals, variables, and constants. They are
1. <= Used to assign a value to signal
2. := Used to assign a variable, constant or generic, used for also establishing initial values.
3. => Used to assign values to individual vector or with others.
Logical Operators
Used to perform to logical operations. The data must be of type Bit, Std_logic or std_ulogic. The
logical operators are:
1. NOT
2. AND
3. OR
4. NAND
5. NOR , XOR & XNOR
Relational Operators
Used for making comparisons. The data can be of any types listed above. The relational
(Comparison) operators listed below:
1. = Equal to
2. /= not equal to
3. < Greater than
4. > Lesser than
5. <= Greater than
6. >= Lesser than
Shift Operators
Used for shifting data.
1. Sll: Shift left logic
2. Sla: shift left arithmetic
12
3. Srl: Shift right logic
4. Sra: Shift right arithmetic
5. Rol:Rotateleft
6. Ror: Rotate right
Arithmetic Operators Used to perform arithmetic operations. The data can be of integer,
signed, Unsigned or a real.
The different types of arithmetic operations are:
Addition operator (+)
Subtract Operator (-)
Multiplication operator (*)
Division Operator (/)
Modulus (MOD)
Remainder (REM)
14
delay, and it represents an infinitesimally small delay. This small delay corresponds to a zero delay
with respect to simulation time and does not correspond to any real simulation time.
To understand the behavior of this architecture body, consider an event happening on one of the
input signals, say input port B at time T. This would cause the concurrent signal assignment
statements 1,3, and 6, to be triggered. Their right -hand-side expressions would be evaluated and the
corresponding values would be scheduled to be assigned to the target signals at time (T+A). When
simulation time advances to (T+A), new values to signals Z(3), BBAR, and Z(1), are assigned.
Since the value of BBAR changes, this will in turn trigger signal assignment statements, 2 and 4.
Eventually, at time (T+2A), signals Z(0) and Z(2) will be assigned their new values. The semantics
of this concurrent behavior indicate that the simulation, as defined by the language, is event-
triggered and that simulation time advances to the next time unit when an event is scheduled to
occur. Simulation time could also advance a multiple of delta time units. For example, events may
have been scheduled to occur at times 1,3,4,4+A, 5,6,6+A, 6+2A, 6+3A, 10,10+A, 15, 15+A time
units.
The after clause may be used to generate a clock signal as shown in the following concurrent signal
assignment statement
CLK <= not CLK after 10 ns;
Structural Model
An entity is modeled as a set of components connected by signals, that is, as a net-list. The
behavior of the entity is not explicitly apparent from its model. The component instantiation
statement is the primary mechanism used for describing such a model of an entity. COMPONENT
& PORT MAP statements are used to implement structural modeling. The component instantiation
statements are concurrent statements, and their order of appearance in the architecture body is
therefore not important. A component can be instantiated any number of times.Each instantiation
must have a unique component label.
Component Declaration
A component in a structural description must first be declared using a component declaration. A
component declaration declares the name and the interface of a component (similar to the
entity).The interface specifies the mode and the type of ports.
The syntax of a simple form of component declaration is:
COMPONENT Component-Name [IS]
PORT(List-of-Interface-Ports);
END COMPONENT [Component-Name ];
The component-name may or may not refer to the name of an entity already existing in a library. If
it does not, it must be explicitly bound to an entity. The binding information can be specified using
a configuration. The List-of-Interface-Ports specifies the name, mode, and type for each port of the
component in a manner similar to that specified in an entity declaration. The names of the ports
may also be different from the names of the ports in the entity to which it may be bound (different
port names can be mapped in a configuration)
Component Instantiation
A component instantiation statement defines a association of formal and actual parameters. It
associates the signals in the entity with the ports of that component.
A format of a component instantiation statement:
Component-Label: Component-Name PORT MAP (association-list);
16
The Component-Label can be any legal identifier and can be considered as the name of the instance.
The Component-Name must be the name of a component declared earlier using a component
declaration. The association-list, associates signals in the entity, called actuals, with the ports of a
component, called formals.
There are two ways to perform the association of formals with actuals:
1. Positional association
2. Named association
In positional association, each actual in the component instantiation is mapped by position with
each port in the component declaration. That is, the first port in the component declaration
corresponds to the first actual in the component instantiation, the second with the second, and so on.
If a port in a component instantiation is not connected to any signal, the keyword OPEN can be
used to signify that the port is not connected.
For example
d1 : dff PORT MAP (data, ck, s1, open);
In named association, an association-list is of the form:
formal1 => actual1 ,formal2=> actual2, ... formaln=> actualn
For example
d1 : dff PORT MAP (d => data, clk => ck, q => s1, qb => s2);
In named association, the ordering of the associations is not important since the mapping between
the actual and formal is explicitly specified.
Dataflow Model
The Data-Flow modeling is a collections of concurrent statements. All the statements must be write
only in the architecture body. There is no meaning to the order of the statements.
There are 3 Data-Flow statement:
– Concurrent Signal Assignment
– Conditional Signal Assignment
– Selected Signal Assignment
17
Concurrent Signal Assignment
The syntax is:
target-signal _1<= expression_1;
target-signal _2<= expression_2;
–Example:
entity decoder is
port (a, b : in std_logic;
d: out std_logic_vector(0 to 3));
end decoder;
architecture DEC_DF of decoder is
signal s1,s2 : std_logic;
begin
s1 <= not a;
s2 <= not b;
d(0) <= s1 and s2;
d(1) <= s1 and b;
d(2) <= a and s2;
d(3) <= a and b;
end DEC_DF;
...
18
value9;
Behavioral Model
The process statement contains sequential statements that describe the functionality of an entity in
sequential terms The sensitivity list is a set of signals which will cause the process to execute in
sequential order when an event occurs.
Syntax
architecture architecture_name of entity_name is
begin
process(sensitivity_list)
20
[variable_declarations;]
begin
sequential assignment statements;
end process;
end architecture_name ;
If statement
– selects statements for execution based upon a condition
Syntax
if condition_1 then
sequential_statement_1;
elsif condition_2 then
sequential_statement_2;
:
:
else sequential_statement_n;
21
end if;
entity decoder is
port (a, b : in std_logic; d: out std_logic_vector(0 to 3));
end decoder;
architecture DEC_IF of decoder is
begin
process (a,b)
begin
if (a = ‘0’ and b = ‘0’) then
d <= “0001”;
elsif (a = ‘0’ and b = ‘1’) then
d <= “0010”;
elsif (a = ‘1’ and b = ‘0’) then
d <= “0100”;
else d<= “1000”;
end if;
end process;
end DEC_IF;
Case statement
– selects one branch of execution from a list of many based upon selected expression
22
Syntax:
case expression is
when choice_1 => statement_1;
when choice_2 => statement_2;
:
when choice_n => statement_n;
end case;
entity decoder is
port (a : in std_logic_vector(0 to 1); d: out std_logic_vector(0 to 3));
end decoder;
architecture DEC_CASE of decoder is
begin
process (a)
begin
case a is
when “00” => d <= “0001”;
when “01” => d <= “0010”;
when “10” => d <= “0100”;
when “11” => d <= “1000”;
end case;
23
end process;
end DEC_CASE;
QUESTION BANK
PART-A
1. Distinguish VHDL and Verilog HDL.
2. Data objects are significant in VHDL Justify.
3. List the operators in VHDL.
4. Formulate the syntax of process statement in VHDL.
5. Develop VHDL code for 2 bit adder.
6. Wait statement is important in VHDL. Support this statement.
7. Justify how signal declaration is done in VHDL
8. Distinguish concurrent signal assignment and sequential signal assignment.
24
9. Justify the importance and objects in VHDL
10. List the data types in VHDL
PART-B
1. In VHDL, data types and operators are the most significant concept, Explain it.
2. Distinguish between dataflow modeling and behavioral modeling of VHDL
3. Illustrate the different language elements in VHDL.
4. Discuss concurrent and sequential assignment statements.
5. Develop a VHDL code for encoder and decoder circuit
25
SCHOOL OF ELECTRICAL AND ELECTRONICS
DEPARTMENT OF ELECTRONICS AND COMMMUNICATION
ENGINEERING
UNIT - II
PROGRAMMING IN HDL – SECA1605
26
II. INTRODUCTION TO VERILOG HDL
Verilog HDL is a hardware description language that can be used to model a digital system at
many levels of abstraction ranging from the algorithmic level to the gate level to the switch level.
The complexity of the digital system being modeled could vary from that of a simple gate to a
complete electronic digital system, or anything in between. The digital system can be described
hierarchically and timing can be explicitly modeled within the same description.
27
Figure 2.1: Typical Design Flow
Design Methodologies
There are two basic types of digital design methodologies: a top-down design methodology and a
bottom-up design methodology. In a top-down design methodology, we define the top-level block
and identify the sub-blocks necessary to build the top-level block. We further subdivide the sub-
blocks until we come to leaf cells, which are the cells that cannot further be divided. Figure 2.2
shows the top-down design process.
Behavioral Level
This level describes a system by concurrent algorithms (Behavioral). Each algorithm itself is
sequential, that means it consists of a set of instructions that are executed one after the other.
Functions, Tasks and Always blocks are the main elements. There is no regard to the structural
realization of the design.
Register-Transfer Level
Designs using the Register-Transfer Level specify the characteristics of a circuit by operations and
the transfer of data between the registers.An explicit clock is used. RTL design contains exact
timing bounds: operations are scheduled to occur at certain times. Modern RTL code definition is
"Any code that is synthesizable is called RTL code".
Gate Level
Within the logic level the characteristics of a system are described by logical links and their timing
properties. All signals are discrete signals. They can only have definite logical values (`0', `1', `X',
`Z`). The usable operations are predefined logic primitives (AND, OR, NOT etc gates). Using gate
level modeling might not be a good idea for any level of logic design. Gate level code is generated
by tools like synthesis tools and this netlist is used for gate level simulation and for backend.
29
Language Elements
Identifiers
Identifiers are names given to objects so that they can be referenced in the design. Identifiers are
made up of alphanumeric characters, the underscore ( _ ), or the dollar sign ( $ ). Identifiers are case
sensitive. Identifiers start with an alphabetic character or an underscore. They cannot start with a
digit or a $ sign
reg value; // reg is a keyword; value is an
identifier input clk; // input is a keyword, clk is an identifier
Comments
Comments can be inserted in the code for readability and documentation. There are two ways to
write comments. A one-line comment starts with "//". Verilog skips from that point to the end of
line. A multiple-line comment starts with "/*" and ends with "*/". Multiple-line comments cannot be
nested. However, one-line comments can be embedded in multiple-line comments.
a = b && c; // This is a one-line comment
/* This is a multiple line comment */
/* This is /* an illegal */ comment */
/* This is //a legal comment */
Format
Verilog HDl is case sensitive. Identifiers differing only in their case are distinct. Verilog HDL, is
free format, constructs may be written across multiple lines , or on one line. White space (newline,
tab, and space characters) have no special significance.
Compiler Directives
Compiler directives are provided in Verilog. All compiler directives are defined by using the
30
‘<keyword> construct. We deal with the two most useful compiler directives.
‘define
The ‘define directive is used to define text macros in Verilog.
The Verilog compiler substitutes the text of the macro wherever it encounters a ‘<macro_name>.
This is similar to the #define construct in C. The defined constants or text macros are used in the
Verilog code by preceding them with a ‘ (back tick).
//define a text macro that defines default word
size //Used as ’WORD_SIZE in the code
’define WORD_SIZE 32
‘include
The ‘include directive allows you to include entire contents of a Verilog source file in another
Verilog file during compilation. This works similarly to the #include in the C programming
language. This directive is typically used to include header files, which typically contain global or
commonly used definitions.
Example ‘include Directive
// Include the file header.v, which contains declarations in the
// main verilog file design.v.
’include header.v
...
...
<Verilog code in file design.v>
...
...
Two other directives, ‘ifdef and ‘timescale, are used frequently.
Value set
Verilog supports four values and eight strengths to model the functionality of real hardware.
Strength levels
31
Data types
Verilog HDL has two groups of data types
(i) Net type
A net type represents a physical connection between structural elements. Its value is determined
from the value of its drivers such as a continuous assignment or a gate output. If no driver is
connected to a net, the net defaults to a value of z.
(ii) Variable type
A variable type represents an abstract data storage element. It is assigned values only within an
always statement or an initial statement, and its value is saved from one assignment to the next. A
variable type has a default value of x.
Net types
Here are the different kinds of nets that belong to the net data type
wire
tri
wor
trior
wand
triand
trireg
tri1
tri0
supply0
supply1
32
Variable types
There are five different kinds of variable types
reg
integer
time
real
realti
me
Register
Registers represent data storage elements. Registers retain value until another value is placed onto
them. Register data types are commonly declared by the keyword reg. The default value for a reg
data type is x.
Example of Register
reg reset; // declare a variable reset that can hold its value
begin
reset = 1’b1; //initialize reset to 1 to reset the digital circuit.
#100 reset = 1’b0; // after 100 time units reset is de asserted.
end
Integer
An integer is a general purpose register data type used for manipulating quantities. Integers are
declared by the keyword integer. Although it is possible to use reg as a general-purpose variable, it
is more convenient to declare an integer variable for purposes such as counting. The default width
for an integer is the host-machine word size, which is implementation-specific but is at least 32 bits.
Registers declared as data type reg store values as unsigned quantities, whereas integers store values
as signed quantities.
integer counter; // general purpose variable used as a counter.
initial counter = -1; // A negative one is stored in the counter
Real
Real number constants and real register data types are declared with the keyword real. They can be
33
specified in decimal notation (e.g., 3.14) or in scientific notation (e.g., 3e6, which is 3 x 106 ). Real
numbers cannot have a range declaration, and their default value is 0. When a real value is assigned
to an integer, the real number is rounded off to the nearest integer.
real delta; // Define a real variable called delta
initial
begin
delta = 4e10; // delta is assigned in scientific notation delta = 2.13;
// delta is assigned a value 2.13
end
integer i; // Define an integer i initial
i = delta; // i gets the value 2 (rounded value of 2.13)
Time
Verilog simulation is done with respect to simulation time. A special time register data type is used
in Verilog to store simulation time. A time variable is declared with the keyword time. The width for
time register data types is implementation specific but is at least 64 bits. The system function $time
is invoked to get the current simulation time.
time save_sim_time; // Define a time variable save_sim_time
initial save_sim_time = $time; // Save the current simulation time
Arrays
Arrays are allowed in Verilog for reg, integer, time, real, realtime and vector register data types.
Multi-dimensional arrays can also be declared with any number of dimensions. Arrays of nets can
also be used to connect ports of generated instances. Each element of the array can be used in the
same fashion as a scalar or vector net. Arrays are accessed by <array_name>[<subscript>]. For
multi-dimensional arrays, indexes need to be provided for each dimension.
integer count[0:7]; // An array of 8 count variables
reg bool[31:0]; // Array of 32 one-bit boolean register variables time
chk_point[1:100]; // Array of 100 time checkpoint variables
reg [4:0] port_id[0:7]; // Array of 8 port_ids; each port_id is 5 bits wide
Parameters
Verilog allows constants to be defined in a module by the keyword parameter. Parameters cannot be
34
used as variables. Parameter values for each module instance can be overridden individually at
compile time. This allows the module instances to be customized. This aspect is discussed later.
Parameter types and sizes can also be defined.
parameter port_id = 5; // Defines a constant port_id
parameter cache_line_width = 256; // Constant defines width of cache line
parameter signed [15:0] WIDTH; // Fixed sign and range for parameter WIDTH
Expressions
An expression is formed using operands and operators. An expression can be used wherever a value
is expected.
Operands
Operands can be constants, integers, real numbers, nets, registers, times, bitselect (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.
integer count, final_count;
final_count = count + 1;//count is an integer operand
real a, b, c;
c = a - b; //a and b are real operands
reg [15:0] reg1,
reg2; reg [3:0]
reg_out;
reg_out = reg1[3:0] ^ reg2[3:0];//reg1[3:0] and reg2[3:0] are //part-select register operands
reg ret_value;
ret_value = calculate_parity(A, B);//calculate_parity is a //function type operand
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.
The table 2.1 shows the complete listing of operator symbols classified by category.
Table 2.1 Operators
35
36
Module
The basic unit of description in Verilog is the module. A module describes the functionality or
structure of a design and also describes the ports through which it communicates externally with
other modules. The structure of a design is described using switch-level primitives, gate-level
primitives and user-defined primitives; data flow behavior of a design is described using continuous
assignments; sequential behavior is described using procedural constructs. A module can also be
instantiated inside another module.
module module_name (port_list );
Declarations:
reg, wire,
parameter, input, output, inout, function , task, ….
Statements :
Initial statement
Always statement
Module instantiation
Gate instantiation
UDP instantiation
Continuous assignment
Generate statement
end module
37
4. Samir Palnitkar” Verilog HDL: A Guide to Digital Design and Synthesis”, Star Galaxy
Publishing; 3rd edition,2005
5. Michael D Ciletti - Advanced Digital Design with VERILOG HDL, 2nd Edition, PHI,
2009.
6. Z Navabi - Verilog Digital System Design, 2nd Edition, McGraw Hill, 2005.
7. Stuart Sutherland, “RTL Modeling With System Verilog for Simulation and
Synthesis: Using System Verilog for ASIC and FPGA Design”,1st Edition, Sutherland
HDL,Inc., 2017.
8. Simon Monk, “Programming FPGAs: Getting Started with Verilog”, 1st Edition, Tata
McGraw Hill,2016.
9. User Guide – “7 Series FPGAs Configurable Logic Block” - (WWW.XILINX.COM)
QUESTION BANK
PART-A
PART-B
3. Operators in verilog are of different types. Support the statement with example.
UNIT - II
PROGRAMMING IN HDL – SECA1605
39
II. INTRODUCTION TO VERILOG HDL
Verilog HDL is a hardware description language that can be used to model a digital system at
many levels of abstraction ranging from the algorithmic level to the gate level to the switch level.
The complexity of the digital system being modeled could vary from that of a simple gate to a
complete electronic digital system, or anything in between. The digital system can be described
hierarchically and timing can be explicitly modeled within the same description.
40
Figure 2.1: Typical Design Flow
Design Methodologies
There are two basic types of digital design methodologies: a top-down design methodology and a
bottom-up design methodology. In a top-down design methodology, we define the top-level block
and identify the sub-blocks necessary to build the top-level block. We further subdivide the sub-
blocks until we come to leaf cells, which are the cells that cannot further be divided. Figure 2.2
shows the top-down design process.
Behavioral Level
This level describes a system by concurrent algorithms (Behavioral). Each algorithm itself is
sequential, that means it consists of a set of instructions that are executed one after the other.
Functions, Tasks and Always blocks are the main elements. There is no regard to the structural
realization of the design.
Register-Transfer Level
Designs using the Register-Transfer Level specify the characteristics of a circuit by operations and
the transfer of data between the registers.An explicit clock is used. RTL design contains exact
timing bounds: operations are scheduled to occur at certain times. Modern RTL code definition is
"Any code that is synthesizable is called RTL code".
Gate Level
Within the logic level the characteristics of a system are described by logical links and their timing
properties. All signals are discrete signals. They can only have definite logical values (`0', `1', `X',
`Z`). The usable operations are predefined logic primitives (AND, OR, NOT etc gates). Using gate
level modeling might not be a good idea for any level of logic design. Gate level code is generated
by tools like synthesis tools and this netlist is used for gate level simulation and for backend.
42
Language Elements
Identifiers
Identifiers are names given to objects so that they can be referenced in the design. Identifiers are
made up of alphanumeric characters, the underscore ( _ ), or the dollar sign ( $ ). Identifiers are case
sensitive. Identifiers start with an alphabetic character or an underscore. They cannot start with a
digit or a $ sign
reg value; // reg is a keyword; value is an
identifier input clk; // input is a keyword, clk is an identifier
Comments
Comments can be inserted in the code for readability and documentation. There are two ways to
write comments. A one-line comment starts with "//". Verilog skips from that point to the end of
line. A multiple-line comment starts with "/*" and ends with "*/". Multiple-line comments cannot be
nested. However, one-line comments can be embedded in multiple-line comments.
a = b && c; // This is a one-line comment
/* This is a multiple line comment */
/* This is /* an illegal */ comment */
/* This is //a legal comment */
Format
Verilog HDl is case sensitive. Identifiers differing only in their case are distinct. Verilog HDL, is
free format, constructs may be written across multiple lines , or on one line. White space (newline,
tab, and space characters) have no special significance.
Compiler Directives
Compiler directives are provided in Verilog. All compiler directives are defined by using the
43
‘<keyword> construct. We deal with the two most useful compiler directives.
‘define
The ‘define directive is used to define text macros in Verilog.
The Verilog compiler substitutes the text of the macro wherever it encounters a ‘<macro_name>.
This is similar to the #define construct in C. The defined constants or text macros are used in the
Verilog code by preceding them with a ‘ (back tick).
//define a text macro that defines default word
size //Used as ’WORD_SIZE in the code
’define WORD_SIZE 32
‘include
The ‘include directive allows you to include entire contents of a Verilog source file in another
Verilog file during compilation. This works similarly to the #include in the C programming
language. This directive is typically used to include header files, which typically contain global or
commonly used definitions.
Example ‘include Directive
// Include the file header.v, which contains declarations in the
// main verilog file design.v.
’include header.v
...
...
<Verilog code in file design.v>
...
...
Two other directives, ‘ifdef and ‘timescale, are used frequently.
Value set
Verilog supports four values and eight strengths to model the functionality of real hardware.
Strength levels
44
Data types
Verilog HDL has two groups of data types
(i) Net type
A net type represents a physical connection between structural elements. Its value is determined
from the value of its drivers such as a continuous assignment or a gate output. If no driver is
connected to a net, the net defaults to a value of z.
(ii) Variable type
A variable type represents an abstract data storage element. It is assigned values only within an
always statement or an initial statement, and its value is saved from one assignment to the next. A
variable type has a default value of x.
Net types
Here are the different kinds of nets that belong to the net data type
wire
tri
wor
trior
wand
triand
trireg
tri1
tri0
supply0
supply1
45
Variable types
There are five different kinds of variable types
reg
integer
time
real
realti
me
Register
Registers represent data storage elements. Registers retain value until another value is placed onto
them. Register data types are commonly declared by the keyword reg. The default value for a reg
data type is x.
Example of Register
reg reset; // declare a variable reset that can hold its value
begin
reset = 1’b1; //initialize reset to 1 to reset the digital circuit.
#100 reset = 1’b0; // after 100 time units reset is de asserted.
end
Integer
An integer is a general purpose register data type used for manipulating quantities. Integers are
declared by the keyword integer. Although it is possible to use reg as a general-purpose variable, it
is more convenient to declare an integer variable for purposes such as counting. The default width
for an integer is the host-machine word size, which is implementation-specific but is at least 32 bits.
Registers declared as data type reg store values as unsigned quantities, whereas integers store values
as signed quantities.
integer counter; // general purpose variable used as a counter.
initial counter = -1; // A negative one is stored in the counter
Real
Real number constants and real register data types are declared with the keyword real. They can be
46
specified in decimal notation (e.g., 3.14) or in scientific notation (e.g., 3e6, which is 3 x 106 ). Real
numbers cannot have a range declaration, and their default value is 0. When a real value is assigned
to an integer, the real number is rounded off to the nearest integer.
real delta; // Define a real variable called delta
initial
begin
delta = 4e10; // delta is assigned in scientific notation delta = 2.13;
// delta is assigned a value 2.13
end
integer i; // Define an integer i initial
i = delta; // i gets the value 2 (rounded value of 2.13)
Time
Verilog simulation is done with respect to simulation time. A special time register data type is used
in Verilog to store simulation time. A time variable is declared with the keyword time. The width for
time register data types is implementation specific but is at least 64 bits. The system function $time
is invoked to get the current simulation time.
time save_sim_time; // Define a time variable save_sim_time
initial save_sim_time = $time; // Save the current simulation time
Arrays
Arrays are allowed in Verilog for reg, integer, time, real, realtime and vector register data types.
Multi-dimensional arrays can also be declared with any number of dimensions. Arrays of nets can
also be used to connect ports of generated instances. Each element of the array can be used in the
same fashion as a scalar or vector net. Arrays are accessed by <array_name>[<subscript>]. For
multi-dimensional arrays, indexes need to be provided for each dimension.
integer count[0:7]; // An array of 8 count variables
reg bool[31:0]; // Array of 32 one-bit boolean register variables time
chk_point[1:100]; // Array of 100 time checkpoint variables
reg [4:0] port_id[0:7]; // Array of 8 port_ids; each port_id is 5 bits wide
Parameters
Verilog allows constants to be defined in a module by the keyword parameter. Parameters cannot be
47
used as variables. Parameter values for each module instance can be overridden individually at
compile time. This allows the module instances to be customized. This aspect is discussed later.
Parameter types and sizes can also be defined.
parameter port_id = 5; // Defines a constant port_id
parameter cache_line_width = 256; // Constant defines width of cache line
parameter signed [15:0] WIDTH; // Fixed sign and range for parameter WIDTH
Expressions
An expression is formed using operands and operators. An expression can be used wherever a value
is expected.
Operands
Operands can be constants, integers, real numbers, nets, registers, times, bitselect (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.
integer count, final_count;
final_count = count + 1;//count is an integer operand
real a, b, c;
c = a - b; //a and b are real operands
reg [15:0] reg1,
reg2; reg [3:0]
reg_out;
reg_out = reg1[3:0] ^ reg2[3:0];//reg1[3:0] and reg2[3:0] are //part-select register operands
reg ret_value;
ret_value = calculate_parity(A, B);//calculate_parity is a //function type operand
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.
The table 2.1 shows the complete listing of operator symbols classified by category.
Table 2.1 Operators
48
49
Module
The basic unit of description in Verilog is the module. A module describes the functionality or
structure of a design and also describes the ports through which it communicates externally with
other modules. The structure of a design is described using switch-level primitives, gate-level
primitives and user-defined primitives; data flow behavior of a design is described using continuous
assignments; sequential behavior is described using procedural constructs. A module can also be
instantiated inside another module.
module module_name (port_list );
Declarations:
reg, wire,
parameter, input, output, inout, function , task, ….
Statements :
Initial statement
Always statement
Module instantiation
Gate instantiation
UDP instantiation
Continuous assignment
Generate statement
end module
50
4. Samir Palnitkar” Verilog HDL: A Guide to Digital Design and Synthesis”, Star Galaxy
Publishing; 3rd edition,2005
5. Michael D Ciletti - Advanced Digital Design with VERILOG HDL, 2nd Edition, PHI,
2009.
6. Z Navabi - Verilog Digital System Design, 2nd Edition, McGraw Hill, 2005.
7. Stuart Sutherland, “RTL Modeling With System Verilog for Simulation and
Synthesis: Using System Verilog for ASIC and FPGA Design”,1st Edition, Sutherland
HDL,Inc., 2017.
8. Simon Monk, “Programming FPGAs: Getting Started with Verilog”, 1st Edition, Tata
McGraw Hill,2016.
9. User Guide – “7 Series FPGAs Configurable Logic Block” - (WWW.XILINX.COM)
QUESTION BANK
PART-A
PART-B
3. Operators in verilog are of different types. Support the statement with example.
UNIT - IV
PROGRAMMING IN HDL – SECA1605
52
IV. FEATURES IN VERILOG HDL
53
Task and function declarations specify the following:
local variables
I/O ports
registers
times
integers
real
events
These declarations all have the same syntax as for the corresponding declarations in a module
definition. If there is more than one output, input, and inout port declared in a task these must be
enclosed within a block.
Task
A task begins with keyword task and ends with keyword endtask
Inputs and outputs are declared after the keyword task.
Local variables are declared after input and output declaration.
Function
A Verilog HDL function is the same as a task, with very little differences, like function cannot drive
more than one output, can not contain delays.
functions are defined in the module in which they are used. It is possible to define functions
in separate files and use compile directive 'include to include the function in the file which
instantiates the task.
functions can not include timing delays, like posedge, negedge, # delay, which means that
functions should be executed in "zero" time delay.
functions can have any number of inputs but only one output. The variables declared within
the function are local to that function. The order of declaration within the function defines
how the variables passed to the function by the caller are used.
functions can take, drive, and source global variables, when no local variables are used.
When local variables are used, basically output is assigned only at the end of function
execution.
functions can be used for modeling combinational logic.
functions can call other functions, but cannot call tasks.
Syntax
A function begins with keyword function and ends with keyword endfunction.
inputs are declared after the keyword function.
Function Rules
Functions are more limited than tasks. The following five rules govern their usage:
• A function definition cannot contain any time controlled statements—that is, any statements
introduced with #, @, or wait.
• Functions cannot enable tasks.
• A function definition must contain at least one input argument.
• A function definition must include an assignment of the function result value to the internal
variable that has the same name as the function.
55
• A function definition can’t contain an inout declaration or an output declaration
Function Declaration and Invocation
Declaration syntax:
function <range_or_type> <func_name>;
<input declaration(s)>
<variable_declaration(s)>
begin
<statements>
end
endfunction
Invocation syntax:
<func_name> (<argument(s)>);
Example
module simple_function();
function myfunction;
input a, b, c, d;
begin
myfunction = ((a+b) + (c-d));
end
endfunction
endmodule
DISPLAY TASKS
$display
$display displays information to standard output and adds a newline character to the end of its
output.
56
$monitor
$monitor continuously monitors and displays the values of any variables or expressions specified as
parameters to the task. Parameters are specified in the same format as for $display.
$monitoron -$monitoron controls a flag to re-enable a previously disabled $monitor.
Syntax: $monitoron;
$monitoroff-$monitoroff controls a flag to disable monitoring.
Syntax: $monitoroff;
$write
$write displays information to standard output without adding a newline character to the end of its
output.
Syntax: $write (list_of_arguments);
The default format of an expression argument that has no format specification is decimal. The
companion $writeb, $writeo, and $writeh tasks specify binary, octal and hex formats, respectively.
58
assign c = a & b;
endmodule
We have described an AND gate using Dataflow modeling. It has two inputs (a,b) and an output (c).
We have used continuous assignment to describe the functionality using the logic equation. This
AND gate can be our DUT.
So, to test our DUT, we have to write the test bench code.
Why do we have to take the trouble to write another code?
With a test bench, we can view all the signals associated with the DUT. No need for physical
hardware.
Writing a test bench is a bit trickier than RTL coding. Verifying a system can take up around 60-
70% of the design process.
63
all assumed to resolve instantaneously. Some designs, such as high speed microprocessors, may
have very tight requirements that must be met. Failure to meet these constraints may result in the
design failing to work at all, or possibly even producing invalid outputs. Thus, the aim of the
designer may be to produce a circuit that functions correctly, and it is equally important that the
circuit also conforms to any timing constraints required of it.
Delays
Delays can be modelled in a variety of ways, depending on the overall design approach that has been
adopted, namely gate-level modelling, dataflow modelling and behavioural modelling.
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
64
The turn-off delay is associated with a gate output transition to the high impedance value (z)
from another value.
Dataflow modeling
Net Declaration Delay
The delay to be attributed to a net can be associated when the net is declared. Thereafter any
changes of the signals being assigned to the net will only be propagated after the specified delay.
e.g. wire #10 out;
assign out = in1 & in2;
If either of the values of in1 or in2 should happen to change before the assigment to out has taken
place, then the assignment will not be carried out, as input pulses shorter than the specified delay are
filtered out. This is known as inertial delay.
65
Regular Assignment Delay
This is used to introduce a delay onto a net that has already been declared.
e.g. wire out; assign #10 out = in1 & in2;
This has a similar effect to the code above, computing the value of in1 & in2 at the time that
the assign statement is executed, and then storing that value for the specified delay (in this case 10
time units), before assigning it to the net out.
Behavioural modelling
Regular Delay or Inter-assignment delay
This is the most common delay used - sometimes also referred to as inter-assignment delay control.
e.g. #10 q = x + y;
It simply waits for the appropriate number of timesteps before executing the command.
Timing controls
Timing controls provide a way to specify the simulation time at which procedural statements will
execute.
There are three methods of timing control
66
Delay based timing control
Event based timing control
Level-sensitive timing control
67
b = 0;
a = #10 0;
b = a;
endmodule
Event OR control
Sometimes a transition on any one of multiple signals or events can trigger the execution of a
statement or a block of statements. This is expressed as an OR of events or signals. The list of events
or signals expressed as an OR is also known as a sensitivity list. The keyword or is used to specify
multiple triggers as shown in below example,
always @(reset or clock or d)
begin
if(reset)
q=1’b0;
else if (clock)
q=d;
end
71
PMOS and NMOS Switches
In Verilog nmos and pmos switches are instantiated as shown in below
nmos n1(out, data, control); // instantiate a nmos switch
pmos p1(out, data, control); // instantiate a pmos switch
Since switches are Verilog primitives, like logic gates, the name of the instance is optional.
Therefore, it is acceptable to instantiate a switch without assigning an instance name
nmos (out, data , control); // instantiate nmos switch ; no instance name
pmos (out, data, control); // instantiate pmos switch; no instance name
Value of the out signal is determined from the values of data and control signals. Logic tables for
out are shown in table. Some combinations of data and control signals cause the gates to output to
either a 1 or 0 or to an z value without a preference for either value. The symbol L stands for 0 or Z;
H stands for 1 or z.
72
CMOS switch
A CMOS switch is instantiated as shown in below,
cmos cl(out, data, ncontrol, pcontrol);//instantiate cmos gate
or
cmos (out, data, ncontrol, pcontrol); //no instance name given
The ncontrol and pcontrol are normally complements of each other. When the ncontrol signal is 1
and pcontrol signal is 0, the switch conducts.
nmos (out, data, ncontrol); //instantiate a nmos switch
pmos (out, data, pcontrol); //instantiate a pmos switch
Since a cmos switch is derived from nmos and pmos switches, it is possible derive the output
value from Table, given values of data, ncontrol, and pcontrol signals.
Bidirectional switches
NMOS, PMOS and CMOS gates conduct from drain to source. It is important to have devices that
conduct in both directions. In such cases, signals on either side of the device can be the driver
signal. Bidirectional switches are provided for this purpose. Three keywords are used to define
bidirectional switches: tran, tranif0, and tranif1.
Symbols for these switches are shown in figure below.
The tran switch acts as a buffer between the two signals inoutl and inout2. Either inoutl
or inout2 can be the driver signal. The tranif0 switch connects the two
signals inoutl and inout2 only if the control signal is logical 0. If the control signal is
a logical 1, the nondriver signal gets a high impedance value z. The driver signal retains value
from its driver. The tranifl switch conducts if the control signal is a logical 1.
These switches are instantiated as shown in below.
tran tl(inoutl, inout2); //instance name tl is optional
73
tranifO (inoutl, inout2, control); //instance name is not specified
Resistive switches reduce signal strengths when signals pass through them. The changes are
shown below. Regular switches retain strength levels of signals from input to output. The exception
is that if the input is of supply, the output is of strength strong. Below table shows the
strength reduction due to resistive switches.
Input strength
supply pull
strong pull
pull weak
weak medium
large medium
medium small
small small
high high
Example-CMOS NAND
75
QUESTION BANK
PART-A
PART-B
2. Develop verilog test bench for half adder and D flip flop
3. Design a moore FSM with an example, Mention the state transition diagram for it.
4. Design a mealy FSM with an example. Mention the state transition diagram for it.
5. Develop a verilog code for 4-Bit ALU also obtain its test bench and simulation results.
6. Design Verilog module for an edge triggered D Flip flop in the data flow model.
76
SCHOOL OF ELECTRICAL AND ELECTRONICS
DEPARTMENT OF ELECTRONICS AND COMMMUNICATION
ENGINEERING
UNIT - V
PROGRAMMING IN HDL – SECA1605
77
V. REALIZING APPLICATIONS IN FPGA
Design Entry
1. Create an ISE project as follows:
2. Create a project.
3. Create files and add to project, including a user constraints (UCF) file.
4. Add any existing files to project.
5. Assign constraints such as timing constraints, pin assignments, and area constraints.
78
Functional Verification
We can verify the functionality of our design at different points in the design flow as follows:
Before synthesis, run behavioral simulation (also known as RTL simulation).
After Translate, run functional simulation (also known as gate-level simulation), using the
SIMPRIM library.
After device programming, run in-circuit verification.
Design Synthesis
The synthesis process will check code syntax and analyze the hierarchy of our design which ensures
that our design is optimized for the design architecture that we have selected. The resulting netlist is
saved to an NGC file (for Xilinx® Synthesis Technology (XST)) or an EDIF file (for Precision, or
Synplify/Synplify Pro).
The synthesis process can be used with the following synthesis technology tools. Select one of the
following for information about running your synthesis tool:
Xilinx Synthesis Technology (XST)
Precision from Mentor Graphics Inc.
Synplify and Synplify Pro from Synplicity Inc.
Design Implementation
Implementation of design as follows:
1. Implement design, which includes the following steps:
Translate
Map
Place and Route
2. Review reports generated by the Implement Design process, such as the Map Report or Place
& Route Report, and change any of the following to improve our design:
Process properties
Constraints
Source files
3. ynthesize and implement our design again until design requirements are met.
79
Timing Verification
We can verify the timing of our design at different points in the design flow as follows:
Run static timing analysis at the following points in the design flow:
After Map
After Place & Route
Run timing simulation at the following points in the design flow:
After Map (for a partial timing analysis of CLB and IOB delays)
After Place and Route (for full timing analysis of block and net delays)
Logic Blocks
A configurable logic block (CLB) is a basic block used to implement the logic behind the VHDL
designs we have been working on all semester. In FPGAs, hundreds or thousands of CLBs are laid
out in an array (commonly a switch matrix) known as the global routing network. All of the CLBs
80
on the FPGA are connected to each other. On the Artix-7 (and other Xilinx 7-series boards), each
CLB contains two Logic Slices (discussed in the following section). The logical layout of a CLB can
be seen in the Figure below.
Logic Slices
The Artix-7 on our board (Artix-7 7A200T) has a total of 33,650 logic slices (16,825 CLBs). Each
logic slice contains four 6-input LUTs and eight flip-flops. This corresponds to 134,600 total6-
inputLUTs.
There are three possible types of logic slices: SLICEM, SLICEL, and SLICEX. However, in the
Artix-7, SLICEX slices are unused; of the 33,650 logic slices, 22,100 are SLICEL and 11,550 are
SLICEM.
In the logic slices, three major SLICEM subsystems can be seen: 1. the four 6-input LUTs, 2. the
eight flip-flops, and 3. the fast carry logic.
1. Look-up tables
If you need a refresher on how a hardware LUT works, In a SLICEM, there are four 64x1 RAMs
which are used to realize 5 or 6-variable functions; the truth table for the function is stored in the
RAM and the inputs are used as the input addresses. As an example, let's try to realize a full adder
using RAM. In class, we will derive the truth table for sum and carry and show how they can be
inserted into a LUT. It is important for the further development of the lecture to point out that sum
= a xor b xor c and that you can represent cout = ((a xor b) and cin) or (a and b) This last form is
pretty nutty, but is also very useful.
2. Flip Flops
There are 8 flip flops in each logic slice.
81
3. Fast Carry Logic
The fast carry logic is designed explicitly to realize a variation of a carry look-ahead adder.
Consider the construction of a 4-bit adder with inputs A=a3,a2,a1,a0 , B=b3,b2,b1,b0 , and a carry
in c0. Each slice of the adder can either generate a carry bit or propagate its carry in to the carry
out.
Propagate -- pi is equal to 1 when the inputs to a bit slice are such that any carry in will be
propagated.
Generate -- gi is equal to 1 when the inputs to a bit slice are such that a carry will be
generated.
We can represent the cout of a slice as cout = g + p*cin. This arrangement is effectively what is
happening in the carry logic block in the middle of each logic slice.
Interconnect
A logical figure of how the CLBs on the Artix-7 are interconnected to each other can be seen in the
Figure 5.3
82
DSP Slice
Apart from the slices which make up the CLBs discussed above, the Artix-7 also contains DSP
slices. The Artix-7 we are using contains 700 DSP48E1 slices. Each DSP48E1 slice contains a pre-
adder, a 25 x 18 multiplier, an adder, and an accumulator. A picture of a DSP slice can be seen in
the Figure 5.4.
83
Figure 5.5 : CLB diagram
The LUTs in 7 series FPGAs can be configured as either a 6-input LUT with one output, or as two
5-input LUTs with separate outputs but common addresses or logic inputs. Each 5-input LUT output
can optionally be registered in a flip-flop. Four such 6-input LUTs and their eight flip-flops as well
as multiplexers and arithmetic carry logic form a slice, and two slices form a CLB. Four flip-flops
per slice (one per LUT) can optionally be configured as latches. In that case, the remaining four flip-
flops in that slice must remain unused. Approximately two-thirds of the slices are SLICEL logic
slices and the rest are SLICEM, which can also use their LUTs as distributed 64-bit RAM or as 32-
bit shift registers (SRL32) or as two SRL16s. Modern synthesis tools take advantage of these highly
efficient logic, arithmetic, and memory features. Expert designers can also instantiate them.
Device Resources
The CLB resources are scalable across all the 7 series families, providing a common architecture
that improves efficiency, IP implementation, and design migration. The number of CLBs and the
ratio between CLBs and other device resources differentiates the 7 series families. Migration
between the 7 series families does not require any design changes for the CLBs.
Device capacity is often measured in terms of logic cells, which are the logical equivalent of a
classic four-input LUT and a flip-flop. The 7 series FPGA CLB six-input LUT, abundant flip-flops
and latches, carry logic, and the ability to create distributed RAM or shift registers in the SLICEM,
increase the effective capacity. The ratio between the number of logic cells and 6-input LUTs is
1.6:1.
85
Pinout Planning
Although the use of most resources affects the resulting device pinout, CLB usage has little effect on
pinouts because they are distributed throughout the device. The ASMBL™ architecture provides
maximum flexibility with CLBs on both sides of most I/Os.
The best approach is to let the tools choose the I/O locations based on the FPGA requirements.
Results can be adjusted if necessary for board layout considerations. The timing constraints should
be set so that the tools can choose optimal placement for the design requirements.
Carry logic cascades vertically up a column, so wide arithmetic buses might drive a vertical
orientation to other logic, including I/O.
While most 7 series devices are available in flip-chip packages, taking full advantage of the
distributed I/O in the ASMBL architecture, the smaller devices are available in wire-bond packages
at a lower cost. In these packages, some pins are naturally closer to the I/Os and special resources
than others, so pin placement should be done after the internal logic is defined.
Slice Description
Every slice contains:
Four logic-function generators (or look-up tables)
Eight storage elements
Wide-function multiplexers
Carry logic These elements are used by all slices to provide logic, arithmetic, and ROM
functions.
In addition, some slices support two additional functions: storing data using distributed RAM and
shifting data with 32-bit registers. Slices that support these additional functions are called SLICEM;
others are called SLICEL. SLICEM represents a superset of elements and connections found in all
slices. Each CLB can contain two SLICEL or a SLICEL and a SLICEM.
86
The distinguishing feature of the two slice types is the configurability of the SLICEM. SLICEM can
be configured so that the look-up tables within it can act as shift registers or as data storage (creating
distributed memory on the chip) in addition to its normal logic functionality.
A note on naming: the ‘M’ may be an indication of its ability to act as distributed memory, while the
‘L’ may be an indication of its exclusive logic functionality. This is just speculative but it can be
helpful to remember which is which.
87
Figure 5.7 : SLICEL
Storage Elements
There are eight storage elements per slice. Four can be configured as either edge-triggered D-type
flip-flops or level-sensitive latches. The D input can be driven directly by a LUT output via
AFFMUX, BFFMUX, CFFMUX, or DFFMUX, or by the BYPASS slice inputs bypassing the
function generators via AX, BX, CX, or DX input. When configured as a latch, the latch is
transparent when the CLK is Low.
89
There are four additional storage elements that can only be configured as edge-triggered D-type flip-
flops. The D input can be driven by the O5 output of the LUT or the BYPASS slice inputs via AX,
BX, CX, or DX input. When the original four storage elements are configured as latches, these four
additional storage elements cannot be used.
Programmable Interconnect
In Fig 5.8 , a hierarchy of interconnect resources can be seen. There are long lines that can be used
to connect critical CLBs that are physically far from each other on the chip without inducing much
delay. Theses long lines can also be used as buses within the chip.
There are also short lines that are used to connect individual CLBs that are located physically close
to each other. Transistors are used to turn on or off connections between different lines. There are
also several programmable switch matrices in the FPGA to connect these long and short lines
together in specific, flexible combinations.
Three-state buffers are used to connect many CLBs to a long line, creating a bus. Special long lines,
called global clock lines , are specially designed for low impedance and thus fast propagation times.
These are connected to the clock buffers and to each clocked element in each CLB. This is how the
clocks are distributed throughout the FPGA, ensuring minimal skew between clock signals arriving
at different flip-flops within the chip.
In an ASIC, the majority of the delay comes from the logic in the design, because logic is connected
with metal lines that exhibit little delay. In an FGPA, however, most of the delay in the chip comes
from the interconnect, because the interconnect – like the logic – is fixed on the chip. In order to
connect one CLB to another CLB in a different part of the chip often requires a connection through
many transistors and switch matrices, each of which introduces extra delay.
91
Figure 5.8 : Four variable implementation
Any function of four variables together with some functions of six variables can be implemented by
a single CLB
F(a,b,c,d,e,f) = a•b•F1 + a•b’•F2 + a’•b•F3 + a’•b’•F4
F1 = F(a=1, b=1);
F2 = F(a=1, b=0);
F3 = F(a=0, b=1);
F4 = F(a=0, b=0)
Condition: Among F1-F4, three of them are constant (e.g. F1=1, F2=F3=0)
92
Figure 5.10 : 2 to 4 decoding circuit
94
Storage Elements in Xilinx CLB
Each CLB contains two edge-triggered D flip-flops. They can be configured as positive-edge-
triggered or negative-edge-triggered. ‰
Each D flip-flop has clock enable signal E, which is active high. ‰
Each D flip-flop can be set or reset by SR signal. A global reset or reset signal is also available for
set or reset all D flip-flops once the device is powered up.
FPGA Implementation of Finite State Machines
Example of Finite State Machine
95
Figure 5.15 : State transition diagram
State Encoding
Binary encoding: minimum number of D flip-flops
96
It needs two D flip-flps
Implementation Using Binary Encoding
Excitation table
97
Figure 5.17 : FPGA implementation
QUESTION BANK
PART- A
2. Define CLB
PART- B
99