Professional Documents
Culture Documents
VHDL Presentation
1. Brief introduction to VHDL structure Entity Architecture Structural/Data Flow/Behavioral descriptions What is it Syntax Special Cases File I/O Declaration Open/Close Textio Test Benches What are they How to use examples
2
2.
3.
4.
VHDL Presentation
4. Aliases What are aliases for? Object Aliases How to simplify complex data structure with aliases. Signature Non-object Aliases Subprograms Similar idea to other programming language Parameter modes Functions Procedures Generics and Configurations Motivation How to use them
3
5.
6.
VHDL
VHDL is a acronym which stands for VHSIC Hardware Description Language VHSIC stands for Very High Speed Integrated Circuits The purpose of this programming language is to assist circuit designers to describe the characteristics of circuit.
4
The architecture
which describes the function of the component or circuit
5
The Entity
The entity syntax
Name of Entity
Name of Input Pins
entity latch is port (s,r: in bit; q, nq: out bit); end latch;
Latch
nq
Name of Output pins
The Architecture
The architecture syntax
Description of the
architecture (what it is) architecture structure of latch is begin q<= r nor nq; nq<= s nor q; end structure;
r q
nq s
Description of circuit
Description types
VHDL can be structured in three different ways.
Structural Data flow Behavioral
Usually, a mixture of all three methods are used in the design of the circuit
8
Structural Description
Structural description uses text to show how components of a circuit are put together
similar to a schematic capture approach to designing a circuit It is to combine smaller blocks or predefined components into a larger circuit by describing the way that the blocks interact
Structural Syntax
Architecture description
entity latch is describes the architecture is of port (s,r: in bit; the method structure description q, nq: out bit); and belongs to the entity latch end latch; architecture structure of latch is Component Pin Specifications component nor_gate These are used to describe the input port (a,b: in bit; and output pins of the component c: out bit); nor_gate that will be used in the architecture section end component; begin Mapping pins to n1: nor_gate port map (r, nq, q); component n2: nor_gate port map (s=>a, q=>b, nq=>c); The command port map is used to end structure; show how the input and output pins
Description Representation
Architecture
a
nor_gate c
a
nor_gate c
nq
Entity
11
Internal Signals
It is also possible to use internal signals to the architecture These are signals that are only used for connectivity within the architecture. This would be used if two components inputs and outputs are connected together without being connected to any pin described in the entity They are defined between the architecture line and the begin line
A
architecture structure of full_adder is component halfadder port (a,b: in bit; B carry, sum: out bit); end component; signal link : bit; C begin ... End structure;
a sum
link
sum
Sum
HalfAdder
b carry b
HalfAdder
carry
Carry
Full Adder
12
Component Reusability
allows the re-use of specific components of the design (Latch, Flip-flops, half-adders, etc)
Design Independent
allows for replacing and testing components without redesigning the circuit
13
Data Flow
Data flow describes how the data flows through the circuit, from input to output It uses built in functions to describe the flow of data All commands in Data flow are concurrent (occur at the same time) Data flow operates in discrete time, when changes occur on the input, it immediately affects the output of the circuit This method is like the more traditional way of designing a circuit using gates For some traditional hardware designers, it is easier to use the data flow method, since it deals with the traditional method of designing circuits.
14
describes the architecture is of the method data flow description and belongs to the entity latch
r
q
nq 15
Behavioral Descriptions
Unlike the other two methods for describing the architecture, behavioral description is like a black box approach to modeling a circuit
It is designed to do a specific task, how it does it is irrelevant
It is used to model complex components which are hard to model using basic design elements Behavioral is often more powerful and allows for easy implementation of the design Most texts they combine both data flow and behavioral descriptions into one
16
Behavioral description
Behavioral descriptions are supported inside a process statement A process is used to describe complex behaviors of the circuit The contents of a process can include sequential statements These sequential statements are similar to commands in conventional programming languages (it, for, etc) which can only be used in the body of a process statement Although, inside a process is sequential, the process itself is concurrent, all processes in a architecture begin execution at the same time The process statement is declared in the body of the architecture in the same way as signal assignments in data flow 17
Elements of a Process
Processes can have a list of signals that they depend on, a sensitivity list, or they can use wait signals to make the process wait for a event to occur (not both) They are only execute if the signals in the sensitivity list change This makes it critical to ensure that the signals that the process depends on are in the sensitivity list Each process is executed once upon power up of the system Wait statements are similar to sensitivity lists, but have the advantage of forcing a process to wait at any point within the process, not just the beginning.
18
count: process (x) variable cnt : integer := -1; begin cnt:=cnt + 1; end process
19
Variables
Variables in VHDL behave similar to those in conventional programming languages They are used to represent the state of a process and are local to that process They are declared in a similar way to that of a signal in data flow or structural descriptions
variable TempVar : integer := -1;
As shown above, Variables are declared before the begin keyword of a process
20
It should be realized that signals and variables are different. On the left both commands in the process are concurrent, they occur at the same time. This results in z not being the opposite of y but the opposite value of x when the process is begun Since the example on the right is using variable, which are sequential, the value of z is the complement of y. Signal assignment statements do not take effect immediately Variable assignments take effect immediately
21
Data Flow
Describes how data flows from input to output
Behavioral
Describes the behavior of the circuit within a process
process (r,s) begin if (r nor nq) then q <= 1; else q <= 0; endif ... end process
22
23
Once you have defined the type of file in use, the next step is the file declaration.
A file declaration creates one or more file objects (pointers) of a given file type. File declarations occur between the process statement and the begin statement (similar to variables) There are different declarations depending on the version of VHDL being used.
24
File Declaration
The syntax for VHDL-93 is followed:
file identifier (,) : subtype_indication [open file_open_kind is filename ];
file_open_kind: read_mode write_mode append_mode
Example: file infile: IntegerFileType open read_mode is inputdata.txt file outfile: IntegerFileType open write_mode is outputdata.txt;
Example: file infile: IntegerFileType is in inputdata.txt; file outfile: IntegerFileType is out outputdata.txt;
25
file_open / file_close
Another way of opening files in VHDL-93 is similar to the conventional C programming language
the object of the file is created but the file is opened and closed within the body of the code
file_open and file_close commands are used to open and close the files.
FILE identifier : file_type; PROCEDURE FILE_OPEN(FILE identifier: file_type; file_name: IN STRING; open_kind: FILE_OPEN_KIND := READ_MODE); PROCEDURE FILE_OPEN(status: OUT FILE_OPEN_STATUS; FILE identifier: file_type; file_name: IN STRING; open_kind: FILE_OPEN_KIND := READ_MODE); PROCEDURE FILE_CLOSE(FILE identifier: file_type);
26
Advantage of file_open/file_close
Determine how to open the file within program (read, write, append) Can determine the name of the file you wish to open during the program (ie. User type in keyboard) Allows the system to ensure the file is opened properly
file_open_status is used to verify the open operation is successfully. Problems can occur if the file is declared in a component that is used multiple times. Each instant of the component will attempt to open the same file
27
Textio Package
Textio is a standardized library for VHDL that allows data to be stored to a monitor or to a file in ASCII format The standard library must be included at the top of the code
use std.textio.all;
This increases the portability the data that is being stored so that it may be used on other simulators or platforms It allows external software to read results for analyzing (spreadsheet, human eye, etc). When defining a file for reading and writing using the Textio functions, the file declaration is of file type text It is based on the concept of dynamic strings, accessed using pointers of type line Textio uses the same idea as normal read/write to write the line of text to a file, but uses a command called writeline. The difference is when creating the string of text, it converts all data to text 29
A write function converts the data to text and appends it to the end of the variable
This data can be bit, bit_vector, time, integer, real, boolean, character and string
Writeline is used to write the information in the variable to the file, then resetting the variable to null.
30
Declaration of variables
Overflow 15
Pointer s
O v e r
o w
1 5 NULL
31
This is a procedure that is called to read in specific characters from a file, and place them into a vector
The Vector for data to be stored were passed down as arguments of the procedure
It should be noted that the file is opened in a procedure. This makes the file local to this procedure and is closed when procedure is finished
33
Example
procedure write_to_file is file FilePtr : data_file_type open write_mode is datafile; begin end procedure write_to_file;
34
Verifies that the VHDL code meets the circuits specifications Test benches should be easily modified, allowing for future use with other code Should be Easy to understand the behavior of the test bench
35
Given a known input, does the system generate the expected output
b) To apply these stimulus to the VHDL code under test and collect the actual output responses c) To compare the output responses with the values expected
36
Stimulus Generation/Response
There is three general ways of generating a simulation for testing
1. Repetitive patterns
Patterns can generated using different frequencies and periods Combination of waveforms
(Waveform A and B)
2. 3.
Lookup table
Constant table Keyboard Data file
I/O data
Response Handling
The response from the system can be dumped to a file to be analyzed by a external program or human eye (Textio). Analyzed by test bench to verify expected output.
37
Test Bench
Unit Under Test Monitor Program that generates output Resulting Output File
38
39
--Defining the variable "CLK_PERIOD" --to be equal to 20 nano seconds constant CLK_PERIOD : time:= 20 ns;
BEGIN --Defining external interface signals --to Unit Under Test. UUT : full_adder PORT MAP ( a => a, b => b, c => c, sum => sum, carry => carry); READDATA: process file out_file : TEXT is in data.txt"; variable buf : line; variable A,B,C : std_logic ; begin readline (f , buf ); --read a line from the file. read( buf , A ) ; --read a character from the line. read( buf , B ) ; read( buf , C ) ; a<=A; b<=B; c<=C; wait for CLK_PERIOD; end process
MONITOR: process variable output_line : line; file out_file : TEXT is out "results.txt"; Begin write (output_line ,a); write (output_line, b); write (output_line, c); write (output_line, sum); write (output_line, carry); writeline (out_file, output_line); wait a,b,c,sum,carry; end process; END testbench_arch;
40