1 / 10

Introdução ao VHDL

Introdução ao VHDL. João M. P. Cardoso. library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity count is Port ( clk : in std_logic; reset : in std_logic; cnt : out std_logic_vector(2 downto 0)); end count;.

diana-cole
Download Presentation

Introdução ao VHDL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introdução ao VHDL João M. P. Cardoso

  2. library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity count is Port ( clk : in std_logic; reset : in std_logic; cnt : out std_logic_vector(2 downto 0)); end count; architecture Behavioral of count is signal cnt1 : std_logic_vector(2 downto 0); begin process(clk, reset) begin if reset = '1' then cnt1 <= (others => '0'); elsif clk'event AND clk = '1' then cnt1 <= cnt1 + 1; end if; end process; cnt <= cnt1; end Behavioral; Um Contador de 0 a 7

  3. Simulação • Descrição em VHDL de uma bancada de teste • Instância o componente • Define o valor dos sinais • Só serve para simulação! • Criação de um ficheiro do tipo Test Bench Waveform • Permite a atribuição de valores aos sinais utilizando uma interface gráfica

  4. LIBRARY ieee; USE ieee.std_logic_1164.ALL; USE ieee.numeric_std.ALL; ENTITY testbench IS END testbench; ARCHITECTURE behavior OF testbench IS COMPONENT count PORT( clk : IN std_logic; reset : IN std_logic; cnt : OUT std_logic_vector(2 downto 0) ); END COMPONENT; SIGNAL clk : std_logic; SIGNAL reset : std_logic; SIGNAL cnt : std_logic_vector(2 downto 0); SIGNAL clock : std_logic := '0'; -- for simulation BEGIN uut: count PORT MAP( clk => clk, reset => reset, cnt => cnt ); clock <= not clock after 10 ns; -- T = 20ns clk <= clock; -- *** Test Bench - User Defined Section *** tb : PROCESS BEGIN reset <= '1'; wait for 20 ns; reset <= '0'; wait for 200 ns; --wait; -- will wait forever END PROCESS; -- *** End Test Bench - User Defined Section *** END; Bancada de Teste

  5. ModelSim XE II/Starter 5.7c • Janela de ondas do simulador

  6. library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity seven_seg is Port ( inp_data : in std_logic_vector(3 downto 0); out_data : out std_logic_vector(7 downto 0)); end seven_seg; architecture Behavioral of seven_seg is begin process(inp_data) begin case inp_data is when "0000" => out_data <= "10000001"; when "0001" => out_data <= "11001111"; when "0010" => out_data <= "10010010"; when "0011" => out_data <= "10000110"; when "0100" => out_data <= "11001100"; when "0101" => out_data <= "10100100"; when "0110" => out_data <= "10100001"; when "0111" => out_data <= "10001111"; when "1000" => out_data <= "10000000"; when "1001" => out_data <= "10000100"; when others => out_data <= "11111111"; end case; end process; end Behavioral; Descodificador de Sete Segmentos

  7. Reset CEM FSM da máquina de bebidas Abre Sensor de Moedas Mecanismo de Libertar Lata CINQ Clock Exemplo: Máquina de Bebidas • Disponibiliza a lata depois de 150 ou mais escudos terem sido depositados • Uma única abertura para moedas (50$00 e 100$00) • Não dá troco

  8. Estado Entrada Próx. SaídaActual CEM CINQ Estado open 0$ 0 0 0$ 0 0 1 50$ 0 1 0 100$ 0 1 1 – – 50$ 0 0 50$ 0 0 1 100$ 0 1 0 150$ 0 1 1 – –100$ 0 0 100$ 0 0 1 150$ 0 1 0 150$ 0 1 1 – –150$ – – 150$ 1 Reset 0$ CINQ 50$ CEM CINQ 100$ CEM CEM + CINQ 150$ [open] Tabela de estados Simbólica Exemplo: Máquina de Bebidas • Tabela e Diagrama de Estados

  9. library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity fsm is Port ( clk : in std_logic; reset : in std_logic; CEM : in std_logic; CINQ : in std_logic; s_open : out std_logic); end fsm; architecture Behavioral of fsm is type state_type is (zero, cinquenta, st_cem, cent_cinq); signal current_state, next_state: state_type; begin fsm2: process(reset, clk) begin if reset = '1' then current_state <= zero; elsif clk'event AND clk='1' then current_state <= next_state; end if; end process; fsm1: process(current_state, CEM, CINQ) begin case current_state is when zero => s_open <= '0'; if CINQ = '1' then next_state <= cinquenta; else next_state <= zero; end if; when cinquenta => s_open <= '0'; if CINQ = '1' then next_state <= st_cem; elsif CEM = '1' then next_state <= cent_cinq; else next_state <= cinquenta; end if; when st_cem => s_open <= '0'; if CINQ = '1' OR CEM = '1' then next_state <= cent_cinq; else next_state <= st_cem; end if; when cent_cinq => s_open <= '1'; next_state <= zero; when others => s_open <= '0'; next_state <= zero; end case; end process; end Behavioral; Exemplo: Máquina de Bebidas

  10. Exemplo: Máquina de Bebidas • Quantos Flip-Flops existem no hardware sintetizado? • Modificar as directivas de síntese para utilizar o menor número de FFs possível • 4 estados => 2 FFs

More Related