lustrec-tests / vhdl_json / vhdl_files / 2-exportOK / ghdl / ghdl / testsuite / gna / bug23165 / mwe_working / counter.vhd @ 3fd18385
History | View | Annotate | Download (598 Bytes)
1 | 3fd18385 | Arnaud Dieumegard | -- counter |
---|---|---|---|
2 | -- clk: clock input |
||
3 | -- en: enable input |
||
4 | -- rst: reset input |
||
5 | -- dir: direction pin (1 = up, 0 = down) |
||
6 | -- q: output |
||
7 | |||
8 | library ieee; |
||
9 | use ieee.std_logic_1164.all; |
||
10 | use ieee.numeric_std.all; |
||
11 | |||
12 | entity counter is |
||
13 | generic ( |
||
14 | width : positive := 16 |
||
15 | ); |
||
16 | |||
17 | port ( |
||
18 | clk : in std_logic; |
||
19 | q : out std_logic_vector(width-1 downto 0) |
||
20 | ); |
||
21 | end counter; |
||
22 | |||
23 | architecture behav of counter is |
||
24 | signal cnt : unsigned(width-1 downto 0) := to_unsigned(0, width); |
||
25 | begin |
||
26 | process |
||
27 | begin |
||
28 | wait until rising_edge(clk); |
||
29 | cnt <= cnt + to_unsigned(1, cnt'length); |
||
30 | end process; |
||
31 | q <= std_logic_vector(cnt); |
||
32 | end behav; |