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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64/] [rtl/] [lib/] [counter.v] - Blame information for rev 46

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 46 robfinch
// ============================================================================
2
// (C) 2007 Robert Finch
3
// All Rights Reserved.
4
//
5
//      counter.v
6
//              generic up counter
7
//
8
// This source file is free software: you can redistribute it and/or modify 
9
// it under the terms of the GNU Lesser General Public License as published 
10
// by the Free Software Foundation, either version 3 of the License, or     
11
// (at your option) any later version.                                      
12
//                                                                          
13
// This source file 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            
16
// GNU General Public License for more details.                             
17
//                                                                          
18
// You should have received a copy of the GNU General Public License        
19
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
20
//                                                                          
21
// ============================================================================
22
//
23
module counter(rst, clk, ce, ld, d, q, tc);
24
parameter WID=8;
25
parameter pMaxCnt={WID{1'b1}};
26
input rst;
27
input clk;
28
input ce;
29
input ld;
30
input [WID:1] d;
31
output [WID:1] q;
32
reg [WID:1] q;
33
output tc;
34
 
35
assign tc = &q;
36
 
37
always @(posedge clk)
38
if (rst)
39
        q <= 1'b0;
40
else if (ce) begin
41
        if (ld)
42
                q <= d;
43
        else if (tc)
44
                q <= 1'b0;
45
        else
46
                q <= q + 1'b1;
47
end
48
 
49
endmodule

powered by: WebSVN 2.1.0

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