Sunteți pe pagina 1din 39

Electrnica Digital

BOLILLA N5 DISEO LGICO COMBINACIONAL


Diagramas de tiempo. Tiempo de propagacin.
Buses
Arquitecturas bsicas de circuitos combinacionales.
Decodificadores Codificadores. Multiplexores. Compuertas OR-
exclusiva. Comparadores, Sumadores y ALU.
Descripcin en VHDL
Dispositivos de tres estados.
MULTIPLEXORES

entradas salida

seleccin

D0

Multiplexor Q
Dn

seleccin
MULTIPLEXORES

Si tienen n lneas de seleccin puede tener hasta 2n entradas

Para n=1
A B sel Q
A 0 0 0 0
0 0 1 0
Mux Q 0 1 0 0
0 1 1 1
2a1
1 0 0 1
B
1 0 1 0
1 1 0 1
1 1 1 1
sel

sel out
0 A
1 B
A B sel Q
0 0 0 0 AB
0 0 1 0 00 01 11 10
sel
0 1 0 0
0 0 0 1 1
0 1 1 1
1 0 0 1 1 0 1 1 0
1 0 1 0
1 1 0 1
1 1 1 1 Q = A.sel + B.sel

En vhdl

Q <= A when sel=0 else B;


MULTIPLEXORES

74xx151
MULTIPLEXORES

MULTIPLEXOR COMO GENERADOR DE FUNCIONES

F(x,y,z)=(0,1,5,6)

I0
I1
I2 F(x,y,z)
I3
I4
I5
I6
I7

ABC
"0"

x y z
MULTIPLEXORES

Un multiplexor de 2n entradas puede realizar cualquier funcin de n+1 variables

Ej F(x,y,z)= (0,1,5,6)
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 1
1 1 1 0

y z F(x,y,z)
0 0 F1(x)= x
0 1 F2(x)= 1
1 0 F3(x)= x
1 1 F4(x)= 0
DEMULTIPLEXORES

Tiene la funcin opuesta el multiplexor, el dato de la entrada se lleva a la salida determinada


por las lneas de seleccin

dato A B Y0 Y1 Y2 Y3
0 0 0 0 0 0 0
dato
Y0 0 0 1 0 0 0 0
Y1 0 1 0 0 0 0 0

Y2 0 1 1 0 0 0 0
1 0 0 1 0 0 0
A Y3
B 1 0 1 0 1 0 0
1 1 0 0 0 1 0
1 1 1 0 0 0 1
DEMULTIPLEXORES
dato
Y0
Y1 library IEEE;
Y2 use IEEE.STD_LOGIC_1164.ALL;
A Y3
B
entity demux is
Port ( dato : in STD_LOGIC;
a : in STD_LOGIC;
b : in STD_LOGIC;
Y : out STD_LOGIC_VECTOR(3 downto 0));
dato A B Y0 Y1 Y2 Y3 end demux;
0 0 0 0 0 0 0
architecture Behavioral of demux is
0 0 1 0 0 0 0
begin
0 1 0 0 0 0 0 Y(0) <= dato when (b='0' and a='0') else '0';
0 1 1 0 0 0 0 Y(1) <= dato when (b='0' and a='1') else '0';
1 0 0 1 0 0 0 Y(2) <= dato when (b='1' and a='0') else '0';
Y(3) <= dato when (b='1' and a='1') else '0';
1 0 1 0 1 0 0
1 1 0 0 0 1 0 end Behavioral;
1 1 1 0 0 0 1
EJEMPLO DE APLICACIN MULTIPLEXOR Y DEMULTIPLEXORES

D0 D0

Mux DeMux

D7 D7

sel 3 3
COMPUERTAS OR EXCLUSIVAS
COMPUERTAS OR EXCLUSIVAS

Se puede usar como detector o generador de paridad


COMPARADORES

Existen circuitos que permiten comparar dos nmeros binarios:


Comparadores de igualdad:

Comparador de 1 bit

library IEEE; library IEEE;


use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_1164.ALL;
entity comp_1bit is entity comp_1bit is
Port ( a,b : in STD_LOGIC; Port ( a,b : in STD_LOGIC;
diff : out STD_LOGIC); diff : out STD_LOGIC);
end comp_1bit; end comp_1bit;
architecture Behavioral of comp_1bit is architecture Behavioral of comp_1bit is
begin begin
diff <= a xor b; diff <= '1' when a /= b else '0';
end Behavioral; end Behavioral;
COMPARADORES

