Advertisement
DomMisterSoja

fibonacci

Apr 9th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 3.07 KB | None | 0 0
  1. library ieee;                                                         --biblioteca utilizada: ieee
  2. use ieee.std_logic_1164.all;                                          --inclui todo o pacote padrão 1164
  3. use ieee.numeric_std.all;
  4.  
  5. entity fibonacci is                                                   --inicio da declaração da entidade
  6.   port(                                                               --onde colocamos as entradas e as saidas
  7.     clk, rst : in std_logic;                                          --entrada padrão lógico
  8.     start : in std_logic;                                             --entrada padrão lógico
  9.     i : in std_logic_vector(4 downto 0);
  10.     ready, done : out std_logic;                                      --saída padrão lógico
  11.     f : out std_logic_vector(12 downto 0)
  12. );
  13. end fibonacci;                                                        --final da declaração da entidade
  14.  
  15. architecture arch of fibonacci is                                     --inicio da declaração da arquitetura
  16.   type state_type is (idle, op, done_state);
  17.   signal state_reg, state_next : state_type;
  18.  
  19.   signal t0_reg, t0_next : unsigned (12 downto 0);
  20.   signal t1_reg, t1_next : unsigned (12 downto 0);
  21.   signal n_reg, n_next : unsigned (4 downto 0);
  22.  
  23.   begin                                                               --registradores de estado e de dados
  24.     process(clk, rst)
  25.       begin
  26.         if rst = '1' then
  27.       state_reg <= idle;
  28.       t0_reg <= (others => '0');
  29.       t1_reg <= (others => '0');
  30.       n_reg <= (others => '0');
  31.     elsif clk'event and clk = '1' then
  32.       state_reg <= state_next;
  33.       t0_reg <= t0_next;
  34.       t1_reg <= t1_next;
  35.       n_reg <= n_next;
  36.     end if;
  37.     end process;
  38.  
  39.     process(state_reg, t0_reg, t1_reg, n_reg, start, i, n_next)      --lógico do próximo estado
  40.       begin
  41.     ready <= '0';
  42.     done <= '0';
  43.     state_next <= state_reg;
  44.     t0_next <= t0_reg;
  45.     t1_next <= t1_reg;
  46.     n_next <= n_reg;
  47.  
  48.     case state_reg is
  49.       when idle =>
  50.       ready <= '1';
  51.       if start = '1' then
  52.         t0_next <= (others => '0');
  53.         t1_next <= (0 => '1', others => '0');
  54.         n_next <= unsigned(i);
  55.         state_next <= op;
  56.       end if;
  57.  
  58.       when op =>
  59.         if n_reg = 0 then                                        --caso o usuario escolha o iesimo numero sendo 0, o circuito retornara o valor 0
  60.           t1_next <= (others => '0');
  61.           state_next <= done_state;
  62.         elsif n_reg = 1 then                                     --caso o usuario escolha o iesimo numero sendo 1, o circuito retornara o valor 1, pois setamos no estado idle t1 = 1
  63.           state_next <= done_state;
  64.         else
  65.           t1_next <= t1_reg + t0_reg;
  66.           t0_next <= t1_reg;
  67.           n_next <= n_reg - 1;
  68.         end if;
  69.    
  70.       when done_state =>
  71.         done <= '1';
  72.         state_next <= idle;
  73.     end case;
  74.       end process;
  75.   f <= std_logic_vector(t1_reg);
  76. end architecture;                                                    --final da declaração da arquitetura+++
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement