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

Subversion Repositories vga_lcd

[/] [vga_lcd/] [tags/] [beta/] [counter.vhd] - Blame information for rev 62

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 rherveille
--
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
 
10
 
11
library ieee;
12
use ieee.std_logic_1164.all;
13
use ieee.std_logic_arith.all;
14
 
15
package count is
16
        -- run-once down-counter
17
        component ro_cnt is
18
        generic(SIZE : natural := 8);
19
        port(
20
                clk : in std_logic; -- master clock
21
                nReset : in std_logic := '1'; -- asynchronous active low reset
22
                rst : in std_logic := '0'; -- synchronous active high reset
23
 
24
                cnt_en : in std_logic := '1'; -- count enable
25
                go : in std_logic; -- load counter and start sequence
26
                done : out std_logic; -- done counting
27
                D : in unsigned(SIZE -1 downto 0); -- load counter value
28
                Q : out unsigned(SIZE -1 downto 0); -- current counter value
29
 
30
                ID : in unsigned(SIZE -1 downto 0) := (others => '0') -- initial data after reset
31
        );
32
        end component ro_cnt;
33
 
34
        -- general purpose up-down counter
35
        component ud_cnt is
36
        generic(
37
                SYNCH_RCO : bit := '0'; -- NO
38
                SIZE : natural := 8
39
        );
40
        port(
41
                clk : in std_logic; -- master clock
42
                nReset : in std_logic := '1'; -- asynchronous active low reset
43
                rst : in std_logic := '0'; -- synchronous active high reset
44
 
45
                cnt_en : in std_logic := '1'; -- count enable
46
                ud : in std_logic := '0'; -- up / not down
47
                nld : in std_logic := '1'; -- synchronous active low load
48
                D : in unsigned(SIZE -1 downto 0); -- load counter value
49
                Q : out unsigned(SIZE -1 downto 0); -- current counter value
50
 
51
                resD : in unsigned(SIZE -1 downto 0) := (others => '0'); -- initial data after reset
52
 
53
                rci : in std_logic := '1'; -- carry input
54
                rco : out std_logic -- carry output
55
        );
56
        end component ud_cnt;
57
 
58
end package count;
59
 
60
--
61
-- run-once down-counter, counts D+1 cycles before generating 'DONE'
62
--
63
library ieee;
64
use ieee.std_logic_1164.all;
65
use ieee.std_logic_arith.all;
66
 
67
entity ro_cnt is
68
        generic(SIZE : natural := 8);
69
        port(
70
                clk : in std_logic; -- master clock
71
                nReset : in std_logic := '1'; -- asynchronous active low reset
72
                rst : in std_logic := '0'; -- synchronous active high reset
73
 
74
                cnt_en : in std_logic := '1'; -- count enable
75
                go : in std_logic; -- load counter and start sequence
76
                done : out std_logic; -- done counting
77
                D : in unsigned(SIZE -1 downto 0); -- load counter value
78
                Q : out unsigned(SIZE -1 downto 0); -- current counter value
79
 
80
                ID : in unsigned(SIZE -1 downto 0) := (others => '0') -- initial data after reset
81
        );
82
end entity ro_cnt;
83
 
84
architecture structural of ro_cnt is
85
        component ud_cnt is
86
        generic(
87
                SYNCH_RCO : bit := '0'; -- NO
88
                SIZE : natural := 8
89
        );
90
        port(
91
                clk : in std_logic; -- master clock
92
                nReset : in std_logic := '1'; -- asynchronous active low reset
93
                rst : in std_logic := '0'; -- synchronous active high reset
94
 
95
                cnt_en : in std_logic := '1'; -- count enable
96
                ud : in std_logic := '0'; -- up / not down
97
                nld : in std_logic := '1'; -- synchronous active low load
98
                D : in unsigned(SIZE -1 downto 0); -- load counter value
99
                Q : out unsigned(SIZE -1 downto 0); -- current counter value
100
 
101
                resD : in unsigned(SIZE -1 downto 0) := (others => '0'); -- initial data after reset
102
 
103
                rci : in std_logic := '1'; -- carry input
104
                rco : out std_logic -- carry output
105
        );
