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

Subversion Repositories usb2uart

[/] [usb2uart/] [trunk/] [rtl/] [lib/] [clk_ctl.v] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 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: clk_ctl
46
//
47
// Description:  Generic clock control logic , clk-out = mclk/(2+clk_div_ratio)
48
//
49
//  
50
// #################################################################
51
 
52
 
53
module clk_ctl (
54
   // Outputs
55
       clk_o,
56
   // Inputs
57
       mclk,
58
       reset_n,
59
       clk_div_ratio
60
   );
61
 
62
//---------------------------------
63
// CLOCK Default Divider value.
64
// This value will be change from outside
65
//---------------------------------
66
parameter  WD = 'h1;
67
 
68
//---------------------------------------------
69
// All the input to this block are declared here
70
// --------------------------------------------
71
   input        mclk          ;// 
72
   input        reset_n       ;// primary reset signal
73
   input [WD:0] clk_div_ratio ;// primary clock divide ratio
74
                               // output clock = selected clock / (div_ratio+1)
75
 
76
//---------------------------------------------
77
// All the output to this block are declared here
78
// --------------------------------------------
79
   output       clk_o             ; // clock out
80
 
81
 
82
 
83
//------------------------------------
84
// Clock Divide func is done here
85
//------------------------------------
86
reg  [WD-1:0]    high_count       ; // high level counter
87
reg  [WD-1:0]    low_count        ; // low level counter
88
reg              mclk_div         ; // divided clock
89
 
90
 
91
assign clk_o  = mclk_div;
92
 
93
always @ (posedge mclk or negedge reset_n)
94
begin // {
95
   if(reset_n == 1'b0)
96
   begin
97
      high_count  <= 'h0;
98
      low_count   <= 'h0;
99
      mclk_div    <= 'b0;
100
   end
101
   else
102
   begin
103
      if(high_count != 0)
104
      begin // {
105
         high_count    <= high_count - 1;
106
         mclk_div      <= 1'b1;
107
      end   // }
108
      else if(low_count != 0)
109
      begin // {
110
         low_count     <= low_count - 1;
111
         mclk_div      <= 1'b0;
112
      end   // }
113
      else
114
      begin // {
115
         high_count    <= clk_div_ratio[WD:1] + clk_div_ratio[0];
116
         low_count     <= clk_div_ratio[WD:1] + 1;
117
         mclk_div      <= ~mclk_div;
118
      end   // }
119
   end   // }
120
end   // }
121
 
122
 
123
endmodule
124
 

powered by: WebSVN 2.1.0

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