OpenCores
URL https://opencores.org/ocsvn/uart16750/uart16750/trunk

Subversion Repositories uart16750

[/] [uart16750/] [trunk/] [rtl/] [vhdl/] [slib_counter.vhd] - Blame information for rev 17

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 hasw
--
2
-- Counter
3
--
4
-- Author:   Sebastian Witt
5
-- Date:     27.01.2008
6 10 hasw
-- Version:  1.2
7 2 hasw
--
8
-- This code is free software; you can redistribute it and/or
9
-- modify it under the terms of the GNU Lesser General Public
10
-- License as published by the Free Software Foundation; either
11
-- version 2.1 of the License, or (at your option) any later version.
12
--
13
-- This code is distributed in the hope that it will be useful,
14
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
15
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
-- Lesser General Public License for more details.
17
--
18
-- You should have received a copy of the GNU Lesser General Public
19
-- License along with this library; if not, write to the
20
-- Free Software  Foundation, Inc., 59 Temple Place, Suite 330,
21
-- Boston, MA  02111-1307  USA
22
--
23
 
24
LIBRARY IEEE;
25
USE IEEE.std_logic_1164.all;
26
USE IEEE.numeric_std.all;
27
 
28
-- Counter
29
entity slib_counter is
30
    generic (
31
        WIDTH       : natural := 4       -- Counter width
32
    );
33
    port (
34
        CLK         : in std_logic;      -- Clock
35
        RST         : in std_logic;      -- Reset
36
        CLEAR       : in std_logic;      -- Clear counter register
37
        LOAD        : in std_logic;      -- Load counter register
38
        ENABLE      : in std_logic;      -- Enable count operation
39
        DOWN        : in std_logic;      -- Count direction down
40
        D           : in std_logic_vector(WIDTH-1 downto 0);    -- Load counter register input
41
        Q           : out std_logic_vector(WIDTH-1 downto 0);   -- Shift register output
42
        OVERFLOW    : out std_logic      -- Counter overflow
43
    );
44
end slib_counter;
45
 
46
architecture rtl of slib_counter is
47 10 hasw
    signal iCounter : unsigned(WIDTH downto 0);         -- Counter register
48 2 hasw
begin
49
    -- Counter process
50
    COUNT_SHIFT: process (RST, CLK)
51
    begin
52
        if (RST = '1') then
53
            iCounter <= (others => '0');                -- Reset counter register
54
        elsif (CLK'event and CLK='1') then
55
            if (CLEAR = '1') then
56
                iCounter <= (others => '0');            -- Clear counter register
57
            elsif (LOAD = '1') then                     -- Load counter register
58 10 hasw
                iCounter <= unsigned('0' & D);
59 2 hasw
            elsif (ENABLE = '1') then                   -- Enable counter
60
                if (DOWN = '0') then                    -- Count up
61 10 hasw
                    iCounter <= iCounter + 1;
62 2 hasw
                else                                    -- Count down
63 10 hasw
                    iCounter <= iCounter - 1;
64 2 hasw
                end if;
65
            end if;
66
            if (iCounter(WIDTH) = '1') then             -- Clear overflow
67
                iCounter(WIDTH) <= '0';
68
            end if;
69
        end if;
70
 
71
    end process;
72
 
73
    -- Output ports
74 10 hasw
    Q        <= std_logic_vector(iCounter(WIDTH-1 downto 0));
75 2 hasw
    OVERFLOW <= iCounter(WIDTH);
76
end rtl;
77
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.