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

Subversion Repositories versatile_library

[/] [versatile_library/] [trunk/] [rtl/] [verilog/] [counters.v] - Blame information for rev 40

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 unneback
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  Versatile library, counters                                 ////
4
////                                                              ////
5
////  Description                                                 ////
6
////  counters                                                    ////
7
////                                                              ////
8
////                                                              ////
9
////  To Do:                                                      ////
10
////   - add more counters                                        ////
11
////                                                              ////
12
////  Author(s):                                                  ////
13
////      - Michael Unneback, unneback@opencores.org              ////
14
////        ORSoC AB                                              ////
15
////                                                              ////
16
//////////////////////////////////////////////////////////////////////
17
////                                                              ////
18
//// Copyright (C) 2010 Authors and OPENCORES.ORG                 ////
19
////                                                              ////
20
//// This source file may be used and distributed without         ////
21
//// restriction provided that this copyright statement is not    ////
22
//// removed from the file and that any derivative work contains  ////
23
//// the original copyright notice and the associated disclaimer. ////
24
////                                                              ////
25
//// This source file is free software; you can redistribute it   ////
26
//// and/or modify it under the terms of the GNU Lesser General   ////
27
//// Public License as published by the Free Software Foundation; ////
28
//// either version 2.1 of the License, or (at your option) any   ////
29
//// later version.                                               ////
30
////                                                              ////
31
//// This source is distributed in the hope that it will be       ////
32
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
33
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
34
//// PURPOSE.  See the GNU Lesser General Public License for more ////
35
//// details.                                                     ////
36
////                                                              ////
37
//// You should have received a copy of the GNU Lesser General    ////
38
//// Public License along with this source; if not, download it   ////
39
//// from http://www.opencores.org/lgpl.shtml                     ////
40
////                                                              ////
41
//////////////////////////////////////////////////////////////////////
42
 
43 40 unneback
`ifdef CNT_SHREG_WRAP
44
`define MODULE cnt_shreg_wrap
45
module `BASE`MODULE ( q, rst, clk);
46
`undef MODULE
47 4 unneback
 
48
   parameter length = 4;
49 5 unneback
   output reg [0:length-1] q;
50
   input rst;
51
   input clk;
52
 
53
    always @ (posedge clk or posedge rst)
54
    if (rst)
55
        q <= {1'b1,{length-1{1'b0}}};
56
    else
57
        q <= {q[length-1],q[0:length-2]};
58
 
59
endmodule
60 40 unneback
`endif
61 5 unneback
 
62 40 unneback
`ifdef CNT_SHREG_CE_WRAP
63
`define MODULE cnt_shreg_ce_wrap
64
module `BASE`MODULE ( cke, q, rst, clk);
65
`undef MODULE
66 5 unneback
 
67
   parameter length = 4;
68 4 unneback
   input cke;
69
   output reg [0:length-1] q;
70
   input rst;
71
   input clk;
72
 
73
    always @ (posedge clk or posedge rst)
74
    if (rst)
75
        q <= {1'b1,{length-1{1'b0}}};
76
    else
77
        if (cke)
78 5 unneback
            q <= {q[length-1],q[0:length-2]};
79 4 unneback
 
80
endmodule
81 40 unneback
`endif
82 4 unneback
 
83 40 unneback
`ifdef CNT_SHREG_CE_CLEAR
84
`define MODULE cnt_shreg_ce_clear
85
module `BASE`MODULE ( cke, clear, q, rst, clk);
86
`undef MODULE
87 4 unneback
 
88
   parameter length = 4;
89 5 unneback
   input cke, clear;
90 4 unneback
   output reg [0:length-1] q;
91
   input rst;
92
   input clk;
93
 
94
    always @ (posedge clk or posedge rst)
95
    if (rst)
96
        q <= {1'b1,{length-1{1'b0}}};
97
    else
98
        if (cke)
99
            if (clear)
100
                q <= {1'b1,{length-1{1'b0}}};
101
            else
102
                q <= q >> 1;
103
 
104
endmodule
105 40 unneback
`endif
106 4 unneback
 
107 40 unneback
`ifdef CNT_SHREG_CE_CLEAR_WRAP
108
`define MODULE cnt_shreg_ce_clear_wrap
109
module `BASE`MODULE ( cke, clear, q, rst, clk);
110
`undef MODULE
111 4 unneback
 
112 5 unneback
   parameter length = 4;
113
   input cke, clear;
114
   output reg [0:length-1] q;
115
   input rst;
116
   input clk;
117
 
118
    always @ (posedge clk or posedge rst)
119
    if (rst)
120
        q <= {1'b1,{length-1{1'b0}}};
121
    else
122
        if (cke)
123
            if (clear)
124
                q <= {1'b1,{length-1{1'b0}}};
125
            else
126
            q <= {q[length-1],q[0:length-2]};
127
 
128
endmodule
129 40 unneback
`endif

powered by: WebSVN 2.1.0

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