Mudanças entre as edições de "DLP29006-Engtelecom (Diário) - Prof. Marcos Moecke"
(→ATUAL) |
|||
Linha 422: | Linha 422: | ||
:: Ler sobre o problema do repique das chaves mecânicas [https://my.eng.utah.edu/~cs5780/debouncing.pdf A Guide to Debouncing] | :: Ler sobre o problema do repique das chaves mecânicas [https://my.eng.utah.edu/~cs5780/debouncing.pdf A Guide to Debouncing] | ||
− | + | ||
;Encontro 11 (27 abr.): | ;Encontro 11 (27 abr.): | ||
*Realização da [https://wiki.sj.ifsc.edu.br/index.php/DLP29006-Engtelecom_(Di%C3%A1rio)_-_Prof._Marcos_Moecke#AE3_-_Programa.C3.A7.C3.A3o_do_kit_Mercurio_IV AE3 - Programação do kit Mercurio IV]. | *Realização da [https://wiki.sj.ifsc.edu.br/index.php/DLP29006-Engtelecom_(Di%C3%A1rio)_-_Prof._Marcos_Moecke#AE3_-_Programa.C3.A7.C3.A3o_do_kit_Mercurio_IV AE3 - Programação do kit Mercurio IV]. | ||
+ | {{collapse bottom}} | ||
+ | |||
+ | ===Unidade 3 - Tipos de Dados e Operadores em VHDL=== | ||
+ | * 10 Encontros | ||
+ | |||
+ | ====ATUAL==== | ||
+ | {{collapse top | expand=true | Unidade 3 - Tipos de Dados e Operadores em VHDL}} | ||
+ | ;Encontro 12 (3 mai.): | ||
+ | *Comentários no código (duplo traço --) | ||
+ | -- Isso eh uma linha de comentario | ||
+ | y <= a * b ; --o sinal y recebe o resultado da multiplicacao a x b | ||
+ | *Representação de caracteres, strings e números em VHDL. No circuito, os caracteres são representados através de bits de acordo com a [https://www.lookuptables.com/text/ascii-table tabela ASCII] básica (00 a 7F). A definição dessa tabela é feita o pacote '''[[standard.vhd]]''' da biblioteca '''std'''. | ||
+ | :*Caracteres (entre aspas simples) | ||
+ | caracter: 'A' 'x' '#' (com aspas simples) | ||
+ | |||
+ | :*Palavras (entre aspas duplas), é definida no VHDL como um vetor de caracteres. | ||
+ | <syntaxhighlight lang=vhdl> | ||
+ | type string is array (positive range <>) of character; | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | string: "IFSC" "teste" "teste123" | ||
+ | |||
+ | :*Números em geral | ||
+ | elemento ("bit") único: '0' '1' 'Z' (entre aspas simples) | ||
+ | vetor de elementos ("bits"): "0110" "101001Z" (entre aspas duplas) | ||
+ | vetor de 1 elemento ("bit"): "0" "1" (entre aspas duplas) | ||
+ | inteiros: 5 1101 1102 (sem aspas) | ||
+ | |||
+ | :*Números binários: | ||
+ | 0 -> '0' | ||
+ | 7 (em base 2) -> "0111" ou b"0111" ou B"0111" | ||
+ | 1023 (em base 2) -> "001111111111" ou b"1111111111" ou B"1111111111" | ||
+ | |||
+ | :*Números octais: | ||
+ | 44 (em base 8) -> 5*8^1 + 4*8^0 -> O"54" ou o"54" | ||
+ | 1023 (em base 8)-> 1*8^3 + 7*8^2 + 7*8^1 + 7*8^0 -> o"1777" 8#1777# | ||
+ | |||
+ | :*Números Hexadecimais: | ||
+ | 1023 (em base 16) -> 3*16^2 + 15*16^1 + 15*16^0 = X"3FF" ou x"3FF" 16#3FF# | ||
+ | |||
+ | :*Números decimais: | ||
+ | 1023 -> 1023 ou 1_023 | ||
+ | 1000 -> 1000 ou 1_000 ou 1E3 | ||
+ | ::Cuidado ao usar o "_" pois algumas ferramentas não o reconhecem. | ||
+ | |||
+ | :*Números em outras bases (de 2 a 16) | ||
+ | 85 (em base 5) -> (3*5^2 + 2*5^1 + 0*5^0) -> 5#320# | ||
+ | 1539 (em base 3) -> (2*3^2+0*3^1+1*3^0)*3^4 -> 3#201#E4 | ||
+ | |||
+ | *Tipos de dados em VHDL. | ||
+ | :*Objetos de VHDL: '''CONSTANT''', '''SIGNAL''', '''VARIABLE''', '''FILE'''. | ||
+ | |||
+ | O objeto '''CONSTANT''' pode ser declarado na parte declarativa da ENTITY, ARCHITECTURE, PACKAGE, PACKAGE_BODY, BLOCK, GENERATE, PROCESS, FUNCTION e PROCEDURE. | ||
+ | <syntaxhighlight lang=vhdl> | ||
+ | |||
+ | constant <constant_name> : <type> := <constant_value>; | ||
+ | |||
+ | -- Declarações comuns de constantes | ||
+ | |||
+ | constant GND : std_logic := '0'; | ||
+ | constant VCC : std_logic := '1'; | ||
+ | constant SSD_0 : std_logic_vector(0 to 6) := "1111110"; | ||
+ | constant MAX : natural := 44; | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | O objeto '''SIGNAL''' pode ser declarado na parte declarativa da ENTITY, ARCHITECTURE, PACKAGE, BLOCK, GENERATE. Os sinais não podem ser declarados no código sequencial (PROCESS, FUNCTION e PROCEDURE), mas podem ser usados. | ||
+ | |||
+ | <syntaxhighlight lang=vhdl> | ||
+ | -- Signal sem valor default | ||
+ | -- Para atribuir um valor a um signal use "<=" como operador. | ||
+ | |||
+ | signal <name> : <type>; | ||
+ | |||
+ | -- Signal com valor default | ||
+ | signal <name> : <type> := <default_value>; | ||
+ | |||
+ | -- Declarações comuns de signals | ||
+ | |||
+ | signal <name> : std_logic; | ||
+ | signal <name> : std_logic_vector(<msb_index> downto <lsb_index>); | ||
+ | signal <name> : integer; | ||
+ | signal <name> : integer range <low> to <high>; | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | O objeto '''VARIABLE''' (variável) só pode ser declarada e usada dentro do escopo no código sequencial (PROCESS, FUNCTION e PROCEDURE). | ||
+ | |||
+ | <syntaxhighlight lang=vhdl> | ||
+ | -- Variables devem ser declarada em process ou subprogramas. | ||
+ | -- Para atribuir um valor a um variable use ":=" como operador. | ||
+ | |||
+ | -- Variable sem valor default. | ||
+ | variable <name> : <type>; | ||
+ | |||
+ | -- Variable com valor default. | ||
+ | variable <name> : <type> := <default_value>; | ||
+ | |||
+ | -- Declarações comuns de variables | ||
+ | variable <name> : std_logic; | ||
+ | variable <name> : std_logic_vector(<msb_index> downto <lsb_index>); | ||
+ | variable <name> : integer; | ||
+ | variable <name> : integer range <low> to <high>; | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | :*Palavra chave '''OTHERS''' para formação de agregados | ||
+ | Exemplos de declaração de CONSTANT, SIGNAL, VARIABLE, inicializando o valor usando o agregados | ||
+ | |||
+ | <syntaxhighlight lang=vhdl> | ||
+ | CONSTANT a: BIT_VECTOR(5 DOWNTO 0) := (OTHERS => '0'); -- "000000" | ||
+ | |||
+ | CONSTANT b: BIT_VECTOR(7 DOWNTO 0) := (7 => '0', OTHERS => '1'); -- "01111111" | ||
+ | CONSTANT c: BIT_VECTOR(7 DOWNTO 0) := (7 => '0', 6 DOWNTO 0 => '1'); -- "01111111" | ||
+ | CONSTANT d: BIT_VECTOR(7 DOWNTO 0) := "01111111"; | ||
+ | |||
+ | SIGNAL e: STD_LOGIC_VECTOR(7 DOWNTO 0); -- Not initialized | ||
+ | SIGNAL f: STD_LOGIC_VECTOR(1 TO 8) := (2|3|8 => '1', 4 => 'Z', OTHERS => '0' ); -- "011Z0001" | ||
+ | |||
+ | VARIABLE g: BIT_VECTOR(1 TO 16); -- Not initialized | ||
+ | VARIABLE h: BIT_VECTOR(1 TO 16) := (1 TO 8 => '1', OTHERS => '0'); -- "1111111100000000" | ||
+ | |||
+ | </syntaxhighlight> | ||
+ | |||
+ | :: Ver pag. 31 a 35 de <ref name="PEDRONI2010b"/> | ||
+ | |||
+ | :* Bibliotecas padrão IEEE ('''[[Std logic 1164.vhd]]''', '''[[Numeric std.vhd]]'''). | ||
+ | ::* '''ATENÇÃO!!! Não use as bibliotecas que não são padrão (''std_logic_arith, std_logic_unsigned, std_logic_signed''''') | ||
+ | |||
+ | * Classificação dos tipos de dados. | ||
+ | |||
+ | A biblioteca [[standard.vhd]] define os tipos BIT, BIT_VECTOR, BOOLEAN, INTEGER, NATURAL, POSITIVE, CHARACTER, STRING. | ||
+ | |||
+ | <syntaxhighlight lang=vhdl> | ||
+ | package standard is | ||
+ | type boolean is (false,true); | ||
+ | type bit is ('0', '1'); | ||
+ | type severity_level is (note, warning, error, failure); | ||
+ | type integer is range -2147483647 to 2147483647; | ||
+ | type real is range -1.0E308 to 1.0E308; | ||
+ | type time is range -2147483648 to 2147483647 | ||
+ | units | ||
+ | fs; | ||
+ | ps = 1000 fs; | ||
+ | ns = 1000 ps; | ||
+ | us = 1000 ns; | ||
+ | ms = 1000 us; | ||
+ | sec = 1000 ms; | ||
+ | min = 60 sec; | ||
+ | hr = 60 min; | ||
+ | end units; | ||
+ | subtype natural is integer range 0 to integer'high; | ||
+ | subtype positive is integer range 1 to integer'high; | ||
+ | type string is array (positive range <>) of character; | ||
+ | type bit_vector is array (natural range <>) of bit; | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | A biblioteca [[Std logic 1164.vhd]] define os tipos STD_(U)LOGIG, STD_(U)LOGIG_VECTOR. | ||
+ | |||
+ | <syntaxhighlight lang=vhdl> | ||
+ | PACKAGE std_logic_1164 IS | ||
+ | TYPE std_ulogic IS ( 'U', -- Uninitialized | ||
+ | 'X', -- Forcing Unknown | ||
+ | '0', -- Forcing 0 | ||
+ | '1', -- Forcing 1 | ||
+ | 'Z', -- High Impedance | ||
+ | 'W', -- Weak Unknown | ||
+ | 'L', -- Weak 0 | ||
+ | 'H', -- Weak 1 | ||
+ | '-' -- Don't care | ||
+ | ); | ||
+ | TYPE std_ulogic_vector IS ARRAY ( NATURAL RANGE <> ) OF std_ulogic; | ||
+ | SUBTYPE std_logic IS resolved std_ulogic; | ||
+ | TYPE std_logic_vector IS ARRAY ( NATURAL RANGE <>) OF std_logic; | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | A biblioteca [[Std logic 1164.vhd]] ainda define algumas funções importantes como a '''rising_edge''' que determina se um sinal está na borda de subida (usado em sinais de clock). | ||
+ | |||
+ | <syntaxhighlight lang=vhdl> | ||
+ | ------------------------------------------------------------------- | ||
+ | -- conversion functions | ||
+ | ------------------------------------------------------------------- | ||
+ | FUNCTION To_bit ( s : std_ulogic; xmap : BIT := '0') RETURN BIT; | ||
+ | FUNCTION To_bitvector ( s : std_logic_vector ; xmap : BIT := '0') RETURN BIT_VECTOR; | ||
+ | FUNCTION To_StdULogic ( b : BIT ) RETURN std_ulogic; | ||
+ | FUNCTION To_StdLogicVector ( b : BIT_VECTOR ) RETURN std_logic_vector; | ||
+ | |||
+ | ------------------------------------------------------------------- | ||
+ | -- edge detection | ||
+ | ------------------------------------------------------------------- | ||
+ | FUNCTION rising_edge (SIGNAL s : std_ulogic) RETURN BOOLEAN; | ||
+ | FUNCTION falling_edge (SIGNAL s : std_ulogic) RETURN BOOLEAN; | ||
+ | |||
+ | ------------------------------------------------------------------- | ||
+ | -- edge detection | ||
+ | ------------------------------------------------------------------- | ||
+ | FUNCTION rising_edge (SIGNAL s : std_ulogic) RETURN BOOLEAN IS | ||
+ | -- altera built_in builtin_rising_edge | ||
+ | BEGIN | ||
+ | RETURN (s'EVENT AND (To_X01(s) = '1') AND | ||
+ | (To_X01(s'LAST_VALUE) = '0')); | ||
+ | END; | ||
+ | |||
+ | </syntaxhighlight> | ||
+ | |||
+ | A biblioteca [[Numeric std.vhd]] define os tipos UNSIGNED e SIGNED. | ||
+ | |||
+ | <syntaxhighlight lang=vhdl> | ||
+ | package NUMERIC_STD is | ||
+ | type UNSIGNED is array (NATURAL range <>) of STD_LOGIC; | ||
+ | type SIGNED is array (NATURAL range <>) of STD_LOGIC; | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | A biblioteca [[Numeric std.vhd]] ainda define os operadores (abs, "+", "-", "*", "\", rem, mod, sll, slr, ror, rol), comparações ("=", '/=', ">", ">=", "<", "<=") e operadores lógicos (not, and, nand, or, nor, xor, xnor) para os tipos SIGNED e UNSIGNED. Além disso também define algumas funções muito utilizadas como: | ||
+ | |||
+ | <syntaxhighlight lang=vhdl> | ||
+ | --============================================================================ | ||
+ | -- RESIZE Functions | ||
+ | --============================================================================ | ||
+ | function RESIZE (ARG: SIGNED; NEW_SIZE: NATURAL) return SIGNED; | ||
+ | function RESIZE (ARG: UNSIGNED; NEW_SIZE: NATURAL) return UNSIGNED; | ||
+ | |||
+ | --============================================================================ | ||
+ | -- Conversion Functions | ||
+ | --============================================================================ | ||
+ | function TO_INTEGER (ARG: UNSIGNED) return NATURAL; | ||
+ | function TO_INTEGER (ARG: SIGNED) return INTEGER; | ||
+ | function TO_UNSIGNED (ARG, SIZE: NATURAL) return UNSIGNED; | ||
+ | function TO_SIGNED (ARG: INTEGER; SIZE: NATURAL) return SIGNED; | ||
+ | |||
+ | </syntaxhighlight> | ||
+ | |||
+ | :: Ver pag. 73 a 78 de <ref name="PEDRONI2010b"/> | ||
+ | |||
+ | :* Resumo dos Tipos predefinidos. | ||
+ | {| class="wikitable sortable" border="1" cellpadding="3" cellspacing="0" style="text-align:left; font-size:100%" bgcolor="#efefef" | ||
+ | ! scope="col" width=15% align="left"| Tipo de Dado | ||
+ | ! scope="col" width=10% align="left"| Package | ||
+ | ! scope="col" width=7% align="left"| Library | ||
+ | ! scope="col" width=50% align="left"| Valores | ||
+ | ! scope="col" width=15% align="left"| Observações | ||
+ | |- | ||
+ | | BOOLEAN || standard || std || TRUE e FALSE || sintetizável | ||
+ | |- | ||
+ | | BIT || standard || std || valores '0', '1' || sintetizável | ||
+ | |- | ||
+ | | INTEGER || standard || std || números inteiros de 32 bits [de -2^31 até + (2^31 - 1)] || sintetizável | ||
+ | |- | ||
+ | | NATURAL || standard || std || números inteiros não negativos [de 0 até + (2^31 - 1)] || sintetizável | ||
+ | |- | ||
+ | | POSITIVE || standard || std || números inteiros positivos [de 1 até + (2^31 - 1)] || sintetizável | ||
+ | |- | ||
+ | | BOOLEAN_VECTOR || standard (2008) || std || vetor de BOOLEAN || sintetizável | ||
+ | |- | ||
+ | | BIT_VECTOR || standard || std || vetor de BIT || sintetizável | ||
+ | |- | ||
+ | | INTEGER_VECTOR || standard || std || vetor de INTEGER || sintetizável | ||
+ | |- | ||
+ | | REAL || standard || std || números reais [de -1.0E-38 até + 1.0E38] || simulação | ||
+ | |- | ||
+ | | CHARACTER || standard || std || caracteres ASCII || | ||
+ | |- | ||
+ | | STRING || standard || std || vetor de CHARACTER || | ||
+ | |- | ||
+ | | STD_LOGIC || std_logic_1164 || ieee || valores 'U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-' || sintetizável | ||
+ | |- | ||
+ | | STD_LOGIC_VECTOR || std_logic_1164 || ieee || vetor de STD_LOGIC || sintetizável | ||
+ | |- | ||
+ | | SIGNED || numeric_std || ieee || STD_LOGIC_VECTOR que aceitam operações aritméticas com sinal|| sintetizável | ||
+ | |- | ||
+ | | UNSIGNED || numeric_std || ieee || STD_LOGIC_VECTOR que aceitam operações aritméticas sem sinal || sintetizável | ||
+ | |- | ||
+ | | SIGNED || numeric_bit || ieee || BIT_VECTOR que aceitam operações aritméticas com sinal || sintetizável | ||
+ | |- | ||
+ | | UNSIGNED || numeric_bit || ieee || BIT_VECTOR que aceitam operações aritméticas sem sinal || sintetizável | ||
+ | |- | ||
+ | | SIGNED || std_logic_arith || ieee || STD_LOGIC_VECTOR que aceitam operações aritméticas com sinal || sintetizável (não é padrão, não utilizar) | ||
+ | |- | ||
+ | | UNSIGNED || std_logic_arith || ieee || STD_LOGIC_VECTOR que aceitam operações aritméticas sem sinal || sintetizável (não é padrão, não utilizar) | ||
+ | |- | ||
+ | | UFIXED || fixed_pkg + (2008) || ieee || números de ponto fixo sem sinal|| sintetizável | ||
+ | |- | ||
+ | | SFIXED || fixed_pkg + (2008) || ieee || números de ponto fixo com sinal|| sintetizável | ||
+ | |- | ||
+ | | FLOAT || float_pkg + (2008) || ieee || Números de ponto flutuante || sintetizável | ||
+ | |} | ||
+ | |||
+ | * Tipos de dados predefinidos: FIXED e FLOAT (apenas conhecer) | ||
+ | |||
+ | *Função resize | ||
{{collapse bottom}} | {{collapse bottom}} | ||
Edição das 15h58min de 3 de maio de 2022
Registro on-line das aulas
Unidade 1 - Introdução a disciplina
- 4 ENCONTROS
Unidade 1 - Introdução a disciplina | ||||
---|---|---|---|---|
|
Unidade 2 - Introdução ao VHDL e ambienta EDA - QUARTUS
- 7 ENCONTROS
Unidade 2 - Introdução ao VHDL e ambienta EDA - QUARTUS |
---|
library library_name;
use library_name.package_name.all;
entity entity_name is
[generic (
cons_name1: const_type const_value;
cons_name2: const_type const_value;
...
cons_nameN: const_type const_value);]
[port (
signal_name1: mode signal_type;
signal_name2: mode signal_type;
...
signal_nameN: mode signal_type);]
[declarative_part]
[begin
statement_part]
end [entity] [entity_name];
architecture arch_name of entity_name is
[declarative_part]
begin
statement_part
end [architecture] [arch_name];
library std;
use std.standard.all;
entity nand_gate is
port (a, b: in bit; x: out bit);
end entity;
architecture nome_arch of nand_gate is
begin
x <= a nand b;
end architecture;
Exemplo de descrição de um multiplexador de 4 entradas entity mux_novo is
port
(
-- Input ports
X: in bit_vector (3 downto 0);
S : in bit_vector (1 downto 0);
-- Output ports
Y : out bit
);
end entity mux_novo;
-- Implementação com lógica pura
architecture v_logica_pura of mux_novo is
begin
Y <= (X(0) and (not S(1)) and (not S(0))) or
(X(1) and (not S(1)) and (S(0))) or
(X(2) and (S(1)) and (not S(0))) or
(X(3) and (S(1)) and (S(0)));
end architecture Logica_pura;
-- Implementação com WHEN ELSE
architecture v_WHEN of mux_novo is
begin
Y <= X(0) when S = "00" else
X(1) when S = "01" else
X(2) when S = "10" else
X(3);
end architecture v_WHEN;
-- Implementação com WITH SELECT
architecture v_WITH_SELECT of mux_novo is
begin
with S select
Y <= X(0) when "00", -- note o uso da ,
X(1) when "01",
X(2) when "10",
X(3) when others; -- note o uso de others, para todos os demais valores.
-- Não pode ser substituido por "11" mesmo que o signal seja bit_vector.
end architecture v_WITH_SELECT;
-- Implementação com IF ELSE
architecture v_IF_ELSE of mux_novo is
begin
-- Uma arquitetura vazia como essa é denominada de STUB,
-- Pode ser utilizada em um projeto durante para conferir as conexões externas.
-- Posteriormente a arquitetura será descrita.
end architecture v_IF_ELSET;
-- Design Unit que associa a architecture com a entity
configuration cfg_ifsc of mux_novo is
-- for v_WITH_SELECT end for;
for v_WHEN end for;
end configuration;
Figura 2.1 - Código RTL do mux 4x1 v_logica_pura Figura 2.2 - Código RTL do mux 4x1 v_WHEN Figura 2.3 - Código RTL do mux 4x1 v_WITH_SELECT
Figura 2.4 - Technology Map do mux 4x1 para a família Cyclone
Figura 2.5 - Elemento Lógico usado no mux 4x1 para a família Cyclone (node properties)
No entanto se utilizarmos um dispositivo FPGA da família Stratix III, que tem LUT tem 6 entradas, será necessário apenas 1 LE, conforme ilustrado a seguir. Figura 2.5 - Technology Map do mux 4x1 para a família Stratix III
-- Declaração das bibliotecas e pacotes
LIBRARY ieee;
USE ieee.std_logic_1164.all;
-- Especificação de todas as entradas e saídas do circuito
ENTITY flip_flop IS
PORT (d, clk, rst: IN STD_LOGIC;
q: OUT STD_LOGIC);
END;
-- Descrição de como o circuito deve funcionar
ARCHITECTURE flip_flop OF flip_flop IS
BEGIN
PROCESS (clk, rst)
BEGIN
IF (rst='1') THEN
q <= '0';
ELSIF (clk'EVENT AND clk='1') THEN
q <= d;
END IF;
END PROCESS;
END;
Figura 2.2 - Código RTL do Exemplo 2.2
Figura 2.3 - Technology Map do Exemplo 2.2
Figura 2.4 - Chip Planner do Exemplo 2.2
Figura 2.5 - RTL 4 FF
Figura 2.6 - Simulação Funcional de 4 FF 100ns Figura 2.7 - Simulação Temporal de 4 FF 100ns
IMPORTANTE: Na prática normalmente não é necessário fazer a simulação temporal, pois através do Time Quest Report é possível verificar se o circuito atende as restrições de tempo.
create_clock -name CLK50MHz -period 50MHz [get_ports {*}]
Video motivational para apreender FPGA, VHDL Microsoft's Bing* Intelligent Search with Intel® FPGAs
ls /opt/altera/13.0sp1/quartus/libraries/vhdl/std
ls /opt/altera/13.0sp1/quartus/libraries/vhdl/ieee
ls /opt/altera/13.0sp1/quartus/libraries/vhdl/mentor/arithmetic (Mentor Graphics) ls /opt/altera/13.0sp1/quartus/libraries/vhdl/synopsys/ieee (Synopsys)
ls /opt/altera/16.0/quartus/libraries/vhdl/ieee/2008
LIBRARY ieee;
USE ieee.std_logic_1164.all;
ENTITY registered_comp_add_v1 IS
PORT (clk: IN STD_LOGIC;
a, b: IN INTEGER RANGE 0 TO 7;
reg_comp: OUT STD_LOGIC;
reg_sum: OUT INTEGER RANGE 0 TO 15);
END ENTITY;
ARCHITECTURE ifsc_v1 OF registered_comp_add_v1 IS
SIGNAL comp: STD_LOGIC;
SIGNAL sum: INTEGER RANGE 0 TO 15;
BEGIN
comp <= '1' WHEN a>b ELSE '0';
sum <= a + b;
PROCESS (clk)
BEGIN
IF (clk'EVENT AND clk='1') THEN
reg_comp <= comp;
reg_sum <= sum;
END IF;
END PROCESS;
END ARCHITECTURE;
Figura 2.10 - Código RTL do Exemplo 2.3
|
Unidade 3 - Tipos de Dados e Operadores em VHDL
- 10 Encontros
ATUAL
Unidade 3 - Tipos de Dados e Operadores em VHDL | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
-- Isso eh uma linha de comentario y <= a * b ; --o sinal y recebe o resultado da multiplicacao a x b
caracter: 'A' 'x' '#' (com aspas simples)
type string is array (positive range <>) of character;
string: "IFSC" "teste" "teste123"
elemento ("bit") único: '0' '1' 'Z' (entre aspas simples) vetor de elementos ("bits"): "0110" "101001Z" (entre aspas duplas) vetor de 1 elemento ("bit"): "0" "1" (entre aspas duplas) inteiros: 5 1101 1102 (sem aspas)
0 -> '0' 7 (em base 2) -> "0111" ou b"0111" ou B"0111" 1023 (em base 2) -> "001111111111" ou b"1111111111" ou B"1111111111"
44 (em base 8) -> 5*8^1 + 4*8^0 -> O"54" ou o"54" 1023 (em base 8)-> 1*8^3 + 7*8^2 + 7*8^1 + 7*8^0 -> o"1777" 8#1777#
1023 (em base 16) -> 3*16^2 + 15*16^1 + 15*16^0 = X"3FF" ou x"3FF" 16#3FF#
1023 -> 1023 ou 1_023 1000 -> 1000 ou 1_000 ou 1E3
85 (em base 5) -> (3*5^2 + 2*5^1 + 0*5^0) -> 5#320# 1539 (em base 3) -> (2*3^2+0*3^1+1*3^0)*3^4 -> 3#201#E4
O objeto CONSTANT pode ser declarado na parte declarativa da ENTITY, ARCHITECTURE, PACKAGE, PACKAGE_BODY, BLOCK, GENERATE, PROCESS, FUNCTION e PROCEDURE. constant <constant_name> : <type> := <constant_value>;
-- Declarações comuns de constantes
constant GND : std_logic := '0';
constant VCC : std_logic := '1';
constant SSD_0 : std_logic_vector(0 to 6) := "1111110";
constant MAX : natural := 44;
O objeto SIGNAL pode ser declarado na parte declarativa da ENTITY, ARCHITECTURE, PACKAGE, BLOCK, GENERATE. Os sinais não podem ser declarados no código sequencial (PROCESS, FUNCTION e PROCEDURE), mas podem ser usados. -- Signal sem valor default
-- Para atribuir um valor a um signal use "<=" como operador.
signal <name> : <type>;
-- Signal com valor default
signal <name> : <type> := <default_value>;
-- Declarações comuns de signals
signal <name> : std_logic;
signal <name> : std_logic_vector(<msb_index> downto <lsb_index>);
signal <name> : integer;
signal <name> : integer range <low> to <high>;
O objeto VARIABLE (variável) só pode ser declarada e usada dentro do escopo no código sequencial (PROCESS, FUNCTION e PROCEDURE). -- Variables devem ser declarada em process ou subprogramas.
-- Para atribuir um valor a um variable use ":=" como operador.
-- Variable sem valor default.
variable <name> : <type>;
-- Variable com valor default.
variable <name> : <type> := <default_value>;
-- Declarações comuns de variables
variable <name> : std_logic;
variable <name> : std_logic_vector(<msb_index> downto <lsb_index>);
variable <name> : integer;
variable <name> : integer range <low> to <high>;
Exemplos de declaração de CONSTANT, SIGNAL, VARIABLE, inicializando o valor usando o agregados CONSTANT a: BIT_VECTOR(5 DOWNTO 0) := (OTHERS => '0'); -- "000000"
CONSTANT b: BIT_VECTOR(7 DOWNTO 0) := (7 => '0', OTHERS => '1'); -- "01111111"
CONSTANT c: BIT_VECTOR(7 DOWNTO 0) := (7 => '0', 6 DOWNTO 0 => '1'); -- "01111111"
CONSTANT d: BIT_VECTOR(7 DOWNTO 0) := "01111111";
SIGNAL e: STD_LOGIC_VECTOR(7 DOWNTO 0); -- Not initialized
SIGNAL f: STD_LOGIC_VECTOR(1 TO 8) := (2|3|8 => '1', 4 => 'Z', OTHERS => '0' ); -- "011Z0001"
VARIABLE g: BIT_VECTOR(1 TO 16); -- Not initialized
VARIABLE h: BIT_VECTOR(1 TO 16) := (1 TO 8 => '1', OTHERS => '0'); -- "1111111100000000"
A biblioteca standard.vhd define os tipos BIT, BIT_VECTOR, BOOLEAN, INTEGER, NATURAL, POSITIVE, CHARACTER, STRING. package standard is
type boolean is (false,true);
type bit is ('0', '1');
type severity_level is (note, warning, error, failure);
type integer is range -2147483647 to 2147483647;
type real is range -1.0E308 to 1.0E308;
type time is range -2147483648 to 2147483647
units
fs;
ps = 1000 fs;
ns = 1000 ps;
us = 1000 ns;
ms = 1000 us;
sec = 1000 ms;
min = 60 sec;
hr = 60 min;
end units;
subtype natural is integer range 0 to integer'high;
subtype positive is integer range 1 to integer'high;
type string is array (positive range <>) of character;
type bit_vector is array (natural range <>) of bit;
A biblioteca Std logic 1164.vhd define os tipos STD_(U)LOGIG, STD_(U)LOGIG_VECTOR. PACKAGE std_logic_1164 IS
TYPE std_ulogic IS ( 'U', -- Uninitialized
'X', -- Forcing Unknown
'0', -- Forcing 0
'1', -- Forcing 1
'Z', -- High Impedance
'W', -- Weak Unknown
'L', -- Weak 0
'H', -- Weak 1
'-' -- Don't care
);
TYPE std_ulogic_vector IS ARRAY ( NATURAL RANGE <> ) OF std_ulogic;
SUBTYPE std_logic IS resolved std_ulogic;
TYPE std_logic_vector IS ARRAY ( NATURAL RANGE <>) OF std_logic;
A biblioteca Std logic 1164.vhd ainda define algumas funções importantes como a rising_edge que determina se um sinal está na borda de subida (usado em sinais de clock). -------------------------------------------------------------------
-- conversion functions
-------------------------------------------------------------------
FUNCTION To_bit ( s : std_ulogic; xmap : BIT := '0') RETURN BIT;
FUNCTION To_bitvector ( s : std_logic_vector ; xmap : BIT := '0') RETURN BIT_VECTOR;
FUNCTION To_StdULogic ( b : BIT ) RETURN std_ulogic;
FUNCTION To_StdLogicVector ( b : BIT_VECTOR ) RETURN std_logic_vector;
-------------------------------------------------------------------
-- edge detection
-------------------------------------------------------------------
FUNCTION rising_edge (SIGNAL s : std_ulogic) RETURN BOOLEAN;
FUNCTION falling_edge (SIGNAL s : std_ulogic) RETURN BOOLEAN;
-------------------------------------------------------------------
-- edge detection
-------------------------------------------------------------------
FUNCTION rising_edge (SIGNAL s : std_ulogic) RETURN BOOLEAN IS
-- altera built_in builtin_rising_edge
BEGIN
RETURN (s'EVENT AND (To_X01(s) = '1') AND
(To_X01(s'LAST_VALUE) = '0'));
END;
A biblioteca Numeric std.vhd define os tipos UNSIGNED e SIGNED. package NUMERIC_STD is
type UNSIGNED is array (NATURAL range <>) of STD_LOGIC;
type SIGNED is array (NATURAL range <>) of STD_LOGIC;
A biblioteca Numeric std.vhd ainda define os operadores (abs, "+", "-", "*", "\", rem, mod, sll, slr, ror, rol), comparações ("=", '/=', ">", ">=", "<", "<=") e operadores lógicos (not, and, nand, or, nor, xor, xnor) para os tipos SIGNED e UNSIGNED. Além disso também define algumas funções muito utilizadas como: --============================================================================
-- RESIZE Functions
--============================================================================
function RESIZE (ARG: SIGNED; NEW_SIZE: NATURAL) return SIGNED;
function RESIZE (ARG: UNSIGNED; NEW_SIZE: NATURAL) return UNSIGNED;
--============================================================================
-- Conversion Functions
--============================================================================
function TO_INTEGER (ARG: UNSIGNED) return NATURAL;
function TO_INTEGER (ARG: SIGNED) return INTEGER;
function TO_UNSIGNED (ARG, SIZE: NATURAL) return UNSIGNED;
function TO_SIGNED (ARG: INTEGER; SIZE: NATURAL) return SIGNED;
|
ATIVIDADE EXTRA-CLASSE (AE)
A soma das atividades Extra-classe será correspondente a 20% do conceito final na disciplina. A entrega das mesmas será feita pelo Moodle da disciplinas, e cada dia de atraso irá descontar 0,2 na nota da atividade. Muitas dessas atividades também possuem BÔNUS que são adicionados aos conceitos das avaliações A1 e A2. Para os BÔNUS só serão considerados projetos entregues no prazo.
AE1 - Palavras-cruzadas INTRODUÇÃO
AE1 - Palavras-cruzadas INTRODUÇÃO |
---|
AE2 - Conhecendo os dispositivos lógicos programáveis
AE2 - Conhecendo os dispositivos lógicos programáveis |
---|
|
AE3 - Programação do kit Mercurio IV
AE3 - Programação do kit Mercurio IV |
---|
entity counter is
generic (WIDTH : in natural := 4);
port (
RST : in std_logic;
CLK : in std_logic;
LOAD : in std_logic;
DATA : in std_logic_vector(WIDTH-1 downto 0);
R0 : out std_logic
Q : out std_logic_vector(WIDTH-1 downto 0));
end entity;
architecture ifsc_v1 of counter is
signal Q_aux : std_logic(WIDTH-1 downto 0);
begin
process(RST,CLK) is
begin
if RST = '1' then
Q_aux <= (others => '0');
elsif rising_edge(CLK) then
if LOAD= '1' then
Q_aux <= DATA;
else
Q_aux <= std_logic_vector(unsigned(Q_aux) + 1);
end if;
end if;
end process;
-- Adaptacao feita devido a matriz de leds acender com ZERO
Q <= not Q_aux;
-- Para acender um led eh necessario colocar ZERO na linha correspondente da matriz.
R0 <= '0';
end architecture;
CLK: PIN_Y17 ou PIN_V21 DATA[3]: PIN_H18 DATA[2]: PIN_H20 DATA[1]: PIN_K21 DATA[0]: PIN_J21 LOAD: PIN_Y22 Q[3]: PIN_J6 Q[2]: PIN_K8 Q[1]: PIN_J8 Q[0]: PIN_L8 RST: PIN_W21 R0: PIN_F10
-- insira na declaração das portas da entity a linha
LCD_BACKLIGHT: out std_logic;
-- insira na architecture a linha
LCD_BACKLIGHT <= '0';
LCD_BACKLIGHT: PIN_V10
entity COUNTER_db is
...
CLK50MHz : in std_logic;
...
end entity
architecture ifsc_v2 of COUNTER_db is
...
signal CLK_db: std_logic := '0';
...
begin
-- debouncer de 10ms
process (CLK50MHz, CLK, RST, CLK_db) is
constant max_cnt: natural := 500000; -- 500000 10ms para clk 20ns
variable cnt_db : integer range 0 to max_cnt-1;
begin
if (RST = '1') then
cnt_db := 0;
CLK_db <= '0';
elsif ((CLK = '0') and (CLK_db = '0')) or
((CLK = '1') and (CLK_db = '1')) then
cnt_db := 0;
elsif (rising_edge(CLK50MHz)) then
if (cnt_db = max_cnt - 1) then
CLK_db <= not CLK_db;
else
cnt_db := cnt_db + 1;
end if;
end if;
end process;
...
-- Troque no process(RST,CLK) a entrada '''CLK''' do circuito anterior pela entrada '''CLK_db'''
CLK50MHz: PIN_T1
create_clock -name CLK50MHz -period 50MHz [get_ports -no_case {clk*}]
|