-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcounterN2.vhd
49 lines (40 loc) · 1.37 KB
/
counterN2.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
-- Contador ascedente descendente, enable, com carga, iterrupçao
entity counterN2 is
generic(N: positive := 8);
port(
-- entradas de controle
clock, reset: in std_logic;
enb, asc, load: in std_logic;
-- entrada de dados
d: in std_logic_vector(N-1 downto 0);
-- saida de controle
interrupt: out std_logic;
-- saida de dados
q: out std_logic_vector(N-1 downto 0)
);
end;
architecture canonical of counterN2 is
--type State is std_logic_vector(N-1 downto 0); --mudar apenas o que esta dentro do is
signal nextState, actualState: unsigned(N-1 downto 0); --State;
begin
-- -- Next-State Logic -- --
nextState <= unsigned(d) when load='1' else
actualState+1 when enb='1' and asc='1' else
actualState-1 when enb='1' else
actualState;
-- Memory Element (State Element) -- sera SEMPRE igual
process(clock, reset) is -- sequencial
begin
if reset='1' then
actualState <= (others=>'0'); -- MUDAR apenas o que o actualState recebe
elsif rising_edge(clock) then -- clock'event and clock='1' NAO USAR. MELHOR rising_edge()
actualState <= nextState;
end if;
end process; -- utilizar process para setar apenas um valor, caso outro fazer outro process
-- -- Output Logic -- --
q <= std_logic_vector(actualState);
interrupt <= '1' when actualState=2**N-1 else '0';
end;