Professional Documents
Culture Documents
Chapter6c-Combinational Logic Design Practices
Chapter6c-Combinational Logic Design Practices
Chapter6c-Combinational Logic Design Practices
4 Encoders in VHDL
Behavioral VHDL program for a 8-input priority encoder
library IEEE;
use IEEE.std_logic_1164.all;
entity V74x148 is
port (
EI_L: in STD_LOGIC;
I_L: in STD_LOGIC_VECTOR (7 downto 0);
A_L: out STD_LOGIC_VECTOR (2 downto 0);
EO_L, GS_L: out STD_LOGIC
);
end V74x148;
architecture V74x148h of V74x148 is
signal EI : STD_LOGIC; --active-high version of input
signal I : STD_LOGIC_VECTOR(7 downto 0); --active-high version of inputs
signal EO, GS : STD_LOGIC; --active-high version of output
Signal A : STD_LOGIC_VECTOR(2 downto 0); --active-high version of outputs
begin
process (EI_L, I_L, EI, EO, GS, I, A)
variable j: INTEGER range 7 downto 0;
begin
EI <= not EI_L; --convert input
I <= not I_L; --convert inputs
EO <= '1'; GS <= '0'; A <= "000";
if (EI)='0' then EO <= '0';
else for j in 7 downto 0 loop
if I(j)='1' then
GS <= '1'; EO <= '0'; A <= CONV_STD_LOGIC_VECTOR(j,3);
exit;
end if;
end loop;
end if;
EO_L<=not EO; --convert output
GS_L<=not GS; --convert output
A_L<=not A; --convert outputs
end process;
end V74x148h;
6.6 Three-state Devices
8-to-1 MUX
Inputs
D0 0
D1 8:1
1
... MUX
D6
...
6 Y Output
D7 7
S2 S1 S0
Select
CBA
8-to-1
MUX
Circuit
6.7.2 Expanding Multiplexers
S1 S 0
Expanding
Multiplexers
6.7.3 Demultiplexers
Demultiplexers are digital switches connect data from one input
source to one of n outputs.
Usually implemented by using n-to-2n binary decoders where the
decoder’s enable line is used for data input of the demultiplexer.
2X4
Select Decoder
s bits Demux b bits lines One of
Select four 1-bit
One of n outputs
Y0 = D·S1'·S0' S1 So Y0 Y1 Y2 Y3
0 0 D 0 0 0
Y1 = D·S1'·S0
Data D demux
0 1 0 D 0 0
Y2 = D·S1·S0' 1 0 0 0 D 0
1 1 0 0 0 D
Y3 = D·S1·S0
S1 S0
select
Y0 = D·S1'·S0'
2x4
S1 Decoder Y1 = D·S1'·S0
S0 Y2 = D·S1·S0'
E Y3 = D·S1·S0
D
Mux-Demux Application
Example
(1) F AB BC AC
( 2) F (0,3,5,8,10,11,14 ) x (1,6,13)
Solution
: Transform the logic function
E
(1) F AB BC AC D0
ABC ABC ' A' BC AB ' C D1
D2
(3,5,6,7) F
D3
D4
D5
Number of variables D6
equal to number of D7
A2 A1 A0
address
Explanation : determine
the address and input
The output function expression of 8-1 multiplexer is :
7
Y mi Di A2 ' A1 ' A0 ' D0 A2 ' A1 ' A0 D1 A2 ' A1 A0 ' D2 A2 ' A1 A0 D3
i 0
E
D0
D0=0 D1=0 D1
D2
D2=0 D3=1 D3 F
D4
D5
D4=0 D5=1
D6
D7
D6=1 D7=1 A2 A1 A0
1 A B C
Implement logic function using Multiplexers
(continue)
AB00 01 11 10
CD
00 1 1
10 x 1 1
Comparing expressions
A
B C D
Implement logic function using Multiplexers
(Example 2)
F ( X ,Y , Z ) (1,2,3,4,5,6)
Solution
: Transform the logic function
F ( X , Y , Z ) (1,2,3,4,5,6)
XY00 01 11 10
Z
0 1 1 1
X ' Z X ' Y XY ' XZ '
1 1 1 1
3
Y m D
i0
i i A1 ' A0 ' D0 A1 ' A0 D1 A1 A0 ' D 2 A1 A0 D3
((X(XY)’)’)’+((Y(XY)’)’)’
= X(XY)’+Y(XY)’
= XY’+X’Y
6.8.2 Parity Circuits
Odd parity circuit (its output is 1 if an odd
number of its inputs are 1)
Detects any single-bit error
Parity tree
Faster with balanced tree structure
6.8.6 Parity Circuits in VHDL
Behavioral VHDL for 9-input parity checker
library IEEE;
use IEEE.std_logic_1164.all;
entity parity9 is
port (
I: in STD_LOGIC_VECTOR (1 to 9);
EVEN, ODD: out STD_LOGIC );
end parity9;
architecture parity9p of parity9 is
begin
process (I)
variable p : STD_LOGIC;
begin
p := I(1);
for j in 2 to 9 loop
if I(j) = '1' then p := not p;
end if;
end loop;
ODD <= p;
EVEN <= not p;
end process;
end parity9p;
architecture parity9p of parity9 is
begin
example: I =“100110101”
process (I) I(1) … I(9)
variable p : STD_LOGIC; p j I(j) p:=not p
begin ‘1’
p := I(1);
for j in 2 to 9 loop
if I(j) = '1' then p := not p;
end if;
end loop;
ODD <= p;
EVEN <= not p;
end process;
end parity9p;
architecture parity9p of parity9 is
begin
example: I =“100110101”
process (I) I(1) … I(9)
variable p : STD_LOGIC; p j I(j) p:=not p
begin ‘1’
p := I(1); ‘1’ 2 ‘0’ --
for j in 2 to 9 loop
if I(j) = '1' then p := not p;
end if;
end loop;
ODD <= p;
EVEN <= not p;
end process;
end parity9p;
architecture parity9p of parity9 is
begin
example: I =“100110101”
process (I) I(1) … I(9)
variable p : STD_LOGIC; p j I(j) p:=not p
begin ‘1’
p := I(1); ‘1’ 2 ‘0’ --
for j in 2 to 9 loop ‘1’ 3 ‘0’ --
if I(j) = '1' then p := not p;
end if;
end loop;
ODD <= p;
EVEN <= not p;
end process;
end parity9p;
architecture parity9p of parity9 is
begin
example: I =“100110101”
process (I) I(1) … I(9)
variable p : STD_LOGIC; p j I(j) p:=not p
begin ‘1’
p := I(1); ‘1’ 2 ‘0’ --
for j in 2 to 9 loop ‘1’ 3 ‘0’ --
if I(j) = '1' then p := not p; ‘1’ 4 ‘1’ ‘0’
end if;
end loop;
ODD <= p;
EVEN <= not p;
end process;
end parity9p;
architecture parity9p of parity9 is
begin
example: I =“100110101”
process (I) I(1) … I(9)
variable p : STD_LOGIC; p j I(j) p:=not p
begin ‘1’
p := I(1); ‘1’ 2 ‘0’ --
for j in 2 to 9 loop ‘1’ 3 ‘0’ --
if I(j) = '1' then p := not p; ‘1’ 4 ‘1’ ‘0’
end if; ‘0’ 5 ‘1’ ‘1’
end loop;
ODD <= p;
EVEN <= not p;
end process;
end parity9p;
architecture parity9p of parity9 is
begin
example: I =“100110101”
process (I) I(1) … I(9)
variable p : STD_LOGIC; p j I(j) p:=not p
begin ‘1’
p := I(1); ‘1’ 2 ‘0’ --
for j in 2 to 9 loop ‘1’ 3 ‘0’ --
if I(j) = '1' then p := not p; ‘1’ 4 ‘1’ ‘0’
end if; ‘0’ 5 ‘1’ ‘1’
end loop; ‘1’ 6 ‘0’ --
‘1’ 7 ‘1’ ‘0’
ODD <= p;
‘0’ 8 ‘0’ --
EVEN <= not p;
‘0’ 9 ‘1’ ‘1’
end process;
end parity9p;
architecture parity9p of parity9 is
begin
example: I =“100110101”
process (I) I(1) … I(9)
variable p : STD_LOGIC; p j I(j) p:=not p
begin ‘1’
p := I(1); ‘1’ 2 ‘0’ --
for j in 2 to 9 loop ‘1’ 3 ‘0’ --
if I(j) = '1' then p := not p; ‘1’ 4 ‘1’ ‘0’
end if; ‘0’ 5 ‘1’ ‘1’
end loop; ‘1’ 6 ‘0’ --
‘1’ 7 ‘1’ ‘0’
ODD <= p;
‘0’ 8 ‘0’ --
EVEN <= not p;
‘0’ 9 ‘1’ ‘1’
end process;
end parity9p; ODD <=‘1’, EVEN<=‘0’
6.9 Comparators
6.9.1 Structure
1-bit comparator
( The active-high
output is asserted
if the inputs are
different )
4-bit comparator
6.9.2 Iterative Circuits
Cascaded by n identical modules
6.9.3 Iterative Comparator Circuit
Compare two n-bit values X and Y
6.9.4 8-bit Magnitude
Comparator
Asserted if all 8
input pairs are equal.
Asserted if
P[7-0]>Q[7-0]