4-bit comparator
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
DIFF
entity comp_4bit is
Port ( a,b : in STD_LOGIC_vector(3 downto 0);
diff : out STD_LOGIC);
end comp_4bit;

architecture Behavioral of comp_4bit is


begin
diff <= (a(0) xor b(0)) or (a(1) xor b(1))
or(a(2) xor b(2))or (a(3) xor b(3));
library IEEE;
end Behavioral;
use IEEE.STD_LOGIC_1164.ALL;
entity comp_4bit is
Port ( a,b : in STD_LOGIC_vector(3 downto 0);
diff : out STD_LOGIC);
end comp_4bit;

architecture Behavioral of comp_4bit is


begin
diff <= '1' when a/=b else '0';
end Behavioral;
COMPARADORES

Comparadores de magnitud:

A
A B a>b a=b a<b
a <b
a=b
a>b
A > B 1 0 0
B
A = B 0 1 0
A < B 0 0 1
COMPARADORES

Comparador de magnitud de 2bits: Entradas Salidas

a1 a0 b1 b0 a>b a=b a<b

0 0 0 0 0 1 0

0 0 0 1 0 0 1

0 0 1 0 0 0 1

0 0 1 1 0 0 1

0 1 0 0 1 0 0

0 1 0 1 0 1 0

0 1 1 0 0 0 1
A B a>b a=b a<b
0 1 1 1 0 0 1
A > B 1 0 0 1 0 0 0 1 0 0
A = B 0 1 0 1 0 0 1 1 0 0

A < B 0 0 1 1 0 1 0 0 1 0

1 0 1 1 0 0 1

1 1 0 0 1 0 0

1 1 0 1 1 0 0

1 1 1 0 1 0 0

1 1 1 1 0 1 0
COMPARADORES

Entradas Salidas
a1 a0 b1 b0 a>b a=b a<b
0 0 0 0 0 1 0
0 0 0 1 0 0 1
0 0 1 0 0 0 1
0 0 1 1 0 0 1
0 1 0 0 1 0 0
0 1 0 1 0 1 0
0 1 1 0 0 0 1
0 1 1 1 0 0 1
1 0 0 0 1 0 0
1 0 0 1 1 0 0
1 0 1 0 0 1 0
1 0 1 1 0 0 1
1 1 0 0 1 0 0
1 1 0 1 1 0 0
1 1 1 0 1 0 0
1 1 1 1 0 1 0
COMPARADORES

library IEEE;
Comparador use IEEE.STD_LOGIC_1164.ALL;
de magnitud
entity comparador is
A 8
a>b
may Port ( a : in STD_LOGIC_VECTOR (7 downto 0);
b : in STD_LOGIC_VECTOR (7 downto 0);
a=b igu may : out STD_LOGIC;
a<b men igu : out STD_LOGIC;
B 8 men : out STD_LOGIC);
end comparador;

architecture Behavioral of comparador is


begin
may <= '1' when a>b else '0';
igu <= '1' when a=b else '0';
men <= '1' when a<b else '0';
end Behavioral;
COMPARADORES

Si se quiere comparar 2 nmeros A y B de 6 bits cada uno con comparadores de 4


bits:
A = (a5, a4, a3, a2, a1, a0) y B = (b5, b4, b3, b2, b1, b0)

a0 a3
a1 a>b a4 a>b
a2 a=b a5 a=b
a<b a<b

b0 b3
b1 b4
b2 b5
COMPARADORES

Existen comparadores comerciales con entradas adicionales

P Q in< in= in> P<Q P=Q P>Q

P > Q x x x 0 0 1
P < Q x x x 1 0 0
P = Q 0 1 0 0 1 0
P = Q 1 0 0 1 0 0
P = Q 0 0 1 0 0 1
COMPARADORES

Comparar dos nmeros Q y P de 8 bits cada uno


P = (p7,p6,p5,p4,p3,p2,p1,p0) y Q =( q7,q6,q5,q4,q3,q2,q1,q0)

P0 P4
P1 P5
P2 P6
P3 P7

P<Q
< <
in < in <
= = P=Q
V in = in =
in >
>
in > >
P>Q
Q0 Q4
Q1 Q5
Q3 Q6
Q3 Q7
SUMADORES

Suma de 2 bits

x y Cout Suma
0 0 0 0 x S
0 1 0 1 y Cout
1 0 0 1
1 1 1 0

