A apresentação está carregando. Por favor, espere

A apresentação está carregando. Por favor, espere

VHDL Introdução Paulo C. Centoducatte fevereiro de 2005

Apresentações semelhantes


Apresentação em tema: "VHDL Introdução Paulo C. Centoducatte fevereiro de 2005"— Transcrição da apresentação:

1 VHDL Introdução Paulo C. Centoducatte fevereiro de 2005
1 VHDL Introdução Paulo C. Centoducatte fevereiro de 2005

2 VHDL - Comandos seqüenciais
2 Chamada de procedimentos (também concorrente) Assertion (também concorrente) Assinalamento de sinal (também concorrente) Assinalamento de variáveis WAIT IF, CASE NEXT EXIT, RETURN, LOOP NULL

3 VHDL - Atribuição Condicional
3 Cláusula IF Cláusula WHEN Cláusula CASE

4 VHDL - Cláusula IF IF (condição 1) THEN Cláusula acertiva 1;
4 IF (condição 1) THEN Cláusula acertiva 1; ELSEIF (condição 2) THEN Cláusula acertiva 2; ELSE Cláusula acertiva 3; END IF;

5 VHDL - Cláusula IF Process (acao, cor) IF cor = verde THEN
5 Process (acao, cor) IF cor = verde THEN acao <= va_em_frente; ELSEIF cor = amarelo THEN acao <= atencao; ELSE acao <= pare; END IF;

6 VHDL - Cláusula IF latchD: process (dado,enable) begin
6 latchD: process (dado,enable) begin IF enable = ‘1’ THEN Q <= dado; notQ <= not dado END IF; end process latchD;

7 VHDL - Cláusula IF Architecture rtl of sps is
7 Architecture rtl of sps is signal prec : std_ulogic; signal Xsp : std_logic_vector(7 downto 0) := “ ”; begin process(clk) if (clk´event and clk´last_value = ‘0’ and clk = ‘1’) then if en_sr = ‘0’ then ultimo_bit <= Xsp(7); Xsp(7 downto 1) <= Xsp(6 downto 0); Xsp(0) <= IO; elseif em_load = ‘1’ then Xsp <= bus_data; end if; end if; end process; end rtl; -- Conversor paralelo/serie -- shift right -- carga paralela

8 VHDL - Escrever o processo de um contador de 4 bits
8 Architecture rtl of contador is signal cont : unsigned(3 downto 0) := “0000”; begin process(reset,clk) if reset = ‘1’ then cont <= “0000”; elseif (clk´event and clk = ‘1’) then if enable = ‘1’ then if incr = ‘1’ then cont <= cont + “0001”; else cont <= cont - “0001”; end if; end if; end process; end rtl;

9 VHDL - Cláusula When (concorrente)
9 Atribuição WHEN condição sinal <= atribuição WHEN valor_expressão Exemplo: acao <= prosseguir WHEN sinal_verde;

10 VHDL - Seletor out <= in1 WHEN sel else in0; if sel = ‘1’ then
10 out <= in1 WHEN sel else in0; if sel = ‘1’ then out <= in1; else out <= in0; out <= in0 WHEN sel0 else in1 WHEN sel1 else in2 WHEN sel2 else in3 WHEN sel3 else inx;

11 VHDL- Cláusula With (concorrente)
11 WITH expressão SELECT signal <= atribuição WHEN valor_expressão Exemplo: WITH cor SELECT acao <= prosseguir WHEN “verde”, parar WHEN “vermelho”, alerta WHEN OTHERS;

12 VHDL- Cláusula With with regsel select
12 with regsel select z <= A after Tprop when “00’, B after Tprop when “01”, C after Tprop when “10”, D after Tprop when “11”, “X” after Tprop when others;

13 VHDL- Cláusula With signal Y : std_logic_vector(0 to3);
13 signal Y : std_logic_vector(0 to3); signal opcode : std_logic_vector(0 to 1); with opcode select Y <= “0001” when “00”, “0010” when “01”, “0100” when “10”, “1000” when “11”;

14 VHDL- Exercícios 14 Escrever o modelo vhdl de um multiplexador 2x1 com 8 bits de dados usando WHEN usando IF usando somente comando de atribuição simples Signal temp : std_logic_vector(7 downto 0); Begin temp <= (s,s,s, others => s); -- s é o sinal de seleção y <= (temp and IN1) or (not temp and IN0);

15 VHDL- Cláusula Case CASE sinal IS
15 CASE sinal IS WHEN “condição 1” => dado <= dado1; WHEN “condição 2” => dado <= dado2; WHEN others => dado <= dado3; END CASE;

16 VHDL- Cláusula Case signal p : integer range 0 to 3;
16 signal p : integer range 0 to 3; signal y : std_logic_vector(0 to 1); CASE p IS WHEN 0 => y <= “10”; WHEN 1 => y <= A; WHEN 2 => y <= B WHEN 3 => y <= “01”; END CASE;

