1 | library ieee;
|
2 | use ieee.std_logic_1164.all;
|
3 | use ieee.std_logic_unsigned.all;
|
4 |
|
5 | entity counter4 is
|
6 | port(count:out std_logic_vector(3 downto 0);
|
7 | clk:in std_logic;
|
8 | reset:in std_logic);
|
9 | end counter4;
|
10 |
|
11 | architecture behav_counter4 of counter4 is
|
12 |
|
13 | component ha port (a: in std_logic;
|
14 | b: in std_logic;
|
15 | sum: out std_logic;
|
16 | c_out: out std_logic);
|
17 | end component;
|
18 |
|
19 | component fa port (a, b, cin : in std_logic;
|
20 | sum, c_out : out std_logic);
|
21 | end component;
|
22 |
|
23 | signal ain,s,c:std_logic_vector(3 downto 0);
|
24 | signal bin:std_logic_vector(3 downto 0):="0001";
|
25 |
|
26 | --configuration specification
|
27 | for all:ha use entity work.ha(rtl);
|
28 | for all:fa use entity work.fa(fa_behav);
|
29 |
|
30 | begin
|
31 | u1:ha port map(a => ain(0), b => bin(0), sum => s(0), c_out => c(0));
|
32 | u2:fa port map(a => ain(1), b => bin(1), sum => s(1), cin => c(0), c_out => c(1));
|
33 | u3:fa port map(a => ain(2), b => bin(2), sum => s(2), cin => c(1), c_out => c(2));
|
34 | u4:fa port map(a => ain(3), b => bin(3), sum => s(3), cin => c(2), c_out => c(3));
|
35 |
|
36 |
|
37 | counter:process(clk, reset) --process(sensitivity list)
|
38 | begin
|
39 | if reset'event and (reset = '1') then
|
40 | ain <= (others => '0');
|
41 |
|
42 | elsif (clk'event and clk='1') then
|
43 | ain <= s;
|
44 | count <= s;
|
45 |
|
46 | end if;
|
47 | end process;
|
48 |
|
49 | end behav_counter4;
|