1 |
2 |
craighaywo |
----------------------------------------------------------------------------------
|
2 |
|
|
-- This program is free software; you can redistribute it and/or
|
3 |
|
|
-- modify it under the terms of the GNU General Public License
|
4 |
|
|
-- as published by the Free Software Foundation; either version 2
|
5 |
|
|
-- of the License, or (at your option) any later version.
|
6 |
|
|
--
|
7 |
|
|
-- This program is distributed in the hope that it will be useful,
|
8 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
9 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
10 |
|
|
-- GNU General Public License for more details.
|
11 |
|
|
--
|
12 |
|
|
-- You should have received a copy of the GNU General Public License
|
13 |
|
|
-- along with this program; if not, write to the Free Software
|
14 |
|
|
-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
15 |
|
|
-- 02111-1307, USA.
|
16 |
|
|
--
|
17 |
|
|
-- ©2011 - X Engineering Software Systems Corp. (www.xess.com)
|
18 |
|
|
----------------------------------------------------------------------------------
|
19 |
|
|
|
20 |
|
|
----------------------------------------------------------------------------------
|
21 |
|
|
-- Modules for generating a clock frequency from a master clock and for transferring
|
22 |
|
|
-- a clock signal from the clock network to a logic input or an output pin.
|
23 |
|
|
----------------------------------------------------------------------------------
|
24 |
|
|
|
25 |
|
|
|
26 |
|
|
library IEEE;
|
27 |
|
|
use IEEE.STD_LOGIC_1164.all;
|
28 |
|
|
|
29 |
|
|
package ClkGenPckg is
|
30 |
|
|
|
31 |
|
|
--**********************************************************************
|
32 |
|
|
-- Generate a clock frequency from a master clock.
|
33 |
|
|
--**********************************************************************
|
34 |
|
|
component ClkGen is
|
35 |
|
|
generic (
|
36 |
|
|
BASE_FREQ_G : real := 12.0; -- Input frequency in MHz.
|
37 |
|
|
CLK_MUL_G : natural range 1 to 32 := 25; -- Frequency multiplier.
|
38 |
|
|
CLK_DIV_G : natural range 1 to 32 := 3 -- Frequency divider.
|
39 |
|
|
);
|
40 |
|
|
port (
|
41 |
|
|
i : in std_logic; -- Clock input (12 MHz by default).
|
42 |
|
|
o : out std_logic; -- Generated clock output (100 MHz by default).
|
43 |
|
|
o_b : out std_logic; -- Negative-phase generated clock output (inverse of 'o' output).
|
44 |
|
|
clkToLogic_o : out std_logic -- Clock signal that can go to an output pin or logic-gate input.
|
45 |
|
|
);
|
46 |
|
|
end component;
|
47 |
|
|
|
48 |
|
|
--**********************************************************************
|
49 |
|
|
-- Send a clock signal to an output pin or some logic that's not
|
50 |
|
|
-- on an FPGA clock network.
|
51 |
|
|
--**********************************************************************
|
52 |
|
|
component ClkToLogic is
|
53 |
|
|
port (
|
54 |
|
|
clk_i : in std_logic; -- Positive-phase of clock input.
|
55 |
|
|
clk_ib : in std_logic; -- Negative-phase of clock input.
|
56 |
|
|
clk_o : out std_logic -- Clock output that's suitable as a logic input.
|
57 |
|
|
);
|
58 |
|
|
end component;
|
59 |
|
|
|
60 |
|
|
end package;
|
61 |
|
|
|
62 |
|
|
|
63 |
|
|
library IEEE, UNISIM;
|
64 |
|
|
use IEEE.STD_LOGIC_1164.all;
|
65 |
|
|
use work.CommonPckg.all;
|
66 |
|
|
use work.ClkGenPckg.all;
|
67 |
|
|
use UNISIM.VComponents.all;
|
68 |
|
|
|
69 |
|
|
--**********************************************************************
|
70 |
|
|
-- Generate a clock frequency from a master clock.
|
71 |
|
|
--**********************************************************************
|
72 |
|
|
entity ClkGen is
|
73 |
|
|
generic (
|
74 |
|
|
BASE_FREQ_G : real := 12.0; -- Input frequency in MHz.
|
75 |
|
|
CLK_MUL_G : natural range 1 to 32 := 25; -- Frequency multiplier.
|
76 |
|
|
CLK_DIV_G : natural range 1 to 32 := 3 -- Frequency divider.
|
77 |
|
|
);
|
78 |
|
|
port (
|
79 |
|
|
i : in std_logic; -- Clock input (12 MHz by default).
|
80 |
|
|
o : out std_logic; -- Generated clock output (100 MHz by default).
|
81 |
|
|
o_b : out std_logic; -- Negative-phase generated clock output (inverse of 'o' output).
|
82 |
|
|
clkToLogic_o : out std_logic -- Clock signal that can go to an output pin or logic-gate input.
|
83 |
|
|
);
|
84 |
|
|
end entity;
|
85 |
|
|
|
86 |
|
|
architecture arch of ClkGen is
|
87 |
|
|
signal genClkP_s : std_logic; -- Positive phase of generated clock.
|
88 |
|
|
signal genClkN_s : std_logic; -- Negative phase of generated clock.
|
89 |
|
|
begin
|
90 |
|
|
|
91 |
|
|
u0 : DCM_SP
|
92 |
|
|
generic map (
|
93 |
|
|
CLKDV_DIVIDE => 2.0,
|
94 |
|
|
CLKFX_DIVIDE => CLK_DIV_G, -- Can be any interger from 1 to 32
|
95 |
|
|
CLKFX_MULTIPLY => CLK_MUL_G, -- Can be any integer from 1 to 32
|
96 |
|
|
CLKIN_DIVIDE_BY_2 => false, -- TRUE/FALSE to enable CLKIN divide by two feature
|
97 |
|
|
CLKIN_PERIOD => 1000.0 / BASE_FREQ_G, -- Specify period of input clock in ns
|
98 |
|
|
CLKOUT_PHASE_SHIFT => "NONE", -- Specify phase shift of NONE, FIXED or VARIABLE
|
99 |
|
|
CLK_FEEDBACK => "NONE", -- Specify clock feedback of NONE, 1X or 2X
|
100 |
|
|
DESKEW_ADJUST => "SYSTEM_SYNCHRONOUS",
|
101 |
|
|
DLL_FREQUENCY_MODE => "LOW", -- HIGH or LOW frequency mode for DLL
|
102 |
|
|
DUTY_CYCLE_CORRECTION => true, -- Duty cycle correction, TRUE or FALSE
|
103 |
|
|
PHASE_SHIFT => 0, -- Amount of fixed phase shift from -255 to 255
|
104 |
|
|
STARTUP_WAIT => false) -- Delay configuration DONE until DCM LOCK, TRUE/FALSE
|
105 |
|
|
port map (
|
106 |
|
|
RST => '0', -- DCM asynchronous reset input
|
107 |
|
|
CLKIN => i, -- Clock input (from IBUFG, BUFG or DCM)
|
108 |
|
|
CLKFX => genClkP_s, -- Positive-phase of generated clock output
|
109 |
|
|
CLKFX180 => genClkN_s -- Negative-phase of generated clock output.
|
110 |
|
|
);
|
111 |
|
|
|
112 |
|
|
o <= genClkP_s;
|
113 |
|
|
o_b <= genClkN_s;
|
114 |
|
|
|
115 |
|
|
-- Create a clock signal that can go to an output pin or to a logic-gate input.
|
116 |
|
|
u1 : ClkToLogic
|
117 |
|
|
port map (
|
118 |
|
|
clk_i => genClkP_s,
|
119 |
|
|
clk_ib => genClkN_s,
|
120 |
|
|
clk_o => clkToLogic_o
|
121 |
|
|
);
|
122 |
|
|
end architecture;
|
123 |
|
|
|
124 |
|
|
|
125 |
|
|
library IEEE, UNISIM;
|
126 |
|
|
use IEEE.STD_LOGIC_1164.all;
|
127 |
|
|
use work.CommonPckg.all;
|
128 |
|
|
use UNISIM.VComponents.all;
|
129 |
|
|
|
130 |
|
|
--**********************************************************************
|
131 |
|
|
-- Send a clock signal to an output pin or some logic that's not
|
132 |
|
|
-- on an FPGA clock network.
|
133 |
|
|
--**********************************************************************
|
134 |
|
|
entity ClkToLogic is
|
135 |
|
|
port (
|
136 |
|
|
clk_i : in std_logic; -- Positive-phase of clock input.
|
137 |
|
|
clk_ib : in std_logic; -- Negative-phase of clock input.
|
138 |
|
|
clk_o : out std_logic -- Clock output that's suitable as a logic input.
|
139 |
|
|
);
|
140 |
|
|
end entity;
|
141 |
|
|
|
142 |
|
|
architecture arch of ClkToLogic is
|
143 |
|
|
begin
|
144 |
|
|
-- Use ODDR2 to transfer clock signal from FPGA's clock network to the logic fabric.
|
145 |
|
|
-- (This stops the synthesis tools from complaining about using a clock as an input
|
146 |
|
|
-- to a logic gate or when driving a pin for an external clock signal.)
|
147 |
|
|
u1 : ODDR2
|
148 |
|
|
port map (
|
149 |
|
|
Q => clk_o,
|
150 |
|
|
C0 => clk_i,
|
151 |
|
|
C1 => clk_ib,
|
152 |
|
|
CE => YES,
|
153 |
|
|
D0 => ONE,
|
154 |
|
|
D1 => ZERO,
|
155 |
|
|
R => ZERO,
|
156 |
|
|
S => ZERO
|
157 |
|
|
);
|
158 |
|
|
end architecture;
|