17 VHDL - Comando NULL 17 Utilizado no caso de não ser necessário nenhuma ação em uma alternativa que precisa ser coberta Exemplo: case opcode is when add => Acc := Acc + operando; when sub => Acc := Acc - operando; when nop => NULL; end case;

18 VHDL - Exercício 18 Utilizado o comando case escreva um conversor do código binário para o código Gray

19 VHDL - Loop loop comando_1 comando_2; end loop; Exemplo: begin
19 loop comando_1 comando_2; end loop; Exemplo: begin count <= count_value; wait until clk = '1'; count_value := (count_value + 1) mod 16;

20 VHDL - Next e Exit begin count <= count_value; loop
20 begin count <= count_value; loop wait until clk = '1' or reset = '1'; exit when reset = '1'; count_value := (count_value + 1) mod 16; end loop; count_value := 0; -- at this point, reset = '1’ wait until reset = '0'; loop comando_1 next when condição; comando_2; end loop;

21 VHDL - While loops result <= sum; entity cos is
21 entity cos is port ( theta : in real; result : out real ); end entity cos; ….. sum := 1.0; term := 1.0; n := 0; while abs(term) > abs (sum / 1.0E6) loop n := n + 2; term := (-term) * theta**2 / real(((n-1) * n)); sum := sum + term; end loop; result <= sum;

22 VHDL – For Loops entity cos is
22 entity cos is port ( theta : in real; result : out real ); end entity cos; ….. sum := 1.0; term := 1.0; for n in 1 to 9 loop term := (-term) * theta**2 / real(((2*n-1) * 2*n)); sum := sum + term; end loop; result <= sum;

23 VHDL – For Loops variable a, b : integer; begin a := 10;
23 variable a, b : integer; begin a := 10; for a in 0 to 7 loop b := a; end loop; -- a = 10, and b = 7 wait;

