Rev Author Line No. Line
4918 kaklik 1 library ieee;
2 use ieee.std_logic_1164.all;
3 use ieee.numeric_std.all;
4  
5 entity up_counter is
6 generic (
7  
8 G_MIN_NUMBER : natural := 0;
9 G_MAX_NUMBER : natural := 10
10  
11 );
12 port (
13  
14 i_clk : in std_logic;
15 i_rst : in std_logic;
16  
17 -- Count when this input is '1'
18 i_valid : in std_logic;
19  
20 -- Output the actual number
21 o_data : out natural := G_MIN_NUMBER;
22 o_carry : out std_logic := '0'
23  
24 );
25 end up_counter;
26  
27 architecture rtl of up_counter is
28  
29 signal number : natural range G_MIN_NUMBER to G_MAX_NUMBER := G_MIN_NUMBER;
30  
31 begin
32  
33 o_data <= number;
34  
35 counter : process( i_clk )
36 begin
37  
38 if( rising_edge( i_clk ) ) then
39  
40 o_carry <= '0';
41  
42 if( i_rst = '1' ) then
43 number <= G_MIN_NUMBER;
44 elsif( i_valid = '1' ) then
45 -- count up:
46 if( number = G_MAX_NUMBER ) then
47 number <= G_MIN_NUMBER;
48 o_carry <= '1';
49 else
50 number <= number + 1;
51 end if;
52  
53 end if;
54 end if;
55 end process;
56  
57 end architecture;