Você está na página 1de 21

Descripcin y prctica con el ISE

Design Suite

EDIG

Content
Simulacin: Test benches
Ejemplos

EDIG

VHDL: Testbenches

EDIG

Flujo de Trabajo con FPGAs

Escritura
del cdigo

Simulacin

Sntesis
bitstream

Depuracin y
optimizacin

EDIG

Flujo de trabajo con FPGAs


Especificacin

Desarrollo
Descripcin del sistema en un lenguaje de
descripcin hardware (VHDL)

Verificacin

Sntesis lgica

Transformacin del cdigo a elementos


circuitales

Comprobacin mediante
simulaciones de que el
funcionamiento es el descrito
en la especificacin

Colocacin y rutado
Asignacin de los circuitos e interconexiones
a elementos concretos dentro de la FPGA

EDIG

Programacin

Test

Configuracin de los elementos asignados a


la funcin lgica correspondiente

Comprobacin mediante tests


de que el funcionamiento es el
descrito en la especificacin

Simulacin
Necesitamos comprobar que el circuito que
hemos diseado cumple las especificaciones
Ejemplo: la salida de una funcin lgica es correcta
para todas las combinaciones de entrada

En el circuito real los estmulos de las entradas


vendran de una fuente externa, normalmente
otro circuito
Para comprobar el funcionamiento tenemos que
simular estas fuentes externas y ver que las
salidas son correctas
El componente que realiza esta funcin se llama
testbench (banco de pruebas)
EDIG

Testbench
Un testbench es una entidad/arquitectura VHDL
con las siguientes caractersticas:
La entidad est vaca, no tiene puertos de entrada o
salida
Emplea una descripcin estructural y el diseo que se
va a comprobar se introduce con un component
instantiation
Normalmente se conoce al diseo que se va a comprobar
como DUT (design under test) o UUT (unit under test)

Los estmulos se generan asignando valores variables


con el tiempo a las seales que se conectan a las
entradas del DUT
Las salidas del DUT se conectan a seales del testbench
EDIG

Uso de after
Una manera sencilla de generar estmulos
variables en el tiempo es emplear asignaciones de
seales con after.
y <= 1, 0 after 2ns, 1 after 4ns;

Tenemos que asegurarnos de cubrir todos los


casos que queramos comprobar.
El simulador nos mostrar un cronograma, o
diagrama de tiempo de las seales, que
proporciona las formas de onda de las salidas en
funcin de las entradas que hayamos definido.
Visualmente, tenemos que verificar que el
comportamiento es el esperado.
EDIG

Ejemplo Puerta and


library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity puertaand is
Port ( entradax : in STD_LOGIC;
entraday : in STD_LOGIC;
salida : out STD_LOGIC);
end puertaand;
------------------------------------------------

architecture Behavioral of puertaand is


begin
salida <= (entradax and entraday);
end Behavioral;
---------------------------------------------------

EDIG

Ejemplo Puerta and Test bench


Un test bench es un
archivo vhdl que nos
permite generar seales
para probar una entity
El mismo test bench es una
entidad pero sin entradas/salidas
(Parte 1)
Declaramos el mdulo que
queremos probar como un
componente para conexin
estructural (Parte 2)
Declaraciones
Declaramos seales internas para
entradas y salidas, in_vector y
salidaS (Parte 3)

EDIG

LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY andtestbench IS
END andtestbench;

ARCHITECTURE behavior OF andtestbench IS


COMPONENT puertaand
PORT( entradax : IN std_logic;
entraday : IN std_logic;
salida : OUT std_logic
);
END COMPONENT;
--Entradas
signal in_vector : std_logic_vector(1 downto 0)
:= "00";
--Salidas
signal salidaS : std_logic ;

Ejemplo Puerta and Test bench


BEGIN

Conectamos estructuralmente la
entidad que queremos
probar/simular a las seales
internas que hemos definido
(Parte 4)

Damos valores a nuestras seales


internas a nuestro gusto y variando
con el tiempo (Parte 5)

uut: puertaand PORT MAP (


entradax => in_vector(1),
entraday => in_vector(0),
salida => salidaS
);
in_vector <= "00",
"01" after 2ns,
"10" after 4ns,
"11" after 6 ns;
END;

EDIG

Ejemplo : Puerta XOR


Vamos a crear una puerta XOR a partir de sus
componentes:
A
A
B

S
B

S = AB + AB
EDIG

VHDL : Ejemplo Puerta XOR


library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity AAND2 is
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
S : out STD_LOGIC);
end AAND2;
architecture Behavioral of AAND2 is
begin
S<=A and B;
end Behavioral;
-----------------------------library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity NNOT1 is
Port ( A : in STD_LOGIC;
S : out STD_LOGIC);
end NNOT1;
architecture Behavioral of NNOT1 is
begin
S<=not A;
end Behavioral;

EDIG

--------------------------------library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity OOR2 is
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
S : out STD_LOGIC);
end OOR2;
architecture Behavioral of OOR2 is
begin
S <= A or B;
end Behavioral;

