Sunteți pe pagina 1din 44

1

VHDL 1
VHDL VHDL VHDL
Ingeniera Ingeniera de de Telecomunicacin Telecomunicacin
Susana Borromeo Lpez
Electrnica Digital I I Electrnica Digital I I
Ingeniera de
Telecomunicacin
Introduccin al VHDL 2 ElectrnicaDigital II
Indice
1. Conceptos bsicos
2. VHDL para sntesis
3. VHDL para simulacin
4. VHDL estructural
2
Introduccin al VHDL 3 ElectrnicaDigital II
1995
1995 1995
1998
1998 1998
2001
2001 2001
2004
2004 2004
2007
2007 2007
2010
2010 2010
Tamao de
las pistas (m)
Tamao de Tamao de
las pistas ( las pistas ( m) m) 0.35
0.35
0.25
0.25
0.18
0.18
0.13
0.13
0.10
0.10
0.07
0.07
Tamao de
los dados (cm
2
)
Tamao de Tamao de
los dados (cm los dados (cm
2 2
) ) 2.5
2.5
3.0
3.0
3.6
3.6
4.3
4.3
5.2
5.2
6.3
6.3
Memorias
(#bits)
Memorias Memorias
(#bits) (#bits) 64M
64M
256M
256M
1G
1G
4G
4G
16G
16G
64G
64G
Circuitos lgicos
(#transistores)
Circuitos lgicos Circuitos lgicos
(#transistores) (#transistores) 10M
10M
21M
21M
46M
46M
110M
110M
260M
260M
570M
570M
Frecuencia
(MHz)
Frecuencia Frecuencia
( (MHz MHz) ) 300
300
450
450
600
600
800
800
1000
1000
1100
1100
N entradas y
salidas
N entradas y N entradas y
salidas salidas 512
512
512
512
512
512
512
512
800
800
1024
1024
Interconexiones
(m)
Interconexiones Interconexiones
(m) (m) 380
380
840
840
2100
2100
4100
4100
6300
6300
10000
10000
El futuro de los CIs (SIA Roadmap)
Aumento en la complejidad de los circuitos
Hay que disminuir los tiempos de desarrollo
Hay que disminuir los costes
Facilitar la gestin de equipos de diseo
Lenguajes de
Descripcin
De Hardware
Lenguajes de
Descripcin
De Hardware
Introduccin al VHDL 4 ElectrnicaDigital II
VHDL: Caractersticas generales
VHDL =VHSIC Hardware Description Language
(VHSIC =VeryHigh Speed Integrated Circuits)
En diciembre de 1984 se acepta por el IEEE Standards Board y se
publica su primera versin en 1987 (VHDL-87). Revisado en 1993 y
2000 (ms informacin en http://www.vhdl.org )
Al ser un estndar es portable
No es un lenguaje de programacin: con el VHDL no se programa
sino que se codifica
Independiente del dispositivo
Permiten representar tanto el comportamiento como la estructura de
los circuitos
Cada diseo tiene que tener definida una interfaz (para conectarse
con el resto de elementos) y una especificacin comportamental
precisa (para simularlo)
Ejecucin CONCURRENTE y SECUENCIAL
3
Introduccin al VHDL 5 ElectrnicaDigital II
Las sentencias
concurrentes se
ejecutan todas en
paralelo.
...
A <= B and C;
B <= 1 when D = 0
else 0;
D <= F(E) or G;
...
Reflejan la ejecucin
paralela del hardware
Ejecucin concurrente y secuencial
concurrente
Las sentencias
secuenciales se ejecutan
una detrs de otra
Permiten el modelado
sencillo de los algoritmos
(como un programa en C)
secuencial
function F(X) is
begin
if X = 0 then
return 1;
else
return 0;
end if;
end function;
function F(X) is
begin
if X = 0 then
return 1;
else
return 0;
end if;
end function;
Cdigo secuencial
Cdigo concurrente
Siempre hay sentencias
concurrentes, algunas de las
cuales se ejecutan de forma
secuencial
Siempre hay sentencias
concurrentes, algunas de las
cuales se ejecutan de forma
secuencial
Introduccin al VHDL 6 ElectrnicaDigital II
Flujo de diseo con VHDL
Modelar el diseo
en VHDL
Test
en VHDL
Simulacin
Funcional
Funciona?
Herramienta de Sntesis Lgica
Netlist
Place &Route
Restricciones
al diseo
Eleccin del
dispositivo
Archivo de configuracin Anlisis temporal esttico
Programador de
PLD, JTAG
4
Introduccin al VHDL 7 ElectrnicaDigital II
Proceso de traduccin de una descripcin comportamental a una
descripcin lgica, para una tecnologa objetivo y bajo unas
determinadas restricciones
Sntesis Sntesis
Sntesis RT
Mapeo tecnolgico
Optimizacin
Descripcin VHDL
AND
XOR
FF
NOT
MUX
Modelo lgico genrico Circuito lgico mapeado
Circuito lgico optimizado
TEC
Tmax
Restricciones
Biblioteca
del
fabricante
Introduccin al VHDL 8 ElectrnicaDigital II
O
p
c
i
o
n
a
l
entity
architecture
configuration
package
package body
describe el interfaz con el exterior y las caractersticas
comunes de todas las posibles realizaciones de un componente
describe la operacin del dispositi vo, la funcionalidad o su
estructura interna. Est asociada a una entity
selecciona los componentes a utilizar dentro de la biblioteca de
diseo
contiene un conjunto de declaraciones de tipos y subprogramas
comunes a varias unidades de diseo
define los cuerpos de los subprogramas que se han declarado
en el package al que est asociado
Qu tiene un modelo VHDL? Qu tiene un modelo VHDL?
5
Introduccin al VHDL 9 ElectrnicaDigital II
Qu tiene un modelo VHDL? Qu tiene un modelo VHDL?
A1
M1
M2
M3
A2 A3
function SUMA (A,B: bit) return bit;
constant N : integer = 16;
...
function SUMA (A,B: bit) return bit;
constant N : integer = 16;
... ...
function SUMA (A,B: bit_vector) return bit_vector is
begin
return CONV_BIT_VECTOR (A + B); ...
function SUMA (A,B: bit_vector) return bit_vector is
begin
return CONV_BIT_VECTOR (A + B); ...
O
p
c
i
o
n
a
l
entity
architecture
configuration
package
package body
!
!
!
!
Introduccin al VHDL 10 ElectrnicaDigital II
library <nombre_librera>
use <nombre_librera>.<nombre_paquete>.all
Estructura bsica de un archivo fuente VHDL Estructura bsica de un archivo fuente VHDL
entity <nombre_entidad>is
<listado de puertos>
-- Declaracin de pines
end <nombre_entidad>;
architecture <nombre_arquitectura>of <nombre_entidad> is
-- Declaracin de seales internas
-- Declaracin de tipos de datos definidos por el usuario
-- Declaracin de componentes en caso de instanciacin
begin
-- Cuerpo de la arquitectura
-- Se define la funcionalidad del diseo con:
-- Asignaciones concurrentes
-- Procesos
-- Instanciacin de componentes
end <nombre_arquitectura>;
Encabezamiento
Entidad
Arquitectura
!
!
!
!
!
!
6
Introduccin al VHDL 11 ElectrnicaDigital II
Estructura bsica de un archivo fuente VHDL Estructura bsica de un archivo fuente VHDL
configuration <nombre_configuracin>of <nombre_entidad>is
for <nombre_arquitectura>
end for;
end <nombre_configuracin>;
Configuracin
Una librera (library) es una asociacin de packages que contienen a su vez definiciones de tipos
de datos, componentes, etc
Tipo de datos y procedimientos de lectura y escritura para
std_logic y std_logic_vector
std_logic_textio ieee
Operaciones aritmticas con signo y de comparacin y
conversin con std_logic_vector
std_logic_unsigned ieee
Operaciones aritmticas con signo y de comparacin y
conversin con std_logic_vector
std_logic_signed ieee
Tipos signed y unsigned y operaciones std_logic_arith ieee
Tipos std_logic y std_logic_vector std_logic_1164 ieee
Librera por defecto work
Tipos de dato como line y text textio std
Tipos bsicos de VHDL: bit, bit_vector, boolean standard std
Descripcin Package Librera
Packages
predefinidos
Introduccin al VHDL 12 ElectrnicaDigital II
entity <nombre_entidad>is
port ( <nombre_puerto1>: <modo_puerto1><tipo_puerto1>;
...
<nombre_puertoN>: <modo_puerto_N><tipopuertoN>);
end <nombre_entidad>;
entity <nombre_entidad>is
port ( <nombre_puerto1>: <modo_puerto1><tipo_puerto1>;
...
<nombre_puertoN>: <modo_puerto_N><tipopuertoN>);
end <nombre_entidad>;
VHDL. Entidad y arquitectura VHDL. Entidad y arquitectura
Para cada puerto se especifica el modo y el tipo
El modo define la direccin del flujo de datos del
puerto visto desde la entidad.
IN
OUT
INOUT
BUFFER
IN
IN
OUT
INOUT
BUFFER
entity MUX is
port( E0,E1 : in bit;
SEL: in bit;
Z : out bit);
end MUX;
entity MUX is
port( E0,E1 : in bit;
SEL: in bit;
Z : out bit);
end MUX;
E0
E1
SEL
Z
0
1
7
Introduccin al VHDL 13 ElectrnicaDigital II
VHDL. Entidad y arquitectura VHDL. Entidad y arquitectura
entity DECOD2a4 is
port( E0,E1,ENABLE : in bit;
S0,S1,S2,S3 : out bit);
end DECOD2a4;
entity DECOD2a4 is
port( E0,E1,ENABLE : in bit;
S0,S1,S2,S3 : out bit);
end DECOD2a4;
DECODIFICADOR
2a4
E0
E1
ENABLE
S0
S1
S2
S3
entity <nombre_entidad>is
port ( <nombre_puerto1>: <modo_puerto1><tipo_puerto1>;
...
<nombre_puertoN>: <modo_puerto_N><tipo_puertoN>);
end <nombre_entidad>;
entity <nombre_entidad>is
port ( <nombre_puerto1>: <modo_puerto1><tipo_puerto1>;
...
<nombre_puertoN>: <modo_puerto_N><tipo_puertoN>);
end <nombre_entidad>;
Introduccin al VHDL 14 ElectrnicaDigital II
entity <nombre_entidad>is
port ( <nombre_puerto1>: <modo_puerto1><tipo_puerto1>;
...
<nombre_puertoN>: <modo_puerto_N><tipopuertoN>);
end <nombre_entidad>;
entity <nombre_entidad>is
port ( <nombre_puerto1>: <modo_puerto1><tipo_puerto1>;
...
<nombre_puertoN>: <modo_puerto_N><tipopuertoN>);
end <nombre_entidad>;
VHDL. Entidad y arquitectura VHDL. Entidad y arquitectura
sumador binario de
8 bits
SUMA8
B(7:0) A(7:0)
Sum(7:0)
Cout
entity SUMA8 is
port( A : in bit_vector(7 downto 0);
B : in bit_vector(7 downto 0);
SUM : out bit_vector(7 downto 0);
COUT : out bit);
end SUMA8;
entity SUMA8 is
port( A : in bit_vector(7 downto 0);
B : in bit_vector(7 downto 0);
SUM : out bit_vector(7 downto 0);
COUT : out bit);
end SUMA8;
8
Introduccin al VHDL 15 ElectrnicaDigital II
architecture DF of MUX is
begin
Z <=E0 when SEL =0
else E1;
end DF;
architecture COMP of MUX is
begin
P: process(E0, E1, SEL)
begin
if SEL =0 then
Z <=E0;
else
Z <=E1;
end if;
end process P;
end COMP;
architecture DF of MUX is
begin
Z <=E0 when SEL =0
else E1;
end DF;
architecture COMP of MUX is
begin
P: process(E0, E1, SEL)
begin
if SEL =0 then
Z <=E0;
else
Z <=E1;
end if;
end process P;
end COMP;
VHDL. Entidad y arquitectura VHDL. Entidad y arquitectura
entity MUX is
port( E0,E1 : in bit;
SEL : in bit;
Z : out bit);
end MUX;
entity MUX is
port( E0,E1 : in bit;
SEL : in bit;
Z : out bit);
end MUX;
entity <nombre_entidad>is
port ( <nombre_puerto1>: <modo_puerto1><tipo_puerto1>;
...
<nombre_puertoN>: <modo_puerto_N><tipopuertoN>);
end <nombre_entidad>;
entity <nombre_entidad>is
port ( <nombre_puerto1>: <modo_puerto1><tipo_puerto1>;
...
<nombre_puertoN>: <modo_puerto_N><tipopuertoN>);
end <nombre_entidad>;
architecture <nombre_arquitectura>of <nombre_entidad>is
<declaraciones>;
begin
<sentencias_concurrentes>;
end <nombre_arquitectura>;
architecture <nombre_arquitectura>of <nombre_entidad>is
<declaraciones>;
begin
<sentencias_concurrentes>;
end <nombre_arquitectura>;
Introduccin al VHDL 16 ElectrnicaDigital II
architecture DF of MUX is
begin
Z <=E0 when SEL =0
else E1;
end DF;
architecture COMP of MUX is
begin
P: process(E0, E1, SEL)
begin
if SEL =0 then
Z <=E0;
else
Z <=E1;
end if;
end process P;
end COMP;
architecture DF of MUX is
begin
Z <=E0 when SEL =0
else E1;
end DF;
architecture COMP of MUX is
begin
P: process(E0, E1, SEL)
begin
if SEL =0 then
Z <=E0;
else
Z <=E1;
end if;
end process P;
end COMP;
VHDL. Descripcin VHDL. Descripcin comportamental comportamental
entity <nombre_entidad>is
port ( <nombre_puerto1>: <modo_puerto1><tipo_puerto1>;
...
<nombre_puertoN>: <modo_puerto_N><tipopuertoN>);
end <nombre_entidad>;
entity <nombre_entidad>is
port ( <nombre_puerto1>: <modo_puerto1><tipo_puerto1>;
...
<nombre_puertoN>: <modo_puerto_N><tipopuertoN>);
end <nombre_entidad>;
entity MUX is
port( A,B,C : in bit;
SELA,SELB : in bit;
Z : out bit);
end MUX;
entity MUX is
port( A,B,C : in bit;
SELA,SELB : in bit;
Z : out bit);
end MUX;
!
!
Especifica el comportamiento
del diseo en funcin de los
valores de las entradas
Especifica el comportamiento
del diseo en funcin de los
valores de las entradas
architecture <nombre_arquitectura>of <nombre_entidad>is
<declaraciones>;
begin
<sentencias_concurrentes>;
end <nombre_arquitectura>;
architecture <nombre_arquitectura>of <nombre_entidad>is
<declaraciones>;
begin
<sentencias_concurrentes>;
end <nombre_arquitectura>;
9
Introduccin al VHDL 17 ElectrnicaDigital II
configuration MUX_conf of MUX is
for estructural
for U1: INV use work.entity INV ( comportamental); end for;
for U2,U3: AND2 use work.entity AND2 ( comportamental); end for;
for U4: OR2 use work.entity OR2 ( comportamental); end for;
end for;
end MUX_conf ;
architecture estructural of MUX2 is
-- declaracin de componentes
component AND2
port (I0,I1:in std_logic; o:out std_logic);
end component;
component OR2
port (I0,I1:in std_logic; o:out std_logic);
end component;
component INVERSOR
port (I:in std_logic; o:out std_logic);
end component;
-- declaracin de seales
signal S1,S2,S3: std_logic;
begin
--Instanciacin de componentes
U1: INVERSOR port map (SEL,S1);
U2: AND2 port map (A,S1,S2);
U3: AND2 port map (SEL,B,S3);
U4: OR2 port map (S2,S3,Z);
end estructural;
VHDL. Descripcin estructural VHDL. Descripcin estructural
entity MUX is
port( A,B : in bit;
SEL : in bit;
Z : out bit);
end MUX;
entity MUX is
port( A,B : in bit;
SEL : in bit;
Z : out bit);
end MUX;
Describe la entidad como un
conjunto de componentes
conectados entre s por seales
Describe la entidad como un
conjunto de componentes
conectados entre s por seales
E0
E1
SEL
Z
0
1
S2
S3
S1
A
SEL
B
Z
A
B
Introduccin al VHDL 18 ElectrnicaDigital II
configuration identificador of identificador_entidad is
for identificador arquitectura
for ref_componente: identificador_componente
use librera.identificador_entidad(identificador_arquitectura)
end for;
..
end for;
end identificadir_configuracion ;
VHDL. Descripcin estructural VHDL. Descripcin estructural
10
Introduccin al VHDL 19 ElectrnicaDigital II
VHDL. Sumador completo para dos nmeros de 1 VHDL. Sumador completo para dos nmeros de 1 bit bit
entity SUMA is
port( A,B : in bit;
Cin : in bit;
SUM : out bit;
COUT : out bit);
end SUMA;
entity SUMA is
port( A,B : in bit;
Cin : in bit;
SUM : out bit;
COUT : out bit);
end SUMA;
Full Adder
A B
Sum
Cout Cin
Ejemplo tpico de VHDL
ESTRUCTURAL!!!!
Ejemplo tpico de VHDL
ESTRUCTURAL!!!!
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
Cin A B
0
0
0
1
0
1
1
1
Cout
0
1
1
0
1
0
0
1
Sum
Cout = Cin (A + B) + A B
Sum = Cin + (A + B)
Introduccin al VHDL 20 ElectrnicaDigital II
OR2
AND2
OR2
AND2
XOR2
XOR2
A
B
Cin
Cout
Sum
S1
S2
S3
S4
VHDL. Sumador completo para dos nmeros de 1 VHDL. Sumador completo para dos nmeros de 1 bit bit
11
Introduccin al VHDL 21 ElectrnicaDigital II
OR2
AND2
OR2
AND2
XOR2
XOR2
A
B
Cin
Cout
Sum
S1
S2
S3
S4
architecture ESTRUC of FA is
component AND2
port( A, B: in bit; S: out bit);
end component;
component OR2
port( A, B: in bit; S: out bit);
end component;
component XOR2
port( A, B: in bit; S: out bit);
end component;
signal S1, S2, S3, S4: bit;
begin
C1: OR2 port map (A, B, S1);
C2: AND2 port map (A, B, S2);
C3: AND2 port map (S1, Cin, S3);
C4: OR2 port map (S3, S2, Cout);
C5: XOR2 port map (A, B, S4);
C6: XOR2 port map (S4, Cin, Sum);
end ESTRUC;
configuration CFG_EST of FA is
for ESTRUC
for C1, C4: OR2
use entityWORK.OR2(RETR);
end for;
for C2, C3: AND2
use entityWORK.AND2(RETR);
end for;
for C5, C6: XOR2
use entityWORK.XOR2(RETR);
end for;
end for;
end CFG_EST;
paso de parmetros por posicin
c
o
n
f
i
g
u
r
a
c
i

n

e
x
t
e
r
n
a
VHDL. Sumador completo para dos nmeros de 1 VHDL. Sumador completo para dos nmeros de 1 bit bit
Introduccin al VHDL 22 ElectrnicaDigital II
Modelar un divisor de 10 y basndose en ese mdulo realizar un divisor por 1000
VHDL. Descripcin estructural VHDL. Descripcin estructural
DIV10 DIV10 DIV10
CE CE CE
reset reset reset
reset
Clk1000
CE
Clk100_enable Clk10_enable
myClk1
12
Introduccin al VHDL 23 ElectrnicaDigital II
Descripcin estructural Descripcin estructural
entity divisor1000 is
Port ( clk1000 : in std_logic;
reset : in std_logic;
CE : in std_logic; -- Seal de habilitacion de cuenta
myclk1 : out std_logic);
end divisor1000;
architecture Behavioral of divisor1000 is
-- Declaracin componente
COMPONENT divisor10
PORT(
reset : IN std_logic;
clk10 : IN std_logic;
CE : IN std_logic;
clk1 : OUT std_logic
);
END COMPONENT;
-- Declaracin de seales
signal clk10_enable: std_logic;
signal clk100_enable: std_logic;
begin
-- Instanciacin del componente
Inst_divisor10: divisor10 PORT MAP(
reset =>reset ,
clk10 =>clk1000,
CE =>'1',
clk1 =>clk100_enable
);
-- Instanciacin del componente
Inst_divisor100: divisor10 PORT MAP(
reset =>reset,
clk10 =>clk1000,
CE =>clk100_enable,
clk1 =>clk10_enable
);
-- Instanciacin del componente
Inst_divisor1000: divisor10 PORT MAP(
reset =>reset ,
clk10 =>clk1000,
CE =>clk10_enable,
clk1 =>myclk1
);
end Behavioral;
Introduccin al VHDL 24 ElectrnicaDigital II
ndice general de la sintaxis ndice general de la sintaxis
Unidades de diseo
Unidades de diseo
Entidades
Arquitecturas
Configuraciones
Paquetes
Body packages
1 Declaraciones
Declaraciones 4
Tipos
Constantes
Seales
Variables
Ficheros
Alias
Componentes
Manejo bibliotecas
Manejo bibliotecas
Library
Use
2 Operadores
Operadores 7
Sent. concurrentes
Sent. concurrentes 5 Sent. secuenciales
Sent. secuenciales 6
Subprogramas
Subprogramas
Procedimientos
Funciones
3
Subtipos
Bloques
Asig. concurrentes
Ref. componentes
Generate
Procesos
Asig. variables
case
Bucles loop y while
If, elsif, else
Assert
wait
Atributos
Atributos 8
Atrib. rango
Atrib. tipos
Atr. seales
13
Introduccin al VHDL 25 ElectrnicaDigital II
ndice general de la sintaxis ndice general de la sintaxis
Unidades de diseo
Unidades de diseo
Entidades
Arquitecturas
Configuraciones
Paquetes
Body packages
1 Declaraciones
Declaraciones 4
Tipos
Constantes
Seales
Variables
Ficheros
Alias
Componentes
Manejo bibliotecas
Manejo bibliotecas
Library
Use
2 Operadores
Operadores 7
Sent. concurrentes
Sent. concurrentes 5 Sent. secuenciales
Sent. secuenciales 6
Subprogramas
Subprogramas
Procedimientos
Funciones
3
Subtipos
Bloques
Asig. concurrentes
Ref. componentes
Generate
Procesos
Asig. variables
case
Bucles loop y while
If, elsif, else
Assert
wait
Atributos
Atributos 8
Atrib. rango
Atrib. tipos
Atr. seales
Introduccin al VHDL 26 ElectrnicaDigital II
aparecen en entornos
concurrentes o
secuenciales
son visibles en toda la
arquitectura
los puertos de E/S deben
ser seales
llevan informacin del
valor y el tiempo en el
que tomarn ese valor
asignacin <=
seales seales
slo aparecen dentro de
procesos y subprogramas
(entornos secuenciales)
slo son visibles dentro
del proceso o
subprograma donde se
han declarado
toman el valor asignado
de forma inmediata
asignacin :=
variables variables
signal S1: integer;
aparecen y se declaran
en entornos
secuenciales
concurrentes
su visibilidad depende
de dnde estn
declaradas
toman su valor en la
declaracin y no
puede ser modificado
constantes constantes
VHDL. Seales, variables y constantes VHDL. Seales, variables y constantes
variable V1: bit; constant C1: real:=3;
14
Introduccin al VHDL 27 ElectrnicaDigital II
La asignacin de las seales se realiza de forma concurrente
Sentencias:
asignacin simple
asignacin condicional
asignacin selectiva
Asignacin de seales Asignacin de seales
entity WAVEFORMS is
port( SAL1 : out bit_vector(1 downto 0);
SAL2 : out bit_vector(1 downto 0)
);
end WAVEFORMS;
architecture DF of WAVEFORMS is
SAL1 <= 00,
01after 10 ns,
10after 20 ns,
11after 30 ns;
SAL2 <= 11,
10after 10 ns,
01after 20 ns,
00after 30 ns;
end DF;
entity WAVEFORMS is
port( SAL1 : out bit_vector(1 downto 0);
SAL2 : out bit_vector(1 downto 0)
);
end WAVEFORMS;
architecture DF of WAVEFORMS is
SAL1 <= 00,
01after 10 ns,
10after 20 ns,
11after 30 ns;
SAL2 <= 11,
10after 10 ns,
01after 20 ns,
00after 30 ns;
end DF;
asignacin simple asignacin simple
de seal de seal
0ns 10ns 20ns 30ns
SAL1(0)
SAL1(1)
SAL2(0)
SAL2(1)
Introduccin al VHDL 28 ElectrnicaDigital II
Asignacin de seales Asignacin de seales
architecture DF2 of MUX8 is
begin
Y <=E(0) when SEL =000,
E(1) when SEL =001,
E(2) when SEL =010,
E(3) when SEL =011,
E(4) when SEL =100,
E(5) when SEL =101,
E(6) when SEL =110,
else E(7);
end DF2;
architecture DF2 of MUX8 is
begin
Y <=E(0) when SEL =000,
E(1) when SEL =001,
E(2) when SEL =010,
E(3) when SEL =011,
E(4) when SEL =100,
E(5) when SEL =101,
E(6) when SEL =110,
else E(7);
end DF2;
<S_D><= <EXP1>when <EXP_BOOLEAN1>,
<EXP2>when <EXP_BOOLEAN2>,
else <EXPn>;
<S_D><= <EXP1>when <EXP_BOOLEAN1>,
<EXP2>when <EXP_BOOLEAN2>,
else <EXPn>;
Es similar a una sentencia if
<S_D>podr ser una salida o una
seal interna (no una entrada)
Las salidas de la entidad no pueden
aparecer en <EXP_BOOLEANi>ni en
<EXP1>... <EXPn>
asignacin asignacin
condicional condicional
15
Introduccin al VHDL 29 ElectrnicaDigital II
Asignacin de seales Asignacin de seales
Se deben cubrir todos los casos
posibles de la seal SEL
<S_D>podr ser una salida o una seal
interna (no una entrada)
Las salidas de la entidad no pueden
aparecer en <EXPRESION>ni en
<EXP1>... <EXPn>
entity MUX8 is
port( E : in bit_vector(7 downto 0);
SEL: in bit_vector(2 downto 0);
Y : out bit);
end MUX8;
architecture DF1 of MUX8 is
begin
with SEL select
Y <= E(0) when 000,
E(1) when 001,
E(2) when 010,
E(3) when 011,
E(4) when 100,
E(5) when 101,
E(6) when 110,
E(7) when 111;
end DF1;
entity MUX8 is
port( E : in bit_vector(7 downto 0);
SEL: in bit_vector(2 downto 0);
Y : out bit);
end MUX8;
architecture DF1 of MUX8 is
begin
with SEL select
Y <= E(0) when 000,
E(1) when 001,
E(2) when 010,
E(3) when 011,
E(4) when 100,
E(5) when 101,
E(6) when 110,
E(7) when 111;
end DF1;
with <EXPRESION>select
<S_D><= <EXP1>when <CASO1>,
<EXP2>when <CASO2>| <CASO3>,
<EXPn>when others;
with <EXPRESION>select
<S_D><= <EXP1>when <CASO1>,
<EXP2>when <CASO2>| <CASO3>,
<EXPn>when others;
asignacin asignacin
selectiva selectiva
Introduccin al VHDL 30 ElectrnicaDigital II
VHDL. Tipos de datos VHDL. Tipos de datos
Todos los objetos en VHDL son de un tipo dado. Un tipo de datos se caracteriza por el
conjunto de que puede tomar y los operadores que se le puede aplicar
Los objetos se crean mediante DECLARACIONES. En stas se especifica la clase y el
tipo del objeto se le asocia un identificador
<clase> <nombre_objeto>: <tipo> [:= <valor_inicial>]
signal S1: integer;
variable V1: bit;
constant C1: real:=3;
ASIGNACIONES. Asignar el valor de una expresin a un objeto
El operador := se utiliza en la asignacin de valores a constantes y variables
El operador <= se utiliza en la asignacin de valores a seales
!
!
16
Introduccin al VHDL 31 ElectrnicaDigital II
VHDL. Tipos de datos VHDL. Tipos de datos
Tipos Enumerados
Datos que pueden tomar cualquier valor especificado en un conjunto finito o lista
Boolean. Pueden tomar dos valores: True o False
Bit. Pueden tomar dos valores 0 1
Std_logic. Definido en el estndar IEEE 1164. Pueden tomar como valores
U -- Sin inicializar
X -- Desconocido Fuerte, cortocircuito en simulacin
0 -- 0 lgico fuerte, equivale a Vss
1 -- 1 lgico fuerte, equivale a Vdd
Z -- Alta impedancia
W -- Desconocido
L -- 0 lgico dbil, resistencia de pull-down
H -- 1 lgico dbil, resistencia de pull-up
- -- No importa se sintetiza en 0 1
Definido por el usuario. Se suelen usar en la descripcin de mquinas de estado:
type <nombre_tipo>is (<lista de valores>);
type ESTADO is (VERDE, AMARILLO, ROJ O);
!
!
Introduccin al VHDL 32 ElectrnicaDigital II
VHDL. Tipos de datos VHDL. Tipos de datos
Tipos numricos
Incluyen los tipos: natural, entero, real
type <nombre_tipo>is range literal {to| downto} literal;
Integer. Los enteros se representan en VHDL con 32 bits en complemento a 2. Si no
se acota el rango en la declaracin, las herramientas de sntesis sintetizan 32 bits
signal CONT: integer range 0 to 7
Vectores
Bit_vector. Vector de elementos tipo bit.
signal A,B: bit_vector (0 to 7)
signal C,D: bit_vector (7 downto 0)
Se puede asignar un valor a un elemento o a un segmento del vector
C(3) <=0; -- En la asignacin a un elemento se emplean comilla simples
C(3 downto 0) <=1100; -- En la asignacin se emplean comillas dobles
Se puede usar la clusula others para asignar el mismo valor a todo el vector o a
una parte de l
C<=(others =>0); -- Asigna 0 a todo el vector
C<=(7 =>1, others =>0); -- Equivale a C<=100000000;
Std_logic_vector. Vector de elementos tipo std_logic
!
!
17
Introduccin al VHDL 33 ElectrnicaDigital II
VHDL. Tipos de datos VHDL. Tipos de datos
Matrices
Definidos por el usuario:
type <identificador>is array (<indices>) of <tipo elemental>;
type matriz3por4 is array (1 to 3, 1 to 4) of integer;
Ejemplo: Modelado de una memoria de 128 posiciones de 8 bits
type DATA_WORDis array (7 downto 0) of std_logic;
type ROM is array (0 to 127) of DATA_WORD;
Registros
Formados por un conjunto de elementos de distinto tipo.
type <identificador>is record
<identificador del elemento 1 >: <tipo>;
<identificador del elemento 2>: <tipo>;

end record;
Ejemplo: type VECTORTEST is record
A,B : std_logic_vector (3 downto 0);
C,D: std_logic;
end record;
Introduccin al VHDL 34 ElectrnicaDigital II
Operadores Operadores
Op
Op
Descripcin
Descripcin
Operandos
Operandos
Resultado
Resultado
** potencia
entero op entero
real op entero
entero
real
abs abs numrico idem operando
not negacin bit, booleano, vector bits idem operando
* multiplicacin
entero op entero
real op real
fsico op entero
fsico op real
entero op fsico
real op fsico
entero
real
fsico
fsico
fsico
fsico
/ di visin
entero op entero
real op real
fsico op entero
fsico op real
fsico op fsico
entero
real
fsico
fsico
entero
mod mdulo entero op entero entero
rem resto entero op entero entero
+ suma numrico op numrico idem operando
- resta numrico op numrico idem operando
& concatenacin
vector op vector
vector op elemento
elemento op vector
elemento op elemento
vector
vector
vector
vector
M
e
n
o
r

p
r
e
c
e
d
e
n
c
i
a







M
a
y
o
r

p
r
e
c
e
d
e
n
c
i
a
18
Introduccin al VHDL 35 ElectrnicaDigital II
Operadores Operadores
& concatenacin
vector op vector
vector op elemento
elemento op vector
elemento op elemento
vector
vector
vector
vector
Op
Op
Descripcin
Descripcin
Operandos
Operandos
Resultado
Resultado
sll
srl
sla
sra
rol
ror
despl.lgico izq.
despl. lgico der.
Despl. arit. izq.
despl. arit. der.
rotacin izquierda
rotacin derecha
vect. bits op entero
vect. bits op entero
vect. bits op entero
vect. bits op entero
vect. bits op entero
vect. bits op entero
vector bits
vector bits
vector bits
vector bits
vector bits
vector bits
=
/=
<
>
<=
>=
igual que
diferente que
menor que
mayor que
menor o igual que
mayor o igual que
no fichero op idem
no fichero op idem
no fichero op idem
no fichero op idem
no fichero op idem
no fichero op idem
booleano
booleano
booleano
booleano
booleano
booleano
and
or
nand
nor
xor
xnor
y l gica
o lgica
y l gica negada
o lgica negada
o exclusiva
o exclusiva negada
bit,booleano,vect.bits op idem
bit,booleano,vect.bits op idem
bit,booleano,vect.bits op idem
bit,booleano,vect.bits op idem
bit,booleano,vect.bits op idem
bit,booleano,vect.bits op idem
booleano
booleano
booleano
booleano
booleano
booleano
M
e
n
o
r

p
r
e
c
e
d
e
n
c
i
a







M
a
y
o
r

p
r
e
c
e
d
e
n
c
i
a
L

G
I
C
O
S
D
e

r
e
l
a
c
i

n
Introduccin al VHDL 36 ElectrnicaDigital II
Atributos Atributos
Los atributos se aplican a una seal para obtener informacin especfica acerca de ella
<seal>event. Aplicado a una seal de reloj detecta los flancos del reloj
<seal>range. Devuelve el rango de la seal
Atributos de seal
Los atributos se aplican a una seal para obtener informacin especfica acerca de ella
<vector>left. Valor izquierdo del vector
<vector>right. Valor derecho del vector
<vector>low. Valor mnimo del vector
<vector>high. Valor mximo del vector
<vector>length. Nmero de elementos
<vector>range. Devuelve el rango del vector
Atributos de rango de vector
Signal V : bit_vector (15 downto 0);
-- Vleft es 15, Vright es 0,
-- Vlow es 0 , Vhigh es 15,
-- Vrange es 15 downto 0,
-- Vlength es 16
Signal V : bit_vector (15 downto 0);
-- Vleft es 15, Vright es 0,
-- Vlow es 0 , Vhigh es 15,
-- Vrange es 15 downto 0,
-- Vlength es 16
!
!
19
Introduccin al VHDL 37 ElectrnicaDigital II
Palabras reservadas Palabras reservadas
A
ABS
ACCESS
AFTER
ALIAS
ALL
AND
ARCHITECTURE
ARRAY
ASSERT
ATTRIBUTE
B
BEGIN
BLOCK
BODY
BUFFER
BUS
C
CASE
COMPONENT
CONFIGURATION
CONSTANT
D
DISCONNECT
DOWNTO
E
ELSE
ELSIF
END
ENTITY
EXIT
F
FILE
FOR
FUNCTION
G
GENERATE
GENERIC
GUARDED
I
IF
IN
INOUT
IS
L
LABEL
LIBRARY
LINKAGE
LOOP
M
MAP
MOD
N
NAND
NEW
NEXT
NOR
NOT
NULL
O
OF
ON
OPEN
OR
OTHERS
OUT
P
PACKAGE
PORT
PROCEDURE
PROCESS
R
RANGE
RECORD
REGISTER
REM
REPORT
RETURN
S
SELECT
SEVERITY
SIGNAL
SUBTYPE
T
THEN
TO
TRANSPORT
TYPE
U
UNITS
UNTIL
USE
V
VARIABLE
W
WAIT
WHEN
WHILE
WITH
X
XOR
Introduccin al VHDL 38 ElectrnicaDigital II
VHDL. Sentencias de descripcin VHDL. Sentencias de descripcin
Sentencias Concurrentes
PROCESOS
Sentencias de asignacin de seales
Sentencias secuenciales (en el interior de un proceso)
wait
Asignacin de seales y variables
Control de flujo de ejecucin
If-then-else
case
loop
20
Introduccin al VHDL 39 ElectrnicaDigital II
Un proceso (process) es una sentencia concurrente que agrupa en su interior
sentencias que se ejecutan secuencialmente
<ETIQ>: process [(<LISTA_SEALES>)]
<DECLARACIONES>
begin
<SENTENCIAS_SECUENCIALES>
end process <ETIQ>;
<ETIQ>: process [(<LISTA_SEALES>)]
<DECLARACIONES>
begin
<SENTENCIAS_SECUENCIALES>
end process <ETIQ>;
asignaciones de seal y variable
control de flujo
if...then...else...
case...is...when...=>...
while...loop...
for...loop...
loop...
control de ejecucin
lista de sensibilidad
wait on...for...until...
llamada a procedimientos
control de la simulacin: assert
Procesos Procesos
Sentencias Secuenciales
!
!
Introduccin al VHDL 40 ElectrnicaDigital II
Contienen sentencias que se
ejecutan secuencialmente
Los procesos entre s se ejecutan de
forma concurrente
Un proceso comienza a ejecutarse
cuando ocurre un evento en su lista de
sensibilidad o se cumplen las
condiciones de la sentencia wait
Tienen que tener wait o lista de
sensibilidad!!!
Las asignaciones de variable tienen
lugar de forma inmediata
Las asignaciones de seal tienen
lugar cuando se suspende el proceso
architecture COMP of UN_EJ EMPLO is
begin
P1: process(A, C)
begin
if A =1 then
B <=C;
else
B <=not C;
end if;
end process P1;
P2: process
begin
wait on A, C;
if A =1 then
B <=C;
else
B <=not C;
end if;
end process P2;
end COMP;
lista de sensibilidad
Procesos Procesos
!
!
21
Introduccin al VHDL 41 ElectrnicaDigital II
Contienen sentencias que se
ejecutan secuencialmente
Los procesos entre s se ejecutan de
forma concurrente
Un proceso comienza a ejecutarse
cuando ocurre un evento en su lista de
sensibilidad o se cumplen las
condiciones de la sentencia wait
Tienen que tener wait o lista de
sensibilidad!!!
Las asignaciones de variable tienen
lugar de forma inmediata
Las asignaciones de seal tienen
lugar cuando se suspende el proceso
Procesos Procesos
!
!
P1: process
begin
wait on A, B;
X <=A;
Y <=B;
end process P1;
P2: process
begin
wait on A, B;
Y <=B;
X <=A;
end process P2;
=
P2: process (A, B)
begin
Y <=B;
X <=A;
end process P2;
=
Introduccin al VHDL 42 ElectrnicaDigital II
P1: process
begin
wait on A, B;
X <=A;
Y <=B;
end process P1;
espera a que cambien
A B
wait on <SIGNAL_LIST>;
P1: process
begin
wait for 50 ns;
X <=A;
Y <=B;
end process P1;
espera a que pasen
50 ns
wait for <TIME>;
P1: process
begin
wait until ST =1;
X <=A;
Y <=B;
end process P1;
espera a que se cumpla
la condicin ST=1
wait until <COND>;
P1: process(A, B)
begin
X <=A;
Y <=B;
end process P1;
Si se usa wait,
todos los caminos de
control deben tener
un wait
Si se usa wait,
todos los caminos de
control deben tener
un wait
Sentencias secuenciales: Sentencias secuenciales: wait wait
=
22
Introduccin al VHDL 43 ElectrnicaDigital II
entity MUX8 is
port( E : in bit_vector(7 downto 0);
SEL: in bit_vector(2 downto 0);
Y : out bit);
end MUX8;
architecture BEHAV1 of MUX8 is
begin
COMB: process(E, SEL)
begin
if SEL =000then
Y <=E(0);
elsif SEL =001then
Y <=E(1);
elsif SEL =010then
Y <=E(2);
...
else
Y <=E(7);
end if;
end process COMB;
end BEHAV1;
entity MUX8 is
port( E : in bit_vector(7 downto 0);
SEL: in bit_vector(2 downto 0);
Y : out bit);
end MUX8;
architecture BEHAV1 of MUX8 is
begin
COMB: process(E, SEL)
begin
if SEL =000then
Y <=E(0);
elsif SEL =001then
Y <=E(1);
elsif SEL =010then
Y <=E(2);
...
else
Y <=E(7);
end if;
end process COMB;
end BEHAV1;
if <EXPR_BOOLEANA>then
<SENT_SECUENCIALES>
[elsif <EXPR_BOOLEANA>then
<SENT_SECUENCIALES>]
[else
<SENT_SECUENCIALES>]
end if;
if <EXPR_BOOLEANA>then
<SENT_SECUENCIALES>
[elsif <EXPR_BOOLEANA>then
<SENT_SECUENCIALES>]
[else
<SENT_SECUENCIALES>]
end if;
architecture BEHAV1 of DLATCH is
begin
SEQ: process(EN, D)
begin
if EN =1 then
Q <=D;
QB <=not D;
end if;
end process SEQ;
end BEHAV1;
architecture BEHAV1 of DLATCH is
begin
SEQ: process(EN, D)
begin
if EN =1 then
Q <=D;
QB <=not D;
end if;
end process SEQ;
end BEHAV1;
if if- -then then- -else else
Introduccin al VHDL 44 ElectrnicaDigital II
case <EXPR>is
when <CHOICE_1>=>
<SENTENCIAS_SECUENCIALES>
...
[when others =>
<SENTENCIAS_SECUENCIALES>]
end case;
case <EXPR>is
when <CHOICE_1>=>
<SENTENCIAS_SECUENCIALES>
...
[when others =>
<SENTENCIAS_SECUENCIALES>]
end case;
se tienen que considerar
todos los casos
se tienen que considerar
todos los casos
architecture BEHAV2 of MUX8 is
begin
COMB: process(E, SEL)
begin
case SEL is
when 000 =>
Y <=E(0);
when 001 =>
Y <=E(1);
when 010 =>
Y <=E(2);
when 011 =>
Y <=E(3);
when 100 =>
Y <=E(4);
when 101 =>
Y <=E(5);
when 110 =>
Y <=E(6);
when others =>
Y <=E(7);
end case;
end process COMB;
end BEHAV2;
architecture BEHAV2 of MUX8 is
begin
COMB: process(E, SEL)
begin
case SEL is
when 000 =>
Y <=E(0);
when 001 =>
Y <=E(1);
when 010 =>
Y <=E(2);
when 011 =>
Y <=E(3);
when 100 =>
Y <=E(4);
when 101 =>
Y <=E(5);
when 110 =>
Y <=E(6);
when others =>
Y <=E(7);
end case;
end process COMB;
end BEHAV2;
Sentencia Sentencia case case
23
Introduccin al VHDL 45 ElectrnicaDigital II
entity SHIFTER is
port( EN: in bit;
SAL: out bit_vector(7 downto 0));
end SHIFTER;
architecture BEHAV of SHIFTER is
begin
COMB: process (EN)
variable INT: bit_vector(7 downto 0);
begin
INT(0) :=EN;
for i in 7 downto 1 loop
INT(i) :=INT(i-1);
end loop;
SAL <=INT;
end process COMB;
end BEHAV;
entity SHIFTER is
port( EN: in bit;
SAL: out bit_vector(7 downto 0));
end SHIFTER;
architecture BEHAV of SHIFTER is
begin
COMB: process (EN)
variable INT: bit_vector(7 downto 0);
begin
INT(0) :=EN;
for i in 7 downto 1 loop
INT(i) :=INT(i-1);
end loop;
SAL <=INT;
end process COMB;
end BEHAV;
for <INDICE>in <RANGO>loop
<SENTENCIAS_SECUENCIALES>
end loop;
while <EXP_BOOLEANA>loop
<SENTENCIAS_SECUENCIALES>
end loop;
<ETIQ>: loop
<SENTENCIAS_SECUENCIALES>
[exit <ETIQ>when <EXP_BOOLEANA>]
[next <ETIQ>when <EXP_BOOLEANA>]
end loop <ETIQ>;
for <INDICE>in <RANGO>loop
<SENTENCIAS_SECUENCIALES>
end loop;
while <EXP_BOOLEANA>loop
<SENTENCIAS_SECUENCIALES>
end loop;
<ETIQ>: loop
<SENTENCIAS_SECUENCIALES>
[exit <ETIQ>when <EXP_BOOLEANA>]
[next <ETIQ>when <EXP_BOOLEANA>]
end loop <ETIQ>;
Sentencias Sentencias loop loop
Introduccin al VHDL 46 ElectrnicaDigital II
VHDL para sntesis VHDL VHDL para para sntesis sntesis
24
Introduccin al VHDL 47 ElectrnicaDigital II
VHDL. Sntesis de circuitos digitales VHDL. Sntesis de circuitos digitales
No todo el VHDL es SINTETIZABLE
Tipos de datos no soportados: time, real, access, file
De cara a la integracin con otros diseos deben utilizarse tipos
estndar: std_logic o bit
Lgica combinacional
Sentencias de asignacin concurrentes
PROCESOS
Lgica secuencial
If CLKevent and CLK=1
Biestables con RESET asncrono y con reset sncrono
Introduccin al VHDL 48 ElectrnicaDigital II
--asignacin condicional
S1 <= 0 when SEL =1
else 1;
--asignacin selecti va
with SEL select
S1 <= 0 when 1,
1 when 0;
--asignacin simple
S1 <= not SEL;
--llamada a procedimiento
Invierte(S1, SEL);
COMB: process(SEL)
begin
if SEL =1 then
S1 <=0;
else
S1 <=1;
end if;
end process COMB;
Lgica Lgica combinacional combinacional. Construcciones bsicas . Construcciones bsicas
Sentencias Concurrentes
Procesos
Todas las seales ledas en el proceso deben estar en la lista de
sensibilidad del proceso
Todas las salidas deben asignarse sea cual sea el camino de control
25
Introduccin al VHDL 49 ElectrnicaDigital II
Recomendaciones sobre el modelado Recomendaciones sobre el modelado
El modelado de lgica combinacional puede realizarse mediante
sentencias de asignacin concurrente o procesos.
Usar sentencias de asignacin concurrente cuando:
La lgica a modelar es simple (ej: pequeos multiplexores)
Como complemento de lgica secuencial en procesos
Acceso a buses triestado
Necesitamos un control preciso de la sntesis
Usar procesos cuando:
La lgica a modelar es compleja (ej: decodificadores complejos
o lgica secuencial)
Hay que tener cuidado con la inferencia de latches
Introduccin al VHDL 50 ElectrnicaDigital II
CONV1: process(BDCIN)
begin
case BCDIN is -- abcdefg
when 0000=> SEG <=1111110;
when 0001=> SEG <=0110000;
when 0010=> SEG <=1101101;
when 0011=> SEG <=1111001;
when 0100=> SEG <=0110011;
when 0101=> SEG <=1011011;
when 0110=> SEG <=1011111;
when 0111=> SEG <=1110000;
when 1000=> SEG <=1111111;
when 1001=> SEG <=1110111;
when others => SEG <=0000000;
end case;
end process CONV1;
CONV1: process(BDCIN)
begin
case BCDIN is -- abcdefg
when 0000=> SEG <=1111110;
when 0001=> SEG <=0110000;
when 0010=> SEG <=1101101;
when 0011=> SEG <=1111001;
when 0100=> SEG <=0110011;
when 0101=> SEG <=1011011;
when 0110=> SEG <=1011111;
when 0111=> SEG <=1110000;
when 1000=> SEG <=1111111;
when 1001=> SEG <=1110111;
when others => SEG <=0000000;
end case;
end process CONV1;
CONV2: process(BDCIN)
begin
case BCDIN is -- abcdefg
when 0000=> SEG <=1111110;
when 0001=> SEG <=0110000;
when 0010=> SEG <=1101101;
when 0011=> SEG <=1111001;
when 0100=> SEG <=0110011;
when 0101=> SEG <=1011011;
when 0110=> SEG <=1011111;
when 0111=> SEG <=1110000;
when 1000=> SEG <=1111111;
when 1001=> SEG <=1110111;
when others => SEG <=XXXXXXX;
end case;
end process CONV2;
CONV2: process(BDCIN)
begin
case BCDIN is -- abcdefg
when 0000=> SEG <=1111110;
when 0001=> SEG <=0110000;
when 0010=> SEG <=1101101;
when 0011=> SEG <=1111001;
when 0100=> SEG <=0110011;
when 0101=> SEG <=1011011;
when 0110=> SEG <=1011111;
when 0111=> SEG <=1110000;
when 1000=> SEG <=1111111;
when 1001=> SEG <=1110111;
when others => SEG <=XXXXXXX;
end case;
end process CONV2;
n puertas = 47
n puertas = 32
Ejemplo: convertidor BCD a 7 segmentos Ejemplo: convertidor BCD a 7 segmentos
26
Introduccin al VHDL 51 ElectrnicaDigital II
VHDL. DEMUX 3a8 VHDL. DEMUX 3a8
entity DEMUX3a8 is
port( DataIn,Enable : in std_logic;
Control : in std_logic_vector (2 downto 0);
DataOut : out std_logic_vector (7 downto 0));
end DEMUX3a8;
entity DEMUX3a8 is
port( DataIn,Enable : in std_logic;
Control : in std_logic_vector (2 downto 0);
DataOut : out std_logic_vector (7 downto 0));
end DEMUX3a8;
DEMUX3a8
DATAIN
CONTROL (2:0)
DATAOUT (7:0)
architecture Behavioral of demux3a8 is
signal DataEnable: std_logic_vector (3 downto 0);
signal Entrada: std_logic;
begin
DataEnable <=Enable & Control;
Entrada <=DataIn;
with dataEnable SELECT
DataOut <=(7 =>Entrada, others =>'0') when "1111",
(6 =>Entrada, others =>'0')when "1110",
(5 =>Entrada, others =>'0') when "1101",
(4 =>Entrada, others =>'0') when "1100",
(3 =>Entrada, others =>'0') when "1011",
(2 =>Entrada, others =>'0') when "1010",
(1 =>Entrada, others =>'0') when "1001",
(0 =>Entrada, others =>'0') when "1000",
(others =>'0') when others;
end Behavioral;
architecture Behavioral of demux3a8 is
signal DataEnable: std_logic_vector (3 downto 0);
signal Entrada: std_logic;
begin
DataEnable <=Enable & Control;
Entrada <=DataIn;
with dataEnable SELECT
DataOut <=(7 =>Entrada, others =>'0') when "1111",
(6 =>Entrada, others =>'0')when "1110",
(5 =>Entrada, others =>'0') when "1101",
(4 =>Entrada, others =>'0') when "1100",
(3 =>Entrada, others =>'0') when "1011",
(2 =>Entrada, others =>'0') when "1010",
(1 =>Entrada, others =>'0') when "1001",
(0 =>Entrada, others =>'0') when "1000",
(others =>'0') when others;
end Behavioral;
ENABLE
Introduccin al VHDL 52 ElectrnicaDigital II
VHDL. DEMUX 3a8 VHDL. DEMUX 3a8
entity DEMUX3a8 is
port( DataIn,Enable : in std_logic;
Control : in std_logic_vector (2 downto 0);
DataOut : out std_logic_vector (7 downto 0));
end DEMUX3a8;
entity DEMUX3a8 is
port( DataIn,Enable : in std_logic;
Control : in std_logic_vector (2 downto 0);
DataOut : out std_logic_vector (7 downto 0));
end DEMUX3a8;
DEMUX3a8
DATAIN
CONTROL (2:0)
DATAOUT (7:0)
architecture Behavioral of demux3a8 is
signal DataEnable: std_logic_vector (3 downto 0);
signal Entrada: std_logic;
begin
DataEnable <=Enable & Control;
Entrada <=DataIn;
with dataEnable SELECT
DataOut <=(7 =>Entrada, others =>'0') when "1111",
(6 =>Entrada, others =>'0')when "1110",
(5 =>Entrada, others =>'0') when "1101",
(4 =>Entrada, others =>'0') when "1100",
(3 =>Entrada, others =>'0') when "1011",
(2 =>Entrada, others =>'0') when "1010",
(1 =>Entrada, others =>'0') when "1001",
(0 =>Entrada, others =>'0') when "1000",
-- (others =>'0') when others;
end Behavioral;
architecture Behavioral of demux3a8 is
signal DataEnable: std_logic_vector (3 downto 0);
signal Entrada: std_logic;
begin
DataEnable <=Enable & Control;
Entrada <=DataIn;
with dataEnable SELECT
DataOut <=(7 =>Entrada, others =>'0') when "1111",
(6 =>Entrada, others =>'0')when "1110",
(5 =>Entrada, others =>'0') when "1101",
(4 =>Entrada, others =>'0') when "1100",
(3 =>Entrada, others =>'0') when "1011",
(2 =>Entrada, others =>'0') when "1010",
(1 =>Entrada, others =>'0') when "1001",
(0 =>Entrada, others =>'0') when "1000",
-- (others =>'0') when others;
end Behavioral;
ENABLE
Line 49. A value is missing in case.
ERROR:HDLParsers:812
std_logic_vector
27
Introduccin al VHDL 53 ElectrnicaDigital II
entity COD8a3_prior is
port( DataIn : in std_logic_vector (7 downto 0);
DataOut : out std_logic_vector (2 downto 0);
Activo : out std_logic);
end COD8a3_prior;
entity COD8a3_prior is
port( DataIn : in std_logic_vector (7 downto 0);
DataOut : out std_logic_vector (2 downto 0);
Activo : out std_logic);
end COD8a3_prior;
VHDL. Codificador de 8 a 3 con prioridad (I) VHDL. Codificador de 8 a 3 con prioridad (I)
COD8a3
Con prioridad
ACTIVO
DATAIN (7:0) DATAOUT (2:0)
architecture Behavioral of COD8a3_prior is
begin
DataOut<="111" when DataIn (7) ='1' else
"110" when DataIn (6) ='1' else
"101" when DataIn (5) ='1' else
"100" when DataIn (4) ='1' else
"011" when DataIn (3) ='1' else
"010" when DataIn (2) ='1' else
"001" when DataIn (1) ='1' else
"000";
Activo <='0' when DataIn ="00000000" else '1';
end Behavioral;
architecture Behavioral of COD8a3_prior is
begin
DataOut<="111" when DataIn (7) ='1' else
"110" when DataIn (6) ='1' else
"101" when DataIn (5) ='1' else
"100" when DataIn (4) ='1' else
"011" when DataIn (3) ='1' else
"010" when DataIn (2) ='1' else
"001" when DataIn (1) ='1' else
"000";
Activo <='0' when DataIn ="00000000" else '1';
end Behavioral;
Introduccin al VHDL 54 ElectrnicaDigital II
entity COD8a3_prior is
port( DataIn : in std_logic_vector (7 downto 0);
DataOut : out std_logic_vector (2 downto 0);
Activo : out std_logic);
end COD8a3_prior;
entity COD8a3_prior is
port( DataIn : in std_logic_vector (7 downto 0);
DataOut : out std_logic_vector (2 downto 0);
Activo : out std_logic);
end COD8a3_prior;
VHDL. Codificador de 8 a 3 con prioridad (I) VHDL. Codificador de 8 a 3 con prioridad (I)
COD8a3
Con prioridad
ACTIVO
DATAIN (7:0) DATAOUT (2:0)
architecture Behavioral of COD8a3_prior is
begin
DataOut<="111" when DataIn (7) ='1' else
"110" when DataIn (6) ='1' else
"101" when DataIn (5) ='1' else
"100" when DataIn (4) ='1' else
"011" when DataIn (3) ='1' else
"010" when DataIn (2) ='1' else
"001" when DataIn (1) ='1' else
"000";
Activo <='0' when DataIn ="00000000" else '1';
end Behavioral;
architecture Behavioral of COD8a3_prior is
begin
DataOut<="111" when DataIn (7) ='1' else
"110" when DataIn (6) ='1' else
"101" when DataIn (5) ='1' else
"100" when DataIn (4) ='1' else
"011" when DataIn (3) ='1' else
"010" when DataIn (2) ='1' else
"001" when DataIn (1) ='1' else
"000";
Activo <='0' when DataIn ="00000000" else '1';
end Behavioral;
28
Introduccin al VHDL 55 ElectrnicaDigital II
entity COD8a3_prior is
port( DataIn : in std_logic_vector (7 downto 0);
DataOut : out std_logic_vector (2 downto 0);
Activo : out std_logic);
end COD8a3_prior;
entity COD8a3_prior is
port( DataIn : in std_logic_vector (7 downto 0);
DataOut : out std_logic_vector (2 downto 0);
Activo : out std_logic);
end COD8a3_prior;
VHDL. Codificador de 8 a 3 con prioridad (II) VHDL. Codificador de 8 a 3 con prioridad (II)
COD8a3
Con prioridad
ACTIVO
DATAIN (7:0) DATAOUT (2:0)
architecture Behavioral of COD8a3_prior is
begin
P1: process (DataIn)
begin
if DataIn(7) ='1' then
DataOut<="111";
elsif DataIn(6) ='1' then
DataOut <="110";
elsif DataIn(5) ='1' then
DataOut<="101";
elsif DataIn(4) ='1' then
DataOut <="100";
elsif DataIn(3) ='1' then
DataOut<="011";
elsif DataIn(2) ='1' then
DataOut<="010";
elsif DataIn(1) ='1' then
DataOut <="001";
else
DataOut<="000";
end if;
end process P1;
Activo <='0' when DataIn ="00000000" else '1';
end Behavioral;
architecture Behavioral of COD8a3_prior is
begin
P1: process (DataIn)
begin
if DataIn(7) ='1' then
DataOut<="111";
elsif DataIn(6) ='1' then
DataOut <="110";
elsif DataIn(5) ='1' then
DataOut<="101";
elsif DataIn(4) ='1' then
DataOut <="100";
elsif DataIn(3) ='1' then
DataOut<="011";
elsif DataIn(2) ='1' then
DataOut<="010";
elsif DataIn(1) ='1' then
DataOut <="001";
else
DataOut<="000";
end if;
end process P1;
Activo <='0' when DataIn ="00000000" else '1';
end Behavioral;
Introduccin al VHDL 56 ElectrnicaDigital II
entity DECOD2a4 is
port( DATAIN : in std_logic_vector (1 downto 0);
ENABLE : in std_logic;
DATAOUT : out std_logic_vector (3 downto 0));
end DECOD2a4;
entity DECOD2a4 is
port( DATAIN : in std_logic_vector (1 downto 0);
ENABLE : in std_logic;
DATAOUT : out std_logic_vector (3 downto 0));
end DECOD2a4;
DECOD
2a4
ENABLE
VHDL. Decodificador 2a4 (I) VHDL. Decodificador 2a4 (I)
architecture Behavioral of DECOD2a4is
signal DataEnable: std_logic_vector (2 downto 0);
begin
DataEnable <=ENABLE & DATAIN;
with dataEnable SELECT
DATAOUT<="1000" when "111",
"0100" when "110",
"0010" when "101",
"0001" when "100",
"0000" when others;
end Behavioral;
architecture Behavioral of DECOD2a4is
signal DataEnable: std_logic_vector (2 downto 0);
begin
DataEnable <=ENABLE & DATAIN;
with dataEnable SELECT
DATAOUT<="1000" when "111",
"0100" when "110",
"0010" when "101",
"0001" when "100",
"0000" when others;
end Behavioral;
DATAIN (1:0) DATAOUT (3:0)
29
Introduccin al VHDL 57 ElectrnicaDigital II
entity DECOD2a4 is
port( DataIn : in std_logic_vector (1 downto 0);
Enable : in std_logic;
DataOut : out std_logic_vector (3 downto 0));
end DECOD2a4;
entity DECOD2a4 is
port( DataIn : in std_logic_vector (1 downto 0);
Enable : in std_logic;
DataOut : out std_logic_vector (3 downto 0));
end DECOD2a4;
DECOD
2a4
ENABLE
VHDL. Decodificador 2a4 (II) VHDL. Decodificador 2a4 (II)
DATAIN (1:0) DATAOUT (3:0)
architecture Behavioral of DECOD2a4is
begin
P1: process (DataIn,Enable)
begin
if Enable ='1' then
case DataIn is
when "00" =>
DataOut<="0001";
when "01" =>
DataOut<="0010";
when "10" =>
DataOut<="0100";
when "11" =>
DataOut<="1000";
when others =>
DataOut<=(others =>'0');
end case;
else
DataOut<="0000";
end if;
end process P1;
end Behavioral;
architecture Behavioral of DECOD2a4is
begin
P1: process (DataIn,Enable)
begin
if Enable ='1' then
case DataIn is
when "00" =>
DataOut<="0001";
when "01" =>
DataOut<="0010";
when "10" =>
DataOut<="0100";
when "11" =>
DataOut<="1000";
when others =>
DataOut<=(others =>'0');
end case;
else
DataOut<="0000";
end if;
end process P1;
end Behavioral;
Introduccin al VHDL 58 ElectrnicaDigital II
entity DECOD2a4 is
port( DataIn : in std_logic_vector (1 downto 0);
Enable : in std_logic;
DataOut : out std_logic_vector (3 downto 0));
end DECOD2a4;
entity DECOD2a4 is
port( DataIn : in std_logic_vector (1 downto 0);
Enable : in std_logic;
DataOut : out std_logic_vector (3 downto 0));
end DECOD2a4;
DECOD
2a4
ENABLE
VHDL. Decodificador 2a4 (II) VHDL. Decodificador 2a4 (II)
DATAIN (1:0) DATAOUT (3:0)
architecture Behavioral of DECOD2a4is
begin
P1: process (DataIn,Enable)
begin
if Enable ='1' then
case DataIn is
when "00" =>
DataOut<="0001";
when "01" =>
DataOut<="0010";
when "10" =>
DataOut<="0100";
when "11" =>
DataOut<="1000";
-- when others =>
--DataOut<=(others =>'0');
end case;
else
DataOut<="0000";
end if;
end process P1;
end Behavioral;
architecture Behavioral of DECOD2a4is
begin
P1: process (DataIn,Enable)
begin
if Enable ='1' then
case DataIn is
when "00" =>
DataOut<="0001";
when "01" =>
DataOut<="0010";
when "10" =>
DataOut<="0100";
when "11" =>
DataOut<="1000";
-- when others =>
--DataOut<=(others =>'0');
end case;
else
DataOut<="0000";
end if;
end process P1;
end Behavioral;
Line 49. A value is missing in case.
ERROR:HDLParsers:812
std_logic_vector
std_logic_vector
30
Introduccin al VHDL 59 ElectrnicaDigital II
VHDL. Comparador de dos nmeros de dos bits VHDL. Comparador de dos nmeros de dos bits
entity comparador is
port( A,B : in std_logic_vector (1 downto 0)
AigualB,AmayorB,AmenorB : out std_logic);
end comparador;
entity comparador is
port( A,B : in std_logic_vector (1 downto 0)
AigualB,AmayorB,AmenorB : out std_logic);
end comparador;
Comparador B(1:0)
A(1:0)
AigualB
AmayorB
AmenorB
architecture comportamental of comparador is
begin
AigualB <=1 when A=B else 0;
AmayorB<=1 when A>B else 0;
AmenorB<=1 when A<B else 0;
end comportamental;
architecture comportamental of comparador is
begin
AigualB <=1 when A=B else 0;
AmayorB<=1 when A>B else 0;
AmenorB<=1 when A<B else 0;
end comportamental;
library ieee ;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
library ieee ;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
Introduccin al VHDL 60 ElectrnicaDigital II
SEQ: process ( CLK, RESN)
begin
if RESN =0 then
Q <=0;
elsif CLKevent and CLK = 1 then
Q <=D;
end if;
end process SEQ;
ASIN: process( EN, RESN, D)
begin
if RESN =0 then
Q <=0;
elsif EN =1 then
Q <=D;
end if;
end process ASIN;
D
CLK
Q
RESN
D
EN
Q
RESN
biestable
latch
Sntesis de lgica secuencial Sntesis de lgica secuencial
Procesos Secuenciales Sncronos Procesos Secuenciales Asncronos
31
Introduccin al VHDL 61 ElectrnicaDigital II
Toda seal asignada en entre if CLKevent.... y el end if; infiere un
biestable
Toda variable cuyo valor es ledo en alguno de los caminos de ejecucin
(entre el if CLKevent... y el end if) antes de ser asignada infiere un biestable
Toda seal que se no asigne en alguno de los posibles caminos de ejecucin
de un proceso, infiere un latch.
Mtodo
aconsejable para
modelar
biestables
SEQ2: process(CLK)
begin
if CLKevent and CLK =1then
Q <=D;
end if;
end process SEQ2;
Inferencia de biestables: reglas bsicas Inferencia de biestables: reglas bsicas
Introduccin al VHDL 62 ElectrnicaDigital II
Las listas de sensibilidad deben contener, al menos, la seal de reloj y
la inicializacin asncrona, si existe. Si el proceso contiene una parte
combinacional, deber contener adems las seales ledas en dicha
parte (procesos mixtos).
La condicin de inicializacin puede aparecer dentro o fuera de la
condicin del reloj, segn se desee que sea sncrona o asncrona.
SEQ: process( CLK, RESN, SETN)
begin
if RESN =0 then --RESET asncrono
Q <=0;
elsif SETN =0 then --SET asncrono
Q <=1;
elsif CLKevent and CLK = 1 then
if CLEARN =0 then --CLEAR sncrono
Q <=0;
else
Q <=D;
end if;
end if;
end process SEQ;
Inicializacin asncrona de biestables Inicializacin asncrona de biestables
32
Introduccin al VHDL 63 ElectrnicaDigital II
library IEEE;
use IEEE.std_logic_1164.all;
entity DFFRN is
port( CLK : in std_logic;
RN : in std_logic;
EN : in std_logic;
D : in std_logic;
Q : out std_logic);
end DFFRN;
architecture A1 of DFFRN is
begin
SEQ: process(RN, CLK)
begin
if RN =0 then
Q <=0;
elsif CLK = 1 and CLKevent then
if EN =1 then
Q <=D;
end if;
end if;
end process SEQ;
end A1;
significa si el reloj tiene un
flanco de subida
si EN =0 mantiene el valor de Q
cada seal que se asigne
dentro de la condicin
del reloj genera un biestable
cada seal que se asigne
dentro de la condicin
del reloj genera un biestable
Ejemplo: un Ejemplo: un biestable biestable D D
Q D
EN
RN
Introduccin al VHDL 64 ElectrnicaDigital II
architecture DOS of SHRegis
begin
P: process (Clk)
variable V : bit_vector(7 downto 0);
begin
if clkevent and clk = 1 then
V(0) :=Ent; -- Asignacin variable
for i in 1 to 7 loop
V(i) :=Q(i-1); -- Asignacin variable
end loop;
Q <=V;
end if;
end process P;
end DOS;
entitySHReg is
port ( Clk, Ent : in bit;
Q : buffer bit_vector(7 downto 0));
end SHReg;
La misma entidad para
todas las arquitecturas
Ent
architecture UNA of SHRegis
begin
P: process (Clk)
begin
if clkevent and clk = 1 then
q(0) <=Ent;
for i in 1 to 7 loop
q(i) <=q(i-1);
end loop;
end if;
end process P;
end UNA;
Q(0) Q(1) Q(7)
Ejemplo: un registro de desplazamiento Ejemplo: un registro de desplazamiento
!
!
33
Introduccin al VHDL 65 ElectrnicaDigital II
architecture TRES of SHReg is
begin
P: process (Clk)
variable V : bit_vector(7 downto 0);
begin
if clkevent and clk = 1 then
for i in 7 downto 1 loop
V(i) :=Q(i-1);
end loop;
V(0) :=Ent;
Q <=V;
end if;
end process P;
end DOS;
architecture ELEGANTE of SHReg is
begin
P: process (Clk)
begin
if clkevent and clk = 1 then
Q(0) <=Ent;
Q(1 to 7) <=Q(0 to 6);
end if;
end process P;
end ELEGANTE;
Ejemplo: un registro de desplazamiento (II) Ejemplo: un registro de desplazamiento (II)
!
!
Introduccin al VHDL 66 ElectrnicaDigital II
Se pueden modelar con dos procesos. En uno se modela la parte
combinacional y en otro la parte secuencial (registros)
parte combinacional
parte
secuencial
ESTADO
ACTUAL
ESTADO
SIGUIENTE
CLK
entradas salidas
proceso proceso
combinacional combinacional
proceso proceso
secuencial secuencial
Sntesis de mquinas de estados Sntesis de mquinas de estados
34
Introduccin al VHDL 67 ElectrnicaDigital II
CODIFICACIN DE ESTADOS
Enumerado:
type ESTADO is (S0,S1,S2,S3);
One Hot Encoding
type ESTADO is (VERDE, AMARILLO, ROJ O);
attribute ENUM_ENCODING of ESTADO: type is 0001 0010 0100 1000;
Sntesis de mquinas de estados Sntesis de mquinas de estados
!
!
NO VHDL estndar
Introduccin al VHDL 68 ElectrnicaDigital II
INIC
0
DET0
0
DET01
1
1
0
0
1
1
0
entity DETECTA is
port( CLK : in std_logic;
RN : in std_logic;
DIN : in std_logic;
SAL : out std_logic);
end DETECTA;
entity DETECTA is
port( CLK : in std_logic;
RN : in std_logic;
DIN : in std_logic;
SAL : out std_logic);
end DETECTA;
La salida asociado al
estado
La salida asociado al
estado
Sntesis: Mquinas de Sntesis: Mquinas de Moore Moore (I) (I)
C.C.
ENT
F.F.
C.C.
SAL
35
Introduccin al VHDL 69 ElectrnicaDigital II
architecture MOORE of DETECTA is
-- Declaracin tipo ESTADO
type ESTADO is (INIC, DET0, DET01);
-- Declaracin seal de tipo estado
signal ACTUAL, SIGUE : ESTADO;
begin
-- proceso secuencial asignacin estado
SEQ: process(CLK, RN)
begin
if RN =0 then
ACTUAL <=INIC;
elsif CLKevent and CLK = 1 then
ACTUAL <=SIGUE;
end if;
end process SEQ;
...
...
-- proceso combinacional
COMB: process(ACTUAL, DIN)
begin
case ACTUAL is
when INIC =>
SAL <=0; -- la salida asociada al estado
if DIN =1 then
SIGUE <=INIC;
else
SIGUE <=DET0;
end if;
when DET0 =>
SAL <=0;
if DIN =1 then
SIGUE <=DET01;
else
SIGUE <=DET0;
end if;
...
Sntesis: Mquinas de Sntesis: Mquinas de Moore Moore (II) (II)
parte combinacional
parte
secuencial
ESTADO
ACTUAL
ESTADO
SIGUIENTE
CLK
entradas salidas
proceso proceso
combinacional combinacional
proceso proceso
secuencial secuencial
Introduccin al VHDL 70 ElectrnicaDigital II
INIC
DET0
DET01
1/0
0/0
0/0
1/1
1/0
0/0
entity DETECTA is
port( CLK : in std_logic;
RN : in std_logic;
DIN : in std_logic;
SAL : out std_logic);
end DETECTA;
entity DETECTA is
port( CLK : in std_logic;
RN : in std_logic;
DIN : in std_logic;
SAL : out std_logic);
end DETECTA;
La salida depende del
estado actual y la entrada
(asociada a la transicin)
La salida depende del
estado actual y la entrada
(asociada a la transicin)
Sntesis: Mquinas de Sntesis: Mquinas de Mealy Mealy (I) (I)
C.C.
ENT
F.F.
C.C.
SAL
Estilo B
36
Introduccin al VHDL 71 ElectrnicaDigital II
architecture MEALY of DETECTA is
type ESTADO is (INIC, DET0, DET01);
signal ACTUAL, SIGUE : ESTADO;
begin
SEQ: process(CLK, RN)
begin
if RN =0 then
ACTUAL <=INIC;
elsif CLKevent and CLK = 1 then
ACTUAL <=SIGUE;
end if;
end process SEQ;
...
...
COMB: process(ACTUAL, DIN)
begin
case ACTUAL is
when INIC =>
if DIN =1 then
SIGUE <=INIC;
SAL <=0; -- la salida asociada a la transicin
else
SIGUE <=DET0;
SAL <=0;
end if;
when DET0 =>
if DIN =1 then
SIGUE <=DET01;
SAL <=1;
else
SIGUE <=DET0;
SAL <=0;
end if;
Sntesis: Mquinas de Sntesis: Mquinas de Mealy Mealy (II) (II)
parte combinacional
parte
secuencial
ESTADO
ACTUAL
ESTADO
SIGUIENTE
CLK
entradas salidas
proceso proceso
combinacional combinacional
proceso proceso
secuencial secuencial
Introduccin al VHDL 72 ElectrnicaDigital II
architecture behaviour of contador4is
signal CUENTA: std_logic_vector (3 downto 0); -- Seal donde se acumula la cuenta
begin
process (CLK, RN)
begin
if RN =0 then -- reset asncrono
CUENTA <=0000;
elsif CLKevent and CLK =1 then
if E=1 then
CUENTA <=CUENTA +1;
end if;
end if;
end process;
SAL <=CUENTA; -- asignacin al puerto de salida el valor de la seal CUENTA
end behaviour;
Sntesis: Contadores Sntesis: Contadores
entity contador4 is
port ( CLK : in std_logic;
RN : in std_logic;
E : in std_logic;
SAL : out std_logic_vector (3 downto 0));
end contador4;
library IEEE;
use IEEE_STD_LOGIC_1164.all;
use IEEE_ST_LOGIC_UNSIGNED.all;
37
Introduccin al VHDL 73 ElectrnicaDigital II
architecture behaviour of contador4_carga is
signal CUENTA: std_logic_vector (3 downto 0);
begin
process (CLK, RN)
begin
if RN =0 then reset asncrono
CUENTA <=0000;
elsif CLKevent and CLK =1 then
if CARGA=1 then Carga sncrona
CUENTA <=DATO;
else
-- sino se incrementa la cuenta
CUENTA <=CUENTA +1;
end if;
end if;
end process;
SAL <=CUENTA;
end behaviour;
Sntesis: Contador con carga en paralelo Sntesis: Contador con carga en paralelo
entity contador4_carga is
port ( CLK, RN,CARGA : in std_logic;
DATO : in std_logic_vector (3 downto 0);
SAL : out std_logic_vector (3 downto 0));
end contador4_carga;
library IEEE;
use IEEE_STD_LOGIC_1164.all;
use IEEE_ST_LOGIC_UNSIGNED.all;
Introduccin al VHDL 74 ElectrnicaDigital II
architecture behaviour of contador4_updown is
signal CUENTA: std_logic_vector (3 downto 0);
begin
process (CLK, RN)
begin
if RN =0 then reset asncrono
CUENTA <=0000;
elsif CLKevent and CLK =1 then
if UP=1 then -- cuenta ascendente
if (CUENTA <=1111) then
CUENTA <=0000;
else
CUENTA <=CUENTA +1;
end if;
else -- cuenta descendente
if (CUENTA <=0000) then
CUENTA <=1111;
else cuenta descendente
CUENTA <=CUENTA -1;
end if;
end if;
end if;
end process;
SAL <=CUENTA;
end behaviour;
Sntesis: Contadores UP/DOWN Sntesis: Contadores UP/DOWN
entity contador4_updown is
port ( CLK,RN,UP : in std_logic;
SAL : out std_logic_vector (3 downto 0));
end contador4_updown;
library IEEE;
use IEEE_STD_LOGIC_1164.all;
use IEEE_ST_LOGIC_UNSIGNED.all;
38
Introduccin al VHDL 75 ElectrnicaDigital II
architecture EJ EMP of CONTA16is
signal CUENTA: integer range 0 to 2**16 - 1;
begin
COUNT <= conv_std_logic_vector(CUENTA,15);
OVF <= 1 when CUENTA =2**16 - 1 else 0;
SEQ: process(CLK, RN)
begin
if RN =0 then
CUENTA <=0;
elsif CLKevent and CLK = 1 then
if EN =1 then
if CUENTA <2**16 - 1 then
CUENTA <=CUENTA +1;
else
CUENTA <=0;
end if;
end if;
end if;
end process SEQ;
end EJ EMP;
Funcin del paquete
std_logic
Para evitar el
desbordamiento en
simulacin
Asignaciones
concurrentes
Sntesis: Contadores (I) Sntesis: Contadores (I)
Introduccin al VHDL 76 ElectrnicaDigital II
architecture EJ EMP of CONTA16is
signal COUNT : std_logic_vector(15 dowto 0);
const MaxVal : std_logic_vector(15 dowto 0)
:=(others => 1);
begin
OVF <=1 when COUNT =MaxVal else 0;
-- No vale poner COUNT =(others =>1) ??
SEQ: process(CLK, RN)
begin
if RN =0 then
COUNT <=(others =>0);
elsif CLKevent and CLK = 1 then
if EN =1 then
if COUNT =MaxVal then
COUNT <=(others =>0);
else
COUNT <=COUNT +1; -- IEEE.arith
end if;
end if;
end if;
end process SEQ;
end EJ EMP;
Para evitar el
desbordamiento en
simulacin
Asignaciones
concurrentes
Sntesis: Contadores (II) Sntesis: Contadores (II)
Paquete no
estndar
std_logic_arith
(Synopsys)
39
Introduccin al VHDL 77 ElectrnicaDigital II
Usar SEALES siempre que vayan a tener visibilidad fuera del proceso en el que
modifica su valor
Usar VARIABLES siempre que no vayan a tener visibilidad fuera del proceso en el que
se declaran y se usan
Para que una variable no genere un elemento de memoria, es imprescindible que se le
asigne un valor cada vez que se ejecuta el proceso.
Nunca se debe depender de los valores por defecto de las seales y variables.
Nunca se deben inicializar seales y variables en la declaracin
Todas las seales de entradao que se leen en el proceso deben estar en la lista de
sensibilidad
Todas las seales y variables asignadas toman un valor en cada camino de control
Para permitir la optimizacin lgica se puede utilizar el valor -
Es recomendable hacer la lgica secuencial con la construccin if clkevent and clk=1
( 0), no pudiendo aparecer ninguna otra condicin en dicha construccin.
Slo debe aparecer un reloj en cada proceso secuencial. Si se tienen varios relojes, se
deben poner en procesos separados.
La construccin if clkevent and clk=1 ( 0) no debe estar incluida en otra construccin
(por ejemplo en un loop)
No introducir cdigo que genere lgica combinacional en procesos secuenciales a no
ser que se utilicen variables
Recomendaciones: modelado para sntesis Recomendaciones: modelado para sntesis
Introduccin al VHDL 78 ElectrnicaDigital II
Conviene separar la parte secuencial de la combinacional en dos procesos distintos:
El proceso secuencial modela los registros
El proceso combinacional modela la asignacin del estado siguiente
Las asignaciones de los valores de las salidas se pueden hacer en el proceso
combinacional o en unas sentencias concurrentes
Los estados se representarn con un tipo especfico para cada mquina
Las entradas y salidas de los bloques sern de tipo std_logic std_ulogic. Para
asegurar que no se hacen conexiones indeseadas, se pueden usar tipos std_ulogic (no
resueltos)
En bloques de menor jerarqua se pueden utilizar tipos no estndar
Las rplicas (instances) de componentes deben tener el mismo nombre que las
entidades a las que corresponden.
Las seales de entrada que no se vayan a usar se deben poner a un valor fijo (por
ejemplo -, para la optimizacin).
Las seales de salida que no se vayan a usar se dejarn desconectadas.
El sintetizador puede hacer una optimizacin ms eficiente cuando el cdigo con una
misma funcionalidad est agrupado en funciones o procedimientos
No se pueden usar llamadas recursivas
No se deben usar dentro de subprogramas seales o variables que no hayan sido
pasadas como parmetros en la llamada
Recomendaciones: modelado para sntesis Recomendaciones: modelado para sntesis
40
Introduccin al VHDL 79 ElectrnicaDigital II
VHDL para simulacin VHDL VHDL para para simulacin simulacin
Introduccin al VHDL 80 ElectrnicaDigital II
El VHDL fue creado para ser simulado (existe una forma estndar estndar
de simular las descripciones VHDL)
se puede definir en VHDL tanto el circuito a simular como los
estmulos a aplicar
SIMULADOR VHDL
MODELO ESTMULOS
VHDL para simulacin VHDL para simulacin
... adems ...
41
Introduccin al VHDL 81 ElectrnicaDigital II
Modelo de tiempo definido: Simulacin dirigida por eventos
Hardware concurrente: los componentes de un circuito estn siempre
ACTIVOS y operan a la vez.
Cmo se ejecuta un modelo concurrente en una mquina secuencial?:a
travs del SIMULADOR
La simulacin en VHDL es dirigida por eventos: los valores de las seales
NO se evaluan en cada instante, sino cuando alguna de las seales de las
que depende cambia de valor.
VHDL: Simulacin VHDL: Simulacin
1. Anlisis
Unidades de diseo a la biblioteca de funciones
Enlaces entre las distintas unidades
Anlisis sintctico y de coherencia
2. Elaboracin: se genera una red plana de procesos comunicados por
seales
3. Simulacin
Secuencia de procesos
Proceso gestor de elaboracin (KERNEL)
Actualiza los valores de las seales
Comprueba los procesos que deben ejecutarse
Efecta el avance del tiempo
SIMULACIN
Introduccin al VHDL 82 ElectrnicaDigital II
-- generamos el reloj
RELOJ : process
begin
CLK <=0;
wait for CICLO /2;
CLK <=1;
wait for CICLO /2;
end process RELOJ ;
-- generamos el test
TEST: process
begin
RESN <=0;
DATO <=1;
wait for CICLO * 2;
RESN <=1;
wait for CICLO;
DATO <=0;
wait for CICLO * 2;
entity TbBiestable is
end TbBiestable;
architecture SIMULA of TbBiestable is
-- Declaracin de componentes
component Biestable
port (CLK,RESN,DATO : in bit;
Q : out bit);
end component;
-- Declaracin de seales y constantes
signal CLK, RESN, DATO, Q: bit;
constant CICLO: time :=100ns;
begin
-- Colocacin y conexin de componentes
DFF: Biestable
port map (CLK,RESN,DATO,Q);
assert false
report FIN DE LA SIMULACION
severity failure;
end process TEST;
end SIMULA;
declaracin de
la entidad
declaracin de
componentes,
seales y
constantes
colocacin y
conexin de
componentes
asignacin de
valores al resto
de las seales
control del
fin de la simulacin
VHDL para simulacin VHDL para simulacin
Generacin
del reloj
42
Introduccin al VHDL 83 ElectrnicaDigital II
Hay que comprobar que el circuito hace lo que debey que
no hace lo que no debe
Siempre se comprueban:
Inicializaciones
Cambios de modo de funcionamiento
Cobertura de cdigo (100% aconsejable)
Interfaz con su entorno
Simulacin: Bancos de prueba ( Simulacin: Bancos de prueba (Testbench Testbench) )
Introduccin al VHDL 84 ElectrnicaDigital II
Estmulos + modelo VHDL
Inspeccin visual de los resultados
Estmulos + modelo VHDL +
comprobador de resultados
Conocimiento de los resultados a
priori
Estmulos dependientes de los
resultados + modelo VHDL +
comprobador de resultados
Se pueden establecer varios niveles de verificacin
Se pueden establecer varios niveles de verificacin Se pueden establecer varios niveles de verificacin
Modelo
VHDL
Estmulos
Modelo
VHDL
Estmulos Comprobador
Modelo
VHDL
Estmulos Comprobador
Simulacin: Cmo probar un modelo VHDL Simulacin: Cmo probar un modelo VHDL
!
!
43
Introduccin al VHDL 85 ElectrnicaDigital II
Simulacin: Ejemplo Simulacin: Ejemplo
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
-- Circuito sncrono;
-- Reset asncrono activo por nivel bajo;
-- Cuando Load es 1 se carga con el ParrallelData;
-- Cuando Shift es 1 desplaza de los bits menos significativos
-- a los mas significativos e introduce SerialData en el LSB
entity ShiftLoad is
port ( clk : in std_logic;
reset : in std_logic;
Shift : in std_logic;
Load : in std_logic;
SerialData : in std_logic;
ParallelData : in std_logic_vector(7 downto 0);
DataOut : out std_logic_vector(7 downto 0));
end ShiftLoad;
architecture Behavioral of ShiftLoad is
signal DatosInternos: std_logic_vector (7 downto 0);
begin
process (clk, reset)
begin
if reset ='0' then
DatosInternos <=(others =>'0');
elsif clk ='1' and clk'event then
if Load ='1' then
DatosInternos <=ParallelData;
elsif Shift ='1' then
for i i n 7 downto 1 loop
DatosInternos(i) <=DatosInternos (i-1);
end loop;
DatosInternos(0) <=SerialData;
end if;
end if;
end process;
DataOut <=DatosInternos;
end Behavioral;
Introduccin al VHDL 86 ElectrnicaDigital II
Simulacin: Ejemplo Simulacin: Ejemplo
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.numeric_std.ALL;
-- Declaracin de la entidad
ENTITY shiftload_TBShiftLoad_vhd_tb IS
END shiftload_TBShiftLoad_vhd_tb;
ARCHITECTURE behavior OF shiftload_TBShiftLoad_vhd_tb IS
-- Declaracin de componentes
COMPONENT shiftload
PORT( clk : IN std_logic;
reset : IN std_logic;
Shift : IN std_logic;
Load : IN std_logic;
SerialData : IN std_logic;
ParallelData : IN std_logic_vector(7 downto 0);
DataOut : OUT std_logic_vector(7 downto 0));
END COMPONENT;
SIGNAL clk : std_logic;
SIGNAL reset : std_logic;
SIGNAL Shift : std_logic;
SIGNAL Load : std_logic;
SIGNAL SerialData : std_logic;
SIGNAL ParallelData : std_logic_vector(7 downto 0);
SIGNAL DataOut : std_logic_vector(7 downto 0);
constant ciclo : time :=50 ns;
BEGIN
-- Colocacin y conexin de componentes
uut: shiftload PORT MAP(
clk =>clk,
reset =>reset,
Shift =>Shift,
Load =>Load,
SerialData =>SerialData,
ParallelData =>ParallelData,
DataOut =>DataOut
);
-- proceso que genera el reloj
GenCLK: process
begin
clk <='0';
wait for ciclo/2;
clk <='1';
wait for ciclo;
end process GenCLK;
..
-- *** Test Bench - User Defined Section ***

44
Introduccin al VHDL 87 ElectrnicaDigital II
Simulacin: Ejemplo Simulacin: Ejemplo
-- *** Test Bench - User Defined Section ***
tb : PROCESS
BEGIN
--Inicializacin
reset <='0';
Shift <='0';
Load <='0';
SerialData <='0';
ParallelData <=(others =>'0');
wait for ciclo;
assert (DataOut ="00000000")
report "Error en la prueba del reset"
severity error;
wait for ciclo;
-- Desplazamiento
reset <='1';
Shift <='1';
SerialData <='1';
wait for ciclo * 8;
-- Control del fin de la simulacin
assert (DataOut ="11111111")
report "Error en la prueba de desplazamiento"
severity error;
wait for ciclo;
-- Carga
ParallelData <="01010101";
Shift <='0';
Load <='1';
wait for ciclo;
assert (DataOut ="01010101")
report "Error en la prueba de carga"
severity error;
wait for ciclo;
-- Desplazamiento
Shift <='1';
SerialData <='0';
wait for ciclo * 8;
assert (DataOut ="00000000")
report "Error en la segunda prueba de desplazamiento"
severity error;
wait for ciclo;
Load <='1';
ParallelData <=(others =>'1');
wait for ciclo;
assert (DataOut ="00000000" or DataOut ="11111111" )
report "Error al cargar con Shift igual a 1"
severity error;
wait for ciclo;
reset <='0';
wait for ciclo;
assert false
report "Fin de la simulacion"
severity error;
END PROCESS tb;
-- *** End Test Bench - User Defined Section ***
END;
Introduccin al VHDL 88 ElectrnicaDigital II
La descripcin, adems de ptima para sntesis y simulacin,
debe ser legible:
Indentar correctamente el cdigo
Escribir un nico comando por lnea
Comentar el significado de seales y variables, as como la
funcionalidad del cdigo
Poner cabeceras en los ficheros (fecha, dependencias,
autores, etc)
Elegir nombres adecuados para seales, variables,
entidades, procesos, paquetes, funciones, bibliotecas, etc.
Existen guas de estilo para VHDL de dominio pblico: Gua
PRENDA, European Space Agency: VHDL Modeling
Guidelines.
Recomendaciones de estilo Recomendaciones de estilo

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