VHDL
Disciplina: Sistemas Digitais – Profa. Dra. Fernanda Gusmão de Lima Kastensmidt – 2006
Aula
Estrutura do VHDL 6
end process;
architecture name_tipo of name is
<declaração de componentes> 5
<outros comandos> 4
<declaração de sinais> 3 <instanciação de componentes;
begin
end;
Disciplina: Sistemas Digitais – Profa. Dra. Fernanda Gusmão de Lima Kastensmidt – 2006 2 / 37
Aula
7e8
Comandos Sequencias
Disciplina: Sistemas Digitais – Profa. Dra. Fernanda Gusmão de Lima Kastensmidt – 2006
Aula
Comandos Sequenciais 6
Disciplina: Sistemas Digitais – Profa. Dra. Fernanda Gusmão de Lima Kastensmidt – 2006 4 / 37
Aula
Process 6
• Contem comandos sequenciais
• Existe apenas dentro da arquitetura
entity AND_OR_XOR is
• Todos os process rodam ao mesmo port (A,B : in bit;
tempo de maneira concorrente. Z_OR, Z_AND, Z_XOR : out bit);
• A execução dos process são end AND_OR_XOR;
controladas por: architecture RTL of AND_OR_XOR is
– Lista de sensibilidade (sinais begin
end RTL;
Disciplina: Sistemas Digitais – Profa. Dra. Fernanda Gusmão de Lima Kastensmidt – 2006 5 / 37
Aula
Comando: IF… then … else …. 6
if CONDITION then
-- sequential statements
end if;
A condição é uma
if CONDITION then
-- sequential statements
expressão booleana
else Opcional:
-- sequential statements -elsif
end if;
-else
if CONDITION then
-- sequential statements
elsif CONDITION then
-- sequential statements
···
else
-- sequential statements
end if;
Disciplina: Sistemas Digitais – Profa. Dra. Fernanda Gusmão de Lima Kastensmidt – 2006 6 / 37
Aula
IF Statement: Examplo 6
entity IF_STATEMENT is
port (A, B, C, X : in bit_vector (3 downto 0);
Z : out bit_vector (3 downto 0);
end IF_STATEMENT;
Disciplina: Sistemas Digitais – Profa. Dra. Fernanda Gusmão de Lima Kastensmidt – 2006 7 / 37
Aula
Comando: CASE … is… WHEN …. 6
case EXPRESSION is
• Opções não podem ser
when VALUE_1 => coincidentes.
-- sequential statements
• Todas as opções devem
when VALUE_2 | VALUE_3 => ser cobertas:
-- sequential statements • valores simples
• intervalo de valores
when VALUE_4 to VALUE_N => • seleção de valores por
-- sequential statements ("|" que significa "or")
• uso obrigatorio de
when others =>
-- sequential statements
"when others" para
cobrir a(s) ultima(s)
end case ; opções.
Disciplina: Sistemas Digitais – Profa. Dra. Fernanda Gusmão de Lima Kastensmidt – 2006 8 / 37
Aula
entity CASE_STATEMENT is
port (A, B, C, X : in integer range 0 to 15; 6
Z : out integer range 0 to 15;
end CASE_STATEMENT;
Disciplina: Sistemas Digitais – Profa. Dra. Fernanda Gusmão de Lima Kastensmidt – 2006 9 / 37
entity RANGE_2 is Aula
port (A, B, C, X : in bit_vector(3 downto 0); 6
Z : out bit_vector(3 downto 0);
end RANGE_2;
Disciplina: Sistemas Digitais – Profa. Dra. Fernanda Gusmão de Lima Kastensmidt – 2006 10 / 37
entity CONDITIONAL_ASSIGNMENT is Aula
port (A, B, C, X : in bit_vector (3 downto 0);
6
Z_CONC : out bit_vector (3 downto 0);
Z_SEQ : out bit_vector (3 downto 0));
end CONDITIONAL_ASSIGNMENT;
Disciplina: Sistemas Digitais – Profa. Dra. Fernanda Gusmão de Lima Kastensmidt – 2006 11 / 37
Aula
Comando: FOR Loops 6
entity FOR_LOOP is
port (A : in integer range 0 to 3;
Z : out bit_vector (3 downto 0));
end FOR_LOOP;
Disciplina: Sistemas Digitais – Profa. Dra. Fernanda Gusmão de Lima Kastensmidt – 2006 12 / 37
Aula
Loop Sintaxe 6
[LOOP_LABEL :]
for IDENTIFIER in DISCRETE_RANGE loop
-- sequential statements
end loop [LOOP_LABEL] ;
[LOOP_LABEL :]
while CONDITION loop
-- sequential statements
end loop [LOOP_LABEL] ;
Disciplina: Sistemas Digitais – Profa. Dra. Fernanda Gusmão de Lima Kastensmidt – 2006 13 / 37
entity CONV_INT is Aula
port (VECTOR: in bit_vector(7 downto 0); 6
RESULT: out integer);
end CONV_INT;
Disciplina: Sistemas Digitais – Profa. Dra. Fernanda Gusmão de Lima Kastensmidt – 2006 14 / 37
Aula
Comando: WAIT 6
Disciplina: Sistemas Digitais – Profa. Dra. Fernanda Gusmão de Lima Kastensmidt – 2006 15 / 37
Aula
WAIT Statement: Examplos 6
entity FF is
port (D, CLK : in bit;
Q : out bit);
end FF;
Disciplina: Sistemas Digitais – Profa. Dra. Fernanda Gusmão de Lima Kastensmidt – 2006 16 / 37
Aula
WAIT Statement: Examplos 6
STIMULUS: process
begin
SEL <= `0`;
BUS_B <= "0000";
BUS_A <= "1111";
wait for 10 ns;
wait;
end process STIMULUS;
Disciplina: Sistemas Digitais – Profa. Dra. Fernanda Gusmão de Lima Kastensmidt – 2006 17 / 37
Aula
6
READ_CPU : process
begin
wait until CPU_DATA_VALID = `1`;
CPU_DATA_READ <= `1`;
wait for 20 ns;
LOCAL_BUFFER <= CPU_DATA;
wait for 10 ns;
CPU_DATA_READ <= `0`;
end process READ_CPU;
Disciplina: Sistemas Digitais – Profa. Dra. Fernanda Gusmão de Lima Kastensmidt – 2006 18 / 37
Aula
Clocked Process:
6
Detecção da borda do Clock
if
clock_signal_ name'EVENT and clock_signal_ name='1'
clock_signal_ name='1' and clock_signal_ name'EVENT
not clock_signal_ name'STABLE and clock_signal_ name='1'
clock_signal_ name='1' and not clock_signal_ name'STABLE
RISING_EDGE ( clock_signal_ name)
Disciplina: Sistemas Digitais – Profa. Dra. Fernanda Gusmão de Lima Kastensmidt – 2006 19 / 37
Clocked Process: Clock Edge Aula
Detection 6
wait until
•clock_signal_ name'EVENT andclock_signal_ name='1'
•clock_signal_ name='1' and clock_signal_ name'EVENT
•not clock_signal_ name'STABLE and clock_signal_ name='1'
•clock_signal_ name='1' and not clock_signal_ name'STABLE
•RISING_EDGE ( clock_signal_ name)
•clock_signal_ name='1'
Disciplina: Sistemas Digitais – Profa. Dra. Fernanda Gusmão de Lima Kastensmidt – 2006 20 / 37
Detection of a Rising Edge by Use of Aula
Functions 6
Disciplina: Sistemas Digitais – Profa. Dra. Fernanda Gusmão de Lima Kastensmidt – 2006 21 / 37
Aula
Inferindo um Registrador 6
library IEEE;
use IEEE.std_logic_1164.all;
Elementos de memoria são inferidos, ou
entity COUNTER is seja, gerados sempre que os sinais
port (CLK: in std_logic; receberem assinalamentos dentro de
Q : out integer range 0 to 15 ); uma process controlado por relógio
end COUNTER; (clock)
COUNT: 4 flip flops
architecture RTL of COUNTER is
signal COUNT : integer range 0 to 15 ; Q: not used in clocked process
begin
process (CLK)
begin
if CLK`event and CLK = `1` then
if (COUNT >= 9) then
COUNT <= 0;
else
COUNT <= COUNT +1;
end if;
end if;
end process;
Q <= COUNT ;
Disciplina: Sistemas Digitais – Profa. Dra. Fernanda Gusmão de Lima Kastensmidt – 2006 22 / 37
Aula
Asynchronous Set/Reset 6
library IEEE;
use IEEE.std_logic_1164.all;
entity ASYNC_FF is
port (D, CLK, SET, RST : in std_logic;
Q : out std_logic);
end ASYNC_FF;
Disciplina: Sistemas Digitais – Profa. Dra. Fernanda Gusmão de Lima Kastensmidt – 2006 23 / 37
Aula
Clocked Process: Rules 6
process
begin
wait until CLK'event and CLK='1';
if RESET = '1' then Wait-form:
-- synchronous register reset no sensitivity list
else Synchronous reset
-- combinatorics
end if;
end process;
process(CLK, RST)
begin
if (RST = `1`) then If-form:
-- asynchronous register reset only clock and asynchronous
elsif (CLK`event and CLK=`1`) then signals (reset) in sensitivity list
-- combinatorics Synchronous and asynchronous
end if; reset
end process;
Disciplina: Sistemas Digitais – Profa. Dra. Fernanda Gusmão de Lima Kastensmidt – 2006 24 / 37
Aula
6
Bibliotecas IEEE para VHDL
Disciplina: Sistemas Digitais – Profa. Dra. Fernanda Gusmão de Lima Kastensmidt – 2006
Aula
Library IEEE 6
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_textio.all;
use IEEE.std_logic_arith.all;
use IEEE.numeric_bit.all;
use IEEE.numeric_std.all;
use IEEE.std_logic_signed.all;
use IEEE.std_logic_unsigned.all;
use IEEE.math_real.all;
use IEEE.math_complex.all;
Disciplina: Sistemas Digitais – Profa. Dra. Fernanda Gusmão de Lima Kastensmidt – 2006 26 / 37
Aula
library IEEE;
6
use IEEE.std_logic_1164.all;
Disciplina: Sistemas Digitais – Profa. Dra. Fernanda Gusmão de Lima Kastensmidt – 2006 27 / 37
Aula
library IEEE;
6
use IEEE.std_logic_textio.all;
Disciplina: Sistemas Digitais – Profa. Dra. Fernanda Gusmão de Lima Kastensmidt – 2006 28 / 37
Aula
library IEEE;
6
use IEEE.std_logic_arith.all;
Disciplina: Sistemas Digitais – Profa. Dra. Fernanda Gusmão de Lima Kastensmidt – 2006 29 / 37
library IEEE; Aula
use IEEE.numeric_bit.all; 6
use IEEE.numeric_std.all
Disciplina: Sistemas Digitais – Profa. Dra. Fernanda Gusmão de Lima Kastensmidt – 2006 30 / 37
library IEEE; Aula
6
use IEEE.std_logic_signed.all;
use IEEE.std_logic_unsigned.all
• The package std_logic_signed provides signed numerical
computation on type std_logic_vector
Disciplina: Sistemas Digitais – Profa. Dra. Fernanda Gusmão de Lima Kastensmidt – 2006 31 / 37
library IEEE; Aula
use IEEE.math_real.all; 6
use IEEE.math_complex.all;
Disciplina: Sistemas Digitais – Profa. Dra. Fernanda Gusmão de Lima Kastensmidt – 2006 32 / 37
Aula
Disciplina: Sistemas Digitais – Profa. Dra. Fernanda Gusmão de Lima Kastensmidt – 2006
Aula
Variaveis 6
Disciplina: Sistemas Digitais – Profa. Dra. Fernanda Gusmão de Lima Kastensmidt – 2006 34 / 37
Aula
Variaveis vs. Sinais 6
Disciplina: Sistemas Digitais – Profa. Dra. Fernanda Gusmão de Lima Kastensmidt – 2006 35 / 37
Aula
Uso de Variaveis 6
Disciplina: Sistemas Digitais – Profa. Dra. Fernanda Gusmão de Lima Kastensmidt – 2006 36 / 37
Aula
entity PARITY is
port (DATA: in bit_vector (3 downto 0); 6
ODD : out bit);
end PARITY;
Disciplina: Sistemas Digitais – Profa. Dra. Fernanda Gusmão de Lima Kastensmidt – 2006 37 / 37