24 VHDL - Assertion [Label:] assert exp_booleana
24 [Label:] assert exp_booleana [report expressão [severity expressão]; Type severity_level is (note, warning, error, failure) assert valor <= max_valor; “Assertion violation” assert valor <= max_valor Severity = erro report “valor maior que o permitido"; assert valor <= max_valor report “valor maior que o permitido“ severity note;

25 VHDL - Assertion entity SR_flipflop is
25 entity SR_flipflop is port ( S, R : in bit; Q : out bit ); end entity SR_flipflop; architecture checking of SR_flipflop is begin set_reset : process (S, R) is assert S = '1' nand R = '1'; if S = '1' then Q <= '1'; end if; if R = '1' then Q <= '0'; end process set_reset; end architecture checking;

26 VHDL – Atributos de tipos escalar
26 Atributos comuns a todos os tipos escalares: T’left primeiro (mais a esquerda) valor em T T’right último (mais a direita) valor em T T’low menor valor em T T’high maior valor em T T’ascending TRUE se T o range de T é crescente T’image(x) string representando o valor de x T’value(s) o valor em T que é representado por s

27 VHDL - Atributos de tipos escalar
27 VHDL Atributos de tipos escalar type resistance is range 0 to 1E9 units ohm; kohm = 1000 ohm; Mohm = 1000 kohm; end units resistance; type set_index_range is range 21 downto 11; type logic_level is (unknown, low, undriven, high); set_index_range'left = 21; set_index_range'right = 11; set_index_range'low = 11; set_index_range'high = 21; set_index_range'ascending = false; set_index_range'image(14) = "14"; set_index_range'value("20") = 20; resistance'left = 0 ohm; resistance'right = 1E9 ohm; resistance'low = 0 ohm; resistance'high = 1E9 ohm; resistance'ascending = true; resistance'image(2 kohm) = "2000 ohm"; resistance'value("5 Mohm") = 5_000_000 ohm;

28 VHDL - Atributos de tipos escalar
28 VHDL Atributos de tipos escalar Atributos relativos aos tipos escalares discreto e físico: T’pos(x) número da posição de x em T T’val(n) valor em T na posição n T’succ(x) valor em T na posição maior que x T’pred(x) valor em T na posição menor que x T’leftof(x) valor em T na posição a esquerda de x T’rightof(x) valor em T na posição a direita de x

29 VHDL - Atributos de tipos escalar
29 VHDL Atributos de tipos escalar type resistance is range 0 to 1E9 units ohm; kohm = 1000 ohm; Mohm = 1000 kohm; end units resistance; type set_index_range is range 21 downto 11; type logic_level is (unknown, low, undriven, high); logic_level'left = unknown; logic_level'right = high; logic_level'low = unknown; logic_level'high = high; logic_level'ascending = true; logic_level'image(undriven) = "undriven"; logic_level'value("Low") = low; logic_level'pos(unknown) = 0; logic_level'val(3) = high; logic_level'succ(unknown) = low; logic_level'pred(undriven) = low;

30 VHDL - Atributos de tipos array
30 VHDL Atributos de tipos array Atributos A’left(N) A’right(N) A’low(N) A’high(N) A’range(N) A’reverse_range(N) A’length(N) A’ascending(N) Exemplo type A is array ( 1 to 4 , 31 downto 0) of boolean; A’left(1) = 1 A’right(2) = 0 A’low(1) = 1 A’high(2) = 31 A’range(1) is 1 to 4 A’reverse_range(2) is 0 to 31 A’length(2) = 32 A’ascending(1) = true A’ascending(2) = false

31 VHDL – Atributos de Sinais
31 S´delayed(T) - mesmo valor que S porém atrasado de T S´stable(T) booleano: true se não houve evento em S S´quit(T) booleano: true se não houve transação em S S´transaction - bit: alterna entre ´0´ e ´1´ a cada transação em S S´event booleano: true se houve um evento em S S´active booleano: true se houve uma transação em S S´last_event - intervalo de tempo desde o último evento em S S´last_active - intervalo de tempo desde a última transação em S S´last_value - valor de S antes do último evento

32 VHDL – Uso de Atributos Detecção de borda de relógio
32 Detecção de borda de relógio clk’EVENT and clk = ‘1’ Determinação de largura de pulso Sinal’LAST_EVENT >= 5 ns Teste de Hold e Setup clk’LAST_VALUE = ‘0’ AND clk = ‘1’ AND dado’STABLE(min_setup_time)

33 VHDL - Componente Declaração Instanciação Instanciação condicional
33 Declaração Instanciação Instanciação condicional Modelamento Estrutural

34 VHDL - Componente OBS.: Similar a ENTIDADE Declaração de um componente
34 Declaração de um componente component identifier [is] [generic (generic_interface_list);] [port (port_interface_list);] end component [identifier]; OBS.: Similar a ENTIDADE

35 VHDL - Componente Exemplo component flip-flop is
35 Exemplo component flip-flop is generic (Tprop, Tsetup, Thold : delay); port (clk: in bit; clr : in bit; d : in bit; q : out bit); end component flip_flop;

36 VHDL - Componente Instanciação
36 Instanciação Declaração de componente define o tipo do módulo Instaciação de componenente define seu uso em um projeto instatiation_label: [component ] componente_name [generic map (generic_association_list) ] [port map (port_association_list) ];

37 VHDL – Componente (exemplo)
37 Exemplo: entity reg4 is port ( clk, clr : in bit; d : in bit_vector(0 to 3); q : out bit_vector(0 to 3) ); end entity reg4; architecture struct of reg4 is component flipflop is generic ( Tprop, Tsetup, Thold : delay_length ); port ( clk : in bit; clr : in bit; d : in bit; q : out bit ); end component flipflop;

38 VHDL – Componente (exemplo)
38 begin bit0 : component flipflop generic map ( Tprop => 2 ns, Tsetup => 2 ns, Thold => 1 ns ) port map ( clk => clk, clr => clr, d => d(0), q => q(0) ); bit1 : component flipflop port map ( clk => clk, clr => clr, d => d(1), q => q(1) ); bit2 : component flipflop port map ( clk => clk, clr => clr, d => d(2), q => q(2) ); bit3 : component flipflop port map ( clk => clk, clr => clr, d => d(3), q => q(3) ); end architecture struct;

39 VHDL - Configuração configuration identifier of entity_name is
39 configuration identifier of entity_name is for architeture_name { for component_specification binding_indication; end for;} end for; end [ configuration] [ identifier];

40 VHDL - Componente Configuração
40 Configuração FOR nome_da_instancia|others|all: nome_componente -- component_specification USE ENTITY especificação_da_entidade; binding_indication END FOR; FOR inst51: xor_gate USE ENTITY lib_projeto.xor(arq_rtl); FOR bit0,bit1: flipflop use entity work.edge_triggered_Dff(basic); end for; FOR others: flipflop use entity work.edge_triggered_Dff(rtl);

41 VHDL – Exemplo Architecture rtl of top is Component and2
41 Architecture rtl of top is Component and2 port(a, b: in std_logic; c: out std_logic); End component; Component latchD port(d, clk : in std_ulogic; q, notq : out std_logic); For all : and2 use entity work.and2(rtl); For all : latchD use entity work.latchD(rtl); signal Q, NOTQ : std_ulogic := ‘1’; Begin inst_latchD: latchD port map(d1,clk, Q,NOTQ); inst_and2_a: and2 port map(d1,Q,S1); inst_and2_b: and2 port map(d2,NOTQ,S3); End rtl; OBS.: d1, d2 e clk são sinais de entrada e S1, S2 e S3 são sinais de saída


Carregar ppt "VHDL Introdução Paulo C. Centoducatte fevereiro de 2005"

Apresentações semelhantes


Anúncios Google