VHDL - Programming the Field Programmable Gate Array (FPGA)
Introduction to VHDL
VHDL (VHSIC-HDL, Very High Speed Integrated Circuit - Hardware Description Language) is a hardware description language used to describe the behavior of digital circuit designs such as field-programmable gate arrays and integrated circuits. A digital system can be represented at different levels of abstraction.
The highest level of abstraction is the behavioral level of VHDL that describes a digital system in terms of how it behaves. A behavioral description specifies the relationship between the input and output signals instead of describing its components and interconnection between the components. The behavioral description could be a Boolean expression or a Register Transfer Level of abstraction.
The structural level abstraction describes a system as a collection of gates and components. A structural description could be compared to a schematic of interconnected logic gates. It is a representation that is usually closer to the physical realization of a system.
VHDL Constructs - Data Types In VHDL, every signals, variables, and constants must have a data type declaration. Some data types are synthesizable, while others are only for modeling purpose. User-defined types are created with type declarations. Predefined types can be divided into several categories: scalar, composite, access, and file. In addition, there are non-predefined types established by the IEEE standard 1164. Each of these types is listed below.
1. Scalar Types - Enumerated Data Type: An enumerated type is a data type in which the exact values are defined. - bit - "0 or 1" - boolean - "true or false" - character - "literals: 128 characters of the ASCII character set" - Severity_level (literals: note, warning, error, failure) - Numeric - Integer - Physical - Floating_point
2. Composite Types - Array - String (1-dimensional array of type character) - Bit_vector(1-dimensional array of type bit) - Record - Access Types (see access) - File Types (see file)
3. Non-predefined Types: In addition to the predefined types, IEEE standard 1164 adds the following types that are commonly used for modeling digital logic: - Std_ulogic (an enumerated type with the values 'U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-') - Std_logic (same as std_ulogic except that this is a resolved type) - Std_ulogic_vector (an array of std_ulogic) - Std_logic_vector (an array of std_logic)
4. Predefined-Types: Types defined by the IEEE standard 1076.3 are: - Unsigned (an array of std_logic) - Signed (an array of std_logic) - Overloaded arithmetic and conversion operators for types unsigned and signed are defined in the package numeric_std. More information on selecting a data type can be found in the Design Considerations section of the IEEE VHDL Reference Manual.
VHDL Ports The inputs and outputs of a VHDL system are called ports. Each port needs to have its name, mode, and type specified at the entity level using port declarations and the keyword port.
Port directions IN Input port OUT Output port INOUT Bidirectional port BUFFER Buffered outputs (can be read by the architecture of the entity)
Model Constructs 1. Libraries and Packages A library can be considered as a place where the compiler stores information about a design project. VHDL libraries provide a set of packages, components, and functions that simplifies the design. The keyword "library" is used to shows that library packages are going to be added into the VHDL design file. Packages provide a collection of sub-libraries. For example "std_logic" is defined in the package ieee.std_logic_1164 in the ieee library. In order to use the std_logic, we needs to specify the library and package at the beginning of the VHDL file as follows:
library IEEE; use IEEE.std_logic_1164.all;
2. Entity An entity is a specification of the design interfaces. The entity declaration in VHDL defines the name of the entity and lists the input and output ports. The mode describes the direction data is transferred through the port and can take on values of either in, out, inout, or buffer. The type is one of the legal data types described above. Port names with the same mode and type can be listed on the same line separated by commas.
entity entity_name is port (port_name1 : <mode> <type>; port_name2 : <mode> <type>); port_name3 : <mode> <type>); end entity;
Line #1 shows the IEEE standard package Line #2 includes a package from the library Line #4 defines the NAME of the entity Line #5 thru 8 shows the input and output ports and the data types. Line #9 shows that an entity declaration always ends with the keyword end
3. Signal Declarations Signals represent wires within the system and they do not have a direction or mode. Signals that are used for internal connections within a system are declared inside the VHDL architecture. Signals cannot have the same name as a port in the system and each signal must be declared with a type. Syntax: signal name : <type>; Examples: - signal A : bit; - signal x, y, z : integer; - signal F : bit_vector (15 downto 0); - signal C_int : integer range 0 to 255;
4. Architectures The architecture in VHDL describes the behavior of a system. It is a specification of the design's internal implementation. The architecture is where the majority of the design work is conducted. Besides, a single entity can have multiple architectures.
Line #11 shows the architecture_name followed by the entity associated with this architecture. line #13 thru 16 shows the behavioral description of the system inside the "begin" and "end" keywords.
1. D Flip-Flop With Positive-Edge Clock
IO Pins Description D -> Data Input C -> Positive-Edge Clock Q -> Data Output
D Flip-Flop RTL Schematic
2. D Flip-Flop With Negative-Edge Clock and Asynchronous Reset
IO Pins Description D -> Data Input C -> Negative-Edge Clock CLR -> Asynchronous Reset (Active High) Q -> Data Output
D Flip-Flop with clear RTL Schematic
3. D-Flip-Flop With Positive-Edge Clock and Clock Enable
IO Pins Description D -> Data Input C -> Positive-Edge Clock CE -> Clock Enable (Active High) Q -> Data Output
Counters in VHDL
4-Bit Unsigned Up Counter With Asynchronous Reset IO Pins Description C -> Positive-Edge Clock CLR -> Clock Reset (Active High) Q -> Data Output (4-bit)