Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library ieee; --biblioteca utilizada: ieee
- use ieee.std_logic_1164.all; --inclui todo o pacote padrão 1164
- use ieee.numeric_std.all;
- entity fibonacci is --inicio da declaração da entidade
- port( --onde colocamos as entradas e as saidas
- clk, rst : in std_logic; --entrada padrão lógico
- start : in std_logic; --entrada padrão lógico
- i : in std_logic_vector(4 downto 0);
- ready, done : out std_logic; --saída padrão lógico
- f : out std_logic_vector(12 downto 0)
- );
- end fibonacci; --final da declaração da entidade
- architecture arch of fibonacci is --inicio da declaração da arquitetura
- type state_type is (idle, op, done_state);
- signal state_reg, state_next : state_type;
- signal t0_reg, t0_next : unsigned (12 downto 0);
- signal t1_reg, t1_next : unsigned (12 downto 0);
- signal n_reg, n_next : unsigned (4 downto 0);
- begin --registradores de estado e de dados
- process(clk, rst)
- begin
- if rst = '1' then
- state_reg <= idle;
- t0_reg <= (others => '0');
- t1_reg <= (others => '0');
- n_reg <= (others => '0');
- elsif clk'event and clk = '1' then
- state_reg <= state_next;
- t0_reg <= t0_next;
- t1_reg <= t1_next;
- n_reg <= n_next;
- end if;
- end process;
- process(state_reg, t0_reg, t1_reg, n_reg, start, i, n_next) --lógico do próximo estado
- begin
- ready <= '0';
- done <= '0';
- state_next <= state_reg;
- t0_next <= t0_reg;
- t1_next <= t1_reg;
- n_next <= n_reg;
- case state_reg is
- when idle =>
- ready <= '1';
- if start = '1' then
- t0_next <= (others => '0');
- t1_next <= (0 => '1', others => '0');
- n_next <= unsigned(i);
- state_next <= op;
- end if;
- when op =>
- if n_reg = 0 then --caso o usuario escolha o iesimo numero sendo 0, o circuito retornara o valor 0
- t1_next <= (others => '0');
- state_next <= done_state;
- 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
- state_next <= done_state;
- else
- t1_next <= t1_reg + t0_reg;
- t0_next <= t1_reg;
- n_next <= n_reg - 1;
- end if;
- when done_state =>
- done <= '1';
- state_next <= idle;
- end case;
- end process;
- f <= std_logic_vector(t1_reg);
- end architecture; --final da declaração da arquitetura+++
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement