100
VHDL Introduction Dhaval S. Shukla Teaching Assistant,L1 SVNIT,Surat

VHDL Introduction

Embed Size (px)

Citation preview

Page 1: VHDL Introduction

VHDL Introduction

Dhaval S. Shukla

Teaching Assistant,L1

SVNIT,Surat

Page 2: VHDL Introduction

VHDL Introduction

V- VHSIC

Very High Speed Integrated Circuit

H- Hardware

D- Description

L- Language

Page 3: VHDL Introduction

VHDL Benefits

1. Public Standard

2. Technology and Process Independent

Include technology via libraries

3. Supports a variety of design methodologies

1. Behavioral modeling

2. Dataflow or RTL (Register Transfer Language) Modeling

3. Structural or gate level modeling

Page 4: VHDL Introduction

VHDL Benefits (cont)

4. Supports Design Exchange VHDL Code can run on a variety of

systems

5. Supports Design Reuse Code “objects” can be used in multiple

designs

6. Supports Design Hierarchy Design can be implemented as interconnected

submodules

Page 5: VHDL Introduction

VHDL Benefits (cont)7. Supports Synchronous and Asynchronous Designs

8. Supports Design Simulation Functional (unit delay)

Timing (“actual” delay)

9. Supports Design Synthesis Hardware implementation of the design obtained directly from

VHDL code.

10. Supports Design Documentation Original purpose for VHDL – Department of Defense

VHDL

CODE

a11

a22

3a3

4a4

b1

b2

b3

b4

5

6

7

8

Vcc1

0

GND

0

FPLDVHDL

Synthsize

Software

Page 6: VHDL Introduction

VHDL Design Units

Entity Declaration

Describes external view of the design (e.g. I/O)

Architecture Body (AB)

Describes internal view of the design

Configuration Declaration

Package Declaration

Library Declaration

Package Body

Page 7: VHDL Introduction

Architecture Body (AB)

The architecture body contains the internal description of the design entity. The VHDL specification states that a single design entity can contain multiple architecture bodies. Each AB can be used to describe the design using a different level of abstraction.

Page 8: VHDL Introduction

VHDL Statement Terminator

Each VHDL Statements is terminated using a semicolon

;

Page 9: VHDL Introduction

VHDL Comment Operator

To include a comment in VHDL, use the comment operator

-- This is a comment

-- This is an example of a comment

y <= 0; -- can occur at any point

Page 10: VHDL Introduction

Signal Assignment Operator

To assign a value to a signal data object in VHDL, we use the

signal assignment operator

<=Example:

y <= ‘1’; -- signal y is assigned the value ONE

Page 11: VHDL Introduction

Complete AND GATE Example

Library altera;

Use altera.maxplus2.all;

Library ieee;

Use ieee.std_logic_1164.all;

Use ieee.std_logic_arith.all;

Entity and_example is

port(a,b: in std_logic;

ya,yb,yc: out std_logic);

End entity and_example;

Architecture test of and_example is

begin

--- dataflow model (ya)

ya <= a and b;

-- structural model (yb)

and2:a_7408 port map(a,b,yb);

-- behavioral model (yc)

process(a,b)

begin

yc <= ‘0’;

if((a=‘1’) and (b = ‘1’)) then

yc <= ‘1’;

else yc <= ‘0’;

end if;

end process;

End architecture test;

Page 12: VHDL Introduction

AND GATE Example (cont)When synthesized, we obtain the following logic circuit

Ya

Yb

Yc

A

B

Synthesis tool creates three AND

gates.

Maxplus II Block Diagram

Page 13: VHDL Introduction

VHDL Example - Hardware

It is important to remember that VHDL is a “hardware” language, so you must think and code in “hardware.”

Statements within the architecture body run “concurrently.” That is, order does not matter!!!

We’ll introduce “sequential” statements later when I introduce “process blocks”

Page 14: VHDL Introduction

VHDL Example – Hardware

Example – Logic Circuit

a

b

c

d

Y1

Y2

Y

-- Code Fragment A

Architecture test of example is

begin

y1 <= a and b;

y2 <= c and d;

y <= y1 or y2;

end architecture test;

Page 15: VHDL Introduction

VHDL Example – Hardware

Example – Logic Circuit

a

b

c

d

Y1

Y2

Y

-- Code Fragment B

Architecture test of example is

begin

y <= y1 or y2;

y2 <= c and d;

y1 <= a and b;

end architecture test;

Page 16: VHDL Introduction

VHDL Example – Hardware

Example – Logic Circuit

a

b

c

d

Y1

Y2

Y

