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

Subversion Repositories oms8051mini

[/] [oms8051mini/] [trunk/] [rtl/] [lib/] [stat_counter.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 dinesha
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  OMS 8051 cores common library Module                        ////
4
////                                                              ////
5
////  This file is part of the OMS 8051 cores project             ////
6
////  http://www.opencores.org/cores/oms8051mini/                 ////
7
////                                                              ////
8
////  Description                                                 ////
9
////  OMS 8051 definitions.                                       ////
10
////                                                              ////
11
////  To Do:                                                      ////
12
////    nothing                                                   ////
13
////                                                              ////
14
////  Author(s):                                                  ////
15
////      - Dinesh Annayya, dinesha@opencores.org                 ////
16
////                                                              ////
17
////  Revision : Nov 26, 2016                                     //// 
18
////                                                              ////
19
//////////////////////////////////////////////////////////////////////
20
////                                                              ////
21
//// Copyright (C) 2000 Authors and OPENCORES.ORG                 ////
22
////                                                              ////
23
//// This source file may be used and distributed without         ////
24
//// restriction provided that this copyright statement is not    ////
25
//// removed from the file and that any derivative work contains  ////
26
//// the original copyright notice and the associated disclaimer. ////
27
////                                                              ////
28
//// This source file is free software; you can redistribute it   ////
29
//// and/or modify it under the terms of the GNU Lesser General   ////
30
//// Public License as published by the Free Software Foundation; ////
31
//// either version 2.1 of the License, or (at your option) any   ////
32
//// later version.                                               ////
33
////                                                              ////
34
//// This source is distributed in the hope that it will be       ////
35
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
36
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
37
//// PURPOSE.  See the GNU Lesser General Public License for more ////
38
//// details.                                                     ////
39
////                                                              ////
40
//// You should have received a copy of the GNU Lesser General    ////
41
//// Public License along with this source; if not, download it   ////
42
//// from http://www.opencores.org/lgpl.shtml                     ////
43
////                                                              ////
44
//////////////////////////////////////////////////////////////////////
45
 
46
// -----------------------------------------------------------------------
47
// Module Name      : stat_counter.v
48
// Company          : 
49
// Creation date    : 
50
// -----------------------------------------------------------------------
51
// Description      : This is the general purpose statistics counter. 
52
//                 
53
//                    
54
// References       : 
55
// ------------------------------------------------------------------------
56
 
57
//----------------- compiler directives -----------------------------------
58
 
59
// ------------------------------------------------------------------------
60
module stat_counter
61
  (
62
   // Clock and Reset Signals
63
   sys_clk,
64
   s_reset_n,
65
 
66
   count_inc,
67
   count_dec,
68
 
69
   reg_sel,
70
   reg_wr_data,
71
   reg_wr,
72
 
73
   cntr_intr,
74
   cntrout
75
 
76
 
77
   );
78
 
79
parameter CWD    = 1; // Counter Width
80
   //-------------------- Parameters -------------------------------------
81
 
82
   // ------------------- Clock and Reset Signals ------------------------
83
   input                     sys_clk;
84
   input                     s_reset_n;
85
   input                     count_inc; // Counter Increment
86
   input                     count_dec; // counter decrement, assuption does not under flow
87
   input                     reg_sel;
88
   input                     reg_wr;
89
   input  [CWD-1:0]          reg_wr_data;
90
   output                    cntr_intr;
91
   output [CWD-1:0]          cntrout;
92
   // ------------------- Register Declarations --------------------------
93
   reg [CWD-1:0]             reg_trig_cntr;
94
 
95
 
96
// ------------------- Logic Starts Here ----------------------------------
97
 
98
 
99
 
100
always @ (posedge sys_clk or negedge s_reset_n)
101
begin
102
   if (s_reset_n == 1'b0) begin
103
      reg_trig_cntr <= 'b0;
104
   end
105
   else begin
106
      if (reg_sel && reg_wr) begin
107
         reg_trig_cntr <= reg_wr_data;
108
      end
109
      else begin
110
         if (count_inc && count_dec)
111
            reg_trig_cntr <= reg_trig_cntr;
112
         else if (count_inc)
113
              reg_trig_cntr <= reg_trig_cntr + 1'b1;
114
         else if (count_dec)
115
              reg_trig_cntr <= reg_trig_cntr - 1'b1;
116
         else
117
            reg_trig_cntr <= reg_trig_cntr;
118
      end
119
   end
120
end
121
// only increment overflow is assumed  
122
// decrement underflow is not handled 
123
assign cntr_intr = ((reg_trig_cntr + 1) == 'h0 && count_inc) ;
124
 
125
assign cntrout = reg_trig_cntr;
126
 
127
endmodule // must_stat_counter

powered by: WebSVN 2.1.0

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