library IEEE ;
use IEEE.std_logic_1164.all ;
ENTITY example1 IS
PORT ( x1, x2, x3
: IN STD_LOGIC ;
f
: OUT STD_LOGIC) ;
END example1 ;
ARCHITECTURE LogicFunc OF example1 IS
BEGIN
f <= (x1 AND x2) OR (NOT x2 AND x3) ;
END LogicFunc ;
An entity is a simple declaration of a modules inputs and outputs.
An architecture is a detailed description of modules internal structure or behavior.
Mode : specifying the signal direction
In : the signal is an input to the entity.
Out : the signal is an output of the entity.
Inout: the signal can be read as an input or an output of the entity. This mode is typically used for threestate input/output pins.
Buffer: the signal is an output of the entity, and its value can also be read and written inside the entitys
architecture.
Design of Arithmetic Circuits using VHDL
ENTITY fulladd IS
PORT ( Cin, x, y : IN STD_LOGIC ;
s, Cout : OUT STD_LOGIC ) ;
END fulladd ;
ARCHITECTURE LogicFunc OF fulladd IS
BEGIN
s <= x XOR y XOR Cin ;
Cout <= (x AND y) OR (Cin AND x) OR (Cin AND y) ;
END LogicFunc ;
Declaration of a package.
PACKAGE fulladd_package IS
COMPONENT fulladd
PORT ( Cin, x, y
: IN STD_LOGIC ;
s, Cout
: OUT STD_LOGIC ) ;
END COMPONENT ;
END fulladd_package ;
LIBRARY ieee ;
USE ieee.std_logic_1164.all ;
USE work.fulladd_package.all ;
ENTITY adder4 IS
PORT (
Cin
: IN STD_LOGIC ;
X, Y
: IN STD_LOGIC_VECTOR(3 DOWNTO 0) ;
S
: OUT
STD_LOGIC_VECTOR(3 DOWNTO 0) ;
Cout
: OUT
STD_LOGIC ) ;
END adder4 ;
ARCHITECTURE Structure OF adder4 IS
SIGNAL C : STD_LOGIC_VECTOR(1 TO 3) ;
BEGIN
stage0: fulladd PORT MAP ( Cin, X(0), Y(0), S(0), C(1) ) ;
SIGNAL C : STD_LOGIC_VECTOR (1 TO 3)
C<=100 , C(1) = 1, C(2) = 0, C(3)=0
SIGNAL X : STD_LOGIC_VECTOR (3 TO 0)
X<=1100, X(3)=1, X(2)=1, X(1)=0, X(0)=0
ARCHITECTURE
An architecture specifies the behavior, interconnections and components of an entity.
Architecture defines the function of an entity. It specifies the relationship between inputs and outputs.
VHDL architectures are categorized in style as:
o Behavior
o Dataflow
o Structural
A design can use any or all of these styles.
Behavior: the behavior of the entity is expressed using sequentially executed procedural code (very
similar to programming languages like C). Sometimes called high-level description
Rather than specifying the structure of a circuit, you specify a set of statements that when executed in
sequence model the behavior of the entity.
Uses process statement and sequential statements (the ordering of statements inside process is important)
Dataflow: specifies the functionality of the entity (the flow of information) without explicitly specifying
its structure
o It specifies how data will be transferred from signal to signal and input to output without the use
of sequential statements.
o No use of process or sequential statements
Structural: an entity is modeled as a set of components connected by signals
o Components are instantiated and connected together
Components: design entities used in other designs. Before an entity can be used in another design it has
to be declared. A component declaration defines an interface for instantiating a component.
A component declaration may be
o in a package: the package is made accessible by use statement
o might be declared in an architecture declarative region using component statement
Every time a component is used it has to be instantiated. Every instantiation has a name.
Selected Signal Assignment
Selected signal assignment is used to assign one of multiple values to a signal, based on some criteria.
The WITH-SELECT-WHEN structure can be used for this purpose.
Syntax:
WITH selection_signal SELECT
signal_name <= value_a WHEN value1_of_selection_signal,
value_b WHEN value2_of_selection_signal,
value_c WHEN value3_of_selection_signal;
All values of selection_signal must be listed in the when clause
We can use the word OTHERS to cover some of the values
ENTITY mux2to1 IS
PORT ( w0, w1, s : IN STD_LOGIC ;
f
: OUT
STD_LOGIC ) ;
END mux2to1 ;
ARCHITECTURE Behavior OF mux2to1 IS
BEGIN
WITH s SELECT
f <= w0 WHEN '0',
w1 WHEN OTHERS ;
END Behavior ;
IF expression THEN
statement,
{statement;}
ELSIF expression THEN
statement,
{statement;}
ELSE
statement,
{statement;}
END IF;
Case Statement
Syntax:
CASE expression IS
WHEN constant_value =>
statement,
{statement;}
WHEN constant_value =>
statement,
{statement;}
WHEN OTHERS =>
statement,
{statement;}
END CASE
D<=A&B , D=a2a1a0b2b1b0
E=111&A&00 , E=111a2a1a000
B<=A SLL 1, b2=a1, b1=a0, b0=0
B<=A SRL 2; b2=b1=0, b0=a2
B<=A SRA 1; b2=a2, b1=a2, b0=a1
B<=A ROR 2; b2=a1, b1=a0, b0=a2
ENTITY alu IS
PORT (
s
: IN STD_LOGIC_VECTOR(2 DOWNTO 0) ;
A, B : IN STD_LOGIC_VECTOR(3 DOWNTO 0) ;
F
: OUT
STD_LOGIC_VECTOR(3 DOWNTO 0) ) ;
END alu ;
ARCHITECTURE Behavior OF alu IS
BEGIN
PROCESS ( s, A, B )
BEGIN
CASE s IS
WHEN "000" =>
F <= "0000" ;
WHEN "001" =>
F <= B - A ;
WHEN "010" =>
F <= A - B ;
WHEN "011" =>
F <= A + B ;
WHEN "100" =>
F <= A XOR B ;
WHEN "101" =>
F <= A OR B ;
WHEN "110" =>
F <= A AND B ;
WHEN OTHERS =>
F <= "1111" ;
END CASE ;
END PROCESS ;
END Behavior ;