-- Code Fragment C

Architecture test of example is

begin

y2 <= c and d;

y <= y1 or y2;

y1 <= a and b;

end architecture test;

All three code fragments produce the same result

Page 17: VHDL Introduction

VHDL Syntax

Page 18: VHDL Introduction

VHDL Syntax – Entity DeclarationDescribes I/O of the design. I/O Signals

are called ports.The syntax is:

Entity design_name is

port(signal1,signal2,…..:mode type;

signal3,signal4,…..:mode type);

End entity design_name;

Page 19: VHDL Introduction

VHDL Syntax – Entity Example Entity my_example is

port( a,b,c: in std_logic;

s: in std_logic_vector(1 downto 0);

e,f: out std_logic;

y: out std_logic_vector(4 downto 0));

end entity my_example;

Maxplus II Block Diagram

Page 20: VHDL Introduction

Architecture Body Syntax

Architecture name of entity_name isinternal signal and constant declarations

Begin

Concurrent statement 1;

Concurrent statement 2;

Concurrent statement 3;

Concurrent statement 4;

End architecture name;

Page 21: VHDL Introduction

VHDL Program Template

Library altera;

Use altera.maxplus2.all;

Library ieee;

Use ieee.std_logic_1164.all;

Use ieee.std_logic_arith.all;

Entity design_name isport(signal1,signal2,…..:mode type;

signal3,signal4,…..:mode type);End entity design_name;

Architecture name of entity_name is

internal signal and constant declarations

Begin

Concurrent statement 1;

Concurrent statement 2;

Concurrent statement 3;

Concurrent statement 4;

End architecture name;

Page 22: VHDL Introduction

Simple Concurrent StatementsAssignment Operator

Assignment operator <= Ex: y <= a and b; -- defines a AND gate

For simulation purposes only, you may specify a delay.

Ex: y <= a and b after 10 ns;

This is useful if you want to also use VHDL to generate a known test waveform or vector. This is known as a “test bench.” you cannot specify a delay for synthesis purposes.

VHDL

Test Bench

VHDL

Design

Output

Vector

Test

Vector

Page 23: VHDL Introduction

Simple Concurrent StatementsLogical Operators

Logical operatorsAnd, or, nand, nor, xor, xnor, not

Operates on std_logic or Boolean data objects

All operators (except for the not operator) require at least two arguments

Ex: y <= a and b; -- AND gate

Page 24: VHDL Introduction

Simple Concurrent StatementsLogical Operators

Logical operators Examples y <= a and not b;

Use parenthesis to define order of execution

Ex: y<= (a and b) or c; y <= a and (b or c);

Y

a

b

c

Y

c

b

a

Page 25: VHDL Introduction
Page 26: VHDL Introduction

Operators & Data Types

Page 27: VHDL Introduction
Page 28: VHDL Introduction
Page 29: VHDL Introduction
Page 30: VHDL Introduction
Page 31: VHDL Introduction
Page 32: VHDL Introduction
Page 33: VHDL Introduction
Page 34: VHDL Introduction
Page 35: VHDL Introduction
Page 36: VHDL Introduction
Page 37: VHDL Introduction
Page 38: VHDL Introduction
Page 39: VHDL Introduction
Page 40: VHDL Introduction
Page 41: VHDL Introduction
Page 42: VHDL Introduction
Page 43: VHDL Introduction
Page 44: VHDL Introduction
Page 45: VHDL Introduction
Page 46: VHDL Introduction

Inertial Delay

Transport Delay

Page 47: VHDL Introduction

Delays (Cont..)

Page 48: VHDL Introduction
Page 49: VHDL Introduction
Page 50: VHDL Introduction
Page 51: VHDL Introduction
Page 52: VHDL Introduction
Page 53: VHDL Introduction
Page 54: VHDL Introduction
Page 55: VHDL Introduction
Page 56: VHDL Introduction
Page 57: VHDL Introduction
Page 58: VHDL Introduction
Page 59: VHDL Introduction
Page 60: VHDL Introduction
Page 61: VHDL Introduction
Page 62: VHDL Introduction
Page 63: VHDL Introduction

VHDL Sequential Statements

Assignments executed sequentially in processes

Sequential statements

{Signal, variable} assignments

Flow control

IF <condition> THEN <statements> [ELSIF <statements] [ELSE <statements>] END IF;

FOR <range> LOOP <statements> END LOOP;

WHILE <condition> LOOP <statements> END LOOP;

CASE <condition> IS WHEN <value> => <statements>

{WHEN <value> => <statements>}

[WHEN others => <statements>]

END CASE;

