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: M65C02 - WDC W65C02 Microprocessor Re-Implementation
|
46 |
|
|
// Module Name: M65C02_ClkGen
|
47 |
|
|
// Project Name: C:\XProjects\ISE10.1i\M65C02
|
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 |
|
|
// 1.01 13H17 MAM Adapted for use with the M65C02
|
75 |
|
|
//
|
76 |
|
|
// Additional Comments:
|
77 |
|
|
//
|
78 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
79 |
|
|
|
80 |
|
|
module M65C02_ClkGen(
|
81 |
|
|
input nRst, // External Reset Input (active low)
|
82 |
|
|
input ClkIn, // Reference Input Clk
|
83 |
|
|
|
84 |
|
|
output Clk, // Internal Clk - (M/D) x ClkIn
|
85 |
|
|
output Clk_UART, // 2x ClkIn
|
86 |
|
|
output Buf_ClkIn, // Buffered ClkIn
|
87 |
|
|
|
88 |
|
|
output reg Rst // Internal Reset
|
89 |
|
|
);
|
90 |
|
|
|
91 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
92 |
|
|
//
|
93 |
|
|
// Declarations
|
94 |
|
|
//
|
95 |
|
|
|
96 |
|
|
wire DCM_Locked; // DCM Locked Status Signal
|
97 |
|
|
|
98 |
|
|
reg [3:0] DCM_Rst; // Stretched DCM Reset (see Table 3-6 UG331)
|
99 |
|
|
reg nRst_IFD; // Input FF for external Reset signal
|
100 |
|
|
reg [3:0] xRst; // Stretched external reset (BufClkIn)
|
101 |
|
|
wire Rst_M65C02; // Combination of DCM_Rst and xRst
|
102 |
|
|
reg [3:0] Rst_Dly; // Stretched internal reset (BufClkIn)
|
103 |
|
|
wire FE_Rst_Dly; // Falling edge of Rst_Dly (Clk)
|
104 |
|
|
|
105 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
106 |
|
|
//
|
107 |
|
|
// Implementation
|
108 |
|
|
//
|
109 |
|
|
|
110 |
|
|
// Implement internal clock generator using DCM and DFS. DCM/DFS multiplies
|
111 |
|
|
// external clock reference by 4.
|
112 |
|
|
|
113 |
|
|
ClkGen ClkGen (
|
114 |
|
|
.USER_RST_IN(DCM_Rst[0]), // DCM Rst generated on FE Lock
|
115 |
|
|
|
116 |
|
|
.CLKIN_IN(ClkIn), // ClkIn = 14.7456 MHz
|
117 |
|
|
.CLKIN_IBUFG_OUT(Buf_ClkIn), // Buffered ClkIn = 14.7456 MHz
|
118 |
|
|
|
119 |
|
|
.CLKFX_OUT(Clk), // DCM ClkFX_Out = 58.9824 MHz
|
120 |
|
|
|
121 |
|
|
.CLK0_OUT(), // Clk0_Out unused
|
122 |
|
|
.CLK2X_OUT(Clk_UART), // Clk2x_Out (FB) = 29.4912 MHz
|
123 |
|
|
|
124 |
|
|
.LOCKED_OUT(DCM_Locked) // When 1, DCM Locked
|
125 |
|
|
);
|
126 |
|
|
|
127 |
|
|
// Detect falling edge of DCM_Locked, and generate DCM reset pulse at least 4
|
128 |
|
|
// ClkIn periods wide if a falling edge is detected. (see Table 3-6 UG331)
|
129 |
|
|
|
130 |
|
|
fedet FE1 (
|
131 |
|
|
.rst(1'b0), // No reset required for this circuit
|
132 |
|
|
.clk(Buf_ClkIn), // Buffered DCM input Clock
|
133 |
|
|
.din(DCM_Locked), // DCM Locked signal
|
134 |
|
|
.pls(FE_DCM_Locked) // Falling Edge of DCM_Locked signal
|
135 |
|
|
);
|
136 |
|
|
|
137 |
|
|
always @(posedge Buf_ClkIn or posedge FE_DCM_Locked)
|
138 |
|
|
begin
|
139 |
|
|
if(FE_DCM_Locked)
|
140 |
|
|
DCM_Rst <= #1 4'b1111;
|
141 |
|
|
else
|
142 |
|
|
DCM_Rst <= #1 {1'b0, DCM_Rst[3:1]};
|
143 |
|
|
end
|
144 |
|
|
|
145 |
|
|
// Synchronize asynchronous external reset, nRst, to internal clock and
|
146 |
|
|
// stretch (extend) by 16 clock cycles after external reset deasserted
|
147 |
|
|
//
|
148 |
|
|
// With Spartan 3A(N) FPGA family use synchronous reset for reset operations
|
149 |
|
|
// per synthesis recommendations. so only these FFs will use asynchronous
|
150 |
|
|
// reset, and the remainder of the design will use synchronous reset.
|
151 |
|
|
|
152 |
|
|
always @(posedge Buf_ClkIn or negedge DCM_Locked)
|
153 |
|
|
begin
|
154 |
|
|
if(~DCM_Locked)
|
155 |
|
|
nRst_IFD <= #1 0;
|
156 |
|
|
else
|
157 |
|
|
nRst_IFD <= #1 nRst;
|
158 |
|
|
end
|
159 |
|
|
|
160 |
|
|
always @(posedge Buf_ClkIn or negedge DCM_Locked)
|
161 |
|
|
begin
|
162 |
|
|
if(~DCM_Locked)
|
163 |
|
|
xRst <= #1 ~0;
|
164 |
|
|
else
|
165 |
|
|
xRst <= #1 {~nRst_IFD, xRst[2:1]};
|
166 |
|
|
end
|
167 |
|
|
|
168 |
|
|
assign Rst_M65C02 = ((|{~nRst_IFD, xRst}) | ~DCM_Locked);
|
169 |
|
|
|
170 |
|
|
always @(posedge Buf_ClkIn or posedge Rst_M65C02)
|
171 |
|
|
begin
|
172 |
|
|
if (Rst_M65C02)
|
173 |
|
|
Rst_Dly <= #1 ~0;
|
174 |
|
|
else
|
175 |
|
|
Rst_Dly <= #1 {1'b0, Rst_Dly[3:1]};
|
176 |
|
|
end
|
177 |
|
|
|
178 |
|
|
// synchronize Rst to DCM/DFS output clock (if DCM Locked)
|
179 |
|
|
|
180 |
|
|
fedet FE2 (
|
181 |
|
|
.rst(Rst_M65C02),
|
182 |
|
|
.clk(Clk), // System Clock
|
183 |
|
|
.din(|Rst_Dly), // System Reset Delay
|
184 |
|
|
.pls(FE_Rst_Dly) // Falling Edge of Rst_Dly
|
185 |
|
|
);
|
186 |
|
|
|
187 |
|
|
always @(posedge Clk or posedge Rst_M65C02)
|
188 |
|
|
begin
|
189 |
|
|
if(Rst_M65C02)
|
190 |
|
|
Rst <= #1 1;
|
191 |
|
|
else if(FE_Rst_Dly)
|
192 |
|
|
Rst <= #1 0;
|
193 |
|
|
end
|
194 |
|
|
|
195 |
|
|
endmodule
|