Sistemas Digitais
2/51
Objetivos do laboratrio
1. Entender o conceito de circuitos codificadores e
decodificadores (conversores de cdigo).
2. Implementao de codificadores e decodificadores
em VHDL.
3/51
4/51
C1
C
B
A
F1
SW(2)
SW(1)
Mux 4x1
SW(0)
LEDR(7)
LEDR(6)
LEDR(5)
LEDR(4)
LEDR(3)
LEDR(2)
LEDR(1)
LEDR(0)
C2
F2
0
C3
00
01
10
11
F
2 bits
F3
Seleo
SW(17..16)
5/51
C1
C
B
A
SW(11..8)
SW(7..4)
SW(3..0)
4 bits
F1
4 bits
4 bits
Mux 4x1
4 bits
C2
F2
4 bits
C3
00
01
10
11
4
bits
LEDR(7)
LEDR(6)
LEDR(5)
LEDR(4)
LEDR(3)
LEDR(2)
LEDR(1)
LEDR(0)
2 bits
F3
4 bits
Seleo
SW(17..16)
6/51
4 bits
0
1
0101
1000
0001
1000
0001
F2 = 1
F1 = 1101
F2 = 1001
7/51
8/51
Componente C1
library IEEE;
use IEEE.Std_Logic_1164.all;
4 bits
entity C1 is
port (A: in std_logic_vector(3 downto 0);
B: in std_logic_vector(3 downto 0);
C: in std_logic_vector(3 downto 0);
F: out std_logic_vector(3 downto 0)
);
end C1;
architecture c1_estr of C1 is
begin
F <= A or B or C;
end c1_estr;
4 bits
EEL7020 Sistemas Digitais
9/51
Componente C2
library IEEE;
use IEEE.Std_Logic_1164.all;
4 bits
entity C2 is
port (A: in std_logic_vector(3 downto 0);
B: in std_logic_vector(3 downto 0);
F: out std_logic_vector(3 downto 0)
);
end C2;
architecture c2_estr of C2 is
begin
F <= A xor B;
end c2_estr;
4 bits
10/51
Componente C3
library IEEE;
use IEEE.Std_Logic_1164.all;
4 bits
entity C3 is
port (A: in std_logic_vector(3 downto 0);
B: in std_logic_vector(3 downto 0);
C: in std_logic_vector(3 downto 0);
F: out std_logic_vector(3 downto 0)
);
end C3;
architecture c3_estr of C3 is
begin
-- ver lab. sobre componentes
end c3_estr;
11/51
Componente Mux
library IEEE;
use IEEE.Std_Logic_1164.all;
4 bits
entity Mux is
port (w: in std_logic_vector(3 downto 0);
x: in std_logic_vector(3 downto 0);
y: in std_logic_vector(3 downto 0);
z: in std_logic_vector(3 downto 0);
s: in std_logic_vector(1 downto 0);
m: out std_logic_vector(3 downto 0)
);
end Mux;
architecture mux_bhv of Mux is
begin
-- ver lab. sobre Mux
end mux_bhv;
2 bits
F1
F2
F3
sel
12/51
Componente Topo
library ieee;
use ieee.std_logic_1164.all;
entity topo is
port ( SW : IN STD_LOGIC_VECTOR(17 downto 0);
SW(11..8)
SW(7..4)
SW(3..0)
F1
LEDR(3..0)
F2
);
end topo;
architecture topo_estru of topo is
signal F1, F2, F3: std_logic_vector(3 downto 0);
component C1
port (A : in std_logic_vector(3 downto 0);
B : in std_logic_vector(3 downto 0);
C : in std_logic_vector(3 downto 0);
F : out std_logic_vector(3 downto 0));
end component;
component C2
port (A : in std_logic_vector(3 downto 0);
B : in std_logic_vector(3 downto 0);
F : out std_logic_vector(3 downto 0));
end component;
component C3
port (A : in std_logic_vector(3 downto 0);
B : in std_logic_vector(3 downto 0);
C : in std_logic_vector(3 downto 0);
F : out std_logic_vector(3 downto 0)
);
end component;
-- INCLUIR AQUI O Mux
F3
SW(17..16)
begin
L0: C1 port map (SW(3 downto 0),
SW(7 downto 4), SW(11 downto 8), F1);
-- END da architecture
13/51
Decodificadores em VHDL
14/51
Display de 7-segmentos
Um display de 7-segmentos composto por sete LEDs que podem ser
ligados ou desligados de forma independente.
a
b
f
f
b
g
g
g
c
e
e
e
c
d
d
d
Catodo comum
EEL7020 Sistemas Digitais
d
Anodo Comum
15/51
Decod.
7-seg
16/51
Decod.
7-seg
C2
0
0
0
0
1
C1 C0
0 0
0 1
1 0
1 1
1 1
7 bits
6543210
1000001
0001110
0010010
1000110
1111111
Letra
U
F
S
C
17/51
18/51
Componente Decod_UFSC
Decod.
7-seg
library IEEE;
use IEEE.Std_Logic_1164.all;
entity decodUFSC is
port (C: in std_logic_vector(2 downto 0);
F: out std_logic_vector(6 downto 0)
);
7 bits
end decodUFSC;
architecture decod_bhv of
begin
F <= "1000001" when C =
"0001110" when C =
"0010010" when C =
"1000110" when C =
"1111111";
end decod_bhv;
3 bits
decodUFSC is
"000"
"001"
"010"
"011"
else
else
else
else
-----
U
F
S
C
19/51
20/51
21/51
Operao
SW(17..16)
Operando B
SW(15..8)
Resultado
LEDR(7..0)
Operando A
SW(7..0)
22/51
Operao
SW(17..16)
Operando B
SW(15..8)
Seletor SW(17..16)
00
01
10
11
Resultado
LEDR(7..0)
Operando A
SW(7..0)
23/51
Operando B
SW(15 downto 8)
Operando A
SW(7 downto 0)
FPGA
Componente
TOP_CALC
(esse componente possui 7
componentes internamente)
LEDR(7 downto 0)
Seleo da operao
SW(17 downto 16)
24/51
SW(15 downto 8)
Operando A
SW(7 downto 0)
f=A+B
Operando B
8
8
F1
F2
F3
FPGA
f = not A
F = A xor B
F4
Seleo da operao
(+, or, xor, not)
f = A or B
F(7 downto 4)
Decod.
7-seg
00
01
Mux
10
Decod.
4
F(3 downto 0)
11
7-seg
sel
LEDR(7 downto 0)
8
top_calc.vhd
25/51
Projeto hierrquico
Calculadora composta
por 8 componentes,
sendo 7 apresentados a
seguir + o top_calc.
26/51
Projeto hierrquico
27/51
Projeto hierrquico
28/51
entity C1 is
port (A: in std_logic_vector(7 downto 0);
B: in std_logic_vector(7 downto 0);
F: out std_logic_vector(7 downto 0)
);
end C1;
f=A+B
library IEEE;
use IEEE.Std_Logic_1164.all;
use IEEE.std_logic_unsigned.all; -- necessrio para o +
architecture circuito of C1 is
begin
F <= A + B;
end circuito;
29/51
architecture circuito of C2 is
begin
F <= A or B;
end circuito;
f = A or B
entity C2 is
port (A: in std_logic_vector(7 downto 0);
B: in std_logic_vector(7 downto 0);
F: out std_logic_vector(7 downto 0)
);
end C2;
30/51
architecture circuito of C3 is
begin
F <= A xor B;
end circuito;
F = A xor B
entity C3 is
port (A: in std_logic_vector(7 downto 0);
B: in std_logic_vector(7 downto 0);
F: out std_logic_vector(7 downto 0)
);
end C3;
31/51
F = not A
architecture circuito of C4 is
begin
F <= not A;
end circuito;
32/51
architecture circuito
begin
m <= w when s = "00"
x when s = "01"
y when s = "10"
z;
end circuito;
of mux4x1 is
else
else
else
33/51
Componente Decod7seg
8
8
8
F(7 downto 4)
f = A or B
f=A+B
F1
F2
F3
f = not A
F = A xor B
F4
Decod.
7-seg
00
01
Mux
10
Decod.
F(3 downto 0)
11
7-seg
2
8
sel
34/51
begin
Dicas teis
1. O projeto composto por 7 arquivos (8 componentes):
c1.vhd fornecido nos slides anteriores (slide 29)
c2.vhd fornecido nos slides anteriores (slide 30)
c3.vhd fornecido nos slides anteriores (slide 31)
c4.vhd fornecido nos slides anteriores (slide 32)
mux4x1.vhd fornecido nos slides anteriores (slide 33)
decod7seg.vhd a ser desenvolvido (ver exemplo no slide 19)
top_calc.vhd parcialmente fornecido nos slides anteriores (slide 35)
2. Cuidar a utilizao correta do componente decodificador no circuito (topo).
necessrio definir apenas um component decod7seg, e a seguir criar
duas cpias desse componente com o port map (ver top_calc no slide 35).
3. Para implementar o decodificador de binrio para 7-segmentos, utilizar
como base o exemplo do slide 19. Completar a tabela do slide 38, de forma
a obter todos os cdigos em hexadecimal necessrios.
EEL7020 Sistemas Digitais
36/51
Componente Decod7seg
Componente a ser desenvolvido no presente lab.:
Est sendo solicitada a implementao de apenas UM decodificador
Decod.
4
7-seg
37/51
Sada
6543210
Display
0000
1000000
0001
0010
0011
1111001
0100100
0110000
1
2
3
0100
0101
0110
0011001
0010010
0000010
4
5
6
0111
1000
1111000
0000000
7
8
...
...
9, A, b, C, d
1110
1111
0000110
0001110
EEL7020 Sistemas Digitais
E
F
38/51
39/51
end topo_stru;
top_calc
-- END da architecture
EEL7020 Sistemas Digitais
40/51
f=A+B
begin
F1
end topo_stru;
-- END da architecture
EEL7020 Sistemas Digitais
41/51
8
8
end topo_stru;
f = A or B
f=A+B
begin
F1
F2
top_calc
-- END da architecture
EEL7020 Sistemas Digitais
42/51
8
8
f = A or B
f=A+B
begin
F1
F2
8
8
end topo_stru;
F = A xor B
F3
top_calc
-- END da architecture
EEL7020 Sistemas Digitais
43/51
8
8
f = A or B
f=A+B
begin
F2
f = not A
F = A xor B
F3
end topo_stru;
F1
F4
-- END da architecture
EEL7020 Sistemas Digitais
top_calc
44/51
8
8
f = A or B
f=A+B
begin
8
8
end topo_stru;
f = not A
F = A xor B
F1
00
F2
01
F3
Mux
F4
10
F
8
11
2
8
sel
-- END da architecture
EEL7020 Sistemas Digitais
top_calc
45/51
8
8
f = A or B
f=A+B
begin
end topo_stru;
f = not A
F = A xor B
F1
00
F2
01
F3
Mux
F4
10
F
8
Decod.
4
7-seg
F(3 downto 0)
11
2
8
sel
-- END da architecture
EEL7020 Sistemas Digitais
top_calc
46/51
8
F(7 downto 4)
8
8
f = A or B
f=A+B
begin
F = A xor B
F1
7-seg
00
F2
01
F3
Mux
F4
Decod.
10
F
8
Decod.
4
7-seg
F(3 downto 0)
11
2
8
sel
end topo_stru;
f = not A
-- END da architecture
EEL7020 Sistemas Digitais
top_calc
47/51
8
F(7 downto 4)
8
8
f = A or B
f=A+B
begin
F = A xor B
F1
7-seg
00
F2
01
F3
Mux
F4
Decod.
10
F
8
Decod.
4
7-seg
F(3 downto 0)
11
2
8
sel
end topo_stru;
-- END da architecture
f = not A
top_calc
48/51
Operando B
SW(15 downto 8)
Operando A
SW(7 downto 0)
f=A+B
Mini-calculadora de 8 bits
8
8
8
Seleo da operao
(+, or, xor, not)
F = A xor B
f = not A
f = A or B
F(7 downto 4)
F1
7-seg
00
F2
01
F3
Mux
F4
Decod.
10
Decod.
7-seg
F(3 downto 0)
11
2
8
sel
LEDR(7 downto 0)
8
top_calc
49/51
Simulao
50/51
Tabela verdade
Entradas
SW15..0
B A
00
02
05
05
05
05
00
FF
00
03
0A
FF
00
0A
0A
F5
SW17..16
Seleo
00
00
01
01
10
10
11
11
Sadas
F1 = A + B
F2 = A or B
F3 = A xor B
F4 = not A
F1 =
F1 =
F2 =
F2 =
F3 =
F3 =
F4 =
F4 =
Simulao
Simulao
FPGA
FPGA
HEX1 HEX0
LEDR6..0
HEX1 HEX0
LEDR6..0
51/51