WAIT [ON <signal>] [UNTIL <expression>] [FOR <time>] ;

ASSERT <condition> [REPORT <string>] [SEVERITY <level>] ;

Page 64: VHDL Introduction
Page 65: VHDL Introduction

Sequential Statement: if_else_example[3_8_Decoder]

Page 66: VHDL Introduction
Page 67: VHDL Introduction
Page 68: VHDL Introduction

For loop Statement Example: Even Parity Checker

Page 69: VHDL Introduction

Example: A Square Wave generation

Page 70: VHDL Introduction
Page 71: VHDL Introduction

The Wait Statement

Page 72: VHDL Introduction
Page 73: VHDL Introduction
Page 74: VHDL Introduction
Page 75: VHDL Introduction
Page 76: VHDL Introduction
Page 77: VHDL Introduction
Page 78: VHDL Introduction
Page 79: VHDL Introduction
Page 80: VHDL Introduction

Different Style of Writing Code

Page 81: VHDL Introduction

Subprogram

Page 82: VHDL Introduction

Function

Page 83: VHDL Introduction

Function

Page 84: VHDL Introduction

Procedure

Page 85: VHDL Introduction

Procedure

Page 86: VHDL Introduction

Bus ResolutionSmoke Generator

VHDL does not allow multiple concurrent signal assignments to the same signal

Multiple sequential signal assignments are allowed

LIBRARY attlib; USE attlib.att_mvl.ALL;

-- this code will generate an error

ENTITY bus IS

PORT (a, b, c : IN MVL; z : OUT MVL);

END bus;

ARCHITECTURE smoke_generator OF bus IS

SIGNAL circuit_node : MVL;

BEGIN

circuit_node <= a;

circuit_node <= b;

circuit_node <= c;

z <= circuit_node;

END smoke_generator;

Page 87: VHDL Introduction

Bus Resolution Functions

Are used to determine the assigned value when there are multiple signal drivers to the same signal

FUNCTION wired_and (drivers : MVL_VECTOR) RETURN MVL IS

VARIABLE accumulate : MVL := '1';

BEGIN

FOR i IN drivers'RANGE LOOP

accumulate := accumulate AND drivers(i);

END LOOP;

RETURN accumulate;

END wired_and;

Bus resolution functions may be user defined or called from a package

Page 88: VHDL Introduction

Bus ResolutionSmoke Generator Fixed

A signal which has a bus resolution function associated with it may have multiple drivers

LIBRARY attlib; USE attlib.att_mvl.ALL;

USE WORK.bus_resolution.ALL;

ENTITY bus IS

PORT (a, b, c : IN MVL; z : OUT MVL);

END bus;

ARCHITECTURE fixed OF bus IS

SIGNAL circuit_node : wired_and MVL;

BEGIN

circuit_node <= a;

circuit_node <= b;

circuit_node <= c;

z <= circuit_node;

END fixed;

Page 89: VHDL Introduction

Null TransactionsHow can a driver be disconnected (i.e. not influence the output at all)?

Use the null waveform element

Examplebus_out <= NULL AFTER 17 ns;

What happens if all drivers of a resolved signal are disconnected?

Use register kind in signal declaration to keep most recently determined value

Use bus kind in signal declaration if resolution function will determine the value

Examplesignal t : wired_bus BUS;

signal u : BIT REGISTER;

Page 90: VHDL Introduction

Packages encapsulate elements that can be globally shared among two or more design units

A package consists of two parts

Declarations for allelements containedin the package

Necessary definitions for certain objects in package declaration, e.g. subprogram descriptions

Declaration

Body

VHDL Packages

Page 91: VHDL Introduction

Example package contents include:

Subprograms (i.e. functions and procedures)

Data and type declarations such as

User record definitions

User types and enumerated types

Constants

Files

Aliases

Attributes

Component declarations

Entities and Architectures cannot be declared or defined in a package

To use a package, it must be made visible via the use construct

Packages

Page 92: VHDL Introduction

Component & Package

• Component declarations appear in the declarations part of an architecture body.

• Alternately, they may also appear in a package declaration. Items declared in this

package can then be made visible within any architecture body by using the library

and use clauses.

• For example, consider the entity GATING described in the basic example. A

package such as shown may be created to hold the component declarations.

Page 93: VHDL Introduction
Page 94: VHDL Introduction
Page 95: VHDL Introduction
Page 96: VHDL Introduction
Page 97: VHDL Introduction
Page 98: VHDL Introduction
Page 99: VHDL Introduction
Page 100: VHDL Introduction

http://www.vhdl.renerta.com/source/vhd00020.htm