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

Subversion Repositories turbo8051

[/] [turbo8051/] [trunk/] [rtl/] [clkgen/] [clkgen.v] - Blame information for rev 8

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

Line No. Rev Author Line
1 8 dinesha
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  Tubo 8051 cores clockgen 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
module clkgen (
45
               reset_n      ,
46
               fastsim_mode ,
47
               xtal_clk     ,
48
               clkout       ,
49
               gen_resetn   ,
50
               gen_reset    ,
51
               app_clk      ,
52
               uart_ref_clk
53
              );
54
 
55
 
56
 
57
input           reset_n        ; // Async reset signal
58
input         fastsim_mode   ; // fast sim mode = 1
59
input           xtal_clk       ; // Xtal clock-25Mhx 
60
output        clkout         ; // clock output, 250Mhz
61
output        gen_resetn     ; // internally generated reset
62
output        gen_reset      ; // internally generated reset
63
output        app_clk        ; // application clock
64
output        uart_ref_clk   ; // uart 16x Ref clock
65
 
66
 
67
wire          hard_reset_st  ;
68
wire          configure_st   ;
69
wire          wait_pll_st    ;
70
wire          run_st         ;
71
reg           pll_done       ;
72
reg [11:0]         pll_count      ;
73
reg [1:0]          clkgen_ps      ;
74
reg           gen_resetn     ; // internally generated reset
75
reg           gen_reset      ; // internally generated reset
76
 
77
 
78
assign        clkout = app_clk;
79
wire          pllout;
80
/***********************************************
81
 Alternal PLL pr-programmed for xtal: 25Mhz , clkout 250Mhz
82
*********************************************************/
83
 
84
altera_stargate_pll u_pll (
85
        . areset     (!reset_n ),
86
        . inclk0     (xtal_clk),
87
        . c0         (pllout),
88
        . locked     ()
89
       );
90
 
91
 
92
 
93
//---------------------------------------------
94
//
95
// 100us use 25.000 Mhz clock, counter = 2500(0x9C4)
96
 
97
//--------------------------------------------
98
always @(posedge xtal_clk or negedge reset_n)
99
   begin // {
100
      if (!reset_n)
101
      begin // {
102
         pll_count <= 12'h9C4;
103
      end   // }                                                                 
104
      else if (configure_st)
105
      begin // {
106
         pll_count <= (fastsim_mode) ? 12'h040  :  12'h9C4;
107
      end // }
108
      else if (wait_pll_st)
109
      begin // {
110
         pll_count <= (pll_done) ? pll_count : (pll_count - 1'b1);
111
     end // }
112
   end // }
113
 
114
 
115
/************************************************
116
    PLL Timer Counter
117
************************************************/
118
 
119
always @(posedge xtal_clk or negedge reset_n)
120
begin
121
   if (!reset_n)
122
      pll_done <= 0;
123
   else if (pll_count == 16'h0)
124
      pll_done <= 1;
125
   else if (configure_st)
126
      pll_done <= 0;
127
end
128
 
129
 
130
/************************************************
131
  internally generated reset
132
************************************************/
133
always @(posedge xtal_clk or negedge reset_n )
134
begin
135
   if (!reset_n) begin
136
      gen_resetn <=  0;
137
      gen_reset  <=  1;
138
   end else if(run_st ) begin
139
      gen_resetn <=  1;
140
      gen_reset  <=  0;
141
   end else begin
142
      gen_resetn <=  0;
143
      gen_reset  <=  1;
144
   end
145
end
146
 
147
 
148
/****************************************
149
    Reset State Machine
150
****************************************/
151
/*****************************************
152
   Define Clock Gen stat machine state
153
*****************************************/
154
`define HARD_RESET      2'b00
155
`define CONFIGURE       2'b01
156
`define WAIT_PLL        2'b10
157
`define RUN             2'b11
158
 
159
assign hard_reset_st     = (clkgen_ps == `HARD_RESET);
160
assign configure_st      = (clkgen_ps == `CONFIGURE);
161
assign wait_pll_st       = (clkgen_ps == `WAIT_PLL);
162
assign run_st            = (clkgen_ps == `RUN);
163
 
164
always @(posedge xtal_clk or negedge reset_n)
165
begin
166
   if (!reset_n) begin
167
      clkgen_ps <= `HARD_RESET;
168
   end
169
   else begin
170
      case (clkgen_ps)
171
         `HARD_RESET:
172
            clkgen_ps <= `CONFIGURE;
173
 
174
          `CONFIGURE:
175
             clkgen_ps <= `WAIT_PLL;
176
 
177
         `WAIT_PLL:
178
           if (pll_done)
179
             clkgen_ps <= `RUN;
180
      endcase
181
   end
182
end
183
 
184
 
185
//----------------------------------
186
// Generate Application clock 125Mhz
187
//----------------------------------
188
 
189
clk_ctl #(2) u_appclk (
190
   // Outputs
191
       .clk_o         (app_clk),
192
   // Inputs
193
       .mclk          (pllout),
194
       .reset_n       (gen_resetn),
195
       .clk_div_ratio (2'b00)
196
   );
197
 
198
 
199
//----------------------------------
200
// Generate Uart Ref Clock clock 50Mhz
201
// 250Mhz/(2+3) = 50Mhz
202
//----------------------------------
203
 
204
clk_ctl #(3) u_uart_clk (
205
   // Outputs
206
       .clk_o         (uart_ref_clk),
207
 
208
   // Inputs
209
       .mclk          (pllout      ),
210
       .reset_n       (gen_resetn  ),
211
       .clk_div_ratio (3'b011      )
212
   );
213
 
214
 
215
 
216
endmodule

powered by: WebSVN 2.1.0

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