Cout = x y
Suma = x y + x y = x y
SUMADORES

La suma dos nmeros de mas de un bits

Ci x y Ci+1 Suma
0 0 0 0 0
0 0 1 0 1
0 1 0 0 1
0 1 1 1 0
1 0 0 0 1
1 0 1 1 0
1 1 0 1 0
1 1 1 1 1
SUMADORES

Cin x y Cout S
0 0 0 0 0
0 0 1 0 1
0 1 0 0 1
0 1 1 1 0
1 0 0 0 1
1 0 1 1 0
1 1 0 1 0
1 1 1 1 1
SUMADORES

Sumar dos nmeros de 4 bits X (X3 X 2 X1 X0); Y (Y3 Y 2 Y1 Y0);

X = x 3 x2 x1 x0
Y = y3 y2 y1 y0
S = s 3 s2 s1 s0

El retardo aumenta con el nmero de bits


SUMADORES

Carry lookahead: Con esta idea se logran sumadores mas rpidos

En general:
si = xi yi ci
ci+1 = xi.yi +xi.ci + yi.ci = xi.yi +(xi.+ yi).ci
ci+1 = gi + pi.ci

Donde
gi = xi.yi generador
pi = xi+yi propagador
c1 = g0 + p0.c0
c2 = g1 + p1.c1 = g1 + p1.(g0 + p0.c0)
c2 = x1.y1 + (x1 + y1).c1 = x1.y1 + (x1 + y1)(x0.y0 + (x0+ y0).c0

En general: ci = F(xi-1x0, yi-1y0, ci-1c0)


SUMADORES

y3 x3 y2 x2 y1 x1 y0 x0
c3 c2 c1 c1

s3 s2 s1 s0

y3 y2 y1 y0 x3 x2 x1 x0
SUMADORES

Sumadores MSI
SUMADORES

A-B = A +(-B)
Trabajando en complemento a dos, la resta es la suma de A mas el
complemento a 2 de B
El complemento a dos de un nmero, se obtiene cambiando los ceros
por unos, los unos por ceros y luego sumando uno.

A
A-B
-B +
B Comp a 2

Debe verificarse que no se produzca un overflow para que el resultado sea vlido.
Debe cumplirse que :
Si se operan nmeros de distinto signo nunca hay overflow
Si se operan nmeros de igual signo el resultado debe tener el mismo signo
SUMADORES

A7 B7 S7 OVF
0 0 0 0
0 0 1 1
0 1 0 0
0 1 1 0
1 0 0 0
1 0 1 0
1 1 0 1
1 1 1 0

OVF = A7. B7 . S7 + A7 . B7 . S7

A7
B7
S7
OPERACIONES ARITMETICAS EN VHDL

La operacin suma, resta no estn definidas en el estndar VHDL, para los tipos
std_logic_vector . Por ejemplo, ejecutamos check syntx del siguiente cdigo

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity suma_mal is
Port ( a : in STD_LOGIC_VECTOR (7 downto 0);
b : in STD_LOGIC_VECTOR (7 downto 0);
suma : out STD_LOGIC_VECTOR (7 downto 0));
end suma_mal;
architecture Behavioral of suma_mal is
begin
suma <= a + b;
end Behavioral;

Aparece el siguiente mensaje de error:

ERROR:HDLCompiler:1731 - "E:\DIGITAL\2017\msi_2017\suma_mal.vhd" Line 10: found '0'


definitions of operator "+", cannot determine exact overloaded matching definition for "+"
OPERACIONES ARITMETICAS EN VHDL

Para realizar operaciones aritmeticas en VHDL incluiremos otro paquete


ieee.numeric_std.all. La primeras lneas del archivo de texto ser

LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.numeric_std.ALL;

Este paquete introduce dos tipos importantes que van a permitir representar
nmeros para realizar operaciones aritmticas.
Los tipo unsigned y signed. A estos, hay que agregarle otro tipo ya definido
en el estndar, el tipo entero.

A los tipos unsigned y signed hay que declararlos e indicar la cantidad de bits
con que va a trabajar, o bien como puerto de la entity, o si es una seal interna
del siguiente modo:

signal oper1 : unsigned( 7 downto 0);

Indica que oper1 representar un nmero de 8 bits sin signo es decir


10000000 representar el nmero 128, el 11111111 el 255, etc.
OPERACIONES ARITMETICAS EN VHDL

El tipo signed es un arreglo de n bits que representa un nmero expresado en


complemento a 2:

Para usarlo tambin hay que declararlo, com puerto de la entity o de manera similar
al tipo unsigned:

signal oper2 : signed( 7 downto 0);

Indica que oper2 representar un nmero binario de 8 bits con signo( complemento
a 2) es decir:

10000000 representar el nmero -128

01000000 representar el nmero 64

11111111 representar el nmero -1


OPERACIONES ARITMETICAS EN VHDL

VHDL es un lenguaje que permite operaciones entre objetos del mismo tipo
(salvo excepciones)
Si se utiliza el paquete ieee.numeric_std.all, se pueden hacer operaciones
de suma resta, comparacin, etc. entre objetos del mismo tipo, tales como
signed o unsigned.
Por ejemplo

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
entity suma_unsigned is
Port ( a : in unsigned(7 downto 0);
b : in unsigned(7 downto 0);
suma : out unsigned(7 downto 0));
end suma_unsigned;
architecture Behavioral of suma_unsigned is
begin
suma <= a + b;
end Behavioral;

Este cdigo no genera error


OPERACIONES ARITMETICAS EN VHDL

La simulacin de la suma de dos unsigned a y b

La misma simulacin representado en decimal


OPERACIONES ARITMETICAS EN VHDL

En general, en las entidades las seales son de tipo std_logic_vector


Para hacer la operacin se debe hacer previamente una conversin de tipo,
de std_logic a signed o unsigned. Luego para entregar el resultado en std_logic
se debe hacer la conversin de signed o unsigned a std_logic, usando funciones
que estn definidas en el paquete numeric_std
Ejemplo:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
A 8
S entity sumador is
Port ( a,b : in std_logic_vector(7 downto 0);
8 suma : out std_logic_vector(7 downto 0));
B 8
end sumador;
architecture Behavioral of sumador is
-- definir una seal interna
signal aux : unsigned(7 downto 0);

begin
aux <= unsigned(a) + unsigned(b);
suma <= std_logic_vector(aux);

end Behavioral;
OPERACIONES ARITMETICAS EN VHDL

VHDL tiene definido en el estndar el tipo entero ( integer) este tipo permite
Trabajar con nmeros enteros de 32 bits, representados en complemento a 2
Por lo tanto permite trabajar en el rango -2147483648 to +2147483647
Ejemplo:

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity suma_enteros is
Port ( a : in integer;
b : in integer;
suma : out integer);
end suma_enteros;

architecture Behavioral of suma_enteros is

begin
suma <= a - b +5;
end Behavioral;
OPERACIONES ARITMETICAS EN VHDL

Conversores de tipo:
El paquete numeric_std incorpora estas funciones que permiten la
conversin de tipos

Para convertir una seal (A) de tipo signed de 16 bit en entero (NUM)
NUM <= to_integer(A);
El caso inverso de entero a signed de 16 bits
A <= to_signed(NUM,16);
OPERACIONES ARITMETICAS EN VHDL

Supongamos que se quiere hacer la siguiente operacin: S=A + B + 5 , sabiendo que


A y B representan nmeros binarios de 8 bits sin signo.
Para normalizar los diseos, es comun que la interface de la seales sean de tipo
std_logic_vector library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
A S entity suma_enteros is
8 Port ( A,B :in std_logic_vector( 7 downto 0);
S : out std_logic_vector( 7 downto 0));
8
end suma_enteros;
B 8
architecture Behavioral of suma_enteros is
-- definimos seales intermedias
signal a_aux, b_aux: unsigned( 7 downto 0);
signal cinco,s_aux : unsigned( 7 downto 0);
library IEEE;
use IEEE.STD_LOGIC_1164.ALL; begin
use IEEE.NUMERIC_STD.ALL; a_aux <= unsigned(A);
entity suma_enteros is b_aux <= unsigned(B);
Port ( A,B :in std_logic_vector( 7 downto 0); cinco <= to_unsigned(5,8);
S : out std_logic_vector( 7 downto 0)); s_aux <= a_aux + b_aux + cinco;
end suma_enteros; s <= std_logic_vector(s_aux);
architecture Behavioral of suma_enteros is end Behavioral;
begin
s <= std_logic_vector(unsigned(A)+unsigned(B)+to_unsigned(5,8));
end Behavioral;

S-ar putea să vă placă și