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

Subversion Repositories m16c5x

[/] [m16c5x/] [trunk/] [RTL/] [Src/] [M16C5x_ClkGen.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 MichaelA
////////////////////////////////////////////////////////////////////////////////
2
//
3
//  Copyright 2013 by Michael A. Morris, dba M. A. Morris & Associates
4
//
5
//  All rights reserved. The source code contained herein is publicly released
6
//  under the terms and conditions of the GNU Lesser Public License. No part of
7
//  this source code may be reproduced or transmitted in any form or by any
8
//  means, electronic or mechanical, including photocopying, recording, or any
9
//  information storage and retrieval system in violation of the license under
10
//  which the source code is released.
11
//
12
//  The source code contained herein is free; it may be redistributed and/or
13
//  modified in accordance with the terms of the GNU Lesser General Public
14
//  License as published by the Free Software Foundation; either version 2.1 of
15
//  the GNU Lesser General Public License, or any later version.
16
//
17
//  The source code contained herein is freely released WITHOUT ANY WARRANTY;
18
//  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
19
//  PARTICULAR PURPOSE. (Refer to the GNU Lesser General Public License for
20
//  more details.)
21
//
22
//  A copy of the GNU Lesser General Public License should have been received
23
//  along with the source code contained herein; if not, a copy can be obtained
24
//  by writing to:
25
//
26
//  Free Software Foundation, Inc.
27
//  51 Franklin Street, Fifth Floor
28
//  Boston, MA  02110-1301 USA
29
//
30
//  Further, no use of this source code is permitted in any form or means
31
//  without inclusion of this banner prominently in any derived works.
32
//
33
//  Michael A. Morris
34
//  Huntsville, AL
35
//
36
////////////////////////////////////////////////////////////////////////////////
37
 
38
`timescale 1ns / 1ps
39
 
40
////////////////////////////////////////////////////////////////////////////////
41
// Company:         M. A. Morris & Associates 
42
// Engineer:        Michael A. Morris 
43
// 
44
// Create Date:     20:32:33 06/15/2013 
45
// Design Name:     M16C5x - PIC-compatible Extensible Processor Core 
46
// Module Name:     M16C5x_ClkGen 
47
// Project Name:    C:\XProjects\ISE10.1i\M16C5x
48
// Target Devices:  RAM-based FPGAs: XC3S50A-xVQ100; XC3S200A-xVQ100
49
// Tool versions:   Xilinx ISE 10.1i SP3
50
// 
51
// Description: 
52
//
53
//  This module combines an Architecture Wizard IP instatiation of a DCM_SP to 
54
//  generate a 4x clock from an external crystal oscillator. It also generates
55
//  a reset signal to external logic, and a reset signal for internal logic and
56
//  the DCM. An external reset input is accepted, but buffered using a synchro-
57
//  nizer.
58
//  
59
// Dependencies: ClkGen.xaw
60
//
61
// Revision:
62
//
63
//  0.01    13F15   MAM     Creation Date
64
//
65
//  1.00    13F21   MAM     Corrected error in the reset generation logic. An
66
//                          AND reduction operator was applied to external reset
67
//                          shift register. An OR reduction is necessary, and
68
//                          is not applied. Asserting the external reset now
69
//                          generates a reset pulse several clock cycles in
70
//                          width to the internal logic. Added Clk_UART as an
71
//                          output taken from the Clk2X output of DCM. Clk_UART
72
//                          can noew be fixed at 2x ClkIn.
73
//
74
// Additional Comments: 
75
//
76
////////////////////////////////////////////////////////////////////////////////
77
 
78
module M16C5x_ClkGen(
79
    input   nRst,                       // External Reset Input (active low)
80
    input   ClkIn,                      // Reference Input Clk
81
 
82
    output  Clk,                        // Internal Clk - (M/D) x ClkIn
83
    output  Clk_UART,                   // 2x ClkIn
84
    output  BufClkIn,                   // Buffered ClkIn
85
 
86
    output  reg Rst                     // Internal Reset
87
);
88
 
89
////////////////////////////////////////////////////////////////////////////////
90
//
91
//  Declarations
92
//
93
 
94
wire    DCM_Locked;             // DCM Locked Status Signal
95
 
96
reg     [3:0] DCM_Rst;          // Stretched DCM Reset (see Table 3-6 UG331)
97
reg     nRst_IFD;               // Input FF for external Reset signal
98
reg     [3:0] xRst;             // Stretched external reset (BufClkIn)
99
wire    Rst_M16C5x;             // Combination of DCM_Rst and xRst
100
reg     [3:0] Rst_Dly;          // Stretched internal reset (BufClkIn)
101
wire    FE_Rst_Dly;             // Falling edge of Rst_Dly (Clk)
102
 
103
////////////////////////////////////////////////////////////////////////////////
104
//
105
//  Implementation
106
//
107
 
108
//  Implement internal clock generator using DCM and DFS. DCM/DFS multiplies
109
//  external clock reference by 4.
110
 
111
ClkGen  ClkGen (
112
            .USER_RST_IN(DCM_Rst[0]),           // DCM Rst generated on FE Lock 
113
 
114
            .CLKIN_IN(ClkIn),                   // ClkIn          = 14.7456 MHz
115
            .CLKIN_IBUFG_OUT(BufClkIn),         // Buffered ClkIn = 14.7456 MHz
116
 
117
            .CLKFX_OUT(Clk),                    // DCM ClkFX_Out  = 58.9824 MHz 
118
 
119
            .CLK0_OUT(),                        // Clk0_Out unused 
120
            .CLK2X_OUT(Clk_UART),               // Clk2x_Out (FB) = 29.4912 MHz 
121
 
122
            .LOCKED_OUT(DCM_Locked)             // When 1, DCM Locked 
123
        );
124
 
125
//  Detect falling edge of DCM_Locked, and generate DCM reset pulse at least 4
126
//  ClkIn periods wide if a falling edge is detected. (see Table 3-6 UG331)
127
 
128
fedet   FE1 (
129
            .rst(1'b0),             // No reset required for this circuit 
130
            .clk(BufClkIn),         // Buffered DCM input Clock
131
            .din(DCM_Locked),       // DCM Locked signal
132
            .pls(FE_DCM_Locked)     // Falling Edge of DCM_Locked signal
133
        );
134
 
135
always @(posedge BufClkIn or posedge FE_DCM_Locked)
136
begin
137
    if(FE_DCM_Locked)
138
        DCM_Rst <= #1 4'b1111;
139
    else
140
        DCM_Rst <= #1 {1'b0, DCM_Rst[3:1]};
141
end
142
 
143
//  Synchronize asynchronous external reset, nRst, to internal clock and
144
//      stretch (extend) by 16 clock cycles after external reset deasserted
145
//
146
//  With Spartan 3A(N) FPGA family use synchronous reset for reset operations
147
//  per synthesis recommendations. so only these FFs will use asynchronous
148
//  reset, and the remainder of the design will use synchronous reset.
149
 
150
always @(posedge BufClkIn or negedge DCM_Locked)
151
begin
152
    if(~DCM_Locked)
153
        nRst_IFD <= #1 0;
154
    else
155
        nRst_IFD <= #1 nRst;
156
end
157
 
158
always @(posedge BufClkIn or negedge DCM_Locked)
159
begin
160
    if(~DCM_Locked)
161
        xRst <= #1 ~0;
162
    else
163
        xRst <= #1 {~nRst_IFD, xRst[2:1]};
164
end
165
 
166
assign Rst_M16C5x = ((|{~nRst_IFD, xRst}) | ~DCM_Locked);
167
 
168
always @(posedge BufClkIn or posedge Rst_M16C5x)
169
begin
170
    if (Rst_M16C5x)
171
        Rst_Dly <= #1 ~0;
172
    else
173
        Rst_Dly <= #1 {1'b0, Rst_Dly[3:1]};
174
end
175
 
176
//  synchronize Rst to DCM/DFS output clock (if DCM Locked)
177
 
178
fedet   FE2 (
179
            .rst(Rst_M16C5x),
180
            .clk(Clk),              // System Clock
181
            .din(|Rst_Dly),         // System Reset Delay
182
            .pls(FE_Rst_Dly)        // Falling Edge of Rst_Dly
183
        );
184
 
185
always @(posedge Clk or posedge Rst_M16C5x)
186
begin
187
    if(Rst_M16C5x)
188
        Rst <= #1 1;
189
    else if(FE_Rst_Dly)
190
        Rst <= #1 0;
191
end
192
 
193
endmodule

powered by: WebSVN 2.1.0

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