Documente Academic
Documente Profesional
Documente Cultură
DISEÑO DIGITAL
Solución:
UNMSM - FIEE 1
○ Palabra de comando
Tabla No1
suma = 0
Input N
suma = suma + N
N = N - 1
Tabla No2
UNMSM - FIEE 2
○ Implementación del diagrama de estados para la unidad de control.
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity ruta_datos_sum is
port(Input_N: in std_logic_vector(7 downto 0);
clk,cl_ld,ld_dn,done: in std_logic;
z: out std_logic;
Output_SUM: out std_logic_vector(7 downto 0));
end ruta_datos_sum;
UNMSM - FIEE 3
○ Implementación de la unidad de control en VHDL
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity mef_sum is
port(clk,start,z: in std_logic;
cl_ld,ld_dn,done: out std_logic);
end mef_sum;
process(EP,z)
begin
ES <= EP;
case EP is
when S0=> cl_ld<='0';ld_dn<='0';done<='0';
if start='1' then
ES <= S1;
UNMSM - FIEE 4
else
ES <= S0;
end if;
when S1=> cl_ld<='1';ld_dn<='0';done<='0';
ES <= S2;
when S2=> cl_ld<='0';ld_dn<='1';done<='0';
if z='1' then
ES <= S3;
else
ES <= S2;
end if;
when S3=> cl_ld<='0';ld_dn<='0';done<='1';
ES <= S3;
end case;
end process;
end solucion;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity SUMADOR_N_TO_1 is
port(Input_N: in std_logic_vector(7 downto 0);
clk,start: in std_logic;
done: buffer std_logic;
UNMSM - FIEE 5
Output_SUM: out std_logic_vector(7 downto 0));
end SUMADOR_N_TO_1;
component ruta_datos_sum
port(Input_N: in std_logic_vector(7 downto 0);
clk,cl_ld,ld_dn,done: in std_logic;
z: out std_logic;
Output_SUM: out std_logic_vector(7 downto 0));
end component;
component mef_sum
port(clk,start,z: in std_logic;
cl_ld,ld_dn,done: out std_logic);
end component;
begin
U0: ruta_datos_sum PORT MAP (Input_N, clk, cl_ld,
ld_dn, done,z,Output_SUM);
U1: mef_sum PORT MAP (clk, start, z, cl_ld, ld_dn,
done);
end solucion;
UNMSM - FIEE 6
2. Construir un circuito para calcular el factorial de un número N, donde N es un
número de 8 bits ingresado una vez que se pulse START. El circuito debe mostrar el
resultado del factorial (a 32 bits) activando la señal DONE. Considerar el factorial de
0.
Solución:
producto = 1
Input N
While( N > 1 ){
producto = producto * N
N = N - 1
}
Output producto
Donde:
N es un registro de 4 bits.
PRODUCTO es un registro de 32 bits.
Z es una señal de salida que se activa cuando N = 0
COUNT es una señal que cuando se activa decrementa el valor de N en 1
UNMSM - FIEE 7
○ Palabra de comando
Tabla No3
producto = 1
Input N
producto = producto * N
N = N - 1
Tabla No4
UNMSM - FIEE 8
○ Implementación del diagrama de estados para la unidad de control.
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity data_path_fact is
port( input_N: in std_logic_vector(3 downto 0);
clk,set_ldn,ldp_cn,done: in std_logic;
z: out std_logic;
output_producto: out std_logic_vector(31 downto 0));
end data_path_fact;
UNMSM - FIEE 9
N <= "0001";
end if;
end if;
end if;
end process;
end solucion;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity mef_fact is
port(clk,start,z: in std_logic;
set_ldn,ldp_cn,done: out std_logic);
end mef_fact;
UNMSM - FIEE 10
process(EP,z)
begin
ES <= EP;
case EP is
when S0=> set_ldn<='0';ldp_cn<='0';done<='0';
if start='1' then
ES <= S1;
else
ES <= S0;
end if;
when S1=> set_ldn<='1';ldp_cn<='0';done<='0';
ES <= S2;
when S2=> set_ldn<='0';ldp_cn<='1';done<='0';
if z='1' then
ES <= S3;
else
ES <= S2;
end if;
when S3=> set_ldn<='0';ldp_cn<='0';done<='1';
ES <= S3;
end case;
end process;
end solucion;
UNMSM - FIEE 11
○ Implementación del circuito final en VHDL
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity FACTORIAL_N is
port( N: in std_logic_vector(3 downto 0);
clk,start: in std_logic;
done: buffer std_logic;
FACTORIAL: out std_logic_vector(31 downto 0));
end FACTORIAL_N;
architecture SOLUCION of FACTORIAL_N is
component data_path_fact
port( input_N: in std_logic_vector(3 downto 0);
clk,set_ldn,ldp_cn,done: in std_logic;
z: out std_logic;
output_producto: out std_logic_vector(31 downto 0));
end component;
component mef_fact
port(clk,start,z: in std_logic;
set_ldn,ldp_cn,done: out std_logic);
end component;
UNMSM - FIEE 12
○ Simulación del circuito final (calculando el factorial de 8):
UNMSM - FIEE 13
3. Construir un circuito que permita ingresar un número de 8 bits e indique si la
cantidad de 1s es mayor o igual que 0s. El circuito debe iniciar el proceso cuando se
presione la señal START.
Solución:
Input N
contador_1s = 0
veces = 0
While( veces <> 8 ){
if N(0)=1 then
contador_1s = contador_1s+1
end if
N = N >> 1
veces = veces + 1
}
if (contador_1s > = 4) then
FIN = 1
else
FIN = 0
end if
UNMSM - FIEE 14
Donde:
N, es un registro de 8 bits que recibe el dato con los bits 1 a contar.
contador_1s, es un registro de 4 bits que contará la cantidad de 1s que hay
en
el registro N..
veces, es un registro que cuenta la cantidad de operaciones que vamos a
realizar (en este caso 8 veces).
la señal S, toma el valor del bit de menor peso del registro N.
la señal p, es la salida del comparador e indica si el valor del registro
contador_1s es mayor o igual que 4.
la señal z, indica si el registro veces llegó a 8.
○ Palabra de comando
Tabla No5
Input N
contador_1s = 0
veces = 0
UNMSM - FIEE 15
Estas dos operaciones son independientes y se pueden ejecutar en el mismo pulso
de reloj.
N = N >> 1
veces = veces + 1
Tabla No6
UNMSM - FIEE 16
○ Implementación de la ruta de datos en VHDL.
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity ruta_datos_1s is
port(Input_N: in std_logic_vector(7 downto 0);
clk,lcc,up1s,sh_upv,FIN: in std_logic;
S,P,Z,Q: out std_logic);
end ruta_datos_1s;
UNMSM - FIEE 17
Z <= '1' when VECES=8 else '0';
S <= N(0);
P <= '1' when CONTADOR_1S >=4 else '0';
Q <= '1' when FIN = '1' else '0';
end solucion;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity mef_conta1s is
port(clk,S,P,Z,START: in std_logic;
lcc,up1s,sh_upv,FIN: out std_logic);
end mef_conta1s;
UNMSM - FIEE 18
process(clk)
begin
if rising_edge(clk) then
EP <= ES;
end if;
end process;
process(EP)
begin
ES <= EP;
case EP is
when S0=> lcc<='0'; up1s<='0'; sh_upv<='0';
FIN<='0';
if start='1' then
ES <= S1;
else
ES <= S0;
end if;
when S1=> lcc<='1'; up1s<='0'; sh_upv<='0';
FIN<='0';
ES <= S2;
when S2=> lcc<='0'; up1s<='0'; sh_upv<='0';
FIN<='0';
if S='1' then
ES <= S3;
else
ES <= S4;
end if;
when S3=> lcc<='0'; up1s<='1'; sh_upv<='0';
FIN<='0';
ES <= S4;
when S4=> lcc<='0'; up1s<='0'; sh_upv<='1';
FIN<='0';
if Z='0' then
ES <= S2;
else
ES <= S5;
end if;
when S5=> lcc<='0'; up1s<='0'; sh_upv<='0';
FIN<='0';
if P='1' then
ES <= S6;
else
ES <= S0;
end if;
when S6=> lcc<='0'; up1s<='0'; sh_upv<='0';
UNMSM - FIEE 19
FIN<='1';
ES <= S0;
end case;
end process;
end solucion;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity contador_1s is
port(N: in std_logic_vector(7 downto 0);
clk,start: in std_logic;
Q: out std_logic);
end contador_1s;
UNMSM - FIEE 20
component ruta_datos_1s
port(Input_N: in std_logic_vector(7 downto 0);
clk,lcc,up1s,sh_upv,FIN: in std_logic;
S,P,Z,Q: out std_logic);
end component;
component mef_conta1s
port(clk,S,P,Z,START: in std_logic;
lcc,up1s,sh_upv,FIN: out std_logic);
end component;
begin
end solucion;
UNMSM - FIEE 21
UNMSM - FIEE 22
4. Implemente un circuito que permita realizar la división de dos números de 8 bits c/u
(DIVIDENDO y DIVISOR). El circuito debe realizar la división realizando el proceso
de restas sucesivas (DIVIDENDO - DIVISOR), hasta que el DIVIDENDO < DIVISOR.
En cada resta se debe ir incrementando el COCIENTE.
El circuito debe tener una señal de START para cargar los dos valores a dividir,
considerar que el DIVIDENDO siempre es mayor que el DIVISOR.
El circuito a diseñar debe generar una señal DONE para indicar el fin de la
operación, mostrando el COCIENTE y el RESIDUO.
Solución:
cociente = 1
Input DIVIDENDO
Input DIVISOR
While( DIVIDENDO > DIVISOR ){
DIVIDENDO = DIVIDENDO - DIVISOR
cociente = cociente + 1
}
Output DIVIDENDO (; RESIDUO)
Output COCIENTE
UNMSM - FIEE 23
Donde:
DIVIDENDO, DIVISOR, COCIENTE, son registros de 8 bits.
La señal mux selecciona si se carga al DIVIDENDO el dato externo o la resta
del DIVIDENDO - DIVISOR.
La señal z, indica si se continúa con las restas o termina el proceso cuando
el DIVIDENDO < DIVISOR.
○ Palabra de comando
Tabla No7
UNMSM - FIEE 24
Tabla No8
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity ruta_datos7 is
port( INPUT_DIVIDENDO,INPUT_DIVISOR: in
std_logic_vector(7 downto 0);
clk,clr,ld1,mux_ld2,up,done: in std_logic;
z: out std_logic;
OUT_COCIENTE,OUT_RESIDUO: out
UNMSM - FIEE 25
std_logic_vector(7 downto 0));
end ruta_datos7;
process(clk)
begin
if rising_edge(clk) then
if clr='1' then
COCIENTE <= "00000000";
elsif up='1' then
COCIENTE <= COCIENTE+1;
end if;
if ld1='1' then
DIVIDENDO <= DATO;
end if;
if mux_ld2='1' then
DIVISOR <= INPUT_DIVISOR;
end if;
end if;
end process;
end solucion;
UNMSM - FIEE 26
○ Implementación de la unidad de control en VHDL
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity mef7 is
port(clk,start,z: in std_logic;
clr,ld1,mux_ld2,up,done: out std_logic);
end mef7;
process(EP,Z)
begin
ES <= EP;
case EP is
when S0=> clr<='0'; ld1<='0'; mux_ld2<='0';
up<='0'; done<='0';
if start='1' then
ES <= S1;
else
ES <= S0;
end if;
when S1=> clr<='1'; ld1<='1'; mux_ld2<='1';
up<='0';done<='0';
ES <= S2;
when S2=> clr<='0'; ld1<='0'; mux_ld2<='1';
up<='0';done<='0';
ES <= S3;
when S3=> clr<='0'; ld1<='0'; mux_ld2<='0';
up<='0';done<='0';
if z='0' then
ES <= S5;
else
ES <= S4;
UNMSM - FIEE 27
end if;
when S4=> clr<='0'; ld1<='1'; mux_ld2<='0';
up<='1';done<='0';
ES <= S3;
when S5=> clr<='0'; ld1<='0'; mux_ld2<='0';
up<='0';done<='1';
ES <= S0;
end case;
end process;
end solucion;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity RESTADOR is
port(DIVIDENDO,DIVISOR: in std_logic_vector(7 downto 0);
clk,start: in std_logic;
done: BUFFER std_logic;
COCIENTE,RESIDUO: out std_logic_vector(7 downto 0));
end RESTADOR;
UNMSM - FIEE 28
architecture solucion of RESTADOR is
component ruta_datos7
port( INPUT_DIVIDENDO,INPUT_DIVISOR: in
std_logic_vector(7 downto 0);
clk,clr,ld1,mux_ld2,up,done: in std_logic;
z: out std_logic;
OUT_COCIENTE,OUT_RESIDUO: out
std_logic_vector(7 downto 0));
end component;
component mef7
port(clk,start,z: in std_logic;
clr,ld1,mux_ld2,up,done: out std_logic);
end component;
end solucion;
UNMSM - FIEE 29
5.
UNMSM - FIEE 30