Resumen VHDL (21 Páginas)
Resumen VHDL (21 Páginas)
Principles of Digital Logic Design Enoch Hwang Last updated 3/5/2003 5:22 PM
Appendix A − VHDL Summary Page 2 of 21
VHDL is a hardware description language for modeling digital circuits that can range from simple connection
of gates to complex systems. VHDL is an acronym for VHSIC Hardware Description Language, and VHSIC in turn
is an acronym for Very High Speed Integrated Circuits. This appendix gives a brief summary of the basic VHDL
elements and its syntax. Many advance features of the language are omitted. Interested readers should refer to other
references for detail coverage.
A.1.1 Comments
Comments are preceded by two consecutive hyphens ( -- ) and are terminated at the end of the line.
Example:
-- This is a comment
A.1.2 Identifiers
VHDL identifier syntax:
• A sequence of one or more upper case letters, lower case letters, digits, and the underscore.
• Upper and lower case letters are treated the same, i.e. case insensitive.
• The first character must be a letter.
• The last character cannot be the underscore.
• Two underscores cannot be together.
SIGNAL x: BIT;
VARIABLE y: INTEGER;
CONSTANT one: STD_LOGIC_VECTOR(3 DOWNTO 0) := "0001";
The BIT and BIT_VECTOR types are predefined in VHDL. Objects of these types can have the values ‘0’ or ‘1’.
The BIT_VECTOR type is simply a vector of type BIT.
Example:
SIGNAL x: BIT;
SIGNAL y: BIT_VECTOR(7 DOWNTO 0);
Principles of Digital Logic Design Enoch Hwang Last updated 3/5/2003 5:22 PM
Appendix A − VHDL Summary Page 3 of 21
x <= '1';
y <= "0010";
The STD_LOGIC and STD_LOGIC_VECTOR types provide more values than the BIT type for modeling a real circuit
more accurately. Objects of these types can have the following values:
‘0’ − normal 0.
‘1’ − normal 1.
‘Z’ − high impedance.
‘−’ − don’t care.
‘L’ − weak 0.
‘H’ − weak 1.
‘U’ − uninitialized.
‘X’ − unknown.
‘W’ − weak unknown.
The STD_LOGIC and STD_LOGIC_VECTOR types are not predefined and so the two library statements must be
included in order to use these types:
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
If objects of type STD_LOGIC_VECTOR are to be used as binary numbers in arithmetic manipulations, then either
one of the following two USE statements must also be included:
USE ieee.std_logic_signed.ALL;
USE ieee.std_logic_unsigned.all;
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
SIGNAL x: STD_LOGIC;
SIGNAL y: STD_LOGIC_VECTOR(7 DOWNTO 0);
x <= 'Z';
y <= "001-";
INTEGER
The predefined INTEGER type defines binary number objects for use with arithmetic operators. By default, an
INTEGER signal uses 32 bits to represent a signed number. Integers using fewer bits can also be declared with the
RANGE keyword.
Example:
SIGNAL x: INTEGER;
Principles of Digital Logic Design Enoch Hwang Last updated 3/5/2003 5:22 PM
Appendix A − VHDL Summary Page 4 of 21
BOOLEAN
The predefined BOOLEAN type defines objects having the two values TRUE and FALSE.
Example:
SIGNAL x: BOOLEAN;
Enumeration TYPE
An enumeration type allows the user to specify the values that the data object can have.
Syntax:
TYPE identifier IS (value1, value2, … );
Example:
ARRAY
The ARRAY type groups single data objects of the same type together into a one or multi- dimensional array.
Syntax:
TYPE identifier IS ARRAY (range) OF type;
Example:
SUBTYPE
Principles of Digital Logic Design Enoch Hwang Last updated 3/5/2003 5:22 PM
Appendix A − VHDL Summary Page 5 of 21
Arithmetic Operators
+ addition a+b
– subtraction a–b
* multiplication a*b
/ division a/b
MOD modulus a MOD b
REM remainder a REM b
** exponentiation a ** 2
& concatenation 'a' & 'b'
ABS absolute
Relational Operators
= equal
/= not equal
< less than
<= less than or equal
> greater than
>= greater than or equal
Shift Operators
sll shift left logical
srl shift right logical
sla shift left arithmetic
sra shift right arithmetic
rol rotate left
ror rotate right
A.1.6 ENTITY
An ENTITY declaration declares the external or user interface of the module similar to the declaration of a
function. It specifies the name of the entity and its interface. The interface consists of the signals to be passed into
the entity or out from it.
Syntax:
ENTITY entity-name IS
PORT (list-of-port-names-and-types);
END entity-name;
Example:
Principles of Digital Logic Design Enoch Hwang Last updated 3/5/2003 5:22 PM
Appendix A − VHDL Summary Page 6 of 21
A.1.7 ARCHITECTURE
The ARCHITECTURE body defines the actual implementation of the functionality of the entity. This is similar to
the definition or implementation of a function. The syntax for the architecture varies depending on the model
(dataflow, behavioral, or structural) you use.
Syntax for dataflow model::
Principles of Digital Logic Design Enoch Hwang Last updated 3/5/2003 5:22 PM
Appendix A − VHDL Summary Page 7 of 21
END architecture-name;
For each component declaration used, there must be a corresponding entity and architecture for that component.
The PORT MAP statements are concurrent statements.
Example:
BEGIN
U0: myOR PORT MAP (D, V, term1);
S <= term1 AND M;
END Siren_Structural;
A.1.8 PACKAGE
A PACKAGE provides a mechanism to group together and share declarations that are used by several entity units.
A package itself includes a declaration and, optionally, a body. The package declaration and body are usually stored
together in a separate file from the rest of the design units. The file name given for this file must be the same as the
package name. In order for the complete design to synthesize correctly using MAX+PLUS II, you must first
synthesize the package as a separate unit. After that you can synthesize the unit that uses that package.
The PACKAGE declaration contains declarations that may be shared between different entity units. It provides the
interface, that is, items that are visible to the other entity units. The optional PACKAGE BODY contains the
implementations of the functions and procedures that are declared in the PACKAGE declaration.
Syntax for PACKAGE declaration:
PACKAGE package-name IS
type-declarations;
subtype-declarations;
signal-declarations;
variable-declarations;
constant-declarations;
component-declarations;
function-declarations;
procedure-declarations;
END package-name;
Syntax for PACKAGE body:
PACKAGE BODY package-name IS
function-definitions; -- for functions declared in the package declaration
procedure-definitions; -- for procedures declared in the package declaration
END package-name;
Example:
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
Principles of Digital Logic Design Enoch Hwang Last updated 3/5/2003 5:22 PM
Appendix A − VHDL Summary Page 8 of 21
PACKAGE my_package IS
SUBTYPE bit4 IS std_logic_vector(3 DOWNTO 0);
FUNCTION Shiftright (input: IN bit4) RETURN bit4; -- declare a function
SIGNAL mysignal: bit4; -- a global signal
END my_package;
Using a PACKAGE
To use a package, you simply include a LIBRARY and USE statement for that package. Before synthesizing the
module that uses the package, you need to first synthesize the package by itself as a top-level entity.
Syntax:
LIBRARY WORK;
USE WORK.package-name.ALL;
Example:
LIBRARY work;
USE work.my_package.ALL;
Example:
Principles of Digital Logic Design Enoch Hwang Last updated 3/5/2003 5:22 PM
Appendix A − VHDL Summary Page 9 of 21
y <= '1';
z <= y AND (NOT x);
Principles of Digital Logic Design Enoch Hwang Last updated 3/5/2003 5:22 PM
Appendix A − VHDL Summary Page 10 of 21
A.3.1 PROCESS
The PROCESS block contains statements that are executed sequentially. However, the PROCESS statement itself is
a concurrent statement. Multiple process blocks in an architecture will be executed simultaneously. These process
blocks can be combined together with other concurrent statements.
Syntax:
Example:
PROCESS (D, V, M)
BEGIN
term_1 <= D OR V;
S <= term_1 AND M;
END PROCESS;
Principles of Digital Logic Design Enoch Hwang Last updated 3/5/2003 5:22 PM
Appendix A − VHDL Summary Page 11 of 21
Example:
y <= '1';
z <= y AND (NOT x);
signal := expression;
Example:
y := '1';
yn := NOT y;
A.3.4 WAIT
When a process has a sensitivity list, the process always suspends after executing the last statement. An
alternative to using a sensitivity list to suspend a process is to use a WAIT statement, which must also be the first
statement in a process1.
Syntax2:
Example:
IF condition THEN
sequential-statements1;
ELSE
sequential-statements2;
END IF;
IF condition1 THEN
sequential-statements1;
ELSIF condition2 THEN
sequential-statements2;
…
ELSE
sequential-statements3;
1
This is only a MAX+PLUS II restriction.
2
There are three different formats of the WAIT statement, however, MAX+PLUS II only supports one.
Principles of Digital Logic Design Enoch Hwang Last updated 3/5/2003 5:22 PM
Appendix A − VHDL Summary Page 12 of 21
END IF;
Example:
A.3.6 CASE
Syntax:
CASE expression IS
WHEN choices => sequential-statements;
WHEN choices => sequential-statements;
…
WHEN OTHERS => sequential-statements;
END CASE;
Example:
CASE sel IS
WHEN "00" => z <= in0;
WHEN "01" => z <= in1;
WHEN "10" => z <= in2;
WHEN OTHERS => z <= in3;
END CASE;
A.3.7 NULL
The NULL statement does not perform any actions.
Syntax:
NULL;
A.3.8 FOR
Syntax:
Example:
sum := 0;
FOR count IN 1 TO 10 LOOP
sum := sum + count;
3
This is only a MAX+PLUS II restriction.
Principles of Digital Logic Design Enoch Hwang Last updated 3/5/2003 5:22 PM
Appendix A − VHDL Summary Page 13 of 21
END LOOP;
A.3.9 WHILE4
Syntax:
A.3.10 LOOP4
Syntax:
LOOP
sequential-statements;
EXIT WHEN condition;
END LOOP;
A.3.11 EXIT4
The EXIT statement can only be used inside a loop. It causes execution to jump out of the innermost loop and is
usually used in conjunction with the LOOP statement.
Syntax:
A.3.12 NEXT
The NEXT statement can only be used inside a loop. It causes execution to skip to the end of the current iteration
and continue with the beginning of the next iteration. It is usually used in conjunction with the FOR statement.
Syntax:
Example:
sum := 0;
FOR count IN 1 TO 10 LOOP
NEXT WHEN count = 3;
sum := sum + count;
END LOOP;
A.3.13 FUNCTION
Syntax for function declaration:
4
Not supported by MAX+PLUS II.
Principles of Digital Logic Design Enoch Hwang Last updated 3/5/2003 5:22 PM
Appendix A − VHDL Summary Page 14 of 21
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
BEGIN
PROCESS
BEGIN
mysignal <= x;
z <= Shiftright(mysignal);
END PROCESS;
END Behavioral;
A.3.14 PROCEDURE
Syntax for procedure declaration:
PROCEDURE procedure -name (parameter-list);
Syntax for procedure definition:
PROCEDURE procedure-name (parameter-list) IS
BEGIN
sequential-statements;
END procedure-name;
Syntax for procedure call:
procedure -name (actuals);
Parameters in the parameter-list are variables of modes IN, OUT, or INOUT.
Principles of Digital Logic Design Enoch Hwang Last updated 3/5/2003 5:22 PM
Appendix A − VHDL Summary Page 15 of 21
Example:
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
BEGIN
PROCESS
VARIABLE mysignal: bit4;
BEGIN
Shiftright(x, mysignal);
z <= mysignal;
END PROCESS;
END Behavioral;
LIBRARY ieee;
USE ieee.std_logic_1164.all;
Principles of Digital Logic Design Enoch Hwang Last updated 3/5/2003 5:22 PM
Appendix A − VHDL Summary Page 16 of 21
END PROCESS;
END Behavioral;
COMPONENT component-name IS
PORT (list-of-port-names-and-types);
END COMPONENT;
Example:
SIGNAL x0, x1, y0, y1, c0, c1, c2, s0, s1: BIT;
U1: half_adder PORT MAP (x0, y0, c0, c1, s0);
U2: half_adder PORT MAP (x1, y1, c1, c2, s1);
Example (named association):
SIGNAL x0, x1, y0, y1, c0, c1, c2, s0, s1: BIT;
U1: half_adder PORT MAP (cout=>c1, si=>s0, cin=>c0, xi=>x0, yi=>y0);
U2: half_adder PORT MAP (cin=>c1, xi=>x1, yi=>y1, cout=>c2, si=>s1);
Principles of Digital Logic Design Enoch Hwang Last updated 3/5/2003 5:22 PM
Appendix A − VHDL Summary Page 17 of 21
A.4.3 OPEN
The OPEN keyword is used in the PORT MAP association-list to signify that that particular port is not connected or
used.
Example:
A.4.4 GENERATE
The GENERATE statement works like a macro expansion. It provides a simple way to duplicate similar
components.
Syntax:
Example:
BEGIN
Carryv(0) <= Cin;
D
V S
M
Principles of Digital Logic Design Enoch Hwang Last updated 3/5/2003 5:22 PM
Appendix A − VHDL Summary Page 18 of 21
BEGIN
U0: myOR PORT MAP (D, V, term1);
S <= term1 AND M;
-- note how we can have both PORT MAP and signal assignment statements
END Siren_Structural;
A.5.1 CONV_INTEGER()
Converts a std_logic_vector type to an integer;
Requires:
LIBRARY ieee;
USE ieee.std_logic_unsigned.ALL;
Syntax:
CONV_INTEGER(std_logic_vector)
Example:
Principles of Digital Logic Design Enoch Hwang Last updated 3/5/2003 5:22 PM
Appendix A − VHDL Summary Page 19 of 21
LIBRARY ieee;
USE ieee.std_logic_unsigned.ALL;
n := CONV_INTEGER(four_bit);
A.5.2 CONV_STD_LOGIC_VECTOR(,)
Converts an integer type to a std_logic_vector type.
Requires:
LIBRARY ieee;
USE ieee.std_logic_arith.ALL;
Syntax:
CONV_STD_LOGIC_VECTOR (integer, number_of_bits)
Example:
LIBRARY ieee;
USE ieee.std_logic_arith.ALL;
Principles of Digital Logic Design Enoch Hwang Last updated 3/5/2003 5:22 PM
Appendix A − VHDL Summary Page 20 of 21
Index
A L
ARCHITECTURE, 6 LOOP, 13
ARRAY, 4
N
B
NEXT, 13
Behavioral model, 6, 10 NULL, 12
example, 16
BIT, 2 O
BIT_VECTOR, 2
OPEN, 17
BOOLEAN, 4
OTHERS, 12
C
P
CASE, 12
PACKAGE, 7
Comments, 2
PORT MAP, 16
COMPONENT declaration, 16
PROCEDURE, 14
Concurrent signal assignment, 8
PROCESS, 10
Concurrent statements, 8
Conditional signal assignment, 9
CONV_INTEGER, 18 S
CONV_STD_LOGIC_VECTOR, 19 Selected signal assignment, 9
Conversion routines, 18 Sequential signal assignment, 10
Sequential statements, 10
D Signal assignment
Data objects, 2 concurrent, 8
Data operators, 4 conditional, 9
selected, 9
Data types, 2
sequential, 10
Dataflow model, 6, 8
STD_LOGIC, 3
example, 10
STD_LOGIC_VECTOR, 3
DOWNTO, 12
Structural model, 6, 16
example, 17
E
SUBTYPE, 4
ELSIF, 11
ENTITY, 5 T
Enumeration, 4
TO, 12
EXIT, 13
V
F
FOR, 12 Variable assignment, 11
FUNCTION, 13 VHD
Conversion routines, 18
VHDL
G
Basic language elements, 2
GENERATE, 17 Behavioral model, 6, 10
example, 16
I Concurrent statements, 8
Dataflow model, 6, 8
Identifiers, 2 example, 10
IF THEN ELSE, 11
Sequential statements, 10
INTEGER, 3
Structural model, 6, 16
Principles of Digital Logic Design Enoch Hwang Last updated 3/5/2003 5:22 PM
Appendix A − VHDL Summary Page 21 of 21
example, 17 NEXT, 13
VHDL syntax NULL, 12
ARCHITECTURE, 6 OPEN, 17
ARRAY, 4 OTHERS, 12
BIT, 2 PACKAGE, 7
BIT_VECTOR, 2 PORT MAP, 16
BOOLEAN, 4 PROCEDURE, 14
CASE, 12 PROCESS, 10
Comments, 2 Signal assignment
COMPONENT declaration, 16 concurrent, 8
CONV_INTEGER, 18 conditional, 9
CONV_STD_LOGIC_VECTOR, 19 selected, 9
Data objects, 2 sequential, 10
Data operators, 4 STD_LOGIC, 3
Data types, 2 STD_LOGIC_VECTOR, 3
DOWNTO, 12 SUBTYPE, 4
ELSIF, 11 TO, 12
ENTITY, 5 Variable assignment, 11
Enumberation, 4 WAIT, 11
EXIT, 13 WHEN, 12
FOR, 12 WHILE, 13
FUNCTION, 13
GENERATE, 17 W
Identifiers, 2
WAIT, 11
IF THEN ELSE, 11
WHEN, 12
INTEGER, 3
LOOP, 13 WHILE, 13
Principles of Digital Logic Design Enoch Hwang Last updated 3/5/2003 5:22 PM