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

Subversion Repositories vga_lcd

[/] [vga_lcd/] [tags/] [rel_1/] [rtl/] [vhdl/] [counter.vhd] - Blame information for rev 62

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 rudi
--
2
-- Counter.vhd, contains 1) run-once down-counter  2) general purpose up-down riple-carry counter
3
--
4
-- Author: Richard Herveille
5
-- Rev. 1.0 march 7th, 2001
6
-- rev. 1.1 april 17th, 2001. Changed ro_cnt nld generation
7
-- rev. 1.1 april 26th, 2001. Changed SYNCH_RCO (component ud_cnt) from string to bit. Fixed problems with Synplify
8
-- rev. 1.2 may   11th, 2001. Fixed incomplete sensitivity list warning
9
-- rev. 1.3 june  18th, 2001. Changed module order, they are now in compilation order.
10
-- rev. 1.4 june  27th, 2001. Removed 'SYNCH_RCO' parameter, simplifies conversion to verilog. 
11
--                            Fixed a potential bug in "ro_cnt" where 'rci' was not related to 'cnt_en'. 
12
--                            Changed "val" signal generation from process to "when..else.." statement
13
--
14
 
15
 
16
library ieee;
17
use ieee.std_logic_1164.all;
18
use ieee.std_logic_arith.all;
19
 
20
package count is
21
        -- general purpose up-down counter
22
        component ud_cnt is
23
        generic(
24
                SIZE : natural := 8
25
        );
26
        port(
27
                clk : in std_logic; -- master clock
28
                nReset : in std_logic := '1'; -- asynchronous active low reset
29
                rst : in std_logic := '0'; -- synchronous active high reset
30
 
31
                cnt_en : in std_logic := '1'; -- count enable
32
                ud : in std_logic := '0'; -- up / not down
33
                nld : in std_logic := '1'; -- synchronous active low load
34
                D : in unsigned(SIZE -1 downto 0); -- load counter value
35
                Q : out unsigned(SIZE -1 downto 0); -- current counter value
36
 
37
                resD : in unsigned(SIZE -1 downto 0) := (others => '0'); -- initial data after reset
38
 
39
                rci : in std_logic := '1'; -- carry input
40
                rco : out std_logic -- carry output
41
        );
42
        end component ud_cnt;
43
 
44
        -- run-once down-counter
45
        component ro_cnt is
46
        generic(SIZE : natural := 8);
47
        port(
48
                clk : in std_logic; -- master clock
49
                nReset : in std_logic := '1'; -- asynchronous active low reset
50
                rst : in std_logic := '0'; -- synchronous active high reset
51
 
52
                cnt_en : in std_logic := '1'; -- count enable
53
                go : in std_logic; -- load counter and start sequence
54
                done : out std_logic; -- done counting
55
                D : in unsigned(SIZE -1 downto 0); -- load counter value
56
                Q : out unsigned(SIZE -1 downto 0); -- current counter value
57
 
58
                ID : in unsigned(SIZE -1 downto 0) := (others => '0') -- initial data after reset
59
        );
60
        end component ro_cnt;
61
end package count;
62
 
63
--
64
-- general purpose counter
65
--
66
library ieee;
67
use ieee.std_logic_1164.all;
68
use ieee.std_logic_arith.all;
69
 
70
entity ud_cnt is
71
        generic(
72
                SIZE : natural := 8
73
        );
74
        port(
75
                clk : in std_logic; -- master clock
76
                nReset : in std_logic := '1'; -- asynchronous active low reset
77
                rst : in std_logic := '0'; -- synchronous active high reset
78
 
79
                cnt_en : in std_logic := '1'; -- count enable
80
                ud : in std_logic := '0'; -- up / not down
81
                nld : in std_logic := '1'; -- synchronous active low load
82
                D : in unsigned(SIZE -1 downto 0); -- load counter value
83
                Q : out unsigned(SIZE -1 downto 0); -- current counter value
84
 
85
                resD : in unsigned(SIZE -1 downto 0) := (others => '0'); -- initial data after reset
86
 
87
                rci : in std_logic := '1'; -- carry input
88
                rco : out std_logic -- carry output
89
        );
