VHDL
VHDL
VHDL
INTRODUCTION TO VHDL
What is VHDL?
VHDL is the VHSIC Hardware Description Language. VHSIC is an abbreviation for Very
High Speed Integrated Circuit. It can describe the behavior and structure of electronic
systems, but is particularly suited as a language to describe the structure and behavior
of digital electronic hardware designs, such as ASICs and FPGAs as well as
conventional digital circuits.
VHDL is a notation, and is precisely and completely defined by the Language Reference
Manual (LRM). This sets VHDL apart from other hardware description languages, which
are to some extent defined in an ad hoc way by the behavior of tools that use them.
VHDL is an international standard, regulated by the IEEE. The definition of the language
is non-proprietary.
Simulation and synthesis are the two main kinds of tools which operate on the VHDL
language. The Language Reference Manual does not define a simulator, but
unambiguously defines what each simulator must do with each part of the language.
VHDL does not constrain the user to one style of description. VHDL allows designs to be
described using any methodology - top down, bottom up or middle out! VHDL can be
used to describe hardware at the gate level or in a more abstract way. Successful high
level design requires a language, a tool set and a suitable methodology. VHDL is the
language, you choose the tools, and the methodology... well, I guess that's where
Doulos come in to the equation!
ECADLAB(VHDL) 1
ELCTRONICS AND COMMUNICATION ENGINEERING
The development of VHDL was initiated in 1981 by the United States Department of
Defense to address the hardware life cycle crisis. The cost of reprocuring electronic
hardware as technologies became obsolete was reaching crisis point, because the
function of the parts was not adequately documented, and the various components
making up a system were individually verified using a wide range of different and
incompatible simulation languages and tools. The requirement was for a language with a
wide range of descriptive capability that would work the same on any simulator and was
independent of technology or design methodology.
Standardization
The standardization process for VHDL was unique in that the participation and feedback
from industry was sought at an early stage. A baseline language (version 7.2) was
published 2 years before the standard so that tool development could begin in earnest in
advance of the standard. All rights to the language definition were given away by the
DoD to the IEEE in order to encourage industry acceptance and investment.
ASIC Mandate
DoD Mil Std 454 mandates the supply of a comprehensive VHDL description with every
ASIC delivered to the DoD. The best way to provide the required level of description is to
use VHDL throughout the design process.
ECADLAB(VHDL) 2
ELCTRONICS AND COMMUNICATION ENGINEERING
VHDL '93
As an IEEE standard, VHDL must undergo a review process every 5 years (or sooner) to
ensure its ongoing relevance to the industry. The first such revision was completed in
September 1993, and tools conforming to VHDL '93 are now available.
1987 - Mil Std 454 requires comprehensive VHDL descriptions to be delivered with
ASICs
ECADLAB(VHDL) 3
ELCTRONICS AND COMMUNICATION ENGINEERING
Levels of Abstraction
Algorithm
ECADLAB(VHDL) 4
ELCTRONICS AND COMMUNICATION ENGINEERING
RTL
An RTL description has an explicit clock. All operations are scheduled to occur in
specific clock cycles, but there are no detailed delays below the cycle level.
Commercially available synthesis tools do allow some freedom in this respect. A single
global clock is not required but may be preferred. In addition, retiming is a feature that
allows operations to be re-scheduled across clock cycles, though not to the degree
permitted in behavioral synthesis tools.
Gates
A gate level description consists of a network of gates and registers instanced from a
technology library, which contains technology-specific delay information for each gate.
In the diagram above, the RTL level of abstraction is highlighted. This is the ideal level of
abstraction at which to design hardware given the state of the art of today's synthesis
tools. The gate level is too low a level for describing hardware - remember we're trying to
move away from the implementation concerns of hardware design, we want to abstract
to the specification level - what the hardware does, not how it does it. Conversely, the
algorithmic level is too high a level, most commercially available synthesis tools cannot
produce hardware from a description at this level.
In the future, as synthesis technology progresses, we will one day view the RTL level of
abstraction as the “dirty” way of writing VHDL for hardware and writing algorithmic (often
called behavioral) VHDL will be the norm.
ECADLAB(VHDL) 5
ELCTRONICS AND COMMUNICATION ENGINEERING
Scope of VHDL
VHDL is suited to the specification, design and description of digital electronic hardware.
System level
VHDL is not ideally suited for abstract system-level simulation, prior to the hardware-
software split. Simulation at this level is usually stochastic, and is concerned with
modeling performance, throughput, queuing and statistical distributions. VHDL has been
used in this area with some success, but is best suited to functional and not stochastic
simulation.
Digital
VHDL is suitable for use today in the digital hardware design process, from specification
through high-level functional simulation, manual design and logic synthesis down to
gate-level simulation. VHDL tools usually provide an integrated design environment in
this area.
VHDL is not suited for specialized implementation-level design verification tools such as
analog simulation, switch level simulation and worst case timing simulation. VHDL can
be used to simulate gate level fan-out loading effects providing coding styles are
adhered to and delay calculation tools are available. The standardization effort named
VITAL (VHDL Initiative toward ASIC Libraries) is active in this area, and is now bearing
fruit in that simulation vendors have built-in VITAL support. More importantly, many ASIC
vendors have VITAL-compliant libraries, though not all are allowing VITAL-based sign-
off - not yet anyway.
Analogue
In 1999, the IEEE approved Standard 1076.1, which is informally known as VHDL-AMS.
It is a true super-set of VHDL, and includes analog and mixed-signal extensions.
ECADLAB(VHDL) 6
ELCTRONICS AND COMMUNICATION ENGINEERING
Design process
The diagram below shows a very simplified view of the electronic system design process
incorporating VHDL. The central portion of the diagram shows the parts of the design
process which are most impacted by VHDL.
The diagram below summarizes the high level design flow for an ASIC (ie. gate array,
standard cell) or FPGA. In a practical design situation, each step described in the
following sections may be split into several smaller steps, and parts of the design flow
will be iterated as errors are uncovered.
System-level Verification
As a first step, VHDL may be used to model and simulate aspects of the complete
system containing one or more devices. This may be a fully functional description of the
system allowing the FPGA/ASIC specification to be validated prior to commencing
detailed design. Alternatively, this may be a partial description that abstracts certain
properties of the system, such as a performance model to detect system performance
bottle-necks.
ECADLAB(VHDL) 7
ELCTRONICS AND COMMUNICATION ENGINEERING
Once the overall system architecture and partitioning is stable, the detailed design of
each FPGA/ASIC can commence. This starts by capturing the design in VHDL at the
register transfer level, and capturing a set of test cases in VHDL. These two tasks are
complementary, and are sometimes performed by different design teams in isolation to
ensure that the specification is correctly interpreted. The RTL VHDL should be
synthesizable if automatic logic synthesis is to be used. Test case generation is a major
task that requires a disciplined approach and much engineering ingenuity: the quality of
the final FPGA/ASIC depends on the coverage of these test cases.
RTL verification
The RTL VHDL is then simulated to validate the functionality against the specification.
RTL simulation is usually one or two orders of magnitude faster than gate level
simulation, and experience has shown that this speed-up is best exploited by doing more
simulation, not spending less time on simulation. In practice it is common to spend 70-
80% of the design cycle writing and simulating VHDL at and above the register transfer
level, and 20-30% of the time synthesizing and verifying the gates.
Look-ahead Synthesis
Although some exploratory synthesis will be done early on in the design process, to
provide accurate speed and area data to aid in the evaluation of architectural decisions
and to check the engineer's understanding of how the VHDL will be synthesized, the
main synthesis production run is deferred until functional simulation is complete. It is
pointless to invest a lot of time and effort in synthesis until the functionality of the design
is validated.
ECADLAB(VHDL) 8
ELCTRONICS AND COMMUNICATION ENGINEERING
Executable specification
It is often reported that a large number of ASIC designs meet their specifications first
time, but fail to work when plugged into a system. VHDL allows this issue to be
addressed in two ways: A VHDL specification can be executed in order to achieve a high
level of confidence in its correctness before commencing design, and may simulate one
to two orders of magnitude faster than a gate level description. A VHDL specification for
a part can form the basis for a simulation model to verify the operation of the part in the
wider system context (eg. printed circuit board simulation). This depends on how
accurately the specification handles aspects such as timing and initialization. Behavioral
simulation can reduce design time by allowing design problems to be detected early on,
avoiding the need to rework designs at gate level. Behavioral simulation also permits
design optimization by exploring alternative architectures, resulting in better designs.
ECADLAB(VHDL) 9
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 10
ELCTRONICS AND COMMUNICATION ENGINEERING
Click Active-HDL 6.3 icon on desktop then above window will be appeared on the
screen Select create new work space and press ok
ECADLAB(VHDL) 11
ELCTRONICS AND COMMUNICATION ENGINEERING
Type the name in the box under Type the workspace name: and press ok
ECADLAB(VHDL) 12
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 13
ELCTRONICS AND COMMUNICATION ENGINEERING
Click on the button indicated by an arrow located under Synthesis tool: and select
Xilinx XST Vhdl .
ECADLAB(VHDL) 14
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 15
ELCTRONICS AND COMMUNICATION ENGINEERING
Type a name for the design in the box which is under Type the design name and press
Next.
ECADLAB(VHDL) 16
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 17
ELCTRONICS AND COMMUNICATION ENGINEERING
Right click on Add New File then select New and left click on VHDL Source
ECADLAB(VHDL) 18
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 19
ELCTRONICS AND COMMUNICATION ENGINEERING
Type a name in the box under Type the name of the source file to create:
Type a name in the box under Type the name of the entity(optional):
Type a name in the box under Type the name of the architecture body(optional): and
press Next
ECADLAB(VHDL) 20
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 21
ELCTRONICS AND COMMUNICATION ENGINEERING
The above window will be appeared. Then enter the code for your design
ECADLAB(VHDL) 22
ELCTRONICS AND COMMUNICATION ENGINEERING
Then press Compile button shown on the top and in the console box #compile
success 0 errors 0 warnings analysis time : 0.2 [s] will be appeared if the code is
correct
ECADLAB(VHDL) 23
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 24
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 25
ELCTRONICS AND COMMUNICATION ENGINEERING
The above windows will be appeared right click on the input, output signals and click
on select all and press Add button
ECADLAB(VHDL) 26
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 27
ELCTRONICS AND COMMUNICATION ENGINEERING
Right click on the input signal a and click on Simulators and proceed the same process
for other input signals also
ECADLAB(VHDL) 28
ELCTRONICS AND COMMUNICATION ENGINEERING
The above windows will be appeared select Clock in the box under Type: give some
clock shown below and we can select 1 or 0 and then press Apply button and then press
close button
ECADLAB(VHDL) 29
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 30
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 31
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 32
ELCTRONICS AND COMMUNICATION ENGINEERING
After simulation has been finished select run time and press (Alt+F5) or
run button as shown on the top
ECADLAB(VHDL) 33
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 34
ELCTRONICS AND COMMUNICATION ENGINEERING
AIM: To simulate internal structure of all gates using VHDL and verify their operation.
APPARATUS:
S.NO COMPONENT QUANTITY
1. IC 7400 1
2. IC 7402 1
3. IC 7404 1
4. IC 7408 1
5. IC 7436 1
6. IC 7486 1
7. IC CD74HC7266 1
8. Digital Trainer Board 1
THEORY:
Logic gates: Digital systems are said to be constructed by using logic gates. These
gates are the AND, OR, NOT, NAND, NOR, EXOR and EXNOR gates. The basic
operations are described below with the aid of truth tables.
AND gate
The AND gate is an electronic circuit that gives a high output (1) only if all
its inputs are high. A dot (.) is used to show the AND operation i.e. A.B
for a two input (A & B) AND gate, Y = A.B. Bear in mind that this dot is
sometimes omitted i.e. written as AB
ECADLAB(VHDL) 35
ELCTRONICS AND COMMUNICATION ENGINEERING
OR gate
The OR gate is an electronic circuit that gives a high output (1) if one or
more of its inputs are high. A plus (+) is used to show the OR operation.
E.g. output of a 2-input OR gate is Y=A+B.
NOT gate
The NOT gate is an electronic circuit that produces an inverted version of the
input at its output. It is also known as an inverter. If the input variable is A, the
inverted output is known as NOT A. This is also shown as A', or A with a bar
over the top, as shown at the output, i.e., Y= A'
NAND gate
ECADLAB(VHDL) 36
ELCTRONICS AND COMMUNICATION ENGINEERING
NOR gate
The 'Exclusive-OR' gate is a circuit which will give a high output if either,
but not both, of its two inputs are high. An encircled plus sign ( ) is used
to show the EOR operation.When inputs are A and B,output Y of EXOR
gate is Y=A B
EXNOR gate
The 'Exclusive-NOR' gate circuit does the opposite to the EOR gate. It
will give a low output if either, but not both, of its two inputs are high.
The symbol is an EXOR gate with a small circle on the output. The small
circle represents inversion.The output Y of a EXNOR gate with inputs
A&B is given by Y=( A B)′ .
ECADLAB(VHDL) 37
ELCTRONICS AND COMMUNICATION ENGINEERING
The NAND and NOR gates are called universal gates since with either one the
AND and OR functions and NOT can be generated.
Table 1 is a summary truth table of the input/output combinations for the NOT gate
together with all possible input/output combinations for the other gate functions. Also
note that a truth tables with 'n' inputs has 2n rows. You can compare the outputs of
different gates.
ECADLAB(VHDL) 38
ELCTRONICS AND COMMUNICATION ENGINEERING
INTERNAL DIAGRAM:
NOR GATE:
NAND GATE:
ECADLAB(VHDL) 39
ELCTRONICS AND COMMUNICATION ENGINEERING
AND GATE:
NOT GATE:
ECADLAB(VHDL) 40
ELCTRONICS AND COMMUNICATION ENGINEERING
OR GATE:
ECADLAB(VHDL) 41
ELCTRONICS AND COMMUNICATION ENGINEERING
VHDL CODE:
library IEEE;
use IEEE.std_logic_1164.all;
entity gates is
port ( a: in STD_LOGIC;
b: in STD_LOGIC;
and1: out STD_LOGIC;
or1: out STD_LOGIC;
nor1: out STD_LOGIC;
nand1: out STD_LOGIC;
xor1: out STD_LOGIC;
xnor1: out STD_LOGIC);
end gates;
architecture gates of gates is
begin
and1 <= a and b;
or1 <= a or b;
nor1 <= a nor b;
nand1 <= a nand b;
xor1 <= a xor b;
xnor1 <= a xnor b;
end gates;
ECADLAB(VHDL) 42
ELCTRONICS AND COMMUNICATION ENGINEERING
INPUTS OUTPUT
INPUTS OUTPUT
A B Y
A B Y
0V 0V 0V
0V 0V 0V
0V 5V 0V
0V 5V 5V
5V 0V 0V
5V 0V 5V
5V 5V 5V
5V 5V 5V
INPUTS OUTPUT
INPUTS OUTPUT
A B Y
A B Y
0V 0V 5V
0V 0V 0V
0V 5V 0V
0V 5V 5V
5V 0V 0V
5V 0V 5V
5V 5V 5V
5V 5V 0V
ECADLAB(VHDL) 43
ELCTRONICS AND COMMUNICATION ENGINEERING
AND GATE : when all inputs are high output should be high.
OR GATE : when any of input is high output should be high.
NAND GATE : when any of input is low output should be high.
NOR GATE : when any of input is high output should be low.
EX-OR GATE: when input combination contains odd number of
Ones then only output should be high.
EX-NOR GATE: when input combination contains even number of
ones then only output should be high.
ECADLAB(VHDL) 44
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 45
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULTS (HARDWARE):
INPUTS OUTPUT
INPUTS OUTPUT
A B LED
A B LED
0 0 OFF
0 0 OFF
0 1 OFF
0 1 ON
1 0 OFF
1 0 ON
1 1 ON
1 1 ON
INPUTS OUTPUT
INPUTS OUTPUT
A B LED
A B LED
0 0 ON
0 0 ON
0 1 OFF
0 1 ON
1 0 OFF
1 0 ON
1 1 OFF
1 1 OFF
INPUTS OUTPUT
INPUTS OUTPUT
A B LED
A B LED
0 0 ON
0 0 OFF
0 1 OFF
0 1 ON
1 0 OFF
1 0 ON
1 1 ON
1 1 OFF
ECADLAB(VHDL) 46
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULTS (SOFTWARE):
ECADLAB(VHDL) 47
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 48
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULT:
ALL GATES Internal Structures are Simulated and Verified Using Active-HDL
Software and in Hardware Lab Respectively.
INFERENCE:
Theoretical and Practical Results are according to the expected results both for Software
and Hardware.
PRECAUTIONS (SOFTWARE):
1) Follow Getting Started Procedure for the Software you are using.
2) Don’t Forget to instantiate IEEE Libraries At the starting of
the code
3) Follow Syntax and Semantics of the VHDL code throughout
PRECAUTIONS (HARDWARE):
1) Apply the voltages to the IC as per the details given in the data
Sheets.
2) Apply the inputs to the respective pins.
3) First decide which one is MSB and LSB.
4) Take the outputs at appropriate pins.
ECADLAB(VHDL) 49
ELCTRONICS AND COMMUNICATION ENGINEERING
Ans:
ECADLAB(VHDL) 50
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 51
ELCTRONICS AND COMMUNICATION ENGINEERING
+VCC = +5V
R1
R3 R2 0Ohm_1%
0Ohm_1%0Ohm_1%
Q3
2N2222A
Q2 D2
2N2222A 1BH62
Q1
2N2222A Q4
2N2222A
R4
D1
0Ohm_1%
1BH62
ECADLAB(VHDL) 52
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 53
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 54
ELCTRONICS AND COMMUNICATION ENGINEERING
PROCEDURE (SOFTWARE):
PROCEDURE (HARDWARE):
ECADLAB(VHDL) 55
ELCTRONICS AND COMMUNICATION ENGINEERING
AIM: To Simulate internal structure of D FLIP FLOP(IC 7474) using VHDL and verify
Its operation.
APPARATUS:
ECADLAB(VHDL) 56
ELCTRONICS AND COMMUNICATION ENGINEERING
PIN DIAGRAM:
TRUTH TABLE:
INPUTS OUTPUTS
PR CLR CLK D Q Q*
L H X X H L
H L X X L H
L L X X H H
H H H H L
H H L L H
H H L X Q0 Q0*
H = HIGH Logic Level X = Either LOW or HIGH Logic Level Clear
L = LOW Logic Level ↑ = Positive-going transition of the clock.
Q0 = The output logic level of Q before the indicated input conditions were and
established.
ECADLAB(VHDL) 57
ELCTRONICS AND COMMUNICATION ENGINEERING
INTERNAL DIAGRAM:
D = Qt+1
ECADLAB(VHDL) 58
ELCTRONICS AND COMMUNICATION ENGINEERING
VHDL CODE:
library IEEE;
use IEEE.std_logic_1164.all;
entity dff is
port (
d: in STD_LOGIC;
clk: in STD_LOGIC;
clr: in STD_LOGIC;
pr: in STD_LOGIC;
q: out STD_LOGIC;
qbar: out STD_LOGIC);
end dff;
architecture dff of dff is
signal clr1,pr1:std_logic;
begin
clr1<=not clr;
pr1<=not pr;
process(clk,clr1,pr1)
begin
if(pr1='1'and clr1='1')then q<='0';qbar<='0';
elsif(pr1='1'and clr1='0')then q<='1';qbar<='0';
elsif(pr1='0'and clr1='1')then q<='0';qbar<='1';
elsif(clk'event and clr1='1')then q<=d;qbar<=not d;
end if;
end process;
end dff;
ECADLAB(VHDL) 59
ELCTRONICS AND COMMUNICATION ENGINEERING
INPUTS OUTPUTS
PR CLR CLK D Q Q*
0 1 X X 5V 0V
1 0 X X 0V 5V
0 0 X X 5V 5V
1 1 1 5V 0V
1 1 0 0V 5V
1 1 0 X Q0 Q0*
Q0 = The output logic level of Q before the indicated input conditions were and
established.
ECADLAB(VHDL) 60
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 61
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULTS (HARDWARE):
INPUTS OUTPUTS
PR CLR CLK D Q LED Q* LED
0 1 X X ON OFF
1 0 X X OFF ON
0 0 X X ON ON
1 1 1 ON OFF
1 1 0 OFF ON
1 1 0 X Q0 Q0*
ECADLAB(VHDL) 62
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULTS (SOFTWARE):
ECADLAB(VHDL) 63
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 64
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULT:
INFERENCE:
Theoretical and Practical Results are according to the expected results both for Software
and Hardware.
PRECAUTIONS (SOFTWARE):
1) Follow Getting Started Procedure for the Software you are using.
2) Don’t Forget to instantiate IEEE Libraries at the starting of
the code
3) Follow Syntax and Semantics of the VHDL code throughout
PRECAUTIONS (HARDWARE):
1) Apply the voltages to the IC as per the details given in the data
Sheets.
2) Apply the inputs to the respective pins.
3) First decide which one is MSB and LSB.
4)Take the outputs at appropriate pins.
ECADLAB(VHDL) 65
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 66
ELCTRONICS AND COMMUNICATION ENGINEERING
PROCEDURE (SOFTWARE):
PROCEDURE (HARDWARE):
ECADLAB(VHDL) 67
ELCTRONICS AND COMMUNICATION ENGINEERING
AIM: To Simulate internal structure of Decade Counter(IC 7490) using VHDL and verify
Its operation.
APPARATUS:
HARDWARE:
SOFTWARE: Active-HDL
THEORY:
7490 is a 4-bit ripple type decade counter.
Features are:
Output QA is connected to input B for BCD count. Output QD is connected
to input A for qi-binary count. This counter has a gated ‘O’ reset. This
counter contains 4 master-slave FF’s and additional gating to provide a
divide by two counter.
ECADLAB(VHDL) 68
ELCTRONICS AND COMMUNICATION ENGINEERING
TRUTH TABLE:
COUNT OUTPUT
QD QC QB QA
0 L L L L
1 L L L H
2 L L H L
3 L L H H
4 L H L L
5 L H L H
6 L H H L
7 L H H H
8 H L L L
9 H L L H
H = HIGH; L = LOW
ECADLAB(VHDL) 69
ELCTRONICS AND COMMUNICATION ENGINEERING
INTERNAL DIAGRAM:
ECADLAB(VHDL) 70
ELCTRONICS AND COMMUNICATION ENGINEERING
VHDL CODE:
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;
entity dcounter is
port (
clk: in STD_LOGIC;
ro: in STD_LOGIC_VECTOR (2 downto 1):="00";
rg: in STD_LOGIC_VECTOR (2 downto 1):="00";
q:inout unsigned(3 downto 0):="0000"
);
end dcounter;
architecture dcounter of dcounter is
begin
process(clk)
begin
if(ro(1)='1'and ro(2)='1'and rg(1)='0')then q<="0000";
ECADLAB(VHDL) 71
ELCTRONICS AND COMMUNICATION ENGINEERING
COUNT OUTPUT
QD QC QB QA
0 0 0 0 0
1 0 0 0 1
2 0 0 1 0
3 0 0 1 1
4 0 1 0 0
5 0 1 0 1
6 0 1 1 0
7 0 1 1 1
8 1 0 0 0
9 1 0 0 1
L X L X COUNT
L X X L COUNT
X L L X COUNT
ECADLAB(VHDL) 72
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 73
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULTS (HARDWARE):
COUNT OUTPUT
QD LED QC LED QB LED QA LED
0 OFF OFF OFF OFF
1 OFF OFF OFF ON
2 OFF OFF ON OFF
3 OFF OFF ON ON
4 OFF ON OFF OFF
5 OFF ON OFF ON
6 OFF ON ON OFF
7 OFF ON ON ON
8 ON OFF OFF OFF
9 ON OFF OFF ON
ECADLAB(VHDL) 74
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULTS (SOFTWARE):
ECADLAB(VHDL) 75
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 76
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULT:
INFERENCE:
Theoretical and Practical Results are according to the expected results both for Software
and Hardware.
PRECAUTIONS (SOFTWARE):
1) Follow Getting Started Procedure for the Software you are using.
2) Don’t forget to instantiate IEEE Libraries at the starting of
the code.
3) Follow Syntax and Semantics of the VHDL code throughout.
PRECAUTIONS (HARDWARE):
1) Apply the voltages to the IC as per the details given in the data sheets.
2) Apply the inputs to the respective pins.
3) First decide which one is MSB and LSB.
4) Take the outputs at appropriate pins.
ECADLAB(VHDL) 77
ELCTRONICS AND COMMUNICATION ENGINEERING
Ans: A decade counter is also known as mod-10 counter or BCD counter. It is used
In frequency counter, digital voltmeter, digital voltmeter, wrist watches etc.
6. Applications of counter?
Ans: Digital system use counter in a variety of applications, such as digital clocks,
special sequence generators, time-delay circuits, pulse counters, control
state counters, program counters etc.
ECADLAB(VHDL) 78
ELCTRONICS AND COMMUNICATION ENGINEERING
PROCEDURE (SOFTWARE):
1) Follow Getting Started Procedure for the Software you are using.
2) Don’t forget to instantiate IEEE Libraries at the starting of the code.
PROCEDURE (HARDWARE):
ECADLAB(VHDL) 79
ELCTRONICS AND COMMUNICATION ENGINEERING
AIM: To Simulate Internal structure of Four Bit Counter (IC 7493) using VHDL and
Verify its operation.
APPARATUS:
THEORY:
ECADLAB(VHDL) 80
ELCTRONICS AND COMMUNICATION ENGINEERING
PIN DIAGRAM:
TRUTH TABLE:
COUNT OUTPUT
QO Q1 Q2 Q3
0 0 0 0 0
1 1 0 0 0
2 0 1 0 0
3 1 1 0 0
4 0 0 1 0
5 1 0 1 0
6 0 1 1 0
7 1 1 1 0
8 0 0 0 1
9 1 0 0 1
10 0 1 0 1
11 1 1 0 1
12 0 0 1 1
13 1 0 1 1
14 0 1 1 1
15 1 1 1 1
ECADLAB(VHDL) 81
ELCTRONICS AND COMMUNICATION ENGINEERING
INTERNAL DIAGRAM:
VHDL CODE:
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;
entity counter4 is
port (
clk: in STD_LOGIC;
r: in STD_LOGIC_VECTOR (1 downto 0);
q: inout unsigned(3 downto 0):="0000" );
end counter4;
Architecture counter4 of counter4 is
begin
-- <<enter your statements here>>
process (clk)
begin
if(r(0)='1'and r(1)='1')then q<="0000";
elsif (clk'event and clk='1') then q<=q+1;
end if;
end process;
end counter4;
ECADLAB(VHDL) 82
ELCTRONICS AND COMMUNICATION ENGINEERING
COUNT OUTPUT
QO Q1 Q2 Q3
0 0V 0V 0V 0V
1 5V 0V 0V 0V
2 0V 5V 0V 0V
3 5V 5V 0V 0V
4 0V 0V 5V 0V
5 5V 0V 5V 0V
6 0V 5V 5V 0V
7 5V 5V 5V 0V
8 0V 0V 0V 5V
9 5V 0V 0V 5V
10 0V 5V 0V 5V
11 5V 5V 0V 5V
12 0V 0V 5V 5V
13 5V 0V 5V 5V
14 0V 5V 5V 5V
15 5V 5V 5V 5V
ECADLAB(VHDL) 83
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 84
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULTS (HARDWARE):
COUNT OUTPUT
QOLED Q1LED Q2LED Q3LED
0 OFF OFF OFF OFF
1 ON OFF OFF OFF
2 OFF ON OFF OFF
3 ON ON OFF OFF
4 OFF OFF ON OFF
5 ON OFF ON OFF
6 OFF ON ON OFF
7 ON ON ON OFF
8 OFF OFF OFF ON
9 ON OFF OFF ON
10 OFF ON OFF ON
11 ON ON OFF ON
12 OFF OFF ON ON
13 ON OFF ON ON
14 OFF ON ON ON
15 ON ON ON ON
ECADLAB(VHDL) 85
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULTS (SOFTWARE):
ECADLAB(VHDL) 86
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 87
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULT:
Four Bit Counter internal structure is Simulated and verified using Active-HDL
Software and in Hardware Lab Respectively.
INFERENCE:
Theoretical and Practical results are according to the expected results both for Software
and Hardware.
PRECAUTIONS (SOFTWARE):
1) Follow Getting Started Procedure for the Software you are using.
2) Don’t forget to instantiate IEEE Libraries At the starting of
the code.
3) Follow Syntax and Semantics of the VHDL code throughout.
PRECAUTIONS (HARDWARE):
1) Apply the voltages to the IC as per the details given in the data
Sheets.
2) Apply the inputs to the respective pins.
3) First decide which one is MSB and LSB.
4) Take the outputs at appropriate pins.
ECADLAB(VHDL) 88
ELCTRONICS AND COMMUNICATION ENGINEERING
Ans: In asynchronous counter flip flops are connected in such a way that output of first
flip flop drives the clock for next flip flop.
In synchronous counter there is no connection between output of first flip flop and clock
input of next flip flop.
2. Which type of counter is preferred when there are more number of flip flops and why
such a type of counter is preferred?
Ans: synchronous counter is preferred because clock is simultaneously given to all flip
flops there is no problem of propagation delay
3. If a four-bit synchronous counter is designed with 4 flip flops and two AND gates then
determine f max if t pd (propagation delay time ) for each flip flop is 50ns and t pd for each
AND gate is 20ns?
Ans: For a synchronous counter total delay that must be allowed between input clock
pulses is equal to flip flop t pd + AND gate t pd .Thus Tclk 50 + 20 = 70ns and so counter
has f max = 1/ 70ns = 14.3Mhz.
4. A counter has 14 stable states 0000 through 1101 .If input frequency is 50khz what
will be its output frequency?
ECADLAB(VHDL) 89
ELCTRONICS AND COMMUNICATION ENGINEERING
PROCEDURE (SOFTWARE):
PROCEDURE (HARDWARE):
ECADLAB(VHDL) 90
ELCTRONICS AND COMMUNICATION ENGINEERING
AIM: To Simulate Internal structure of Shift Register(IC 7495) using VHDL and verify
Its operation.
APPARATUS:
THEORY:
- IC 7495 is a 4-bit shift register with serial and parallel synchronous operating modes.
- It has serial data (DS) and 4 parallel data (D0-D3) inputs and 4 parallel outputs (Q0-
Q3).
ECADLAB(VHDL) 91
ELCTRONICS AND COMMUNICATION ENGINEERING
TRUTH TABLE:
ECADLAB(VHDL) 92
ELCTRONICS AND COMMUNICATION ENGINEERING
INTERNAL DIAGRAM:
ECADLAB(VHDL) 93
ELCTRONICS AND COMMUNICATION ENGINEERING
VHDL CODE:
library IEEE;
use IEEE.std_logic_1164.all;
entity pshift is
port (
clr: in STD_LOGIC;
ro: in STD_LOGIC;
lo: in STD_LOGIC;
clk: in STD_LOGIC;
s: in STD_LOGIC_VECTOR (0 to 1);
ih: in STD_LOGIC_VECTOR (0 to 3);
q: inout STD_LOGIC_VECTOR (0 to 3)
);
end pshift;
architecture pshift of pshift is
signal qin:std_logic_vector(0 to 3);
begin
process(clk,clr,ih,ro,lo,q,s)
begin
qin<=q;
if(clr=’0’)then q<=”0000”;
elsif(clk’event and clk=’1’)then
if(s=”11”)then q<=ih;
elsif(s=”01”)then q<=ro&qin(0)&qin(1)&qin(2);
elsif(s=”10”)then q(0)<=qin(1);q(1)<=qin(2);q(2)<=qin(3);q(3)<=lo;
elsif(s=”00”)then q<=qin;
end if;
end if;
end process;
end pshift;
ECADLAB(VHDL) 94
ELCTRONICS AND COMMUNICATION ENGINEERING
0 0 0 0
1 0 0 0
1 1 0 0
0 1 1 0
1 0 1 1
0 1 0 1
0 0 1 0
0 0 0 1
0 0 0 0
ECADLAB(VHDL) 95
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 96
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULTS (HARDWARE):
ECADLAB(VHDL) 97
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULTS (SOFTWARE):
ECADLAB(VHDL) 98
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 99
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULT:
Shift Register internal structure is simulated and verified using Active-HDL Software
and in Hardware Lab Respectively.
INFERENCE:
Theoretical and Practical results are according to the expected results both for Software
and Hardware.
PRECAUTIONS (SOFTWARE):
1) Follow Getting Started Procedure for the Software you are using.
2) Don’t forget to instantiate IEEE Libraries At the starting of the code.
3) Follow Syntax and Semantics of the VHDL code throughout.
PRECAUTIONS (HARDWARE):
1) Apply the voltages to the IC as per the details given in the data Sheets.
2) Apply the inputs to the respective pins.
3) First decide which one is MSB and LSB.
4) Take the outputs at appropriate pins.
ECADLAB(VHDL) 100
ELCTRONICS AND COMMUNICATION ENGINEERING
Ans: The binary information shifted from stage to stage within register upon application
of clock pulses. This type of shifting is essential for certain Arithmetic and logical
operations used in microprocessors. This gives rise to a group of registers called shift
registers.
2) What are the different types of shift registers?
Ans: Serial-in serial-out, Serial-in parallel-out, parallel-in serial-out, parallel-in parallel-
out, Bi-Directional shift register.
3) How shifting of data will occur in bidirectional shift register?
Ans: This type of register allows shifting of data either to the left or right side.
4) Draw the diagram for basic data movement in Pseudo-random binary sequence
generator.
Ans:
5. What are the different levels that are present in tristate buffer register?
ECADLAB(VHDL) 101
ELCTRONICS AND COMMUNICATION ENGINEERING
Ans: There are three levels in tristate buffer register they are high, low and high
impedance levels.
Ans: Time delay: SISO can be used to introduce time delay from input to output.
Ring counter: If output shift register is fed back to serial input then this can be
used as a ring counter. Serial to parallel data conversion,
parallel to serial data conversion.
PROCEDURE (SOFTWARE):
PROCEDURE (HARDWARE):
ECADLAB(VHDL) 102
ELCTRONICS AND COMMUNICATION ENGINEERING
AIM: To Simulate Internal structure of Universal Shift Register (IC 74194/195) using
VHDL and Verify its operation.
APPARATUS:
S.NO COMPONENT QUANTITY
1. IC 74194/195 1
2. Digital Trainer Board 1
THEORY (HARDWARE):
The 74194 is a bidirectional shift register designed to incorporate virtually all of the
features a system designer want in a shift register. The circuit contains 46 equivalent
gates and features parallel inputs, parallel outputs, right-shift and left-shift serial inputs,
operating mode control inputs and a direct overriding clear line. The register has four
distinct modes of operation namely;
Parallel (Broadside) Load
Shift Right (In the direction of QA toward QD)
Shift Left (In the direction of QD toward QA)
Inhibit Clock (Do nothing)
Synchronous parallel loading is accomplished by applying the four bits of data and
taking both mode control inputs, S0 and S1, high. The data is loaded into the associated
flip flop and appears at the outputs after the positive transition of the clock input. During
loading, serial data flow is inhibited.
Shift right is accomplished synchronously with the rising edge of the clock pulse when S0
is high and S1 is low. Serial data for this mode is entered at the shift-left serial input.
ECADLAB(VHDL) 103
ELCTRONICS AND COMMUNICATION ENGINEERING
Clocking of the flip flop is inhibited when both mode control inputs are low. The mode
controls should be changed only while the clock input is high.
PIN DIAGRAM:
TRUTH TABLE:
INPUTS OUTPUTS
CLEAR MODE CLOCK SERIAL PARALLEL QA QB QC QD
S1 S0 LEFT RIGHT A B C D
L X X X X X X X X X L L L L
H X X L X X X X X X QA0 QB0 QC0 QD0
H H H X X a b c d a b c d
ECADLAB(VHDL) 104
ELCTRONICS AND COMMUNICATION ENGINEERING
INTERNAL DIAGRAM:
ECADLAB(VHDL) 105
ELCTRONICS AND COMMUNICATION ENGINEERING
VHDL CODE:
library IEEE;
use IEEE.std_logic_1164.all;
entity shift is
generic (n:integer:=4);
port (
r: in STD_LOGIC_VECTOR (n-1 down to 0);
e: in STD_LOGIC;
l: in STD_LOGIC;
w: in STD_LOGIC;
clk: in STD_LOGIC;
q: buffer STD_LOGIC_VECTOR (n-1 downto 0));
end shift;
architecture shift of shift is
begin
process
begin
wait until clk’event and clk=’1’;
if e=’1’ then
if l=’1’ then
q<=r;
ECADLAB(VHDL) 106
ELCTRONICS AND COMMUNICATION ENGINEERING
else contd…
gcnbits:for I in 0 to n-2 loop
q(i)<= q(i+1);
end loop;
q(n-1)<=w;
end if;
end if;
end process;
end shift;
INPUTS OUTPUTS
CLEAR MODE CLOCK SERIAL PARALLEL QA QB QC QD
S1 S0 LEFT RIGHT A B C D
0 X X X X X X X X X 0 0 0 0
1 X X 0 X X X X X X QA0 QB0 QC0 QD0
1 1 1 X X a b c d a b c d
clock= 1 ; input e= 1; input l= 1 output q = r ; output q(0) = q(1); q(1) = q(2); and so
on up to q(n-2) = q(n-1). q(n-1) = input w;
ECADLAB(VHDL) 107
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 108
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULTS (HARDWARE):
INPUTS OUTPUTS
CLEAR MODE CLOCK SERIAL PARALLEL QA QB QC QD
S1 S0 LEFT RIGHT A B C D
0 X X X X X X X X X 0 0 0 0
1 X X 0 X X X X X X QA0 QB0 QC0 QD0
1 1 1 X X a b c d a b c d
ECADLAB(VHDL) 109
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULTS (SOFTWARE):
ECADLAB(VHDL) 110
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 111
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULT:
Universal Shift Register internal structure is simulated and verified using Active HDL
Software and in Hardware Lab Respectively.
INFERENCE:
Theoretical and Practical Results are according to the expected results both for Software
and Hardware.
PRECAUTIONS (SOFTWARE):
1) Follow Getting Started Procedure for the Software you are using.
2) Don’t forget to instantiate IEEE Libraries at the starting of the code.
3) Follow Syntax and Semantics of the VHDL code throughout.
PRECAUTIONS (HARDWARE):
1) Apply the voltages to the IC as per the details given in the data Sheets.
2) Apply the inputs to the respective pins.
3) First decide which one is MSB and LSB.
4) Take the outputs at appropriate pins.
ECADLAB(VHDL) 112
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 113
ELCTRONICS AND COMMUNICATION ENGINEERING
PROCEDURE (SOFTWARE):
PROCEDURE (HARDWARE):
ECADLAB(VHDL) 114
ELCTRONICS AND COMMUNICATION ENGINEERING
AIM: To Simulate the internal structure of a 3- to-8 decoder (IC 74138) using VHDL
and verify its operation.
APPARATUS:
THEORY:
ECADLAB(VHDL) 115
ELCTRONICS AND COMMUNICATION ENGINEERING
The “Absolute Maximum Ratings” are those values beyond which the safety of the
device cannot be guaranteed. The device should not be operated at these limits. The
parametric values defined in the Electrical Characteristics tables are not guaranteed at
the absolute maximum ratings. The “Recommended Operating Conditions” table will
define the conditions for actual device operation. An N-bit decoder has 2N outputs, only
one of which may be activated at a given time. If the device is active-HIGH, then only
one output may be HIGH at any time. If the device is active-LOW, then only one output
may be LOW at any time.
DECODER DETAILS:
TRUTH TABLE:
INPUTS OUTPUTS
G1 G2* C B A Y0 Y1 Y2 Y3 Y4 Y5 Y6 Y7
X L X X X H H H H H H H H
H X X X X H H H H H H H H
L H L L L H L L L L L L L
L H L L H L H L L L L L L
L H L H L L L H L L L L L
L H L H H L L L H L L L L
L H H L L L L L L H L L L
L H H L H L L L L L H L L
L H H H L L L L L L L H L
L H H H H L L L L L L L H
ECADLAB(VHDL) 116
ELCTRONICS AND COMMUNICATION ENGINEERING
INTERNAL DIAGRAM:
Y1 = X2 ` X1 `X0 Y5 = X2 X1 `X0
Y2 = X2 ` X1 X0` Y6 = X2 X1X0`
Y3 = X2 ` X1X0 Y7 = X2 X1X0
ECADLAB(VHDL) 117
ELCTRONICS AND COMMUNICATION ENGINEERING
VHDL CODE:
ECADLAB(VHDL) 118
ELCTRONICS AND COMMUNICATION ENGINEERING
INPUTS OUTPUTS
C B A Y0 Y1 Y2 Y3 Y4 Y5 Y6 Y7
0 0 0 5V 0V 0V 0V 0V 0V 0V 0V
0 0 1 0V 5V 0V 0V 0V 0V 0V 0V
0 1 0 0V 0V 5V 0V 0V 0V 0V 0V
0 1 1 0V 0V 0V 5V 0V 0V 0V 0V
1 0 0 0V 0V 0V 0V 5V 0V 0V 0V
1 0 1 0V 0V 0V 0V 0V 5V 0V 0V
1 1 0 0V 0V 0V 0V 0V 0V 5V 0V
1 1 1 0V 0V 0V 0V 0V 0V 0V 5V
ECADLAB(VHDL) 119
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 120
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULTS (HARDWARE):
INPUTS OUTPUTS
G1 G2* C B A Y0 Y1 Y2 Y3 Y4 Y5 Y6 Y7
LED LED LED LED LED LED LED LED
X L X X X ON ON ON ON ON ON ON ON
H X X X X ON ON ON ON ON ON ON ON
L H L L L ON OFF OFF OFF OFF OFF OFF OFF
L H L L H OFF ON OFF OFF OFF OFF OFF OFF
L H L H L OFF OFF ON OFF OFF OFF OFF OFF
L H L H H OFF OFF OFF ON OFF OFF OFF OFF
L H H L L OFF OFF OFF OFF ON OFF OFF OFF
L H H L H OFF OFF OFF OFF OFF ON OFF OFF
L H H H L OFF OFF OFF OFF OFF OFF ON OFF
L H H H H OFF OFF OFF OFF OFF OFF OFF ON
ECADLAB(VHDL) 121
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULTS (SOFTWARE):
ECADLAB(VHDL) 122
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 123
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULT:
INFERENCE:
Theoretical and Practical results are according to the expected results both for Software
and Hardware.
PRECAUTIONS (SOFTWARE):
1) Follow Getting Started Procedure for the Software you are using.
2) Don’t forget to instantiate IEEE Libraries at the starting of
the code.
3) Follow Syntax and Symantics of the VHDL code throughout.
PRECAUTIONS (HARDWARE):
1) Apply the voltages to the IC as per the details given in the data Sheets.
2) Apply the inputs to the respective pins.
3) First decide which one is MSB and LSB.
4) Take the outputs at appropriate pins.
ECADLAB(VHDL) 124
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 125
ELCTRONICS AND COMMUNICATION ENGINEERING
PROCEDURE (SOFTWARE):
1) Follow Getting Started Procedure for the Software you are using.
2) Don’t forget to instantiate IEEE Libraries at the starting of the code.
PROCEDURE (HARDWARE):
ECADLAB(VHDL) 126
ELCTRONICS AND COMMUNICATION ENGINEERING
AIM: To Simulate internal structure of 4 Bit Comparator(IC 7485) using VHDL and
Verify its operation.
APPARATUS:
THEORY:
This four-bit magnitude comparator performs comparison of straight binary or BCD
codes. Three fully-decoded decisions about two, 4-bit words {A, B} are made and are
externally available at three outputs. This device is fully expandable to any number of
bits without external gates. Words of greater length may be compared by connecting
comparators in cascade. The A>B, A<B, and A=B outputs of a stage handling less
significant bits are connected to the corresponding inputs of the next stage handling
more-significant bits. The stage handling the least-significant bits must
have a high level voltage applied to the A=B input.
ECADLAB(VHDL) 127
ELCTRONICS AND COMMUNICATION ENGINEERING
TRUTH TABLE:
A3=B3 A2>B2 X X X X X X X H L L
A3=B3 A2<B2 X X X X X X X L H L
A3=B3 A2=B2 A1>B1 X X X X X H L L
A3=B3 A2=B2 A1<B1 X X X X X L H L
A3=B3 A2=B2 A1=B1 AO>BO X X X H L L
ECADLAB(VHDL) 128
ELCTRONICS AND COMMUNICATION ENGINEERING
INTERNAL DIAGRAM:
ECADLAB(VHDL) 129
ELCTRONICS AND COMMUNICATION ENGINEERING
VHDL CODE:
library IEEE;
use IEEE.std_logic_1164.all;
entity bit4 is
port (
a0: in STD_LOGIC;
a1: in STD_LOGIC;
a2: in STD_LOGIC;
a3: in STD_LOGIC;
cg: in STD_LOGIC; contd…
b0: in STD_LOGIC;
b1: in STD_LOGIC;
ECADLAB(VHDL) 130
ELCTRONICS AND COMMUNICATION ENGINEERING
b2: in STD_LOGIC;
b3: in STD_LOGIC;
ce: in STD_LOGIC;
cl: in STD_LOGIC;
agb: out STD_LOGIC;
aeb: out STD_LOGIC;
alb: out STD_LOGIC);
end bit4;
architecture bit4 of bit4 is
begin
process(a0,a1,a2,a3,b0,b1,b2,b3,cg,ce,cl)
begin if a3>b3 then agb<='1'; alb<='0';aeb<='0';
elsif a3<b3 then agb<='0'; alb<='1';aeb<='0';
else if a2>b2 then agb<='1'; alb<='0';aeb<='0';
elsif a2<b2 then agb<='0'; alb<='1';aeb<='0';
elsif a1>b1 then agb<='1';alb<='0';aeb<='0';
elsif a1<b1 then agb<='0';alb<='1';aeb<='0';
else if a0>b0 then agb<='1';alb<='0';aeb<='0';
elsif a0<b0 then agb<='0';alb<='1';aeb<='0';
else if(cg='1' and ce='0' and cl='0')then agb<='1';alb<='0';aeb<='0';
elsif(cg='0' and ce='1' and cl='0')then agb<='0';alb<='0';aeb<='1';
elsif(cg='0' and ce='0' and cl='1')then agb<='0';alb<='1';aeb<='0';
elsif(ce='1')then agb<='0';alb<='0';aeb<='1';
elsif(cg='1' and ce='0' and cl='1')then agb<='0';alb<='0';aeb<='0';
elsif(cg='0' and ce='0' and cl='0')then agb<='1';alb<='1';aeb<='0';
end if;
end if;
end if;
end if;
end if;
end process;
end bit4;
ECADLAB(VHDL) 131
ELCTRONICS AND COMMUNICATION ENGINEERING
A3=B3 A2>B2 X X X X X X X 5V 0V 0V
A3=B3 A2<B2 X X X X X X X 0V 5V 0V
A3=B3 A2=B2 A1>B1 X X X X X 5V 0V 0V
A3=B3 A2=B2 A1<B1 X X X X X 0V 5V 0V
A3=B3 A2=B2 A1=B1 AO>BO X X X 5V 0V 0V
ECADLAB(VHDL) 132
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 133
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULTS (HARDWARE):
ECADLAB(VHDL) 134
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULTS (SOFTWARE):
ECADLAB(VHDL) 135
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 136
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULT:
Four bit Comparator internal structure is Simulated and verified using Active-HDL
Software and in Hardware Lab Respectively.
INFERENCE:
Theoretical and Practical results are according to the expected results both for Software
and Hardware.
PRECAUTIONS (SOFTWARE):
1) Follow Getting Started Procedure for the Software you are using.
2) Don’t forget to instantiate IEEE Libraries at the starting of
the code.
3) Follow Syntax and Semantics of the VHDL code throughout.
PRECAUTIONS (HARDWARE):
1) Apply the voltages to the IC as per the details given in the data
Sheets.
2) Apply the inputs to the respective pins.
3) First decide which one is MSB and LSB.
4) Take the outputs at appropriate pins.
ECADLAB(VHDL) 137
ELCTRONICS AND COMMUNICATION ENGINEERING
Ans:
PROCEDURE (SOFTWARE):
PROCEDURE (HARDWARE):
1) Connect the circuit as per the pin diagram.
2) Give proper VCC voltage to the IC.
3) Supply the inputs according to truth table and verify outputs.
ECADLAB(VHDL) 138
ELCTRONICS AND COMMUNICATION ENGINEERING
AIM: To Simulate internal structure of 8X1 MULTIPLEXER (IC 74151) using VHDL and
verify its operation.
APPARATUS:
THEORY:
ECADLAB(VHDL) 139
ELCTRONICS AND COMMUNICATION ENGINEERING
DETAILS:
TRUTH TABLE:
INPUT OUTPUT
SELECT STROBE W Y
C B A S
X X X H H L
L L L L DO’ DO
L L H L D1΄ D1
L H L L D2΄ D2
L H H L D3΄ D3
H L L L D4΄ D4
H L H L D5΄ D5
H H L L D6΄ D6
H H H L D7΄ D7
INTERNAL DIAGRAM:
ECADLAB(VHDL) 140
ELCTRONICS AND COMMUNICATION ENGINEERING
OUTPUT EQUATIONS:
D0 = A`B`C` D1 = AB`C` D2 = A`BC` D3 = ABC` D4 = A`B`C
D5 = AB`C D6 = A`BC D7 = ABC
VHDL CODE:
File: mux8by1
library IEEE;
use IEEE.std_logic_1164.all;
entity mux is
port ( a: in STD_LOGIC; b: in STD_LOGIC;
c: in STD_LOGIC;
d: in STD_LOGIC_VECTOR(7 down to 0); en: in STD_LOGIC;
y: out STD_LOGIC );
end mux;
Architecture mux of mux is
begin
process (a, b,c,d)
begin
if(en='0')then
if(a='0' and b='0' and c='0')then y<=d(0);
elsif(a='0' and b='0' and c='0')then y<=d(0);
elsif(a='0' and b='0' and c='1')then y<=d(1);
elsif(a='0' and b='1' and c='0')then y<=d(2);
elsif(a='0' and b='1' and c='1')then y<=d(3);
elsif(a='1' and b='0' and c='0')then y<=d(4);
elsif(a='1' and b='0' and c='1')then y<=d(5);
elsif(a='1' and b='1' and c='0')then y<=d(6);
elsif(a='1' and b='1' and c='1')then y<=d(7);
end if;
else y<='X';
end if;
end process;
end mux;
ECADLAB(VHDL) 141
ELCTRONICS AND COMMUNICATION ENGINEERING
INPUT OUTPUT
SELECT STROBE
C B A S
W Y
X X X 1 1 0
0 0 0 0 A+B+C A`B`C`
0 0 1 0 A`+B+C AB`C`
0 1 0 0 A+B`+C A`BC`
0 1 1 0 A`+B`+C ABC`
1 0 0 0 A+B+C` A`B`C
1 0 1 0 A`+B+C` AB`C
1 1 0 0 A+B`+C` A`BC
1 1 1 0 A`+B`+C` ABC
ECADLAB(VHDL) 142
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 143
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULTS (HARDWARE):
INPUT OUTPUT
SELECT STROBE
C B A S W Y
X X X 1 1 0
0 0 0 0 A+B+C A`B`C`
0 0 1 0 A`+B+C AB`C`
0 1 0 0 A+B`+C A`BC`
0 1 1 0 A`+B`+C ABC`
1 0 0 0 A+B+C` A`B`C
1 0 1 0 A`+B+C` AB`C
1 1 0 0 A+B`+C` A`BC
1 1 1 0 A`+B`+C` ABC
ECADLAB(VHDL) 144
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULTS (SOFTWARE):
ECADLAB(VHDL) 145
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 146
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULT:
INFERENCE:
Theoretical and Practical results are according to the expected results both for Software
and Hardware.
PRECAUTIONS (SOFTWARE):
1)Follow Getting Started Procedure for the Software you are using.
2)Don’t forget to instantiate IEEE Libraries at the starting of
the code.
3)Follow Syntax and Semantics of the VHDL code throughout.
PRECAUTIONS (HARDWARE):
1) Apply the voltages to the IC as per the details given in the data Sheets.
2) Apply the inputs to the respective pins.
3) First decide which one is MSB and LSB.
4) Take the outputs at appropriate pins.
ECADLAB(VHDL) 147
ELCTRONICS AND COMMUNICATION ENGINEERING
1 X 0
0 0 Select input A
0 1 Select input B
Ans: The multiplexer include data selection and routing, operation sequencing, parallel
to serial conversion, wave form generation and logic function generation.
6. Applications of demultiplexers?
Ans: The demultiplexer include serial to parallel conversion, logic function generation,
operation sequencing.
PROCEDURE (SOFTWARE):
1) Follow Getting Started Procedure for the Software you are
using.
2) Don’t forget to instantiate IEEE Libraries at the starting of
the code.
PROCEDURE (HARDWARE):
1) Connect the circuit as per the pin diagram.
2) Give proper VCC voltage to the IC.
3) Supply the inputs according to truth table and verify outputs.
ECADLAB(VHDL) 148
ELCTRONICS AND COMMUNICATION ENGINEERING
AIM: To Simulate internal structure of 2X4 DEMULTIPLEXER (IC 74155) using VHDL
and Verify its operation.
APPARATUS:
THEORY:
The LS155 and LS156 are Dual 1-of-4 Decoder/Demultiplexers with common Address
inputs and separate gated Enable inputs. When enabled, each decoder section accepts
the binary weighted Address inputs (A0, A1) and provides four mutually exclusive active
LOW outputs (O0–O3). If the Enable requirements of each decoder are not met, all
outputs of that decoder are HIGH.
Each decoder section has a 2-input enable gate. The enable gate for Decoder “a”
requires one active HIGH input and one active LOW input (Ea•Ea). In demultiplexing
applications, Decoder “a” can accept either true or complemented data by using the Ea
or Ea inputs respectively. The enable gate for Decoder “b” requires two active LOW
inputs (Eb•Eb). The LS155 or LS156 can be used as a 1-of-8 Decoder/Demultiplexer by
tying Ea to Eb and relabeling the common connection
as (A2). The other Eb and Ea are connected together to form the common enable.The
LS155 and LS156 can be used to generate all four minterms of two variables. These
four minterms are useful in some applications replacing multiple gate functions.
ECADLAB(VHDL) 149
ELCTRONICS AND COMMUNICATION ENGINEERING
INTERNAL DIAGRAM:
OUTPUT EQUATIONS:
ECADLAB(VHDL) 150
ELCTRONICS AND COMMUNICATION ENGINEERING
VHDL CODE:
library ieee;
use ieee.std_logic_1164.all;
entity TryDeMUX is
port( X: in std_logic;
sel: in std_logic_vector (1 downto 0);
A: out std_logic;
B: out std_logic;
C: out std_logic;
D: out std_logic);
end TryDeMUX;
architecture behaviour of TryDeMUX is
begin
process(sel,X)
begin
case sel is
when "00"=>
A <=X; B <= '0'; C <= '0'; D <= '0';
when "01" =>
B <=X; A <='0'; C <='0'; D <='0';
when "10" =>
C <=X; A <='0'; B <='0'; D <='0';
when others =>
D <=X; A <='0'; B <= '0'; C <='0';
end case;
end process;
end behaviour;
ECADLAB(VHDL) 151
ELCTRONICS AND COMMUNICATION ENGINEERING
When SELECT = 00
A =1; B = '0'; C = '0'; D = '0';
When SELECT = 01
B =1; A ='0'; C ='0'; D ='0';
when SELECT =10
C <=1; A = 0; B = 0; D = 0;
When SELECT = 11
D =1; A = 0; B = 0; C = 0;
ECADLAB(VHDL) 152
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 153
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULTS (HARDWARE):
A0 A1 Ea Ea` O0` O1` O2` O3` Eb` Eb` O0` O1` O2` O3`
X X 0 X ON ON ON ON 1 X ON ON ON ON
X X X 1 ON ON ON ON X 1 ON ON ON ON
0 0 1 0 OFF ON ON ON 0 0 OFF ON ON ON
1 0 1 0 ON OFF ON ON 0 0 ON OFF ON ON
0 1 1 0 ON ON OFF ON 0 0 ON ON OFF ON
1 1 1 0 ON ON ON OFF 0 0 ON ON ON OFF
ECADLAB(VHDL) 154
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULTS (SOFTWARE):
ECADLAB(VHDL) 155
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 156
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULT:
INFERENCE:
Theoretical and Practical results are according to the expected results both for Software
and Hardware.
PRECAUTIONS (SOFTWARE):
1) Follow Getting Started Procedure for the Software you are using.
2) Don’t forget to instantiate IEEE Libraries At the starting of
the code.
3) Follow Syntax and Semantics of the VHDL code throughout.
PRECAUTIONS (HARDWARE):
1) Apply the voltages to the IC as per the details given in the data
Sheets.
2) Apply the inputs to the respective pins.
3) First decide which one is MSB and LSB.
4) Take the outputs at appropriate pins.
ECADLAB(VHDL) 157
ELCTRONICS AND COMMUNICATION ENGINEERING
3. Draw the block diagram for full subtractor using 1:8 Demultiplexer
Ans:
PROCEDURE (SOFTWARE):
1. Follow Getting Started Procedure for the Software you are
using.
2) Don’t forget to instantiate IEEE Libraries at the starting of
the code.
PROCEDURE (HARDWARE):
ECADLAB(VHDL) 158
ELCTRONICS AND COMMUNICATION ENGINEERING
AIM: To Simulate Internal structure of 16X1 MULTIPLEXER (IC 74150) using VHDL
and Verify its operation.
APPARATUS:
THEORY:
These data selectors/multiplexers contain full on-chip decoding to select the desired
data source. The 74150 selects one-of-sixteen data sources; the 74151A selects one-of-
eight data sources. The 74150 and 74151A have a strobe input which must be at a low
logic level to enable these devices. A high level at the strobe forces the W output high
and the Y output (as applicable) low. The 74151A features complementary W and Y
outputs, whereas the 74150 has an inverted (W) output only. The 74151A incorporates
address buffers which have symmetrical propagation delay times through the
complementary paths. This reduces the possibility of transients occurring at the output(s)
due to changes made at the select inputs, even when the 74151A outputs are enabled
(i.e., strobe low). 74LS150 selects one-of-sixteen data lines. Performs parallel-to-serial
conversion. Permits multiplexing from N lines to one line. Also for use as Boolean
function generator.
ECADLAB(VHDL) 159
ELCTRONICS AND COMMUNICATION ENGINEERING
DETAILS:
TRUTH TABLE:
INPUTS OUTPUT
SELECT STROBE
D C B A S W
X X X X H H
L L L L L Eo`
L L L H L E1`
L L H L L E2`
L L H H L E3`
L H L L L E4`
L H L H L E5`
L H H L L E6`
L H H H L E7`
H L L L L E8`
H L L H L E9`
H L H L L E10`
H L H H L E11`
H H L L L E12`
H H L H L E13`
H H H L L E14`
H H H H L E15`
H = High Level; L = low Level; X = Don’t Care; E 0’ , E1’ , … E15’ = The Complement of
the level of the respective E input.
ECADLAB(VHDL) 160
ELCTRONICS AND COMMUNICATION ENGINEERING
INTERNAL DIAGRAM:
ECADLAB(VHDL) 161
ELCTRONICS AND COMMUNICATION ENGINEERING
Eo`= ABCD E1`= A`BCD E2`= AB`CD E3`= A`B`CD E4`= ABC`D
E5`= A`BC`D E6`= AB`C`D E7`= A`B`C`D E8`= ABCD` E9`=A`BCD`
E10`= AB`CD` E11`=A`B`CD` E12`= ABC`D` E13`= A`BC`D`E14`= AB`C`D`
E15`= A`B`C`D`
VHDL CODE:
library IEEE;
use IEEE.std_logic_1164.all;
entity mux16 is
port (
l: in STD_LOGIC_VECTOR (0 to 15);
a: in STD_LOGIC;
b: in STD_LOGIC;
d: in STD_LOGIC;
s: in STD_LOGIC;
c: in STD_LOGIC;
wl: out STD_LOGIC);
end mux16;
architecture mux16 of mux16 is
signal p:std_logic_vector(3 downto 0):="0000";
begin
p(0)<=a;
p(1)<=b;
p(2)<=c;
p(3)<=d;
process (p, s)
begin
if s='1' then wl<='1';
else
case p is contd…
ECADLAB(VHDL) 162
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 163
ELCTRONICS AND COMMUNICATION ENGINEERING
INPUTS OUTPUT
SELECT STROBE
D C B A S W
X X X X 5V 5V
0 0 0 0 0V ABCD
0 0 0 1 0V A`BCD
0 0 1 0 0V AB`CD
0 0 1 1 0V A`B`CD
0 1 0 0 0V ABC`D
0 1 0 1 0V A`BC`D
0 1 1 0 0V AB`C`D
0 1 1 1 0V A`B`C`D
1 0 0 0 0V ABCD`
1 0 0 1 0V A`BCD`
1 0 1 0 0V AB`CD`
1 0 1 1 0V A`B`CD`
1 1 0 0 0V ABC`D`
1 1 0 1 0V A`BC`D`
1 1 1 0 0V AB`C`D`
1 1 1 1 0V A`B`C`D`
ECADLAB(VHDL) 164
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 165
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULTS (HARDWARE):
INPUTS OUTPUT
SELECT STROBE
D C B A S W LED
X X X X 1 ON
0 0 0 0 0 ON when ABCD=1
0 0 0 1 0 ON when A`BCD=1
0 0 1 0 0 ON when AB`CD=1
0 0 1 1 0 ON when A`B`CD=1
0 1 0 0 0 ON when ABC`D=1
0 1 0 1 0 ON when A`BC`D=1
0 1 1 0 0 ON when AB`C`D=1
0 1 1 1 0 ONwhen A`B`C`D=1
1 0 0 0 0 ON when ABCD`=1
1 0 0 1 0 ON when A`BCD`=1
1 0 1 0 0 ON when AB`CD`=1
1 0 1 1 0 ONwhen A`B`CD`=1
1 1 0 0 0 ON when ABC`D`=1
1 1 0 1 0 ONwhen A`BC`D`=1
1 1 1 0 0 ONwhen AB`C`D`=1
1 1 1 1 0 ONwhenA`B`C`D`=1
ECADLAB(VHDL) 166
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULTS (SOFTWARE):
ECADLAB(VHDL) 167
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 168
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULT:
INFERENCE:
Theoretical and Practical results are according to the expected results both for Software
and Hardware.
PRECAUTIONS (SOFTWARE):
1) Follow Getting Started Procedure for the Software you are using.
2) Don’t forget to instantiate IEEE Libraries at the starting of
the code.
3) Follow Syntax and Semantics of the VHDL code throughout.
PRECAUTIONS (HARDWARE):
1) Apply the voltages to the IC as per the details given in the data sheets.
2. Apply the inputs to the respective pins.
3) First decide which one is MSB and LSB.
4) Take the outputs at appropriate pins.
ECADLAB(VHDL) 169
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 170
ELCTRONICS AND COMMUNICATION ENGINEERING
PROCEDURE (SOFTWARE):
1) Follow Getting Started Procedure for the Software you are
using.
2) Don’t forget to instantiate IEEE Libraries at the starting of
the code.
PROCEDURE (HARDWARE):
1) Connect the circuit as per the pin diagram.
2) Give proper VCC voltage to the IC.
3) Supply the inputs according to truth table and verify outputs.
ECADLAB(VHDL) 171
ELCTRONICS AND COMMUNICATION ENGINEERING
AIM: To Simulate Internal structure of 4X16 DEMULTIPLEXER (IC 74154) using VHDL
and Verify its operation.
APPARATUS:
S.NO COMPONENT QUANTITY
1. IC 74154 1
2. Digital Trainer Board 1
THEORY:
The 74154 is a TTL monolithic, 4- line-to-16-line decoder which allows decoding of a 4
bit binary coded input into one of 16 mutually exclusive outputs. The devices provided
with two strobe lines, both of which have to be in the low state in order to perform the
decoding function ;if either of the strobes is high ,all 16 outputs will remain high. The
device can be used as a demultiplexer by passing information from one of the strobes
(the other being low ) to an output selected by the 4 line input address. These
demultiplexers are ideally suited for implementing high performance memory decoders.
ECADLAB(VHDL) 172
ELCTRONICS AND COMMUNICATION ENGINEERING
TRUTH TABLE:
INPUTS OUTPUTS
G1 G2 D C B A 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
L L L L L L H L L L L L L L L L L L L L L L
L L L L L H L H L L L L L L L L L L L L L L
L L L L H L L L H L L L L L L L L L L L L L
L L L L H H L L L H L L L L L L L L L L L L
L L L H L L L L L L H L L L L L L L L L L L
L L L H L H L L L L L H L L L L L L L L L L
L L L H H L L L L L L L H L L L L L L L L L
L L L H H H L L L L L L L H L L L L L L L L
L L H L L L L L L L L L L L H L L L L L L L
L L H L L H L L L L L L L L L H L L L L L L
L L H L H L L L L L L L L L L L H L L L L L
L L H L H H L L L L L L L L L L L H L L L L
L L H H L L L L L L L L L L L L L L H L L L
L L H H L H L L L L L L L L L L L L L H L L
L L H H H L L L L L L L L L L L L L L L H L
L L H H H H L L L L L L L L L L L L L L L H
L H X X X X L L L L L L L L L L L L L L L L
H L X X X X L L L L L L L L L L L L L L L L
H H X X X X L L L L L L L L L L L L L L L L
ECADLAB(VHDL) 173
ELCTRONICS AND COMMUNICATION ENGINEERING
INTERNAL DIAGRAM:
ECADLAB(VHDL) 174
ELCTRONICS AND COMMUNICATION ENGINEERING
VHDL CODE:
library ieee;
use ieee.std_logic_1164.all;
entity TryDeMUX is
port( X: in std_logic;
sel: in std_logic_vector (3 downto 0);
A: out std_logic; B: out std_logic; C: out std_logic; D: out std_logic;
E: out std_logic; F: out std_logic; G: out std_logic; H: out std_logic;
I: out std_logic; J: out std_logic; K: out std_logic; L: out std_logic;
M: out std_logic; N: out std_logic; O: out std_logic; P: out std_logic);
end TryDeMUX;
architecture behaviour of TryDeMUX is
begin
process(sel,X)
begin
case sel is
when "0000"=>
A <=X; B <='0'; C <= '0'; D <= '0'; E <= '0'; F <= '0'; G <= '0';H <= '0'; I <= '0'; J <= '0'; K
<= '0';L <= '0'; M <= '0'; N <= '0';O <= '0';P <= '0';
when "0001"=>
A <='0'; B <=X;C <= '0'; D <= '0'; E <= '0'; F <= '0'; G <= '0';H <= '0'; I <= '0'; J <= '0';K <=
'0'; L <= '0'; M <= '0';N <= '0'; O <= '0'; P <= '0';
when "0010"=>
A <='0'; B <='0'; C <= X; D <= '0'; E <= '0'; F <= '0'; G <= '0';H <= '0'; I <= '0'; J <= '0'; K
<= '0'; L <= '0'; M <= '0';N <= '0'; O <= '0'; P <= '0';
when "0011" =>
A <='0'; B <='0'; C <= '0'; D <= X; E <= '0'; F <= '0'; G <= '0';H <= '0'; I <= '0'; J <= '0'; K
<= '0'; L <= '0'; M <= '0';N <= '0'; O <= '0'; P <= '0';
when "0100" =>
A <='0'; B <='0'; C <= '0'; D <= '0'; E <= X; F <= '0'; G <= '0';H <= '0'; I <= '0'; J <= '0'; K
<= '0'; L <= '0'; M <= '0';N <= '0'; O <= '0'; P <= '0';
when "0101" =>
A <='0'; B <='0'; C <= '0'; D <= '0'; E <= '0'; F <= X; G <= '0';H <= '0'; I <= '0'; J <= '0'; K
<= '0'; L <= '0'; M <= '0';N <= '0'; O <= '0'; P <= '0'; contd…
ECADLAB(VHDL) 175
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 176
ELCTRONICS AND COMMUNICATION ENGINEERING
EXPECTED RESULTS(HARDWARE):
INPUTS OUTPUTS
G1 G2 D C B A 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
0 0 0 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
0 0 0 1 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
0 0 0 1 1 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0
0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0
0 0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0
0 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
0 1 X X X X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 X X X X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 X X X X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
when sel = “1111” then all outputs will be low otherwise respective outputs will be high
depending on the address given on input lines.
ECADLAB(VHDL) 177
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 178
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULTS (HARDWARE):
INPUTS OUTPUTS
G1 G2 D C B A 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
0 0 0 1 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
0 0 0 1 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
0 0 0 1 1 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0
0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0
0 0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0
0 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
0 1 X X X X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 X X X X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 X X X X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ECADLAB(VHDL) 179
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULTS (SOFTWARE):
ECADLAB(VHDL) 180
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 181
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULT:
4X16 DEMULTIPLEXER internal structure is simulated and verified using Active
HDL Software and in Hardware Lab Respectively.
INFERENCE:
Theoretical and Practical results are according to the expected results both for Software
and Hardware.
PRECAUTIONS (SOFTWARE):
1) Follow Getting Started Procedure for the Software you are using.
2) Don’t forget to instantiate IEEE Libraries at the starting of the code.
3) Follow Syntax and Semantics of the VHDL code throughout.
PRECAUTIONS (HARDWARE):
1) Apply the voltages to the IC as per the details given in the data Sheets.
2) Apply the inputs to the respective pins.
3) First decide which one is MSB and LSB.
4) Take the outputs at appropriate pins.
ECADLAB(VHDL) 182
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 183
ELCTRONICS AND COMMUNICATION ENGINEERING
PROCEDURE (SOFTWARE):
1) Follow Getting Started Procedure for the Software you are using.
2) Don’t forget to instantiate IEEE Libraries at the starting of sthe code.
PROCEDURE (HARDWARE):
1) Connect the circuit as per the pin diagram.
2) Give proper VCC voltage to the IC.
3) Supply the inputs according to truth table and verify outputs.
ECADLAB(VHDL) 184
ELCTRONICS AND COMMUNICATION ENGINEERING
AIM: To Simulate Internal structure of 16X4 RAM(IC 74189) using VHDL and
Verify its operation.
APPARATUS:
THEORY:
The CY7C189 and CY7C190 are extremely high performance 64-bit static RAM’s
organized as 16 words by 4 bits. Easy memory expansion n is provided by an active low
chip select (CS) input and three- state outputs. The devices are provided with inverting
(CY7C189) and non inverting (CY7C190) outputs. Writing to the device is accomplished
when the chip select (CS) and write enable (WE) inputs are both low. Data on the four
data inputs (D0 through D3) is written into the memory location specified on the address
pins(A0 through A3). The outputs are preconditioned such that the correct data is present
at the data outputs (O0 through O3) when the write cycle is complete. This precondition
operation insures minimum write recovery times by eliminating the “write recovery
glitch.” Reading the device is accomplished by taking chip select (CS) LOW, while write
enable(WE) remains HIGH. Under these conditions, the contents of the memory location
specified on the address pins will appear on the four output pins (O0 through O3) in
inverted (CY7C189) or non-inverted (CY7C190) format. The four output pins remain in
high-impedance state when chip select (CS) is HIGH or write enable (WE) is LOW.
ECADLAB(VHDL) 185
ELCTRONICS AND COMMUNICATION ENGINEERING
CS΄ WE΄
L L WRITE HIGH
IMPEDENCE
L H READ COMPLEMENT
OF STORED
DATA
H X INHIBIT HIGH
IMPENDENCE
ECADLAB(VHDL) 186
ELCTRONICS AND COMMUNICATION ENGINEERING
INTERNAL DIAGRAM:
Write = CS`WE`
READ = CS`WE
INHIBIT = CS WE
ECADLAB(VHDL) 187
ELCTRONICS AND COMMUNICATION ENGINEERING
VHDL CODE:
library IEEE;
use IEEE.std_logic_1164.all;
entity ram is
port (
cs: in STD_LOGIC;
we: in STD_LOGIC;
re: in STD_LOGIC;
mr: out STD_LOGIC;
mw: out STD_LOGIC
);
end ram;
architecture ram of ram is
begin
process (cs,we,re)
begin
if (cs='0'and we='1'and re='0')then
mr<='0';
mw<='1';
elsif (cs='0'and we='0'and re='1')then
mr<='1';
mw<='0';
end if;
end process;
end ram;
ECADLAB(VHDL) 188
ELCTRONICS AND COMMUNICATION ENGINEERING
CS΄ WE΄
Data is written Tristate
0v 0v Into specified
location
0v +5v Data is read COMPLEMENT OF
from specified STORED DATA
location
+5v X No write or read Tristate
X = don’t care
ECADLAB(VHDL) 189
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 190
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULTS (HARDWARE):
CS΄ WE΄
0v 0v Data is available Tristate
In specified
location
0v +5v Data is retrieved Complement Of
from specified stored data is
location available
+5v X INHIBIT Tristate
X = don’t care
ECADLAB(VHDL) 191
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULTS (SOFTWARE):
ECADLAB(VHDL) 192
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 193
ELCTRONICS AND COMMUNICATION ENGINEERING
RESULT:
16X4 RAM internal structure is simulated and verified using Active-HDL Software
and in Hardware Lab Respectively.
INFERENCE:
Theoretical and Practical results are according to the expected results both for Software
and Hardware.
PRECAUTIONS (SOFTWARE):
1) Follow Getting Started Procedure for the Software you are using.
2) Don’t forget to instantiate IEEE Libraries at the starting of the code.
3) Follow Syntax and Semantics of the VHDL code throughout.
PRECAUTIONS (HARDWARE):
1)Apply the voltages to the IC as per the details given in the data sheets.
2)Apply the inputs to the respective pins.
3)First decide which one is MSB and LSB.
4)Take the outputs at appropriate pins.
ECADLAB(VHDL) 194
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 195
ELCTRONICS AND COMMUNICATION ENGINEERING
Ans:
ECADLAB(VHDL) 196
ELCTRONICS AND COMMUNICATION ENGINEERING
PROCEDURE (SOFTWARE):
1) Follow Getting Started Procedure for the Software you are using.
2) Don’t forget to instantiate IEEE Libraries at the starting of the code.
PROCEDURE (HARDWARE):
ECADLAB(VHDL) 197
ELCTRONICS AND COMMUNICATION ENGINEERING
APPENDIX-A
ECADLAB(VHDL) 198
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 199
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 200
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 201
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 202
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 203
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 204
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 205
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 206
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 207
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 208
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 209
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 210
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 211
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 212
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 213
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 214
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 215
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 216
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 217
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 218
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 219
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 220
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 221
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 222
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 223
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 224
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 225
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 226
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 227
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 228
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 229
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 230
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 231
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 232
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 233
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 234
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 235
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 236
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 237
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 238
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 239
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 240
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 241
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 242
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 243
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 244
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 245
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 246
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 247
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 248
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 249
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 250
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 251
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 252
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 253
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 254
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 255
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 256
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 257
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 258
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 259
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 260
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 261
ELCTRONICS AND COMMUNICATION ENGINEERING
APPENDIX-B
VHDL PROGRAMMING CONCEPTS
Tools
VHDL descriptions of hardware design and test benches are portable between design
tools, and portable between design centres and project partners. You can safely invest
in VHDL modelling effort and training, knowing that you will not be tied in to a single tool
vendor, but will be free to preserve your investment across tools and platforms. Also, the
design automation tool vendors are themselves making a large investment in VHDL,
ensuring a continuing supply of state-of-the-art VHDL tools.
Technology
VHDL permits technology independent design through support for top down design and
logic synthesis. To move a design to a new technology you need not start from scratch
or reverse-engineer a specification - instead you go back up the design tree to a
behavioural VHDL description, then implement that in the new technology knowing that
the correct functionality will be preserved.
Benefits
Executable specification
Validate spec in system context (Subcontract)
Functionality separated from implementation
Simulate early and fast (Manage complexity)
Explore design alternatives
Get feedback (Produce better designs)
Automatic synthesis and test generation (ATPG for ASICs)
Increase productivity (Shorten time-to-market)
Technology and tool independence (though FPGA features may be unexploited)
Portable design data (Protect investment)
A design is described in VHDL using the concept of a design entity. A design entity is
split into two parts, each of which is called a design unit in VHDL jargon. The entity
declaration represents the external interface to the design entity. The architecture body
represents the internal description of the design entity - its behaviour, its structure, or a
mixture of both. Let's imagine we want to describe an and-or-invert (AOI) gate in VHDL.
If we consider the AOI gate as a single chip package, it will have four input pins and one
output pin; we need not concern ourselves with power and ground pins in modelling our
AOI design.
ECADLAB(VHDL) 262
ELCTRONICS AND COMMUNICATION ENGINEERING
Similar to many programming languages, VHDL supports comments. Comments are not
part of the VHDL design, but allow the user to make notes referring to the VHDL code,
usually as an aid to understanding it. Here the comment is a “header” that tells us that
the VHDL describes an AOI gate. It is no more than an aide de memoire in this case. A
VHDL compiler will ignore this line of VHDL. Two hyphens mark the start of a comment,
which is ignored by the VHDL compiler. A comment can be on a separate line or at the
end of a line of VHDL code, but in any case stops at the end of the line.
library IEEE;
use IEEE.STD_LOGIC_1164.all;
Above the entity declaration is a library clause (library IEEE;) and a use clause (use
IEEE.STD_LOGIC_1164.all;). This gives the entity AOI access to all the names declared
within package STD_LOGIC_1164 in the library IEEE, and to data type STD_LOGIC in
particular. More on data types, later.
ECADLAB(VHDL) 263
ELCTRONICS AND COMMUNICATION ENGINEERING
Entity AOI is
The name of the design entity is just an arbitrary label invented by the user. It does not
correspond to a name pre-defined in a VHDL component library. entity and is are VHDL
keywords. This line defines the start of a new VHDL design unit definition. The library
and use clauses, although written before the entity declaration do not define the start the
VHDL description of a design unit, they are context clauses. We can think of an entity
declaration as corresponding to a chip package.
port (
A, B, C, D: in STD_LOGIC;
F : out STD_LOGIC );
The entity declaration includes the name of the entity (AOI in this example), and a set of
port declarations. A port may correspond to a pin on an IC, an edge connector on a
board, or any logical channel of communication with a block of hardware. Each port
declaration includes the name of one or more ports ( e.g., A, B), the direction that
information is allowed to flow through the ports (in, out or inout), and the data type of the
ports (i.e., STD_LOGIC). In our example the port declarations correspond to the pins of
our AOI chip.
The data type of a port defines the set of values that may flow through the port. The
ports are of type STD_LOGIC, which is found in package STD_LOGIC_1164 in library
IEEE. A package is a VHDL language construct where new data types may be defined,
and the particular package STD_LOGIC_1164 is an IEEE standard for representing
digital signals in VHDL. The concept of data type is borrowed by VHDL from the world of
software. It allows the VHDL compiler to ensure that the design is at least reasonably
robust before beginning simulation.
end AOI;
The entity declaration is terminated by the VHDL keyword end. Here we indulge in a little
programming robustness by adding the name of the design entity after the end keyword.
Including the name of the design entity is particularly relevant in large descriptions where
the port list may extend over many screens (or pages); it is good to be reminded of the
name of the design entity whose end we are looking at, lest we forget.
architecture V1 of AOI is
The name of the architecture body (V1) is just an arbitrary label invented by the user. It
is possible to define several alternative architecture bodies for a single design entity, and
the only purpose of the architecture name is to distinguish between these alternatives.
architecture, of and portis are VHDL keywords. Note that when we define an
architecture, we have to tell the VHDL analyzer that the architecture V1 corresponds to
the AOI design entity. You might think that it would be enough to specify the name of the
architecture and that the architecture automatically corresponded to the previously
ECADLAB(VHDL) 264
ELCTRONICS AND COMMUNICATION ENGINEERING
declared entity, but I'm afraid VHDL doesn't work this way! In essence, we can think of
the architecture as the die inside the chip package.
begin
The VHDL keyword begin denotes the end of the architecture declarative region and the
start of the architecture statement part. In this architecture, there is but one statement,
and all the names referenced in this statement are in fact the ports of the design.
Because all of the names used in the architecture statement part are declared in the
entity declaration, the architecture declarative part is empty.
The architecture contains a concurrent signal assignment, which describes the function
of the design entity. The concurrent assignment executes whenever one of the four ports
A, B, C or port D change value. That's it! That's all there is to describing the functionality
of an AOI gate in VHDL. Some might regard the rest of the VHDL code as superfluous
and level a charge of verbosity against VHDL. Of course, the remainder of the VHDL
code is setting the context in which this functionality is defined.
end V1;
The architecture is terminated by the VHDL keyword end. Once again, we reference the
architecture name at the end of the architecture body for the same reason as we did with
the entity. Usually, architecture bodies require sigificantly more code than entity
declarations, hence repeating the name of the architecture is even more relevant.
Another VHDL comment, and that's the end of a VHDL description of an AOI gate.
Internal signals
Shown below is a second architecture V2 of AOI (remember that the architecture name
V2 is completely arbitrary - this architecture is called V2 to distinguish it from the earlier
architecture V1). Architecture V2 describes the AOI function by breaking it down into the
constituent boolean operations. Each operation is described within a separate
concurrent signal assignment. In hardware terms we can think of each assignment as a
die in a hybrid package or a multi-chip module. The signals are the bonding wires or
substrate traces between each die.
Signals
The architecture contains three signals AB, CD and O, used internally within the
architecture. A signal is declared before the begin, of an architecture, and has its own
data type (eg. STD_LOGIC). Technically, ports are signals, so signals and ports are
read and assigned in the same way.
ECADLAB(VHDL) 265
ELCTRONICS AND COMMUNICATION ENGINEERING
Assignments
The assignments within the architecture are concurrent signal assignments. Such
assignments execute whenever a signal on the right hand side of the assignment
changes value. Because of this, the order in which concurrent assignments are written
has no effect on their execution. The assignments are concurrent because potentially
two assignments could execute at the same time (if two inputs changed simultaneously).
The style of description that uses only concurrent assignments is sometimes termed
dataflow.
Delays
Each of the concurrent signal assignments has a delay. The expression on the right
hand side is evaluated whenever a signal on the right hand side changes value, and the
signal on the left hand side of the assignment is updated with the new value after the
given delay. In this case, a change on the port A would propagate through the AOI entity
to the port F, with a total delay of 5 ns.
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity AOI is
F : out STD_LOGIC);
end AOI;
architecture V2 of AOI is
begin
ECADLAB(VHDL) 266
ELCTRONICS AND COMMUNICATION ENGINEERING
end V2;
The example above shows the previously defined design entity AOI being used as a
component within another, higher level design entity MUX2, to create a design hierarchy
with two levels. The design entity MUX2 also contains a second component, named INV.
In order to write the VHDL for this circuit, we need to cover two new concepts:
component instantiation (placing the INV and AOI inside another higher-level design,
MUX2) and port mapping (connecting up the two components to each other and to the
primary ports of MUX2). In VHDL, this is how we can model PCBs assembled from
individual chips, for example.
Components
The two component declarations (for INV and AOI) must match the corresponding entity
declarations exactly with respect to the names, order and types of the ports. We've
already seen enough of the AOI gate, let's see how closely the component and entity
declarations match for the INV design entity.
ECADLAB(VHDL) 267
ELCTRONICS AND COMMUNICATION ENGINEERING
Entity Component
entity INV is component INV
port (A: in STD_LOGIC; port (A: in STD_LOGIC;
F: out STD_LOGIC); F: out STD_LOGIC);
end INV; end component;
The two component declarations (for INV and AOI) appear in the architecture declarative part (that's a VHDL technical
term that means that the component declarations are coded before the begin).
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity MUX2 is
F : out STD_LOGIC);
end;
component INV
F: out STD_LOGIC);
end component;
component AOI
F : out STD_LOGIC);
end component;
begin
end;
ECADLAB(VHDL) 268
ELCTRONICS AND COMMUNICATION ENGINEERING
Instantiation
The architecture STRUCTURE of MUX2 makes instances of INV and AOI through the
component instantiations at the bottom of the architecture (labelled G1 and G2). The
component names (INV and AOI) are references to design entities defined elsewhere.
The instance labels (G1 and G2) identify two specific instances of the components, and
are mandatory.
Port Maps
The ports in a component declaration must usually match the ports in the entity
declaration one-for-one. The component declaration defines the names, order, mode
and types of the ports to be used when the component is instanced in the architecture
body. Instancing a component implies making a local copy of the corresponding design
entity - a component is declared once within any architecture, but may be instanced any
number of times. In this example, there is just one instance of the components AOI and
INV.
Association
Signals in an architecture are associated with ports on a component using a port map. In
effect, a port map makes an electrical connection between “pieces of wire” in an
architecture (signals) and pins on a component (ports). The same signal may be
associated with several ports - this is the way to define interconnections between
components. In our MUX2 example, the signal SELB is associated with the F port of the
INV instance and the C port of the AOI instance.
On the page “Components and Port Maps”, we looked at the VHDL used to describe the
instantiation of components in an architecture. Instantiating components in VHDL
ECADLAB(VHDL) 269
ELCTRONICS AND COMMUNICATION ENGINEERING
enables us to create a design hierarchy, it's just like plugging chips into a PCB. In our
case, the MUX2 is the PCB, the AOI gate andthe inverter (INV) are two chips. But what
about the sockets? Let's look into instantiating components in a little more detail.
Component Declarations
Remember that the two component declarations (for INV and AOI) must match the
corresponding entity declarations exactly with respect to the names, order and types of
the ports. This is important because, as a hardware analogy, the component declaration
is essentially a chip socket for the chip represented by the design entity - the entity
declaration defines the pins of the chip.
Component Instantiation
So, instantiation is essentially a VHDL term for soldering a chip socket into a PCB.
Instantiation also assumes that the socket contains the chip referenced by the same
name as it is plugged into the PCB. However, for our purposes, we can think of
component instantiation as plugging a chip into a PCB, ignoring whether it's socketed or
not.
Port Mapping
The concept of port mapping is little more than soldering the chip socket pins into the
holes of the PCB. Thus in the case of our inverter, the F output pin of the INV chip is
plugged into the F pin of the INV socket. The F pin of the INV socket is soldered to a
PCB trace called SELB.
Similarly, instantiation of the AOI gate can be thought of as soldering the AOI socket into
the MUX2 PCB. In this case, as an example, the SELB trace is soldered to the C pin of
the AOI socket. By default, the AOI socket is assumed to be carrying an AOI chip.
ECADLAB(VHDL) 270
ELCTRONICS AND COMMUNICATION ENGINEERING
component AOI
F : out STD_LOGIC);
end component;
begin
G2: AOI port map (SEL, A, SELB, B, F); -- 3rd item in list is SELB
end;
Default binding
Our current view of component instantiation assumes default binding. In default binding,
the chip socket (component declaration) carries a chip (design entity) of the same name
(say, AOI) as we've already seen. Now in the hardware world, there's no such limitation,
sockets aren't chip specific. VHDL allows the designer the same freedom. The chip
socket and the chip do not have to have the same name, but to implement this facility
requires a configuration to bind the appropriate design entity to the component
instantiation.
Configurations: Part 1
On the page “Plugging Chips into Sockets” it was suggested (in the default binding
section) that an instantiation of a design entity need not have a component declaration of
the same name to be legal VHDL, providing we use a configuration to change the default
binding. In the case of Plugging Chips into Sockets, the emphasis was on establishing
the relationships between component declaration, design entity (particularly its entity
declaration) and component instantiation.
Remember that the design entity (chip package) consists of both an entity declaration
(chip pins) and architecture body (chip die). In Part 1 of Configurations, we will look at
ECADLAB(VHDL) 271
ELCTRONICS AND COMMUNICATION ENGINEERING
selecting one architecture from many architectures of one design entity for instantiation
(essentially specifying which die goes in the package of the chip that will be plugged into
the PCB to maintain our analogy) and in Part 2, we will look at choosing from amongst
different design entities for instantiation (essentially specifying which chip to plug into the
socket).
Configuration
A VHDL description may consist of many design entites, each with several architectures,
and organized into a design hierarchy. The configuration does the job of specifying the
exact set of entities and architectures used in a particular simulation or synthesis run.
A configuration does two things. Firstly, a configuration specifies the design entity used
in place of each component instance (i.e., it plugs the chip into the chip socket and then
the socket-chip assembly into the PCB). Secondly, a configuration specifies the
architecture to be used for each design entity (i.e., which die).
Default configuration5
Shown below is a minimal configuration for the top level entity MUX2. This configuration
selects the architecture to be used (there is only one, STRUCTURE). By default, all
components inside the architecture will be configured to use a design entity of the same
name as the component (i.e., AOI), and the most recently analyzed architecture of each
design entity. We'll tackle the concept of the most recently analyzed architecture in the
next but one article in this series. Suffice to say that in this example we will take v2 to be
the most recently analyzed, by virtue of the fact that we compiled the v1 version of AOI
first and then compiled the v2 version of our AOI design entity a few minutes later (let's
say).
Configuration declaration
The configuration declaration is yet another one of those VHDL design units. Remember
the entity declaration is a design unit as is the architecture body. In the configuration
declaration, for the architecture that we want to configure, we can specify exactly which
components make up the final design entity. In the example below, for the G2 instance
inside our STRUCTURE architecture, we use the V1 architecture of the AOI gate. There
will be absolutely no doubt as to which architecture has been chosen for simulation
because we have specified v1 in the configuration. In the MUX2_default_CFG
configuration, we could change the AOI architecture for simulation by simply re-
compiling v1 after v2 - hardly a robust mechanism for design description! Note, that you
only need to be concerned with configurations of multiple architectures when you have
more than one architecture per design entity in the first place.
ECADLAB(VHDL) 272
ELCTRONICS AND COMMUNICATION ENGINEERING
for STRUCTURE
end for;
end MUX2_default_CFG;
for STRUCTURE
for G2 : AOI
end for;
end for;
end MUX2_specified_CFG;
Once again, let's break the VHDL code down fragment by fragment, using the specified
configuration. Leaving aside the use clause for now, the first line specifies what we are
configuring, configuration is a VHDL keyword and is followed by the name we wish to
give the configuration. After the of keyword we specify the design entity we are
configuring; is is also a keyword. Bracketed with this first line is the last end
configuration_name line. Hence, Configurations usually consist of nested configuration
items, bracketed with end for; statements. The first item is the architecture specification,
the second is the instance specification, and finally the binding indication,
-- block configuration
ECADLAB(VHDL) 273
ELCTRONICS AND COMMUNICATION ENGINEERING
end MUX2_specified_CFG;
for architecture_name
Now, what about that use clause? Let's say the AOI design entity is compiled into the
working library WORK by default. Thus in order for the component_name to be visible
we need a use clause, hence is required.
Configurations: Part 2
Let's review default binding before we go any further. In default binding, the chip socket
(component declaration) carries a chip (design entity) of the same name (say, AOI) as
we've already seen. The chip is inserted into the socket courtesy of a component
instantiation and a configuration declaration. If we omit the configuration or if we use a
default configuration, the socket and chip must have the same name. If we want to
choose a particular die (architecture) for our chip, we must specify the architecture in the
configuration. Now. Suppose we want to create a general-purpose socket and at some
later time, we want to specify which chip will be plugged into the socket. To do this
requires a late-binding configuration declaration.
Order of Analysis
This is one of those topics that doesn't really relate to hardware design. However, you
can't ignore this topic as it is so fundamental to simulating (and to a lesser extent,
synthesizing) your VHDL designs. Anyhow, let's see how hardware-y we can make it!
Remember design units? So far we have used three of the five VHDL design units. An
entity declaration is a primary design unit, as is a configuration declaration. An
architecture body is a secondary design unit. An architecture is a secondary design unit
of the corresponding entity declaration primary design unit. Hence, To simulate a piece
of VHDL code, you need a design environment consisting of an entity declaration and an
architecture body and you also need a testbench. The testbench contains an instance of
the design plus some VHDL code to apply stimuli to the design that is being simulated.
In VHDL terms, the testbench is just another design entity.
ECADLAB(VHDL) 274
ELCTRONICS AND COMMUNICATION ENGINEERING
In the real world, you can goof up and put an empty chip package in to stores. You can
do the same in VHDL, too. Analyzing an entity declaration into a library is OK.
Conversely, a VHDL architecture body must not exist alone (the VHDL storeman will
lose that tiny die!); an architecture won't be put into a library unless there's already an
entity declaration in the library.
To summarise, VHDL design units are analyzed into VHDL libraries. One default library
is provided for you, it is called WORK. Once you have have analyzed all of the design
units you need for a simulation run into a VHDL library, you can run the simulation...
ECADLAB(VHDL) 275
ELCTRONICS AND COMMUNICATION ENGINEERING
Ports can represent busses or vectors as well as single bits. In the example above, the
port SEL is a 2-bit bus, with msb numbered 1 and lsb numbered 0. The type of the port
is STD_LOGIC_VECTOR, which is also defined in package STD_LOGIC_1164 on
library IEEE. Objects of type STD_LOGIC_VECTOR are simply an array of STD_LOGIC
objects.
use IEEE.STD_LOGIC_1164.all;
entity MUX4 is
A, B, C, D: in STD_LOGIC;
In the previous example, an array type was used to allow the description in VHDL of a
vectored port. Array types can be used for internal signals as well as ports. This can be
seen in the MUX4 testbench code below:
entity TEST_MUX4 is
begin
ECADLAB(VHDL) 276
ELCTRONICS AND COMMUNICATION ENGINEERING
end BENCH;
The stimulus for the SEL signal is shown as a waveform, made up of individual
waveform elements. A waveform element consists of an expression followed by a time
specification for when the signal is driven by the value of the expression. In this
particular case, the expression is a STD_LOGIC_VECTOR literal.
STD_LOGIC_VECTOR values can be written as bit string literals. For example both bits
are set to '0 at time 0, while at time 30 ns, SEL(1) is set to '0' and SEL(0) is set to '1'.
Test Benches
So we have a design. But it's unproven. In this tutorial we look at designing a simple test
bench in VHDL.
With VHDL, it is possible to model not only the hardware or system design, but also a
test bench to apply stimulus to the design and to analyze the results, or compare the
ECADLAB(VHDL) 277
ELCTRONICS AND COMMUNICATION ENGINEERING
results of two simulations. In effect, VHDL can be used as a stimulus definition language
as well as a hardware description language. One consequence of using VHDL to model
a test bench is that the test bench is portable between VHDL tools from different
vendors.
Components
A component declaration is needed (component MUX4 ... end component;) in order to
pull the MUX4 entity into the test bench. Think of a component declaration as a chip
socket. It allows a VHDL structural description to be written in a top-down manner,
because the VHDL compiler can check the consistency of the design unit that uses the
component before the corresponding design entity has been written. In order that the
VHDL simulator can bind (more VHDL jargon) the design entity MUX4 to the component
MUX4, the names and types of the ports must match between the entity and the
component.
end;
library IEEE;
use IEEE.STD_LOGIC_1164.all;
component MUX4
end component;
-- signals
begin
end BENCH;
ECADLAB(VHDL) 278
ELCTRONICS AND COMMUNICATION ENGINEERING
Concurrent Assignment
The 5 concurrent signal assignment statements within the test bench define the input
test vectors (eg. A <= 'X', '0' after 10 NS, '1' after 20 NS;). The delays in these
assignments are relative to the time when the assignments execute (ie. time 0), not to
each other (eg. Signal A will change to '1' at 20 NS, not at 30 NS).
end;
library IEEE;
use IEEE.STD_LOGIC_1164.all;
component MUX4
A, B, C, D:in STD_LOGIC;
F :out STD_LOGIC);
end component;
signal A, B, C, D, F: STD_LOGIC;
begin
D <= 'X', '0' after 100 NS, '1' after 110 NS;
ECADLAB(VHDL) 279
ELCTRONICS AND COMMUNICATION ENGINEERING
end BENCH;
The waveforms generated for the SEL, A, B and C signals are shown below.
Bottom-up design
Joining components together is one method of design using VHDL. It's the bottom-up
approach. There's nothing wrong with joining components together to create a design
hierarchy, but using it as your design approach exclusively can restrict your productivity
even though it is possible to create any design you could wish for using VHDL in this
manner. Let's step back a moment and consider how the design of something as simple
as a MUX_2 is being implemented; not at a hardware level but at a conceptual level.
We'll change the MUX_2 so that it has an inverting data path:
begin
ECADLAB(VHDL) 280
ELCTRONICS AND COMMUNICATION ENGINEERING
Coding behavior
At a conceptual level we can specify what we want the design to do using a behavioral
coding style. Using the structural approach, we have to describe explicitly how the
design is to be implemented. Thus a structural approach implies an extra step in the
design process. So, how do we implement (smile) a behavioral coding style? Well, this
can be achieved by writing VHDL code as though we were writing software rather than
describing hardware. We can take our VHDL coding capabilities closer to VHDL
programming, closer to writing software rather than describing hardware. By writing
software rather than describing hardware, we can concentrate on what a design does
rather than how it does it. We can concern ourselves with functionality rather than
implementation. In the same way that mathematicians look to abstract a concept to
make a problem easier to solve and provide more flexible solutions, we can abstract our
designs from VHDL hardware descriptions to VHDL software functions. However, a
software function will still at some point become a hardware description. We can bridge
the gap from software function to hardware description using synthesis.
With the behavioural approach to design, we still have to decide what we want to do, but
that's it. We can use synthesis tools to decide how to implement the functionality we
have (behaviourally) specified. There are still two steps in creating a netlist that meets
our design goals, it's just that with a behavioural approach we use design automation to
complete the second (implementation) step. Hopefully, this can save us time because
we as engineers only have to do one job instead of two. Using a software-oriented
design approach we can reduce the number of design steps.
ECADLAB(VHDL) 281
ELCTRONICS AND COMMUNICATION ENGINEERING
Begin
In VHDL, we usually speak of elements executing rather than operating (or cooperating),
so in VHDL elements can execute concurrently, in parallel or in sequence. We can see
that the AOI and INV components execute concurrently - they communicate via the
internal signals. You might think that they execute in sequence. (Almost!) If SEL
changes and A, B have the same value then the G1 instance of INV executes in parallel
with AOI. As FB does not change value the G3 instance of INV does not execute. This
simple scenario shows the absence of parallel execution (G3 doesn't execute whilst G1
and G2 are executing) and sequential execution (G3 doesn't execute after G2); this
leaves us with concurrency. We often say to ourselves that the AOI and INV are
connected. We now know that being connected means concurrent execution. In our
example, the functionality of the MUX_2 is implemented via components executing
concurrently.
Processes
To create software-style VHDL, we first have to deal with processes. We can think of a
VHDL process as a blob of hardware. Instead of instantiating a component in an
architecture, we can instantiate a process. For our MUX_2 example, let's dispense with
concurrency altogether. Let's use a single process. Processes enable you to code up a
design by describing the design's functionality using statements executing in sequence.
This is different from the way in which components create functionality. Components
create functionality by executing concurrently with respect to each other.
A process can contain signal assignments to describe the functionality of a design. Thus,
we can re-code our MUX_2 example using a single process rather than three
component instantiations. Processes do not have to exist in isolation. A process is a
concurrent statement inside an architecture body just like a component instantiation. We
know that components can be connected together using signals and so too can
processes. So processes execute with respect to each other concurrently, but internally
ECADLAB(VHDL) 282
ELCTRONICS AND COMMUNICATION ENGINEERING
they execute statements in sequence. You can describe functionality using sequential
statements inside processes. And you can create multiple processes within architecture
to create your design. But there are a couple of things you can't do - a component
instance is not a sequential statement so you can't execute a component inside a
process. And you can't embed one process inside another in the way that you can
embed component instances within each other, so there's no way to build a process
hierarchy. To build a design hierarchy, you have to use components.
begin
end;
We can write:
begin
G1: process
end process;
G2: process
ECADLAB(VHDL) 283
ELCTRONICS AND COMMUNICATION ENGINEERING
Processes
Processes are only permitted inside an architecture. The statements within processes
execute sequentially, not concurrently.
Processes can be written in a variety of ways. The most common approach when using
processes to describe designs is to use the form that has a sensitivity list.
We shall use two processes in our MUX_2 design, one to replace the AOI gate, the
other to replace the inverter. We will then merge the two processes to see how a single
process can be used to describe the design.
First of all, let's tackle the AOI gate. All we do is extract the signal assignment from the
v1 architecture and insert it into the process. At this point, the signal assignment is a
sequential signal assignment rather than a concurrent signal assignment. At this stage
all we have done is wrap a process around the signal assignment.
begin
end process;
To make this process complete, we have to remember that we are describing a piece of
combinational logic. From a conceptual point of view, the outputs of a combinational
circuit CAN change when ANY one of the inputs changes. This means that we need to
cause the process to execute when any of the ‘inputs' to the process changes. The way
to do this is to create a sensitivity list for the process from the signals A, B, C and D. The
sensitivity list follows the process keyword as shown:
begin
end process;
However, inside the MUX_2 design, we are using the the ports and signals of that
design, so:
begin
ECADLAB(VHDL) 284
ELCTRONICS AND COMMUNICATION ENGINEERING
end process;
begin
end process;
begin
end process;
Notice that not SEL from the G1 process was used to substitute the SELB in the G2
process. We now have a single process with a sensitivity list made up from only the
MUX_2 ports - no internal signals.
RTL Coding
We saw how to use processes to describe a MUX_2 design. However, the coding
approach used was somewhat low-level, in that the code consisted of binary operators.
In order to adopt high-level design principles, it is necessary to try and describe a design
at a higher level of abstraction. This means thinking about the functionality of the design
rather than its implementation. This allows the synthesis tool to optimize the functionality
you have specified, leaving you to describe what the design does, whilst the synthesis
ECADLAB(VHDL) 285
ELCTRONICS AND COMMUNICATION ENGINEERING
tool's job is to implement the design how it sees fit in order to create the optimal
implementation. The style of coding required for synthesis tools is known as RTL coding.
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity MUX2 is
F : out STD_LOGIC);
end;
begin
end;
For the functionality, let's get conceptual. If sel is a logic 1, a is routed through to the f
output. On the other hand if sel is a logic 0, b is routed through to the f output. Rather
than think about routing one of the inputs through to the output let's think about the
output getting one of the inputs, and let's write the text on separate lines depending
upon whether we are making a decision or performing an action (sometimes referred to
as pseudo-code):
if sel is logic 1
f gets a
otherwise
f gets b
ECADLAB(VHDL) 286
ELCTRONICS AND COMMUNICATION ENGINEERING
f <= a;
else
f <= b;
end if;
Now before we go any further, we'll just take this code snippet a line at a time.
if sel = '1'
The VHDL language allows for many different kinds of sequential statement. The
sequential signal assignment is a signal assignment that can appear inside a process.
You have already come across this statement in the Processes page (assignment to F in
the combined process, if you remember). Here's another: the if statement. Actually this
line is part of the if-else statement that is the entire code snippet. if is a VHDL keyword.
After the if keyword you have a conditional expression, in this case sel = '1' - does sel
have the value logic 1? If so...
f <= a;
f gets the value on the a input. But what if sel is not logic 1?
else
f <= b;
end if;
So, as it turns out, we have described the functionality of the MUX_2 design using a
single sequential statement, the if-else statement. In each branch of this if-else
statement, there is an additional sequential statement, either assigning a to f, or b to f,
depending upon the value of sel. But we have to remember that sequential statements
always live inside a process, so
process (sel, a, b)
begin
ECADLAB(VHDL) 287
ELCTRONICS AND COMMUNICATION ENGINEERING
f <= a;
else
f <= b;
end if;
end
This now enables us to describe a design using a list of concurrent signal assignments,
a hierarchy of designs (using component instances) or a process. Compare the 3
approaches for yourself:
// a hierarchy of designs
// process
process (sel, a, b)
begin
f <= a;
else
f <= b;
end if;
ECADLAB(VHDL) 288
ELCTRONICS AND COMMUNICATION ENGINEERING
end process;
And of course you can mix'n'match coding styles if you wish. On a simple design, such
as a MUX_2 it is perhaps not apparent how succinct the use of processes is in general
compared to component instances and concurrent signal assignments. But you can
readily appreciate that the use of just one process in this design is enabling us to
describe the design in terms of its functionality without regard to the implementation. You
can describe what you want without having to worry about how you are going to
implement the design (because you don't have to - that's the synthesis tool's job!).
If statement
In the last article, we looked at describing hardware conceptually using processes. What
kind of hardware can we describe? What are the limitations? What kinds of VHDL
statement can be used in always blocks to describe hardware? Well, we have already
seen the use of an if statement to describe a multiplexer, so let's dwell on if statements
for this month's tutorial.
begin
-- statements
end process;
The code snippet above outlines a way to describe combinational logic using processes.
To model a multiplexer, an if statement was used to describe the functionality. In
addition, all of the inputs to the multiplexer were specified in the sensitivity list.
ECADLAB(VHDL) 289
ELCTRONICS AND COMMUNICATION ENGINEERING
process (sel, a, b)
begin
f <= a;
else
f <= b;
end if;
end process;
Sensitivity list
It is a fundamental rule of VHDL that only signals (which includes input and buffer ports)
must appear in the sensitivity list.
Combinational logic
It transpires that in order to create VHDL code that can be input to a synthesis tool for
the synthesis of combinational logic, the requirement for all inputs to the hardware to
appear in the sensitivity list is a golden rule.
Golden Rule 1:
To synthesize combinational logic using a process, all inputs to the design must appear
in the sensitivity list.
Altogether there are 3 golden rules for synthesizing combinational logic, we will address
each of these golden rules over the next couple of articles in this tutorial.
If
The if statement in VHDL is a sequential statement that conditionally executes other
sequential statements, depending upon the value of some condition. An if statement
may optionally contain an else part, executed if the condition is false. Although the else
part is optional, for the time being, we will code up if statements with a corresponding
else rather than simple if statements. To incorporate more than one sequential
statement in an if statement, simply list the statements one after the other, there are no
special bracketing rules in VHDL as there are in some programming languages,
ECADLAB(VHDL) 290
ELCTRONICS AND COMMUNICATION ENGINEERING
process (sel, a, b)
begin
f <= a;
g <= not a;
else
f = b;
g = a and b;
end if;
end process;
signal f, g : std_logic;
begin
f <= a;
g <= not a;
else
g <= not b;
else
g <= a and b;
ECADLAB(VHDL) 291
ELCTRONICS AND COMMUNICATION ENGINEERING
else
g <= a or b;
end if;
f <= b;
end if;
end process;
Synthesis considerations
If statements are synthesized by generating a multiplexer for each register assigned
within the if statement. The select input on each mux is driven by logic determined by the
if condition, and the data inputs are determined by the expressions on the right hand
sides of the assignments. During subsequent optimization by a synthesis tool, the
multiplexer architecture may be changed to a structure using and-or-invert gates as
surrounding functionality such as the and, or and not can be merged into complex and-
or-invert gates to yield a more compact hardware implementation.
Synthesizing Latches
In the last article, if statements were used to describe simple combinational logic circuits.
Synthesizing the VHDL code produced multiplexing circuits, although the exact
implementation depends upon the synthesis tool used and the target architecture of the
device. As well as enabling the creation of multiplexers, if statements can also be used
to implement tristate buffers and transparent latches. In this article we will look at how
transparent latches are synthesized from if statements and how to avoid the inadvertent
creation of latches when you meant to create combinational logic circuits from VHDL
code containing if statements.
If Statements
In the processes that have been coded up so far, if-else statements rather than simple if
statements have been used. Let's use a simple if statement rather than an if-else
statement in an example you have already seen:
begin
f <= a;
ECADLAB(VHDL) 292
ELCTRONICS AND COMMUNICATION ENGINEERING
else
f <= b;
end if;
end process;
becomes...
signal sel, a, b : std_logic;
begin
f <= b;
f <= a;
end if;
end process;
Note that the behaviour being described is the same. In the pure_if process, f initially
gets b. Only if sel is active HIGH does f get a. This is perhaps a slightly odd way to
describe a multiplexing circuit but it is accepted by all synthesis tools. Synthesis tools
expect to create circuits responding to only binary ('0' and '1' in VHDL) values. As far as
a synthesis tool is concerned if sel is '1' a is routed through to f. If sel is not '1' it must be
'0' and thus sel being '0' leaves f being driven by the initial assignment from b.
ECADLAB(VHDL) 293
ELCTRONICS AND COMMUNICATION ENGINEERING
begin
f <= a;
end if;
end process;
Incomplete Assignment
Now analyze the behaviour of the code. If sel is '1', f gets a. But what happens when sel
is '0'? Well, very simply, nothing! f does not and can not change. When sel is fixed at '0',
we can change a as much as we like, f will not be assigned the value of a. If we suppose
that an if statement synthesises to a multiplexer, then we must be able to configure the
multiplexer such that f only gets the value of a when sel is '1'. This can be achieved by
feeding back the multiplexer f output back to the '0' input. in hardware terms this is a
transparent latch and this is exactly the hardware synthesized by a synthesis tool given
this VHDL code.
If the target architecture does not contain transparent latches the synthesis tool will
generate multiplexer circuits that employ combinational feedback in order to mimic the
latching behavior required. Now, this is very well but what's really happening here? One
minute if statements create multiplexers, the next they create latches. Well, it's not the if
statements, but the process as a whole that counts. If it is possible to execute a process
without assigning a value to a signal in that process, the signal will be implemented as a
transparent latch. This is known as incomplete assignment.
Note that this golden rule states that all objects must be assigned under all conditions.
This is because signals are not the only VHDL objects, there are also variables in VHDL.
In a later tutorial, we will use variables inside a process to describe functionality.
ECADLAB(VHDL) 294
ELCTRONICS AND COMMUNICATION ENGINEERING
Golden Rule 2:
To synthesize combinational logic using a process, all objects must be assigned under
all conditions.
signal f, g : std_logic;
begin
f <= a;
g <= not a;
else
g <= not b;
g <= a xor b;
end if;
end if;
else
g <= a and b;
else
g <= a nand b;
ECADLAB(VHDL) 295
ELCTRONICS AND COMMUNICATION ENGINEERING
-- oops! no else
-- else
-- g <= ...
end if;
end if;
f <= b;
end if;
end process;
Will you get transparent latches on the f and g outputs? Not easy is it? If you look
carefully you will see that in fact, g is latched when sel is '0', sel_2 is '0' and sel_3 is '0'.
The ‘oops!' comment should help you to see where the complete assignment is NOT
made.
Fortunately, it is possible to save yourself the bother of scouring through the process
code to locate possible incomplete assignments by setting signals to default values at
the start of the process. Using this approach you may get undesired functionality if you
have missed out an assignment (which should be easy to fix) as opposed to unwanted
transparent latches. For our current example,
ECADLAB(VHDL) 296
ELCTRONICS AND COMMUNICATION ENGINEERING
begin
f <= b;
g <= a and b;
f <= a;
g <= not a;
else
g <= not b;
g <= a xor b;
end if;
end if;
else
g <= a and b;
else
g <= a nand b;
end if;
end if;
end if;
end process;
ECADLAB(VHDL) 297
ELCTRONICS AND COMMUNICATION ENGINEERING
Entity
The top of every design hierarchy must be an entity. Entities may range from primitive
circuits to complex assemblies. The entity code typically defines just the interface of the
entity.
entity identifier is
generic ( generic_variable_declarations ) ; -- optional
port ( input_and_output_variable_declarations ) ;
[ declarations , see allowed list below ] -- optional
begin \__ optional
[ statements , see allowed list below ] /
end entity identifier ;
generic_variable_declarations are of the form:
variable_name : variable_type := variable_value ; -- := variable_value optional
input_and_output_variable_declaration are of the form:
variable_name : port_mode variable_type ;
port_mode may be in out inout buffer linkage
entity adder is
generic ( N : natural := 32 ) ;
port ( A : in bit_vector(N-1 downto 0);
B : in bit_vector(N-1 downto 0);
cin : in bit;
Sum : out bit_vector(N-1 downto 0);
Cout : out bit );
end entity adder ;
entity test_bench is -- typical top level, simulatable, entity
end entity test_bench;
entity Latch is
port ( Din: in Word;
Dout: out Word;
Load: in Bit;
Clk: in Bit);
constant Setup: Time := 12 ns;
use WORK.TimingMonitors.all
begin
ECADLAB(VHDL) 298
ELCTRONICS AND COMMUNICATION ENGINEERING
subprogram body
type declaration
subtype declaration
alias declaration
attribute declaration
attribute specification
disconnection specification
use clause
group declaration
Architecture
Used to implement a design entity. There may be more than one architecture for a
design entity. Typical architectures fall into classes such as functional simulation or
detailed logic implementation and may be structural, functional(dataflow) or behavioral.
ECADLAB(VHDL) 299
ELCTRONICS AND COMMUNICATION ENGINEERING
Configuration
Used to bind component instances to design entities and collect architectures to make,
typically, a simulatable test bench. One configuration could create a functional simulation
while another configuration could create the complete detailed logic design. With an
appropriate test bench the results of the two configurations can be compared.Note that
significant nesting depth can occur on hierarchal designs. There is a capability to bind
ECADLAB(VHDL) 300
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 301
ELCTRONICS AND COMMUNICATION ENGINEERING
end for;
use clauses are of the form:
use entity library_name.entity_name
.configuration_name
Package Declaration
Used to declare types, shared variables, subprograms, etc.
package identifier is
[declarations, see allowed list below ]
end package identifier ;
The example is included in the next section, Package Body.
The allowed declarations are:
subprogram declaration
type declaration
subtype declaration
constant, object declaration
signal, object declaration
variable, object declaration – shared
file, object declaration
alias declaration
component declaration
attribute declaration
attribute specification
use clause
group template declaration
group declaration
Declarations not allowed include:
subprogram body
A package body is unnecessary if no
subprograms or
deferred constants are declared in the package declaration.
Package Body
Used to implement the subprograms declared in the package declaration.
package body identifier is
[ declarations, see allowed list below ]
end package body identifier ;
package my_pkg is -- sample package declaration
type small is range 0 to 4096;
procedure s_inc(A : inout small);
function s_dec(B : small) return small;
end package my_pkg;
package body my_pkg is -- corresponding package body
procedure s_inc(A : inout small) is
begin
A := A+1;
end procedure s_inc;
function s_dec(B : small) return small is
begin
ECADLAB(VHDL) 302
ELCTRONICS AND COMMUNICATION ENGINEERING
return B-1;
end function s_dec;
end package body my_pkg;
The allowed declarations are:
subprogram declaration
subprogram body
type declaration
subtype declaration
constant, object declaration
variable, object declaration – shared
file, object declaration
alias declaration
use clause
group template declaration
group declaration
Declarations not allowed include:
signal, object declaration
Subprograms
There are two kinds of subprograms: procedures and functions.Both procedures and
functions written in VHDL must havea body and may have declarations.Procedures
perform sequential computations and return valuesin global objects or by storing values
into formal parameters.Functions perform sequential computations and return a value as
the value of the function. Functions do not change their formal parameters.
Subprograms may exist as just a procedure body or a function body. Subprograms may
also have a procedure declarations or a function declaration. When subprograms are
provided in a package, the subprogram declaration is placed in the package declaration
and the subprogram body is placed in the package body.
Procedure Declaration
Used to declare the calling interface to a procedure.
procedure print_header;
D: file);
Formal parameters are separated by semicolons in the formal parameter list. Each
normal parameter is essentially a declaration of an object that is local to the procedure.
The type definitions used in formal parameters must be visible at the place where the
procedure is being declared. No semicolon follows the last formal parameter inside the
ECADLAB(VHDL) 303
ELCTRONICS AND COMMUNICATION ENGINEERING
C : out real;
D : file ) ;
Procedure Body
Used to define the implementation of the procedure.
begin
sequential statement(s)
procedure print_header is
use STD.textio.all;
begin
The procedure body formal parameter list is defined above in Procedure Declaration.
When a procedure declaration is used then the corresponding procedure body should
have exactly the same formal parameter list. The allowed declarations are:
subprogram declaration
subprogram body
type declaration
subtype declaration
ECADLAB(VHDL) 304
ELCTRONICS AND COMMUNICATION ENGINEERING
alias declaration
use clause
group declaration
Function Declaration
Used to declare the calling and return interface to a function.
Formal parameters are separated by semicolons in the formal parameter list. Each
normal parameter is essentially a declaration of an object that is local to the function.
The type definitions used in formal parameters must be visible at the place where the
function is being declared. No semicolon follows the last formal parameter inside the
parenthesis. Formal parameters may be constants, signals or files. The default is
constant. Formal parameters have the mode in. Files do not have a mode. Note that
inout and out are not allowed for functions. The default is in. The reserved word function
may be preceded by nothing, implying pure, pure or impure.A pure function must not
contain a reference to a file object,slice, subelement, shared variable or signal with
attributessuch as 'delayed, 'stable, 'quiet, 'transaction and must notbe a parent of an
impure function.
Function Body
Used to define the implementation of the function.
return a_type is
begin
ECADLAB(VHDL) 305
ELCTRONICS AND COMMUNICATION ENGINEERING
sequential statement(s)
variable X : float;
begin
-- compute X
return X;
The function body formal parameter list is defined above in Function Declaration. When
a function declaration is used then the corresponding function body should have exactly
the same formal parameter list. The allowed declarations are:
subprogram declaration
subprogram body
type declaration
subtype declaration
alias declaration
use clause
group declaration
ECADLAB(VHDL) 306
ELCTRONICS AND COMMUNICATION ENGINEERING
Context Clause
Used to name a library and make library units visible to the design unit that immediately
follows.
library library_name ;
use library_name.unit_name.all ;
library STD ;
use STD.textio.all;
library ieee ;
use ieee.std_logic_1164.all;
use ieee.std_logic_textio.all;
use ieee.std_logic_arith.all;
use ieee.numeric_std.all;
use ieee.numeric_bit.all;
use WORK.my_pkg.s_inc;
-- select one item from package Note that the .all makes everything visible. It is optional
and when not used the prefix such as ieee.std_logic_1164. must be used on every
reference to an item in the library unit. Specific items in the library unit may be listed in
place of .all . The libraries STD and WORK do not need a library specification on most
systems. library ieee or equivalent library IEEE is needed on most systems.
ECADLAB(VHDL) 307
ELCTRONICS AND COMMUNICATION ENGINEERING
use WORK.my_package.all
entity my_entity is
-- entity stuff
These statements are for use in Processes, Procedures and Functions. The signal
assignment statement has unique properties when used sequentially.
wait statement
assertion statement
ECADLAB(VHDL) 308
ELCTRONICS AND COMMUNICATION ENGINEERING
report statement
ECADLAB(VHDL) 309
ELCTRONICS AND COMMUNICATION ENGINEERING
if statement
Conditional structure.
sequence-of-statements
sequence-of-statements /
sequence-of-statements /
...
else \_ optional
sequence-of-statements /
end if [ label ] ;
if a=b then
c:=a;
ECADLAB(VHDL) 310
ELCTRONICS AND COMMUNICATION ENGINEERING
d:=b;
b:=c;
else
do_it;
end if;
case statement
Execute one specific case of an expression equal to a choice. The choices must be
constants of the same discrete type as the expression.
[ label: ] case expression is
when choice1 =>
sequence-of-statements
when choice2 => \_ optional
sequence-of-statements /
when others => \_ optional if all choices covered
sequence-of-statements /
end case [ label ] ;
case my_val is
when 1 =>
a:=b;
when 3 =>
c:=d;
do_it;
when others =>
null;
end case;
loop statement
Three kinds of iteration statements.
[ label: ] loop
sequence-of-statements -- use exit statement to get out
end loop [ label ] ; [ label: ] for variable in range loop
sequence-of-statements
end loop [ label ] ;
[ label: ] while condition loop
sequence-of-statements
end loop [ label ] ;
loop
input_something;
exit when end_file;
end loop;
for I in 1 to 10 loop
ECADLAB(VHDL) 311
ELCTRONICS AND COMMUNICATION ENGINEERING
return statement
Required statement in a function, optional in a procedure.
null statement
Used when a statement is needed but there is nothing to do.
[ label: ] null ;
null;
begin
ECADLAB(VHDL) 312
ELCTRONICS AND COMMUNICATION ENGINEERING
process statement
[ process_declarative_items ]
begin
sequential statements
Begin
if clear='1' then
end if;
Begin
if clk='1' then
ECADLAB(VHDL) 313
ELCTRONICS AND COMMUNICATION ENGINEERING
write(my_line, counter);
write(my_line, IF_PC);
writeline(output, my_line);
end if;
subprogram declaration
subprogram body
type declaration
subtype declaration
alias declaration
attribute declaration
attribute specification
use clause
group declaration
ECADLAB(VHDL) 314
ELCTRONICS AND COMMUNICATION ENGINEERING
rocess.
fter all other non postponed processes have suspended in that simulation
trigger_some_event ;
Note that a procedure can be defined in a library package and then used
any places. A process can not be similarly defined in a package and may
n equivalent process.
ECADLAB(VHDL) 315
ELCTRONICS AND COMMUNICATION ENGINEERING
ssignment statement.
'0' when 2,
ECADLAB(VHDL) 316
ELCTRONICS AND COMMUNICATION ENGINEERING
optional (architecture_name)
part_name: component_name
port map ( actual arguments ) ;
Given entity gate is
port (in1 : in std_logic ;
in2 : in std_logic ;
out1 : out std_logic) ;
end entity gate;
architecture circuit of gate is ...
architecture behavior of gate is ...
A101: entity WORK.gate(circuit)
port map ( in1 => a, in2 => b, out1 => c );
-- when gate has only one architecture
A102: entity WORK.gate
port map ( in1 => a, in2 => b, out1 => c );
-- when order of actual arguments is used
A103: entity WORK.gate
port map ( a, b, c );
Given an entity
entity add_32 is -- could have several architectures
ECADLAB(VHDL) 317
ELCTRONICS AND COMMUNICATION ENGINEERING
generate statement
Make copies of concurrent statements
label: for variable in range generate -- label required
block declarative items \__ optional
begin /
concurrent statements -- using variable
end generate label ;
label: if condition generate -- label required
block declarative items \__ optional
begin /
concurrent statements
end generate label ;
band : for I in 1 to 10 generate
b2 : for J in 1 to 11 generate
block statement
Used to group concurrent statements, possibly hierarchically.
label : block [ ( guard expression ) ] [ is ]
[ generic clause [ generic map aspect ; ] ]
[ port clause [ port map aspect ; ] ]
[ block declarative items ]
begin
concurrent statements
end block [ label ] ;
clump : block
begin
A <= B or C;
D <= B and not C;
end block clump ;
maybe : block ( B'stable(5 ns) ) is
ECADLAB(VHDL) 318
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 319
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 320
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 321
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 322
ELCTRONICS AND COMMUNICATION ENGINEERING
ECADLAB(VHDL) 323
ELCTRONICS AND COMMUNICATION ENGINEERING
REFERENCES:
Websites:
www.datasheets4u.com
www.alldatasheets.com
www.xilinx.com
www.altera.com
www.mentorgraphics.com
ECADLAB(VHDL) 324