A
B

A
B

VHDL : Ejemplo Puerta XOR


------------------------------library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

signal SN1,SN2,SN3,SN4 : STD_LOGIC;

entity XXOR2
Port ( A
B
S
end XXOR2;

begin
U1 : NNOT1 port map (A,SN1);
U2 : NNOT1 port map (B,SN2);
U3 : AAND2 port map (SN1,B,SN3);
U4 : AAND2 port map (A,SN2,SN4);
U5 : OOR2 port map (SN3,SN4,S);
end Behavioral;

is
: in STD_LOGIC;
: in STD_LOGIC;
: out STD_LOGIC);

architecture Behavioral of XXOR2 is


----------------------------component AAND2
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
S : out STD_LOGIC);
end component;
component OOR2
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
S : out STD_LOGIC);
end component;
component NNOT1
Port ( A : in STD_LOGIC;
S : out STD_LOGIC);
end component;

EDIG

SN1
SN3

S
B

SN4
SN2

Test bench para XOR


Archivo de test bench
Queremos simular el funcionamiento
del mdulo XOR2 anterior:
entity XOR2 is
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
S : out STD_LOGIC);
end XOR2;

Declaramos el mdulo que


queremos probar como un
componente

Declaramos seales para entradas


y salidas

EDIG

LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY test_xor2 IS
END test_xor2;
ARCHITECTURE behavior OF test_xor2 IS
COMPONENT XXOR2
PORT(
A : IN std_logic;
B : IN std_logic;
S : OUT std_logic
);
END COMPONENT;
signal C,D : std_logic;
signal S : std_logic;

VHDL : Ejemplo Puerta XOR


BEGIN

Instanciamos la unidad. Es decir,


asignamos las entradas y salidas a
las seales declaradas
anteriormente
Damos diferentes valores a las
entradas con un intervalo de tiempo
entre ellas. De esta forma se
pueden asignar, por ejemplo, todos
los valores de la tabla de verdad.

uut: XXOR2 PORT MAP (


A => C,
B => D,
S => S
);

C<='0','0' after 2 ns, '1' after 4 ns, '1' after 6 ns;


D<='0','1' after 2 ns, '0' after 4 ns, '1' after 6 ns;
END;

Resultado de la simulacin

VHDL : Ejemplo
Otra forma ms sencilla de introducir una tabla de
verdad
Queremos comprobar el funcionamiento
del mdulo AND2 anterior:
entity AND2 is
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
S : out STD_LOGIC);
end AND2;

Archivo de test bench


LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY test_and2 IS
END test_and2;
ARCHITECTURE behavior OF test_and2 IS

Declaramos el mdulo que


queremos probar como un
componente
Declaramos las entradas como un
nico vector.

COMPONENT AND2
PORT(
A : IN std_logic;
B : IN std_logic;
S : OUT std_logic
);
END COMPONENT;
signal in_vector : std_logic_vector(1 downto 0) := "00";
signal S : std_logic;

VHDL : Ejemplo Puerta XOR


BEGIN

Instanciamos la unidad. Es decir,


asignamos las entradas y salidas a
las seales declaradas
anteriormente
Damos diferentes valores a las
entradas a travs del vector. De
esta forma se pueden asignar, por
ejemplo, todos los valores de la
tabla de verdad.

uut: AND2 PORT


A =>
B =>
S =>
);
in_vector <=

END;

MAP (
in_vector(1),
in_vector(0),
S

"00",
"01" after 2ns,
"10" after 4ns,
"11" after 6ns;

Ejemplo minterms
Implemente la funcin
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

y = a, b, c (0,3)

architecture Behavioral of truth_table is


signal temp : std_logic_vector (2 downto 0);

entity truth_table is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
c : in STD_LOGIC;
y : out STD_LOGIC);
end truth_table;

begin
temp <= a & b & c;
with temp select y <=
'1' when "000",
'1' when "011",
'0' when others;
end Behavioral;

EDIG

Ejemplo funcion lgica


Implemente la funcin f(a,b,c)=ab + bc + ac
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity funcion_f is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
c : in STD_LOGIC;
y : out STD_LOGIC);
end funcion_f;
architecture Behavioral of funcion_f is
begin
y <= (a and b) or (b and (not c)) or (a and c);
end Behavioral;

EDIG

Otro ejemplo estructural


Implemente la funcin g(a,b,c) descrita por el siguiente circuito
a
b
c

Signal 1
a
b

g(a,b,c)

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity funcion_g is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
c : in STD_LOGIC;
y : out STD_LOGIC);
end funcion_g;

architecture structural of funcion_g is


COMPONENT funcion_f
PORT(
a : IN std_logic;
b : IN std_logic;
c : IN std_logic;
y : OUT std_logic
);
END COMPONENT;
signal signal1: std_logic;

EDIG

begin
u1: funcion_f PORT MAP (
a => a,
b => b,
c => c,
y => signal1
);
u2: funcion_f PORT MAP (
a => signal1,
b => a,
c => b,
y => y
);

end structural;

Você também pode gostar