90
end entity ud_cnt;
91
 
92
architecture structural of ud_cnt is
93
        signal Qi : unsigned(SIZE -1 downto 0);
94
        signal val : unsigned(SIZE downto 0);
95
begin
96
        val <= ( ('0' & Qi) + rci) when (ud = '1') else ( ('0' & Qi) - rci);
97
 
98
        regs: process(clk, nReset, resD)
99
        begin
100
                if (nReset = '0') then
101
                        Qi <= resD;
102
                elsif (clk'event and clk = '1') then
103
                        if (rst = '1') then
104
                                Qi <= resD;
105
                        else
106
                                if (nld = '0') then
107
                                        Qi <= D;
108
                                elsif (cnt_en = '1') then
109
                                        Qi <= val(SIZE -1 downto 0);
110
                                end if;
111
                        end if;
112
                end if;
113
        end process regs;
114
 
115
        -- assign outputs
116
        Q <= Qi;
117
        rco <= val(SIZE);
118
end architecture structural;
119
 
120
 
121
--
122
-- run-once down-counter, counts D+1 cycles before generating 'DONE'
123
--
124
library ieee;
125
use ieee.std_logic_1164.all;
126
use ieee.std_logic_arith.all;
127
 
128
entity ro_cnt is
129
        generic(SIZE : natural := 8);
130
        port(
131
                clk : in std_logic; -- master clock
132
                nReset : in std_logic := '1'; -- asynchronous active low reset
133
                rst : in std_logic := '0'; -- synchronous active high reset
134
 
135
                cnt_en : in std_logic := '1'; -- count enable
136
                go : in std_logic; -- load counter and start sequence
137
                done : out std_logic; -- done counting
138
                D : in unsigned(SIZE -1 downto 0); -- load counter value
139
                Q : out unsigned(SIZE -1 downto 0); -- current counter value
140
 
141
                ID : in unsigned(SIZE -1 downto 0) := (others => '0') -- initial data after reset
142
        );
143
end entity ro_cnt;
144
 
145
architecture structural of ro_cnt is
146
        component ud_cnt is
147
        generic(
148
                SIZE : natural := 8
149
        );
150
        port(
151
                clk : in std_logic; -- master clock
152
                nReset : in std_logic := '1'; -- asynchronous active low reset
153
                rst : in std_logic := '0'; -- synchronous active high reset
154
 
155
                cnt_en : in std_logic := '1'; -- count enable
156
                ud : in std_logic := '0'; -- up / not down
157
                nld : in std_logic := '1'; -- synchronous active low load
158
                D : in unsigned(SIZE -1 downto 0); -- load counter value
159
                Q : out unsigned(SIZE -1 downto 0); -- current counter value
160
 
161
                resD : in unsigned(SIZE -1 downto 0) := (others => '0'); -- initial data after reset
162
 
163
                rci : in std_logic := '1'; -- carry input
164
                rco : out std_logic -- carry output
165
        );
166
        end component ud_cnt;
167
 
168
        signal rci, rco, nld : std_logic;
169
begin
170
        gen_ctrl: process(clk, nReset)
171
        begin
172
                if (nReset = '0') then
173
                        rci <= '0';
174
                elsif (clk'event and clk = '1') then
175
                        if (rst = '1') then
176
                                rci <= '0';
177
                        elsif (cnt_en = '1' ) then
178
                                rci <= (go or rci) and not rco;
179
                        end if;
180
                end if;
181
        end process;
182
 
183
        nld <= not go;
184
 
185
        -- hookup counter
186
        cnt : ud_cnt
187
                generic map (SIZE => SIZE)
188
                port map (clk => clk, nReset => nReset, rst => rst, cnt_en => cnt_en, nld => nld, D => D, Q => Q,
189
                        resD => ID, rci => rci, rco => rco);
190
 
191
        done <= rco;
192
end architecture structural;
193
 

powered by: WebSVN 2.1.0

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