Beginning FPGA Programming - Partie34
Beginning FPGA Programming - Partie34
Using Boolean algebra to directly describe the combinational logic in VHDL (VHSIC (very high speed
integrated circuit) Hardware Description Language) may not be a good idea for a design that has more than
four inputs. When the combinational logic design has more than four inputs, the “logic” behind the design
tends to become difficult for other designers to understand. Let's do a quick test. Do you know what the code
in Listing 9-1 describes?
entity code_9_1 is
port (
a_input: in std_logic_vector(1 downto 0); -- 2 bit inputs
b_output: out std_logic_vector(3 downto 0) -- 4 bit outputs
);
end code_9_1;
end behavioral;
Listing 9-1 is a 2-to-4 decoder. Table 9-1 shows the decoder function. You can easily understand the
function of the design when you see the contents of Table 9-1. This is why VHDL provides a couple of ways
to make it easier for humans to understand the combinational logic/Boolean algebra design. Some call
these methods “Concurrent statements.” Following are the most frequently used concurrent statements. As a
quick reminder, there are only two types of statements that you will see a lot in FPGA design. One type is the
concurrent statement and the other is the sequential statement which we will discuss more in Chapter 10.
■■Tip You can use Quartus to show the VHDL in logic gate view. See the following steps.
1.
Save the code from Listing 9-1 into a code_9_1.vhd file and add it to the Quartus
project (Please see Chapter 8 on how to create a project and how to add files)
2.
Set code_9_1.vhd as Top-Level Entity, as shown in Figure 9-1
3.
Click Processing from the menu and click Start compilation (CTRL +L)
4.
After the compilation is done, switch to Hierarchy mode in the Project Navigator
(A in Figure 9-2)
160
Chapter 9 ■ Simplifying Boolean Algebra for FPGA
5.
Right-click the code_9_1 design, click Locate Node, and select Locate in RTL
Viewer (B in Figure 9-2)
Figure 9-3 is the RTL Viewer for the gate logic described in Listing 9-1.
161
Chapter 9 ■ Simplifying Boolean Algebra for FPGA
9.1 Concurrent Statements
In a programming language, program code or statements are processed one statement at a time
(assuming you are using a single-core processor). Each statement needs to wait for the previous statement
to finish. This is good for programming language, which is used to represent a list of instructions for a
processor to execute. It is also easy for humans to write programs like this because we are normally doing
one thing at a time.
VHDL does things differently. Where processors execute statements one at a time, VHDL has the
capability of executing a huge number of statements in parallel. This means that VHDL can run statements
in parallel. Keep in mind that VHDL is used to design real hardware. Running statements (hardware) in
parallel is a piece of cake. If you want to fully unlock the capability of the FPGA (field-programmable gateway
array), then you need to understand the following concurrent signal assignment methods.
In VHDL, most of the concurrent statements exist between begin and end. It is like the code in Listing 9-2.
All four statements are running at the same time. It means that at the same time, b_output(0), b_output(1),
b_output(2), and b_output(3) are updated when a_input(0) and a_input(1) change. The order of these
four statements will NOT create any difference in the final result. These kinds of statements are using
concurrent signal assignment.
end process;
The following sections introduce three more signal assignment operators used in concurrent
statements: When-Else, With-Select, and Case.
■■Tip The order of concurrent statements will have no impact whatsoever on the final result.
162
Chapter 9 ■ Simplifying Boolean Algebra for FPGA
If the first condition (condition_1) is fulfilled, then the assign_value_1 will be assigned to the signal_get_
assignment. If the first condition is not fulfilled and the second condition is fulfilled, then the assign_value_2
will be assigned and drive the output signal_get_assignment. Follow this logic, until all of the conditions
(n-1) are not met, and then assign_value_n will drive the signal_get_assignment. Now let’s see how to use
when/else to do the same thing as the code in Listing 9-1.
Listing 9-4 is an example of using WHEN ELSE to create the same multiplexer as Listing 9-1. Figure 9-4
is the RTL view of the WHEN ELSE design. If you compare it with Figure 9-3, then you will find they are not
the same hardware but similar logic function.
entity when_else_combination is
port (
a_input: in std_logic_vector(1 downto 0); -- 2 bit inputs
b_output: out std_logic_vector(3 downto 0) -- 4 bit outputs
);
end when_else_combination;
Figure 9-4. RTL view of WHEN ELSE combination code in Listing 9-4
There is another example code which is using a WHEN ELSE statement. It is a multiplexer (MUX) with
four 8-bit input selection and one 8-bit output.
163