Professional Documents
Culture Documents
1
The VHDL statements when and select can be employed in concurrent VHDL codes.
These statements are not used in sequential, i.e., clocked, program units.
We can employ VHDL statements when and select for the implementation of
combinational circuits. These statements are employed for the conditional
implementation of the logic circuits.
2
The syntax of the when statement is as follows:
3
The syntax of the select statement is as follows:
4
Example-2.1: Implement the Boolean function 𝑓 𝑥, 𝑦, 𝑧 = 𝑥 ′ 𝑦 ′ + 𝑦′𝑧 using logical
operators.
Solution-2.1: The Boolean function 𝑓 𝑥, 𝑦, 𝑧 = 𝑥 ′ 𝑦 ′ + 𝑦′𝑧 can be implemented using logical
operators as
f<=(not(x) and not(y)) or (not(y) and z)
begin
f<=(not(x) and not(y)) or (not(y) and z);
5
end architecture;
Example-2.2: The truth table of a Boolean function is given as
x y z f ( x, y , z )
0 0 0 1
0 0 1 1
0 1 0 0
0 1 1 0
1 0 0 0
1 0 1 1
1 1 0 0
1 1 1 0
6
Solution-2.2: With when statement, it can be implemented as
7
Example-2.3: Implement the Boolean function 𝑓 𝑥, 𝑦, 𝑧 = 𝑥 ′ 𝑦 ′ + 𝑦′𝑧 using when statement.
Solution-2.3: First, let's construct the truth table of the Boolean function 𝑓 𝑥, 𝑦, 𝑧 = 𝑥 ′ 𝑦 ′ +
𝑦′𝑧.
If the Boolean function 𝑓 𝑥, 𝑦, 𝑧 = 𝑥 ′ 𝑦 ′ + 𝑦′𝑧 is inspected in details, we see that the function
takes the value of 1 for 𝑥 = 𝑦 = 0 or for 𝑦 = 0, 𝑧 = 1.
Considering this information, we can make the truth table of the given Boolean function as in
Table 2-2
8
Table 2-2 Truth table of 𝑓 = 𝑥 ′ 𝑦 ′ + 𝑦′𝑧.
x y z f ( x, y , z )
0 0 0 1
0 0 1 1
0 1 0 0
0 1 1 0
1 0 0 0
1 0 1 1
1 1 0 0
1 1 1 0
9
Regarding the truth table, we can write VHDL program with when statement as in PR 2.2.
entity f_function is
port( x, y, z: in bit;
f: out bit );
end entity;
begin
f<='1' when (x='0' and y='0' and z='0') else
'1' when (x='0' and y='0' and z='1') else
'1' when (x='1' and y='0' and z='1') else
'0';
end architecture;
PR 2.2 Program 2.2. 10
The program in PR 2.2 can also be written as in PR 2.3.
entity f_function is
port( xyz: in bit_vector(2 downto 0);
f: out bit );
end entity;
begin
f<='1' when (xyz(2)='0' and xyz(1)='0' and xyz(0)='0') else
'1' when (xyz(2)='0' and xyz(1)='0' and xyz(0)='1') else
'1' when (xyz(2)='1' and xyz(1)='0' and xyz(0)='1') else
'0';
end architecture;
PR 2.3 Program 2.3.
11
Example-2.4: We can implement the Boolean function 𝑓 𝑥, 𝑦, 𝑧 = 𝑥 ′ 𝑦 ′ + 𝑦′𝑧 using
select statement as in PR 2.4.
entity f_function is
port( x, y, z: in bit;
f: out bit );
end entity;
begin
with (x&y&z) select
f<='1' when "000",
'1' when "001",
'1' when "101",
'0' when others;
end architecture;
12
PR 2.4 Program 2.4.
Example-2.5: Implement the function in equation below using VHDL
Solution-2.5: The real valued function given in the question can be implemented in VHDL as in
PR 2.5
13
entity fx_function is
port( x: in integer;
y: out integer range 0 to 4);
end entity;
begin
with x select
y <= 2 when 1 | 2,
4 when 3 to 6,
0 when others;
end architecture;