Unit 5
Unit 5
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Describing a design:
Entity declaration:
It defines the names, input output signals and modes of a hardware module.
Syntax:
entity entity_name is
Port declaration;
end entity_name;
An entity declaration should starts with ‘entity’ and ends with ‘end’ keywords.
Ports are interfaces through which an entity can communicate with its environment.
Each port must have a name, direction and a type. An entity may have no port
declaration also. The direction will be input, output or inout.
In Port can be read
Out Port can be written
Inout Port can be read and written
Buffer Port can be read and written, it
can have only one source.
Architecture:
It describes the internal description of design or it tells what is there inside design.
Each entity has atleast one architecture and an entity can have many
architecture.
Package declaration:
Package declaration is used to declare components, types, constants, functions and so
on.
Syntax:
package package_name is
Declarations;
end package_name;
Package body:
A package body is used to declare the definitions and procedures that are declared in
corresponding package. Values can be assigned to constants declared in package in package
body.
Syntax:
package body package_name is
Function_procedure definitions;
end package_name;
The internal working of an entity can be defined using different modeling styles inside
architcture body. They are
1. Dataflow modeling.
2. Behavioral modeling.
3. Structural modeling.
Structure of an entity:
Let’s try to understand with the help of one example.
Dataflow modelling:
Data Flow Modelling
In this modelling style, the flow of data through the entity is expressed using concurrent
(parallel) signal. i.e In this style of modelling, the internal working of an entity can be
implemented using concurrent signal assignment.
Besides them, assignments using only operators (AND, NOT, +, *, sll, etc.) can also be
used to construct code.
Finally, a special kind of assignment, called BLOCK, can also be employed in this kind of
code.
In concurrent code, the following can be used −
Operators
The WHEN statement (WHEN/ELSE or WITH/SELECT/WHEN);
The GENERATE statement;
The BLOCK statement
Let’s take half adder example which is having one XOR gate and a AND gate.
Library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity ha_en is
port (A,B:in bit;S,C:out bit);
end ha_en;
end ha_ar;
Behavioral modelling:
In this style of modeling, the internal working of an entity can be implemented using set of
statements.
It contains:
Process statements
Sequential statements
Signal assignment statements
Wait statements
Process statement is the primary mechanism used to model the behavior of an entity.
It contains sequential statements, variable assignment (:=) statements or signal
assignment (<=) statements etc..
Inside the process the execution of statements will be sequential and if one entity
is having two processes the execution of these processes will be concurrent. At the
end it waits for another event to occur.
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity ha_beha_en is
port(
A : in BIT;
B : in BIT;
S : out BIT;
C : out BIT
);
end ha_beha_en;
end ha_beha_ar;
Here whenever there is a change in the value of a or b the process statements are executed.
Structural modeling:
In this modeling, an entity is described as a set of interconnected components. A
component instantiation statement is a concurrent statement. Therefore, the order
of these statements is not important.
use IEEE.STD_LOGIC_1164.all;
entity fa_en is
port(A,B,Cin:in bit; SUM, CARRY:out bit);
end fa_en;
component ha_en
port(A,B:in bit;S,C:out bit);
end component;
signal C1,C2,S1:bit;
begin
end fa_ar;
The program we have written for half adder in dataflow modeling is instantiated
as shown above.
o ha_en is the name of the entity in dataflow modeling. C1, C2, S1 are the
signals used for internal connections of the component which are declared
using the keyword signal.
o Port map is used to connect different components as well as connect
components to ports of the entity.
X Y Z
0 0 0
0 1 0
1 0 0
1 1 1
VHDL Code:
Library ieee;
use ieee.std_logic_1164.all;
entity and1 is
port(x,y:in bit ; z:out bit);
end and1;
entity or1 is
port(x,y:in bit ; z:out bit);
end or1;
X Y
0 1
1 0
VHDL Code:
Library ieee;
use ieee.std_logic_1164.all;
entity not1 is
port(x:in bit ; y:out bit);
end not1;
Library ieee;
use ieee.std_logic_1164.all;
entity nand1 is
port(a,b:in bit ; c:out bit);
end nand1;
X Y z
0 0 1
0 1 0
1 0 0
1 1 0
VHDL Code:
Library ieee;
use ieee.std_logic_1164.all;
entity nor1 is
port(a,b:in bit ; c:out bit);
end nor1;
architecture virat of nor1 is
begin
c<=a nor b;
end virat;
X Y Z
0 0 1
0 1 1
1 0 1
1 1 0
VHDL Code:
Library ieee;
use ieee.std_logic_1164.all;
entity xor1 is
port(a,b:in bit ; c:out bit);
end xor1;
Library ieee;
use ieee.std_logic_1164.all;
entity xnor1 is
port(a,b:in bit ; c:out bit);
end xnor1;
Library ieee;
use ieee.std_logic_1164.all;
entity half_adder is
port(a,b:in bit; sum,carry:out bit);
end half_adder;
For Example, if n = 2 then the mux will be of 4 to 1 mux with 4 input, 2 selection line and 1
output as shown below.
Truth Table for Multiplexer 4 to 1
library ieee;
use ieee.std_logic_1164.all;
entity MUX4_1 is
port ( Sel : in std_logic_vector(1 downto 0);
A, B, C, D : in std_logic;
Y : out std_logic );
end MUX4_1;
library ieee;
use ieee.std_logic_1164.all;
entity MUX4_1 is
port ( Sel0,Sel1 : in std_logic;
A, B, C, D : in std_logic;
Y : out std_logic );
end MUX4_1;
architecture structural of MUX4_1 is
component inv
port (pin : in std_logic;
pout :out std_logic);
end component;
component and3
port (a0,a1,a2: in std_logic;
aout:out std_logic);
end component;
component or4
port (r0,r1,r2,r3:in std_logic;
rout:out std_logic);
end component;
signal selbar0,selbar1,t1,t2,t3,t4: std_logic;
begin
INV0: inv port map (Sel0, selbar0);
INV1: inv port map (Sel1, selbar1);
A1: and3 port map (A, selbar0, selbar1, t1);
A2: and3 port map (B, Sel0, selbar1, t2);
A3: and3 port map (C, selbar0, Sel1, t2);
A4: and3 port map (D, Sel0, Sel1, t4);
O1: or4 port map (t1, t2, t3, t4, Y);
end structural;
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity mux_4to1 is
port(
A,B,C,D : in STD_LOGIC;
S0,S1: in STD_LOGIC;
Z: out STD_LOGIC
);
end mux_4to1;
Following is the VHDL code for a 4-to-1 1-bit MUX using an If statement.
library ieee;
use ieee.std_logic_1164.all;
entity mux is
port (a, b, c, d : in std_logic;
s : in std_logic_vector (1 downto 0);
o : out std_logic);
end mux;
The following table shows pin definitions for a 4-to-1 1-bit MUX using a
Case statement.
IO Pins Description
a, b, c, d Data Inputs
s[1:0] MUX selector
o Data Output
library ieee;
use ieee.std_logic_1164.all;
entity mux is
port (a, b, c, d : in std_logic;
s : in std_logic_vector (1 downto 0);
o : out std_logic);
end mux;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity mux2_1 is
port(A,B : in STD_LOGIC;
S: in STD_LOGIC;
Z: out STD_LOGIC);
end mux2_1;
What is Verilog ?
Behavioral level
Register-transfer level
Gate level
Register−Transfer Level
Designs using the Register−Transfer Level specify the characteristics of a circuit using
operations and the transfer of data between the registers.
A model that describes the flow of data between registers and how a design process
these data Gate Level
Switch Level
A model that describes the transistors and the interconnections between them
Comments
There are two forms to represent the comments
1) Single line comments begin with the token // and end with carriage return.
Ex.: //this is single line syntax
2) Multiline comments begins with the token /* and end with token */
Ex.: /* this is multiline Syntax*/
The half adder truth table and schematic (fig-1) is mentioned below. The boolean
expressions are:
S= A (EXOR) B
C=A.B
Input-A Input-B Output-S Output-C
0 0 0 0
0 1 1 0
1 0 1 0
1 1 0 1
module ha ( a, b, s, c)
input a, b;
output s, c;
assign s= a ^ b;
assign c= a & b;
end module
Half Substractor
The half substractor truth table and schematic (fig-2) is mentioned below. The boolean
expressions are:
D= A (EXOR) B
Br=A'.B
module hs ( a, b, d, br)
input a, b;
output d, br;
assign d= a ^ b;
assign br= ~a & b;
end module
Full Substractor
The full substractor truth table and schematic (fig-3) is mentioned below. The boolean
expressions are:
D= A (EXOR) B (EXOR) C
Br=A'.B + B.Cin + A'.Cin
module fs ( a, b, c, d, br)
input a, b, c;
output d, br;
assign d= a ^ b ^ c;
assign br=(( ~a)& (b | c)) | (b & c);
end module
Verilog HDL Program for FULL ADDER
always @(a or b or c or d or s)
begin
if (s == 2'b00) o = a;
else if (s == 2'b01) o = b;
else if (s == 2'b10) o = c;
else o = d;
end
endmodule
Verilog Code
Following is the Verilog Code for a 4-to-1 1-bit MUX using a Case statement.
module mux (a, b, c, d, s, o);
input a,b,c,d;
input [1:0] s;
output o;
reg o;
always @(a or b or c or d or s)
begin
case (s)
2'b00 : o = a;
2'b01 : o = b;
2'b10 : o = c;
default : o = d;
endcase
end
endmodule
a) VHDL stands for vhsic hardware description language and is mainly used for
modelling a digital circuit at higher level of abstraction and it's IEEE standard is 1076–
2008
While Verilog is also a HDL (Hardware Description Language) but can be used as HVL
(Hardware Verification Language) to some extent and it's IEEE standard is 1364–2005
and its IEEE standard is 1364–2005.
b) VHDL has its origin and syntax derived from Ada programming language while
Verilog has its syntax originated from C programming language.
c) VHDL has wide range of data types like scalar,composite,access and file type which
are further classified into wide range which makes it quite verbose while Verilog has
mainly two data type like wire and reg which makes it easy to use.
e) VHDL has 9 valued logic primarily U,X,0,1,Z,W,L,H,- and Verilog is a 4 valued logic
0,1,X,Z.
g) VHDL is typecast language while Verilog is non type cast language.( Type casting is a
way to convert a variable from one data type to another data type )
h) VHDL has mainly 5 ports like in,out,input,buffer and linkage while Verilog has only
3 ports in,out,input.
I) Procedures and functions are placed in a package so that they can be available to any
design unit that wishes to use them in case of vhdl while in case of Verilog there is no
concept of package and to make functions and tasks accessible they are placed in a
separate file and can be included using 'include compiler directive.