106
        end component ud_cnt;
107
 
108
        signal rci, rco, nld : std_logic;
109
begin
110
        gen_ctrl: process(clk, nReset)
111
        begin
112
                if (nReset = '0') then
113
                        rci <= '0';
114
                elsif (clk'event and clk = '1') then
115
                        if (rst = '1') then
116
                                rci <= '0';
117
                        else
118
                                rci <= (go or rci) and not rco;
119
                        end if;
120
                end if;
121
        end process;
122
 
123
        nld <= not go;
124
 
125
        -- hookup counter
126
        cnt : ud_cnt
127
                generic map (SIZE => SIZE, SYNCH_RCO => '0')
128
                port map (clk => clk, nReset => nReset, rst => rst, cnt_en => cnt_en, nld => nld, D => D, Q => Q,
129
                        resD => ID, rci => rci, rco => rco);
130
 
131
        done <= rco;
132
end architecture structural;
133
 
134
 
135
 
136
--
137
-- general purpose counter
138
--
139
library ieee;
140
use ieee.std_logic_1164.all;
141
use ieee.std_logic_arith.all;
142
 
143
entity ud_cnt is
144
        generic(
145
                SYNCH_RCO : bit := '0'; -- NO
146
                SIZE : natural := 8
147
        );
148
        port(
149
                clk : in std_logic; -- master clock
150
                nReset : in std_logic := '1'; -- asynchronous active low reset
151
                rst : in std_logic := '0'; -- synchronous active high reset
152
 
153
                cnt_en : in std_logic := '1'; -- count enable
154
                ud : in std_logic := '0'; -- up / not down
155
                nld : in std_logic := '1'; -- synchronous active low load
156
                D : in unsigned(SIZE -1 downto 0); -- load counter value
157
                Q : out unsigned(SIZE -1 downto 0); -- current counter value
158
 
159
                resD : in unsigned(SIZE -1 downto 0) := (others => '0'); -- initial data after reset
160
 
161
                rci : in std_logic := '1'; -- carry input
162
                rco : out std_logic -- carry output
163
        );
164
end entity ud_cnt;
165
 
166
architecture structural of ud_cnt is
167
        signal Qi : unsigned(SIZE -1 downto 0);
168
        signal val : unsigned(SIZE downto 0);
169
begin
170
        nval: process(rci, ud, Qi)
171
        begin
172
                if (ud = '1') then
173
                        val <= ('0' & Qi) + rci;
174
                else
175
                        val <= ('0' & Qi) - rci;
176
                end if;
177
        end process nval;
178
 
179
        regs: process(clk, nReset, resD)
180
        begin
181
                if (nReset = '0') then
182
                        Qi <= resD;
183
                elsif (clk'event and clk = '1') then
184
                        if (rst = '1') then
185
                                Qi <= resD;
186
                        else
187
                                if (nld = '0') then
188
                                        Qi <= D;
189
                                elsif (cnt_en = '1') then
190
                                        Qi <= val(SIZE -1 downto 0);
191
                                end if;
192
                        end if;
193
                end if;
194
        end process regs;
195
 
196
        -- assign outputs
197
        Q <= Qi;
198
 
199
        gen_rco:
200
        if (SYNCH_RCO = '0') generate
201
                rco <= val(SIZE);
202
        end generate;
203
        gen_srco:
204
        if (SYNCH_RCO = '1') generate
205
                process(clk, nReset)
206
                begin
207
                        if (nReset = '0') then
208
                                rco <= '0';
209
                        elsif (clk'event and clk = '1') then
210
                                if (rst = '1') then
211
                                        rco <= '0';
212
                                else
213
                                        if (cnt_en = '1') then
214
                                                rco <= val(SIZE);
215
                                        end if;
216
                                end if;
217
                        end if;
218
                end process;
219
        end generate;
220
end architecture structural;
221
 
222
 
223
 
224
 
225
 
226
 
227
 

powered by: WebSVN 2.1.0

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