Beginning FPGA Programming - Partie35.1
Beginning FPGA Programming - Partie35.1
entity when_else_mux is
port (
mux_sel: in std_logic_vector(1 downto 0); -- 2 bit MUX Select
a_input: in std_logic_vector(7 downto 0);
b_input: in std_logic_vector(7 downto 0);
c_input: in std_logic_vector(7 downto 0);
d_input: in std_logic_vector(7 downto 0);
m_output: out std_logic_vector(7 downto 0)
);
end when_else_mux;
Listing 9-7 shows the exact same function as Listing 9-1 but using With/Select.
164
Chapter 9 ■ Simplifying Boolean Algebra for FPGA
entity with_select_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 with_select_combination;
Figure 9-5. RTL view of WITH SELECT combination code Listing 9-7
165
Chapter 9 ■ Simplifying Boolean Algebra for FPGA
From the differences between Figure 9-4 and Figure 9-5, you can tell that there is something different
between the two concurrent statements approach. The first one (WHEN/ELSE methods) added a priority
condition in the input. The logic will check condition_1 first. If it passes then the result will send to the
output (the Equal3 condition from Figure 9-4). For the WITH SELECT combination code, it uses MUX to
implement the design without any priority decoding. The WITH/SELECT statement can ONLY depend on
the value of a single expression. WHEN/ELSE statements, however, can depend on the values of multiple
expressions.
Listing 9-8 uses the same example for MUX with a four 8-bit input selection and one 8-bit output, this
time using a select statement. Figure 9-6 shows the RTL of the MUX design using WITH SELECT design.
entity with_select_mux is
port (
mux_sel: in std_logic_vector(1 downto 0); -- 2 bit inputs MUX select
a_input: in std_logic_vector(7 downto 0);
b_input: in std_logic_vector(7 downto 0);
c_input: in std_logic_vector(7 downto 0);
d_input: in std_logic_vector(7 downto 0);
m_output: out std_logic_vector(7 downto 0)
);
end with_select_mux;
166
Chapter 9 ■ Simplifying Boolean Algebra for FPGA
Figure 9-6. RTL view of WITH SELECT combination code Listing 9-8
167
Chapter 9 ■ Simplifying Boolean Algebra for FPGA
■■Tip Remember to add when others at the end of the alternative list.
The case statement is a good example to show the difference between programming software and
designing hardware. In the C programming language, switch case statements are examined from top to
bottom. In VHDL, all the cases are examined at the same time. C programs are limited by the processor only
allowing comparison of a limited number (most of the time it is one) of condition and branch locations. In
hardware design, we can design as many conditions and branches as we want.
Listing 9-10 shows the exact same function as described in Listing 9-1 except here we are using case
statements. The case statements need to be within the process begin and end process keywords. The
process must be sensitive to all the inputs (in this case a_input), because the output of the decoder (b_
output) must change when a_input changes.
entity case_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 case_combination;
end behavioral;
168