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

Subversion Repositories mips_enhanced

[/] [mips_enhanced/] [trunk/] [grlib-gpl-1.0.19-b3188/] [lib/] [opencores/] [ata/] [ud_cnt.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dimamali
---------------------------------------------------------------------
2
----                                                             ----
3
----  Generic Up/Down counter (ripple carry architecture)        ----
4
----                                                             ----
5
----  Author: Richard Herveille                                  ----
6
----          richard@asics.ws                                   ----
7
----          www.asics.ws                                       ----
8
----                                                             ----
9
---------------------------------------------------------------------
10
----                                                             ----
11
---- Copyright (C) 2001, 2002 Richard Herveille                  ----
12
----                          richard@asics.ws                   ----
13
----                                                             ----
14
---- This source file may be used and distributed without        ----
15
---- restriction provided that this copyright statement is not   ----
16
---- removed from the file and that any derivative work contains ----
17
---- the original copyright notice and the associated disclaimer.----
18
----                                                             ----
19
----     THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY     ----
20
---- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   ----
21
---- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   ----
22
---- FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      ----
23
---- OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         ----
24
---- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    ----
25
---- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   ----
26
---- GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        ----
27
---- BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  ----
28
---- LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  ----
29
---- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  ----
30
---- OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         ----
31
---- POSSIBILITY OF SUCH DAMAGE.                                 ----
32
----                                                             ----
33
---------------------------------------------------------------------
34
 
35
--
36
--  CVS Log
37
--
38
--  $Id: ud_cnt.vhd,v 1.1 2002/03/01 03:49:03 rherveille Exp $
39
--
40
--  $Date: 2002/03/01 03:49:03 $
41
--  $Revision: 1.1 $
42
--  $Author: rherveille $
43
--  $Locker:  $
44
--  $State: Exp $
45
--
46
-- Change History:
47
--               $Log: ud_cnt.vhd,v $
48
--               Revision 1.1  2002/03/01 03:49:03  rherveille
49
--               Changed internal counter libraries.
50
--               Split counter.vhd into separate files.
51
--               Core is in same state as Verilog version now.
52
--
53
 
54
 
55
library ieee;
56
use ieee.std_logic_1164.all;
57
--use ieee.std_logic_arith.all;
58
library grlib;
59
use grlib.stdlib.all;
60
 
61
entity ud_cnt is
62
        generic(
63
                SIZE : natural := 8;
64
                RESD : natural := 0
65
        );
66
        port(
67
                clk    : in  std_logic;                  -- master clock
68
                nReset : in  std_logic := '1';           -- asynchronous active low reset
69
                rst    : in  std_logic := '0';           -- synchronous active high reset
70
 
71
                cnt_en : in  std_logic := '1';           -- count enable
72
                ud     : in  std_logic := '0';           -- up / not down
73
                nld    : in  std_logic := '1';           -- synchronous active low load
74
                d      : in  std_logic_vector(SIZE -1 downto 0); -- load counter value
75
                q      : out std_logic_vector(SIZE -1 downto 0); -- current counter value
76
 
77
                rci    : in  std_logic := '1';           -- carry input
78
                rco    : out std_logic                   -- carry output
79
        );
80
end entity ud_cnt;
81
 
82
architecture structural of ud_cnt is
83
        signal Qi : std_logic_vector(SIZE -1 downto 0);
84
        signal val : std_logic_vector(SIZE downto 0);
85
begin
86
        val <= ( ('0' & Qi) + rci) when (ud = '1') else ( ('0' & Qi) - rci);
87
 
88
        regs: process(clk, nReset)
89
        begin
90
                if (nReset = '0') then
91
                        Qi <= conv_std_logic_vector(RESD, SIZE);
92
                elsif (clk'event and clk = '1') then
93
                        if (rst = '1') then
94
                                Qi <= conv_std_logic_vector(RESD, SIZE);
95
                        else
96
                                if (nld = '0') then
97
                                        Qi <= D;
98
                                elsif (cnt_en = '1') then
99
                                        Qi <= val(SIZE -1 downto 0);
100
                                end if;
101
                        end if;
102
                end if;
103
        end process regs;
104
 
105
        -- assign outputs
106
        Q <= Qi;
107
        rco <= val(SIZE);
108
end architecture structural;
109
 

powered by: WebSVN 2.1.0

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