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

Subversion Repositories turbo8051

[/] [turbo8051/] [trunk/] [rtl/] [lib/] [stat_counter.v] - Blame information for rev 50

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

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

powered by: WebSVN 2.1.0

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