Файл: Digital design with CPLD applications and VHDL (R. Dueck, 2000).pdf
ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 13.06.2025
Просмотров: 8101
Скачиваний: 6
FIGURE 4.31
2-line-to-4-line Decoder
4.6 • Text Design File (VHDL) |
137 |
‘W’, –– Weak Unknown ‘L’, –– Weak 0
‘H’, –– Weak 1 ‘-’ –– Don’t care
“Forcing” levels are deemed to be the equivalent of a gate output. “Weak” levels are specified by a pull-up or pull-down resistor. (“Weak” levels are usually used in circuit modeling, where it is important to distinguish between gate outputs and pull-up/down. These levels will not be of importance to us.) The ‘Z’ state is used as the high-impedance state of a tristate buffer.
The majority of applications can be handled by ‘X’, ‘0’, ‘1’, and ‘Z’ values.
To use STD_LOGIC in a VHDL file, you must include the following reference to the VHDL library called ieee and the std_logic_1164 package before the entity declaration:
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
Table 4.1 Some Common VHDL Types
How |
|||
Type |
Values |
Written |
Examples |
BIT |
0 or 1 |
Single quotes |
‘0’, ‘1’ |
STD_LOGIC |
U, X, 0, 1, Z, W, L, H, - |
Single quotes |
‘X’, ‘0’, ‘1’, ‘Z’ |
INTEGER |
Whole numbers |
No quotes |
4095, 7, -120, -1 |
BIT_VECTOR |
Multiple instances of 0 or 1 |
Double quotes |
“100110” |
STD_LOGIC_VECTOR |
Multiple instances of U, |
Double |
“1001100”, |
X, 0, 1, Z, W, L, H, - |
quotes |
“00ZZ11”, |
|
“ZZZZZZZZ” |
|||
Why use STD_LOGIC rather than BIT, if we only use ‘0’ and ‘1’ values? The usual reason is for compatibility with existing VHDL components that might be used in our design entities. For example, the Altera Library of Parameterized Modules (LPM) contains
D0
D1
Y0
Y1
Y2
Y3
138 |
C H A P T E R |
4 • Introduction to PLDs and MAX+PLUS II |
|
predesigned components that are written using STD_LOGIC types. To include these com- |
|||
ponents in a VHDL design, the design must be written with STD_LOGIC types, as well. |
|||
The INTEGER type can take on whole-number values. When used in a VHDL file, an |
|||
integer is written without quotes. Table 4.1 summarizes the BIT, STD_LOGIC, and INTE- |
|||
GER types, as well as the BIT_VECTOR and STD_LOGIC_VECTOR types. |
|||
EXAMPLE 4.3 |
Figure 4.31 shows the logic diagram of a 2-line-to-4-line decoder. The circuit detects the |
||
presence of a particular binary code and makes one and only one output HIGH, depending |
|||
on the value of the 2-bit number D1D0. Write a VHDL file that describes the decoder. |
|||
two inputs and four outputs, which are numerically related. We |
|||
decode1.vhd |
|||
as separate names, as we could the four outputs. Or, we could |
|||
show the inputs and outputs as two groups of related ports, called vectors. The elements of |
|||
the vector can be treated separately or as a group. |
|||
Case 1: separate variables |
|||
LIBRARY ieee; |
|||
USE ieee.std_logic_1164.ALL; |
|||
ENTITY decode1 IS |
|||
PORT( |
||
d1, d0 |
: IN |
STD_LOGIC; |
y0, y1, y2, y3 |
: OUT |
STD_LOGIC); |
END decode1; |
decode2.vhd
decode2a.vhd
ARCHITECTURE decoder1 OF decode1 IS
BEGIN
y0 |
<= |
(not |
d1) |
and (not |
d0); |
|
y1 |
<= |
(not |
d1) |
and ( |
d0); |
|
y2 |
<= |
( |
d1) |
and |
(not d0); |
|
y3 |
<= |
( |
d1) |
and |
( |
d0); |
END decoder1;
Case 2: vectors (elements treated separately)
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY decode2 IS |
||||
PORT ( |
||||
d |
: IN |
STD_LOGIC_VECTOR (1 downto 0); |
||
y |
: OUT STD_LOGIC_VECTOR (3 downto 0)); |
|||
END decode2; |
||||
ARCHITECTURE decoder2 OF decode2 IS |
||||
BEGIN |
||||
y(0) |
<= |
(not |
d(1)) and (not d(0)); |
|
y(1) |
<= |
(not |
d(1)) and ( |
d(0)); |
y(2) |
<= |
( |
d(1)) and (not d(0)); |
|
y(3) |
<= |
( |
d(1)) and ( |
d(0)); |
END decoder2;
In Case 2, we specify the length of the vector by the construct (3 downto 0), indicating that Y3 is the leftmost bit in the vector. We could also use the constructs (0 to 3), (4 downto 1), or (1 to 4), depending on our requirements. Each individual element of the vector is specified by a number in parentheses.
Case 3: vectors (elements treated as a group)
—— decode2a.vhd
—— 4-channel decoder
4.6 • Text Design File (VHDL) |
139 |
—— Makes one and only one output HIGH for each
—— binary combination of (d1, d0).
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY decode2a IS
PORT (
d : IN STD_LOGIC_VECTOR (1 downto 0); y : OUT STD_LOGIC_VECTOR (3 downto 0));
END decode2a;
ARCHITECTURE decoder OF decode2a IS
BEGIN
——Choose a signal assignment for y
——based on binary value of d
——Default case: all outputs deactivated WITH d SELECT
y <= “0001” WHEN “00”, “0010” WHEN “01”, “0100” WHEN “10”, “1000” WHEN “11”, “0000” WHEN others;
END decoder;
In Case 3, we use a selected signal assignment statement to assign a value to all bits of vector y for each combined value of vector d. For example, when d(1) 0 and d(0) 0, the values assigned to y are: y(3) 1, y(2) 0, y(1) 0, y(0) 0. Similar assignments are made for other values of d. The result is a construct that acts much like a truth table of the decoder circuit. The others clause is necessary to define a default case
FIGURE 4.32
MAX PLUS II Template Menu
FIGURE 4.33
VHDL Template Dialog Box
140 C H A P T E R 4 • Introduction to PLDs and MAX+PLUS II
since the STD_LOGIC_VECTOR type contains values other than ‘0’ and ‘1’.
The multibit values assigned to the vectors, called bit string literals, must be enclosed
in double quotes. |
|
VHDL Templates in MAX PLUS II
MAX PLUS II offers a shortcut to creating VHDL structure in a Template Menu. Figure 4.32 shows this menu, which is available in the MAX PLUS II Text Editor window. To choose a template, select the one desired from the VHDL Template dialog box, shown in Figure 4.33.
Choosing the Entity Declaration template results in the following text:
ENTITY __entity_name IS |
||
GENERIC (__parameter_name : string |
: __default_value; |
|
__parameter_name : integer: __default_value); |
||
PORT ( |
||
__input_name, __input_name |
: IN |
STD_LOGIC; |
__input_vector_name : IN |
STD_LOGIC_VECTOR (__high |
|
downto __low); |
||
__bidir_name, __bidir_name |
: INOUT |
STD_LOGIC; |
__output_name, __output_name : OUT |
STD_LOGIC); |
|
END __entity_name; |
||
To convert this into a valid entity for our use, we delete the lines we do not need and substitute input and output names into the template. For our majority vote circuit, we had inputs called A, B, and C and an output called Y. Thus, we can modify the template to yield the entity declaration:
ENTITY maj_vot2 IS |
||||||||||||
PORT ( |
||||||||||||
a, b, c |
: IN STD_LOGIC; |
|||||||||||
INPUT |
maj_vote |
|||||||||||
A1 |
A |
|||||||||||
INPUT |
||||||||||||
B1 |
B |
Y |
||||||||||
INPUT |
AND2 |
|||||||||||
C1 |
C |
|||||||||||
OUTPUT |
||||||||||||
INPUT |
MAJ_VOT2 |
Y |
||||||||||
A2 |
a |
|||||||||||
INPUT |
y |
|||||||||||
B2 |
b |
|||||||||||
INPUT |
||||||||||||
C2 |
c |
|||||||||||
FIGURE 4.34
GDF Containing Symbols from Other GDF and VHDL Files
y : OUT STD_LOGIC);
END maj_vot2;
Integrating VHDL and Graphical Design Components
We can create a default symbol for the VHDL majority vote function, much as we did for the same function in the Graphic Design File. In the Text Editor File menu, select Create
4.7 • Creating a Physical Design |
141 |
Default Symbol. We can integrate this new symbol into a two-level majority vote circuit, as shown in Figure 4.34. This circuit contains primitives (AND gate, input pins, and output pin), a gdf symbol (maj_vote), and a symbol created from a VHDL file (MAJ_VOT2). Double-clicking on either symbol will bring forward its original design file.
4.7 Creating a Physical Design
K E Y T E R M S
Assignment and Configuration File (acf) A MAX PLUS II file that contains information about the configuration options for a project, including assigned device and pin numbers.
FIGURE 4.35
Pop-up Menu for Pin Assignments
The previous sections have concentrated on the design aspects of a project. Of course, the ultimate goal of this procedure is to create a physical version of the design. Before we can program our majority vote circuit into hardware, we must assign the input and output pin numbers on the target CPLD. At that point we can recompile the design file and program the CPLD.
Assigning Pin Numbers
Before proceeding with this step, make sure that you have assigned a device part number to the design. Save the file and set the project to the current file.
To assign a pin number, click on the pin to highlight it, then right-click to see the popup menu in Figure 4.35. Choose Assign, then Pin/Location/Chip. You could also do this from the Assign menu at the top of the screen.
142 C H A P T E R 4 • Introduction to PLDs and MAX+PLUS II
FIGURE 4.36
Pin/Location/Chip Assignment
Dialog Box
Table 4.2 Pin Assignment for a Majority Vote Circuit
Pin Name |
Pin Number |
A1 |
12 |
B1 |
16 |
C1 |
18 |
A2 |
15 |
B2 |
17 |
C2 |
21 |
Y |
4 |
FIGURE 4.37
Pin Assignments in ACF (Before
Copying)
4.7 • Creating a Physical Design |
143 |
FIGURE 4.38
Pin Assignments in ACF (After Copying)
FIGURE 4.39
Pin Assignments as Seen in gdf File
We can assign pin numbers in the dialog box in Figure 4.36.
Type A1 in the Node Name box, 12 in the Pin box and click Add. Type B1 in the Node Name box, assign this name to pin 16, and click Add. Repeat this procedure until all names are assigned, as in Table 4.2. When all assignments are complete, click OK.
We can also assign pin numbers by editing the Assignment and Configuration File (acf), as shown in Figures 4.37 and 4.38. This technique works especially well if you need to assign pin numbers to a sequence of numerically related inputs and outputs.
Figure 4.37 shows the acf with four pin assignments made. We can add the others easily by using a copy-and-paste procedure. Highlight the line you wish to copy and copy it to the Windows clipboard (use Copy in the File menu or the Copy icon on the toolbar or Ctrl-C). Paste three copies into the acf and modify them so that they represent the remaining required pin assignments, as shown in Figure 4.38.
Figure 4.39 shows the input pin assignments as they appear in the gdf file.