Introduction To VHDL: Unit-1
Introduction To VHDL: Unit-1
Introduction To VHDL: Unit-1
Introduction to VHDL
HDL introduction
• Hardware Description Language (HDL) is an essential computer
aided design (CAD) tool for synthesis of digital systems.
• Requirement of HDL:- Due to complexity, digital systems
cannot be easily realized using discrete integrated circuits(ICs).
• Solution:- 1) Application Specific Integrated Circuits (ASICs)
• 2) Field-Programmable Gate Arrays (FPGAs)
• HDL to describe the system to be implemented in a computer-
language code similar to C/C++.
• Simulators and test benches debug the program.
• Types of HDL:- VHDL & Verilog HDL
• Verilog HDL
7
HDL module structure
• Example:- Consider Half adder ckt.
S = ā b + a bb = a EXOR b
C=ab
VHDL Structure:-
module Half_adder(a,b,S,C);
input a,b;
output S, C;
// Blank lines are allowed
assign S = a ^ b; // statement 1
assign C= a & b; // statement 2
endmodule
Rules cont...
• The parenthesis is followed by a semicolon.
• The order of writing the
• Input and output ports inside the parentheses is irrelevant.
• Carriage return here does not indicate a new statement, the semicolon
does.
• Statements 1 and 2 are signal assignment statements.
entity Half_adder is
port(a: in bit;
b : in bit;
S : out bit;
C: out bit); module Half_adder(a,b,S,C);
end half_adder; input a,b;
output S, C;
architecture dtfl_half of Half_adder is // Blank lines are allowed
begin assign S = a ^ b; // statement 1
S <= a xor b; -- statement 1 assign C= a & b; // statement 2
C <= a and b; -- statement 2 endmodule
--Blank lines are allowed
end dtfl_half;
Types Of Description
There are various types of code writing techniques are
present, selection of one particular style depends on the
available information.
Types of description are:-
1.Data flow description
2.Behavioral description
3.Structural description
4.Switch level description
5.Mixed type description
6.Mixed language description
1. Data flow description
It describes how data flows from input to output.
Usually, the description is done by writing the Boolean function of the
outputs.
The data-flow statements are concurrent.
2. Behavioral description
It describes how output behaves with perticular input.
Example:- In the half adder, the S output can be described as “1” if the
inputs a and b are not equal, otherwise S = “0” & output C can be
described as acquiring a value of “1” only if each input (a and b) is “1”
In behavioral description the architecture (VHDL) or the module (Verilog)
contains the predefined word process (VHDL) or always or initial (Verilog).
Behavioral description is usually used when the Boolean function or the
digital logic of the system is hard to obtain.
architecture beh_half of Half_adder is
begin
process (a, b)
begin
if (a /= b) then
S <= ‘1’;
else
S <= ‘0’;
--Blank lines are allowed
end if;
end process;
end beh_half;
3. Structural Description
It models the system as components or gates.
This description is identified by the presence of the keyword component in
the architecture (VHDL) or gates construct such as and, or, not in the
module (Verilog).
4. Switch-Level Description
It is the lowest level of description.
The system is described using switches or transistors.
Some of the Verilog predefined words used in the switch level description
are nmos, pmos, cmos, tranif0, tran, and tranif1.
VHDL does not have built-in switch-level primitives, but a construct
package can be built to include such primitives.
architecture Invert_switch of Inverter is
component nmos --nmos is one of the key words for switch-level.
port (O1: out std_logic; I1, I2 : in std_logic);
end component;
component pmos --pmos is one of the key words for switch-level.
port (O1: out std_logic ;I1, I2 : in std_logic);
end component;
for all: pmos use entity work. mos (pmos_behavioral);
for all: nmos use entity work. mos (nmos_behavioral);
--The above two statements are referring to a package mos
constant vdd: std_logic := ‘1’;
constant gnd : std_logic:= ‘0’;
begin
p1 : pmos port map (y, vdd, a);
n1: nmos port map (y, gnd, a);
end Invert_switch;
5. Mixed-Type Description
Mixed-type or mixed-style descriptions are those that use
more than one type or style of the above-mentioned
descriptions.
Most of the descriptions of moderate to large systems are
mixed. Some parts of the system may be described using one
type and others using other types of description.
6. Mixed-Language Description
• The user now can write a module in one language (VHDL or
Verilog) and invoke or import a construct (entity or module)
written in the other language.
VHDL Ports
• in: The port is only an input port. In any assignment statement, the port
should appear only on the right-hand side of the statement (i.e., the port
is read).
• out: The port is only an output port. In any assignment statement, the
port should appear only on the left-hand side of the statement (i.e., the
port is updated).
• buffer: The port can be used as both an input and output but can have
only one source (i.e., limited fan out). The port can appear on either the
left- or right-hand side of an assignment statement. A buffer port can only
be connected to another buffer port or to a signal that also has only one
source.
• inout: The port can be used as both an input and output.
• linkage: Same as inout but the port can only correspond to a signal.
Verilog Ports
input: The port is only an input port. In any assignment statement, the
port should appear only on the right-hand side of the statement (i.e., the
port is read).
output: The port is an output port. In contrast to VHDL, the Verilog output
port can appear in either side of the assignment statement.
inout: The port can be used as both an input and output. The inout port
represents a bidirectional bus.
Operators
if (A === B)…..
• This is a bit-by-bit comparison. A or B can include x or high impedance Z;
the result is true (1) if all bits of A match that of B. Otherwise, the result is
false (0).
3. Arithmetic Operators
A. VHDL Arithmetic Operators
• VHDL arithmetic operators operate on numeric and physical operand types.
• Physical data types are those that can be measured in units, such as time.
1100
B. Verilog Shift Operators
Data Types
As HDL is implemented to describe the hardware of a system, to match the
need for describing the hardware data or operands used in the language
must have several types.
3. Access Types
Values belonging to an access type are pointers to objects of
other types. For example:
type ptr_weathr is access forecast;
B. Verilog Data Types
1. Nets
Nets are declared by the predefined word wire. Nets have
values that change continuously by the circuits that are
driving them.
Value Definition
0 Logic 0 (false)
1 Logic 1 (true)
X Unknown
Z High impedance
2. Register
Register, in contrast to nets, stores values until they are
updated.
Register, as its name suggests, represents data-storage
elements. Register is declared by the predefined word reg.
Value Definition
0 Logic 0 (false)
1 Logic 1 (true)
X Unknown
Z High impedance
3. Vectors
Vectors are multiple bits. A register or a net can be declared
as a vector. Vectors are declared by brackets [ ]. Examples of
vectors are:
The first statement declares a net ‘a’. It has four bits, and its
initial value is 1010 (b stands for bit). The second statement
declares a register ‘total’. Its size is eight bits, and its value is
decimal 12 (d stands for decimal). Vectors are implemented in
almost all subsequent chapters.
4. Integers
Integers are declared by the predefined word ‘integer’.
5. Real
Real (floating-point) numbers are declared with the
predefined word real. Examples of real values are 2.4, 56.3,
and 5e12. The value 5e12 is equal to 5 × 1012.
VHDL and verilog comparison
Library ieee;
use ieee.std_logic_1164.all;
entity half_adder is
port(a,b:in bit; sum,carry:out bit);
end half_adder;
Library ieee;
use ieee.std_logic_1164.all;
entity full_adder is
port(a,b,c:in bit;
sum,carry:out bit);
end full_adder;
Library ieee;
use ieee.std_logic_1164.all;
entity mux is
port(S1,S0,D0,D1,D2,D3:in bit;
Y:out bit);
end mux;
Library ieee;
use ieee.std_logic_1164.all;
entity demux is
port(S1,S0,D:in bit;
Y0,Y1,Y2,Y3:out bit);
end demux;
library ieee;
use ieee.std_logic_1164.all;
entity parity_checker is
port (a0,a1,a2,a3 : in std_logic;
p : out std_logic);
end parity_checker;
module counter(count,enable,clk,rst_n);
input enable,clk,rst_n;
output reg[3:0] count;
always @(posedge clk or negedge rst_n)
begin
if(~rst_n) counter <= 4'b0000;
else if(enable) counter <= counter + 4'b0001;
end
Verilog code for ALU