1 |
2 |
jclaytons |
--------------------------------------------------------------------------
|
2 |
|
|
-- Package of Direct Digital Synthesizer (DDS) components
|
3 |
|
|
--
|
4 |
|
|
-- NOTE: These components are for producing digital pulse outputs at
|
5 |
|
|
-- desired frequencies and/or duty cycles. In other words, there
|
6 |
|
|
-- are no modules here which include sinewave lookup tables. For
|
7 |
|
|
-- that type of module, please refer to "dds_sine_pack.vhd"
|
8 |
|
|
--
|
9 |
|
|
|
10 |
|
|
library ieee;
|
11 |
|
|
use ieee.std_logic_1164.all;
|
12 |
|
|
use ieee.numeric_std.all;
|
13 |
|
|
|
14 |
|
|
package dds_pack is
|
15 |
|
|
|
16 |
|
|
component dds_constant_squarewave
|
17 |
|
|
generic (
|
18 |
|
|
OUTPUT_FREQ : real; -- Desired output frequency
|
19 |
|
|
SYS_CLK_RATE : real; -- underlying clock rate
|
20 |
|
|
ACC_BITS : integer -- Bit width of DDS phase accumulator
|
21 |
|
|
);
|
22 |
|
|
port (
|
23 |
|
|
|
24 |
|
|
sys_rst_n : in std_logic;
|
25 |
|
|
sys_clk : in std_logic;
|
26 |
|
|
sys_clk_en : in std_logic;
|
27 |
|
|
|
28 |
|
|
-- Output
|
29 |
|
|
pulse_o : out std_logic;
|
30 |
|
|
squarewave_o : out std_logic
|
31 |
|
|
);
|
32 |
|
|
end component;
|
33 |
|
|
|
34 |
|
|
component dds_squarewave
|
35 |
|
|
generic (
|
36 |
|
|
ACC_BITS : integer -- Bit width of DDS phase accumulator
|
37 |
|
|
);
|
38 |
|
|
port (
|
39 |
|
|
|
40 |
|
|
sys_rst_n : in std_logic;
|
41 |
|
|
sys_clk : in std_logic;
|
42 |
|
|
sys_clk_en : in std_logic;
|
43 |
|
|
|
44 |
|
|
-- Frequency setting
|
45 |
|
|
freq_i : in unsigned(ACC_BITS-1 downto 0);
|
46 |
|
|
|
47 |
|
|
-- Output
|
48 |
|
|
pulse_o : out std_logic;
|
49 |
|
|
squarewave_o : out std_logic
|
50 |
|
|
);
|
51 |
|
|
end component;
|
52 |
|
|
|
53 |
|
|
component dds_squarewave_phase_load
|
54 |
|
|
generic (
|
55 |
|
|
ACC_BITS : integer -- Bit width of DDS phase accumulator
|
56 |
|
|
);
|
57 |
|
|
port (
|
58 |
|
|
|
59 |
|
|
sys_rst_n : in std_logic;
|
60 |
|
|
sys_clk : in std_logic;
|
61 |
|
|
sys_clk_en : in std_logic;
|
62 |
|
|
|
63 |
|
|
-- Frequency setting
|
64 |
|
|
freq_i : in unsigned(ACC_BITS-1 downto 0);
|
65 |
|
|
|
66 |
|
|
-- Synchronous load
|
67 |
|
|
phase_i : in unsigned(ACC_BITS-1 downto 0);
|
68 |
|
|
phase_ld_i : in std_logic;
|
69 |
|
|
|
70 |
|
|
-- Output
|
71 |
|
|
pulse_o : out std_logic;
|
72 |
|
|
squarewave_o : out std_logic
|
73 |
|
|
);
|
74 |
|
|
end component;
|
75 |
|
|
|
76 |
|
|
component dds_constant_clk_en_gen
|
77 |
|
|
generic (
|
78 |
|
|
OUTPUT_FREQ : real; -- Desired output frequency
|
79 |
|
|
SYS_CLK_RATE : real; -- underlying clock rate
|
80 |
|
|
ACC_BITS : integer -- Bit width of DDS phase accumulator
|
81 |
|
|
);
|
82 |
|
|
port (
|
83 |
|
|
|
84 |
|
|
sys_rst_n : in std_logic;
|
85 |
|
|
sys_clk : in std_logic;
|
86 |
|
|
sys_clk_en : in std_logic;
|
87 |
|
|
|
88 |
|
|
-- Output
|
89 |
|
|
clk_en_o : out std_logic
|
90 |
|
|
);
|
91 |
|
|
end component;
|
92 |
|
|
|
93 |
|
|
component dds_clk_en_gen
|
94 |
|
|
generic (
|
95 |
|
|
ACC_BITS : integer -- Bit width of DDS phase accumulator
|
96 |
|
|
);
|
97 |
|
|
port (
|
98 |
|
|
|
99 |
|
|
sys_rst_n : in std_logic;
|
100 |
|
|
sys_clk : in std_logic;
|
101 |
|
|
sys_clk_en : in std_logic;
|
102 |
|
|
|
103 |
|
|
-- Frequency setting
|
104 |
|
|
freq_i : in unsigned(ACC_BITS-1 downto 0);
|
105 |
|
|
|
106 |
|
|
-- Output
|
107 |
|
|
clk_en_o : out std_logic
|
108 |
|
|
);
|
109 |
|
|
end component;
|
110 |
|
|
|
111 |
|
|
component calibrated_clk_en_gen
|
112 |
|
|
generic (
|
113 |
|
|
SYS_CLK_RATE : real -- underlying clock rate
|
114 |
|
|
);
|
115 |
|
|
port (
|
116 |
|
|
|
117 |
|
|
sys_rst_n : in std_logic;
|
118 |
|
|
sys_clk : in std_logic;
|
119 |
|
|
sys_clk_en : in std_logic;
|
120 |
|
|
|
121 |
|
|
-- Frequency setting
|
122 |
|
|
freq_i : in unsigned(31 downto 0); -- some MSBs may be ignored
|
123 |
|
|
|
124 |
|
|
-- Output
|
125 |
|
|
clk_en_o : out std_logic
|
126 |
|
|
);
|
127 |
|
|
end component;
|
128 |
|
|
|
129 |
|
|
component dds_pwm_dac
|
130 |
|
|
generic (
|
131 |
|
|
ACC_BITS : integer -- Bit width of DDS phase accumulator
|
132 |
|
|
);
|
133 |
|
|
port (
|
134 |
|
|
|
135 |
|
|
sys_rst_n : in std_logic;
|
136 |
|
|
sys_clk : in std_logic;
|
137 |
|
|
sys_clk_en : in std_logic;
|
138 |
|
|
|
139 |
|
|
-- Frequency setting
|
140 |
|
|
freq_i : in unsigned(ACC_BITS-1 downto 0);
|
141 |
|
|
|
142 |
|
|
-- Output
|
143 |
|
|
clk_en_o : out std_logic
|
144 |
|
|
);
|
145 |
|
|
end component;
|
146 |
|
|
|
147 |
|
|
component dds_pwm_dac_srv
|
148 |
|
|
generic (
|
149 |
|
|
ACC_BITS : integer -- Bit width of DDS phase accumulator
|
150 |
|
|
);
|
151 |
|
|
port (
|
152 |
|
|
|
153 |
|
|
sys_rst_n : in std_logic;
|
154 |
|
|
sys_clk : in std_logic;
|
155 |
|
|
sys_clk_en : in std_logic;
|
156 |
|
|
|
157 |
|
|
-- Frequency/Phase settings
|
158 |
|
|
phase_load_i : in std_logic;
|
159 |
|
|
phase_val_i : in unsigned(ACC_BITS-1 downto 0);
|
160 |
|
|
freq_i : in unsigned(ACC_BITS-1 downto 0);
|
161 |
|
|
|
162 |
|
|
-- Output
|
163 |
|
|
clk_en_o : out std_logic
|
164 |
|
|
);
|
165 |
|
|
end component;
|
166 |
|
|
|
167 |
|
|
end dds_pack;
|
168 |
|
|
|
169 |
|
|
package body dds_pack is
|
170 |
|
|
end dds_pack;
|
171 |
|
|
|
172 |
|
|
-------------------------------------------------------------------------------
|
173 |
|
|
-- Direct Digital Synthesizer Constant Squarewave module
|
174 |
|
|
-------------------------------------------------------------------------------
|
175 |
|
|
--
|
176 |
|
|
-- Author: John Clayton
|
177 |
|
|
-- Update: Sep. 5, 2002 copied this file from "auto_baud_pack.vhd"
|
178 |
|
|
-- Added tracking functions, and debugged them.
|
179 |
|
|
--
|
180 |
|
|
-- Description
|
181 |
|
|
-------------------------------------------------------------------------------
|
182 |
|
|
-- This is a simple direct digital synthesizer module. It includes a phase
|
183 |
|
|
-- accumulator which increments in order to produce the desired output
|
184 |
|
|
-- frequency in its most significant bit, which is the squarewave output.
|
185 |
|
|
--
|
186 |
|
|
-- In addition to the squarewave output there is a pulse output which is
|
187 |
|
|
-- high for one sys_clk period, during the sys_clk period immediately
|
188 |
|
|
-- preceding the rising edge of the squarewave output.
|
189 |
|
|
--
|
190 |
|
|
-- NOTES:
|
191 |
|
|
-- The accumulator increment word is:
|
192 |
|
|
-- increment = Fout*2^N/Fsys_clk
|
193 |
|
|
--
|
194 |
|
|
-- Where N is the number of bits in the phase accumulator.
|
195 |
|
|
--
|
196 |
|
|
-- There will always be jitter with this type of clock source, but the
|
197 |
|
|
-- long time average frequency can be made arbitrarily close to whatever
|
198 |
|
|
-- value is desired, simply by increasing N.
|
199 |
|
|
--
|
200 |
|
|
-- To reduce jitter, use a higher underlying system clock frequency, and
|
201 |
|
|
-- for goodness sakes, try to keep the desired output frequency much lower
|
202 |
|
|
-- than the system clock frequency. The closer it gets to Fsys_clk/2, the
|
203 |
|
|
-- closer it is to the Nyquist limit, and the output jitter is much more
|
204 |
|
|
-- significant at that point.
|
205 |
|
|
--
|
206 |
|
|
--
|
207 |
|
|
|
208 |
|
|
|
209 |
|
|
library IEEE;
|
210 |
|
|
use IEEE.STD_LOGIC_1164.ALL;
|
211 |
|
|
use IEEE.NUMERIC_STD.ALL;
|
212 |
|
|
use IEEE.MATH_REAL.ALL;
|
213 |
|
|
|
214 |
|
|
entity dds_constant_squarewave is
|
215 |
|
|
generic (
|
216 |
|
|
OUTPUT_FREQ : real := 8000.0; -- Desired output frequency
|
217 |
|
|
SYS_CLK_RATE : real := 48000000.0; -- underlying clock rate
|
218 |
|
|
ACC_BITS : integer := 16 -- Bit width of DDS phase accumulator
|
219 |
|
|
);
|
220 |
|
|
port (
|
221 |
|
|
|
222 |
|
|
sys_rst_n : in std_logic;
|
223 |
|
|
sys_clk : in std_logic;
|
224 |
|
|
sys_clk_en : in std_logic;
|
225 |
|
|
|
226 |
|
|
-- Output
|
227 |
|
|
pulse_o : out std_logic;
|
228 |
|
|
squarewave_o : out std_logic
|
229 |
|
|
);
|
230 |
|
|
end dds_constant_squarewave;
|
231 |
|
|
|
232 |
|
|
architecture beh of dds_constant_squarewave is
|
233 |
|
|
|
234 |
|
|
-- Constants
|
235 |
|
|
constant DDS_INCREMENT : integer := integer(OUTPUT_FREQ*(2**real(ACC_BITS))/SYS_CLK_RATE);
|
236 |
|
|
|
237 |
|
|
-- Signals
|
238 |
|
|
signal dds_phase : unsigned(ACC_BITS-1 downto 0); -- phase accumulator register
|
239 |
|
|
signal dds_phase_next : unsigned(ACC_BITS-1 downto 0);
|
240 |
|
|
|
241 |
|
|
-----------------------------------------------------------------------------
|
242 |
|
|
begin
|
243 |
|
|
|
244 |
|
|
dds_proc: Process(sys_rst_n,sys_clk)
|
245 |
|
|
begin
|
246 |
|
|
if (sys_rst_n = '0') then
|
247 |
|
|
dds_phase <= (others=>'0');
|
248 |
|
|
elsif (sys_clk'event and sys_clk='1') then
|
249 |
|
|
if (sys_clk_en='1') then
|
250 |
|
|
dds_phase <= dds_phase_next;
|
251 |
|
|
end if;
|
252 |
|
|
end if; -- sys_clk
|
253 |
|
|
end process dds_proc;
|
254 |
|
|
dds_phase_next <= dds_phase + DDS_INCREMENT;
|
255 |
|
|
pulse_o <= '1' when sys_clk_en='1' and dds_phase(dds_phase'length-1)='0' and dds_phase_next(dds_phase_next'length-1)='1' else '0';
|
256 |
|
|
squarewave_o <= dds_phase(dds_phase'length-1);
|
257 |
|
|
|
258 |
|
|
end beh;
|
259 |
|
|
|
260 |
|
|
|
261 |
|
|
-------------------------------------------------------------------------------
|
262 |
|
|
-- Direct Digital Synthesizer Variable Frequency Squarewave module
|
263 |
|
|
-------------------------------------------------------------------------------
|
264 |
|
|
--
|
265 |
|
|
-- Author: John Clayton
|
266 |
|
|
-- Update: Jan. 31, 2013 copied code from dds_constant_squarewave, and
|
267 |
|
|
-- modified it to accept a frequency setting input.
|
268 |
|
|
--
|
269 |
|
|
-- Description
|
270 |
|
|
-------------------------------------------------------------------------------
|
271 |
|
|
-- This is a simple direct digital synthesizer module. It includes a phase
|
272 |
|
|
-- accumulator which increments in order to produce the desired output
|
273 |
|
|
-- frequency in its most significant bit, which is the squarewave output.
|
274 |
|
|
--
|
275 |
|
|
-- In addition to the squarewave output there is a pulse output which is
|
276 |
|
|
-- high for one sys_clk period, during the sys_clk period immediately
|
277 |
|
|
-- preceding the rising edge of the squarewave output.
|
278 |
|
|
--
|
279 |
|
|
-- NOTES:
|
280 |
|
|
-- The accumulator increment word is:
|
281 |
|
|
-- increment = Fout*2^N/Fsys_clk
|
282 |
|
|
--
|
283 |
|
|
-- Where N is the number of bits in the phase accumulator.
|
284 |
|
|
--
|
285 |
|
|
-- There will always be jitter with this type of clock source, but the
|
286 |
|
|
-- long time average frequency can be made arbitrarily close to whatever
|
287 |
|
|
-- value is desired, simply by increasing N.
|
288 |
|
|
--
|
289 |
|
|
-- To reduce jitter, use a higher underlying system clock frequency, and
|
290 |
|
|
-- for goodness sakes, try to keep the desired output frequency much lower
|
291 |
|
|
-- than the system clock frequency. The closer it gets to Fsys_clk/2, the
|
292 |
|
|
-- closer it is to the Nyquist limit, and the output jitter is much more
|
293 |
|
|
-- significant as compared to the output period at that point.
|
294 |
|
|
--
|
295 |
|
|
--
|
296 |
|
|
|
297 |
|
|
|
298 |
|
|
library IEEE;
|
299 |
|
|
use IEEE.STD_LOGIC_1164.ALL;
|
300 |
|
|
use IEEE.NUMERIC_STD.ALL;
|
301 |
|
|
use IEEE.MATH_REAL.ALL;
|
302 |
|
|
|
303 |
|
|
entity dds_squarewave is
|
304 |
|
|
generic (
|
305 |
|
|
ACC_BITS : integer := 16 -- Bit width of DDS phase accumulator
|
306 |
|
|
);
|
307 |
|
|
port (
|
308 |
|
|
|
309 |
|
|
sys_rst_n : in std_logic;
|
310 |
|
|
sys_clk : in std_logic;
|
311 |
|
|
sys_clk_en : in std_logic;
|
312 |
|
|
|
313 |
|
|
-- Frequency setting
|
314 |
|
|
freq_i : in unsigned(ACC_BITS-1 downto 0);
|
315 |
|
|
|
316 |
|
|
-- Output
|
317 |
|
|
pulse_o : out std_logic;
|
318 |
|
|
squarewave_o : out std_logic
|
319 |
|
|
);
|
320 |
|
|
end dds_squarewave;
|
321 |
|
|
|
322 |
|
|
architecture beh of dds_squarewave is
|
323 |
|
|
|
324 |
|
|
-- Signals
|
325 |
|
|
signal dds_phase : unsigned(ACC_BITS-1 downto 0); -- phase accumulator register
|
326 |
|
|
signal dds_phase_next : unsigned(ACC_BITS-1 downto 0);
|
327 |
|
|
|
328 |
|
|
-----------------------------------------------------------------------------
|
329 |
|
|
begin
|
330 |
|
|
|
331 |
|
|
dds_proc: Process(sys_rst_n,sys_clk)
|
332 |
|
|
begin
|
333 |
|
|
if (sys_rst_n = '0') then
|
334 |
|
|
dds_phase <= (others=>'0');
|
335 |
|
|
elsif (sys_clk'event and sys_clk='1') then
|
336 |
|
|
if (sys_clk_en='1') then
|
337 |
|
|
dds_phase <= dds_phase_next;
|
338 |
|
|
end if;
|
339 |
|
|
end if; -- sys_clk
|
340 |
|
|
end process dds_proc;
|
341 |
|
|
dds_phase_next <= dds_phase + freq_i;
|
342 |
|
|
pulse_o <= '1' when sys_clk_en='1' and dds_phase(dds_phase'length-1)='0' and dds_phase_next(dds_phase_next'length-1)='1' else '0';
|
343 |
|
|
squarewave_o <= dds_phase(dds_phase'length-1);
|
344 |
|
|
|
345 |
|
|
end beh;
|
346 |
|
|
|
347 |
|
|
|
348 |
|
|
-------------------------------------------------------------------------------
|
349 |
|
|
-- Direct Digital Synthesizer Variable Frequency Squarewave module,
|
350 |
|
|
-- with synchronous phase load
|
351 |
|
|
-------------------------------------------------------------------------------
|
352 |
|
|
--
|
353 |
|
|
-- Author: John Clayton
|
354 |
|
|
-- Update: Aug. 1, 2013 copied code from dds_squarewave, and
|
355 |
|
|
-- modified it to accept a synchronous load input.
|
356 |
|
|
--
|
357 |
|
|
-- Description
|
358 |
|
|
-------------------------------------------------------------------------------
|
359 |
|
|
-- This is a simple direct digital synthesizer module. It includes a phase
|
360 |
|
|
-- accumulator which increments in order to produce the desired output
|
361 |
|
|
-- frequency in its most significant bit, which is the squarewave output.
|
362 |
|
|
--
|
363 |
|
|
-- In addition to the squarewave output there is a pulse output which is
|
364 |
|
|
-- high for one sys_clk period, during the sys_clk period immediately
|
365 |
|
|
-- preceding the rising edge of the squarewave output.
|
366 |
|
|
--
|
367 |
|
|
-- A synchronous load input allows the synthesizer to be adjusted to any
|
368 |
|
|
-- desired initial phase condition. This is useful when using it for
|
369 |
|
|
-- timing and synchronization.
|
370 |
|
|
--
|
371 |
|
|
-- NOTES:
|
372 |
|
|
-- The accumulator increment word is:
|
373 |
|
|
-- increment = Fout*2^N/Fsys_clk
|
374 |
|
|
--
|
375 |
|
|
-- Where N is the number of bits in the phase accumulator.
|
376 |
|
|
--
|
377 |
|
|
-- There will always be jitter with this type of clock source, but the
|
378 |
|
|
-- long time average frequency can be made arbitrarily close to whatever
|
379 |
|
|
-- value is desired, simply by increasing N.
|
380 |
|
|
--
|
381 |
|
|
-- To reduce jitter, use a higher underlying system clock frequency, and
|
382 |
|
|
-- for goodness sakes, try to keep the desired output frequency much lower
|
383 |
|
|
-- than the system clock frequency. The closer it gets to Fsys_clk/2, the
|
384 |
|
|
-- closer it is to the Nyquist limit, and the output jitter is much more
|
385 |
|
|
-- significant as compared to the output period at that point.
|
386 |
|
|
--
|
387 |
|
|
--
|
388 |
|
|
|
389 |
|
|
|
390 |
|
|
library IEEE;
|
391 |
|
|
use IEEE.STD_LOGIC_1164.ALL;
|
392 |
|
|
use IEEE.NUMERIC_STD.ALL;
|
393 |
|
|
use IEEE.MATH_REAL.ALL;
|
394 |
|
|
|
395 |
|
|
entity dds_squarewave_phase_load is
|
396 |
|
|
generic (
|
397 |
|
|
ACC_BITS : integer := 16 -- Bit width of DDS phase accumulator
|
398 |
|
|
);
|
399 |
|
|
port (
|
400 |
|
|
|
401 |
|
|
sys_rst_n : in std_logic;
|
402 |
|
|
sys_clk : in std_logic;
|
403 |
|
|
sys_clk_en : in std_logic;
|
404 |
|
|
|
405 |
|
|
-- Frequency setting
|
406 |
|
|
freq_i : in unsigned(ACC_BITS-1 downto 0);
|
407 |
|
|
|
408 |
|
|
-- Synchronous load
|
409 |
|
|
phase_i : in unsigned(ACC_BITS-1 downto 0);
|
410 |
|
|
phase_ld_i : in std_logic;
|
411 |
|
|
|
412 |
|
|
-- Output
|
413 |
|
|
pulse_o : out std_logic;
|
414 |
|
|
squarewave_o : out std_logic
|
415 |
|
|
);
|
416 |
|
|
end dds_squarewave_phase_load;
|
417 |
|
|
|
418 |
|
|
architecture beh of dds_squarewave_phase_load is
|
419 |
|
|
|
420 |
|
|
-- Signals
|
421 |
|
|
signal dds_phase : unsigned(ACC_BITS-1 downto 0); -- phase accumulator register
|
422 |
|
|
signal dds_phase_next : unsigned(ACC_BITS-1 downto 0);
|
423 |
|
|
|
424 |
|
|
-----------------------------------------------------------------------------
|
425 |
|
|
begin
|
426 |
|
|
|
427 |
|
|
dds_proc: Process(sys_rst_n,sys_clk)
|
428 |
|
|
begin
|
429 |
|
|
if (sys_rst_n = '0') then
|
430 |
|
|
dds_phase <= (others=>'0');
|
431 |
|
|
elsif (sys_clk'event and sys_clk='1') then
|
432 |
|
|
if (sys_clk_en='1') then
|
433 |
|
|
dds_phase <= dds_phase_next;
|
434 |
|
|
end if;
|
435 |
|
|
if (phase_ld_i='1') then
|
436 |
|
|
dds_phase <= phase_i;
|
437 |
|
|
end if;
|
438 |
|
|
end if; -- sys_clk
|
439 |
|
|
end process dds_proc;
|
440 |
|
|
dds_phase_next <= dds_phase + freq_i;
|
441 |
|
|
pulse_o <= '1' when sys_clk_en='1' and dds_phase(dds_phase'length-1)='0' and dds_phase_next(dds_phase_next'length-1)='1' else '0';
|
442 |
|
|
squarewave_o <= dds_phase(dds_phase'length-1);
|
443 |
|
|
|
444 |
|
|
end beh;
|
445 |
|
|
|
446 |
|
|
|
447 |
|
|
-------------------------------------------------------------------------------
|
448 |
|
|
-- Direct Digital Synthesizer Clock Enable Generator, Constant output frequency
|
449 |
|
|
-------------------------------------------------------------------------------
|
450 |
|
|
--
|
451 |
|
|
-- Author: John Clayton
|
452 |
|
|
-- Update: Oct. 4, 2013 Copied code from dds_clk_en_gen, and modified it to
|
453 |
|
|
-- create a clock enable output using generics to set
|
454 |
|
|
-- the frequency.
|
455 |
|
|
--
|
456 |
|
|
-- Description
|
457 |
|
|
-------------------------------------------------------------------------------
|
458 |
|
|
-- This is a simple direct digital synthesizer module. It includes a phase
|
459 |
|
|
-- accumulator which increments in order to produce the desired output
|
460 |
|
|
-- frequency in its most significant bit, which is a squarewave with
|
461 |
|
|
-- some unavoidable jitter.
|
462 |
|
|
--
|
463 |
|
|
-- In this module, the squarewave is not provided as an output, because
|
464 |
|
|
-- this module's purpose is to generate a clock enable signal.
|
465 |
|
|
--
|
466 |
|
|
-- The clock enable output is a pulsed output which, for frequencies below
|
467 |
|
|
-- the Nyquist frequency is high for one sys_clk period, during the sys_clk
|
468 |
|
|
-- period immediately preceding the rising edge of the squarewave output.
|
469 |
|
|
--
|
470 |
|
|
-- A special "trick" is performed inside this module, which is to invert the
|
471 |
|
|
-- pulse output for frequencies above the Nyquist frequency. Since the pulse
|
472 |
|
|
-- train is a perfect 50% duty cycle squarewave at the Nyquist frequency, the
|
473 |
|
|
-- pulse train and its inverse are equivalent at that point... But for
|
474 |
|
|
-- higher frequencies, the squarewave reduces in frequency back down towards
|
475 |
|
|
-- zero Hz. However, since the pulse train is inverted for frequencies above
|
476 |
|
|
-- the Nyquist frequency (Fsys_clk/2), then the output pulse train is high for
|
477 |
|
|
-- a larger and larger fraction of time... essentially forming a nice clock
|
478 |
|
|
-- enable which can be varied from 0% duty cycle, all the way up to N% duty
|
479 |
|
|
-- cycle, where K is given by:
|
480 |
|
|
--
|
481 |
|
|
-- K = max_duty_cycle = 100 * (1-2**(-N)) percent
|
482 |
|
|
--
|
483 |
|
|
-- Where N is the number of bits in the phase accumulator (ACC_BITS)
|
484 |
|
|
--
|
485 |
|
|
--
|
486 |
|
|
-- NOTES:
|
487 |
|
|
-- The accumulator increment word is set by generics:
|
488 |
|
|
-- increment = OUTPUT_FREQ*2^ACC_BITS/SYS_CLK_RATE
|
489 |
|
|
--
|
490 |
|
|
-- Where N is the number of bits in the phase accumulator (ACC_BITS)
|
491 |
|
|
--
|
492 |
|
|
-- There will always be jitter with this type of clock source, but the
|
493 |
|
|
-- clock enable output duty cycle can be adjusted in increments as fine
|
494 |
|
|
-- as may be desired, simply by increasing N.
|
495 |
|
|
--
|
496 |
|
|
--
|
497 |
|
|
|
498 |
|
|
|
499 |
|
|
library IEEE;
|
500 |
|
|
use IEEE.STD_LOGIC_1164.ALL;
|
501 |
|
|
use IEEE.NUMERIC_STD.ALL;
|
502 |
|
|
use IEEE.MATH_REAL.ALL;
|
503 |
|
|
|
504 |
|
|
entity dds_constant_clk_en_gen is
|
505 |
|
|
generic (
|
506 |
|
|
OUTPUT_FREQ : real := 32000000.0; -- Desired output frequency
|
507 |
|
|
SYS_CLK_RATE : real := 50000000.0; -- underlying clock rate
|
508 |
|
|
ACC_BITS : integer := 30 -- Bit width of DDS phase accumulator
|
509 |
|
|
);
|
510 |
|
|
port (
|
511 |
|
|
|
512 |
|
|
sys_rst_n : in std_logic;
|
513 |
|
|
sys_clk : in std_logic;
|
514 |
|
|
sys_clk_en : in std_logic;
|
515 |
|
|
|
516 |
|
|
-- Output
|
517 |
|
|
clk_en_o : out std_logic
|
518 |
|
|
);
|
519 |
|
|
end dds_constant_clk_en_gen;
|
520 |
|
|
|
521 |
|
|
architecture beh of dds_constant_clk_en_gen is
|
522 |
|
|
|
523 |
|
|
-- Constants
|
524 |
|
|
constant DDS_INCREMENT : integer := integer(OUTPUT_FREQ*(2**real(ACC_BITS))/SYS_CLK_RATE);
|
525 |
|
|
constant HALFWAY : integer := integer(2**real(ACC_BITS-1));
|
526 |
|
|
|
527 |
|
|
-- Signals
|
528 |
|
|
signal dds_phase : unsigned(ACC_BITS-1 downto 0); -- phase accumulator register
|
529 |
|
|
signal dds_phase_next : unsigned(ACC_BITS-1 downto 0);
|
530 |
|
|
signal pulse_l : std_logic;
|
531 |
|
|
|
532 |
|
|
-----------------------------------------------------------------------------
|
533 |
|
|
begin
|
534 |
|
|
|
535 |
|
|
dds_proc: Process(sys_rst_n,sys_clk)
|
536 |
|
|
begin
|
537 |
|
|
if (sys_rst_n = '0') then
|
538 |
|
|
dds_phase <= (others=>'0');
|
539 |
|
|
elsif (sys_clk'event and sys_clk='1') then
|
540 |
|
|
if (sys_clk_en='1') then
|
541 |
|
|
dds_phase <= dds_phase_next;
|
542 |
|
|
end if;
|
543 |
|
|
end if; -- sys_clk
|
544 |
|
|
end process dds_proc;
|
545 |
|
|
dds_phase_next <= dds_phase + DDS_INCREMENT;
|
546 |
|
|
pulse_l <= '1' when sys_clk_en='1' and dds_phase(dds_phase'length-1)='0' and dds_phase_next(dds_phase_next'length-1)='1' else '0';
|
547 |
|
|
clk_en_o <= pulse_l when (DDS_INCREMENT<HALFWAY) else not pulse_l;
|
548 |
|
|
|
549 |
|
|
end beh;
|
550 |
|
|
|
551 |
|
|
|
552 |
|
|
-------------------------------------------------------------------------------
|
553 |
|
|
-- Direct Digital Synthesizer Clock Enable Generator
|
554 |
|
|
-------------------------------------------------------------------------------
|
555 |
|
|
--
|
556 |
|
|
-- Author: John Clayton
|
557 |
|
|
-- Update: Oct. 4, 2013 Copied code from dds_squarewave, and modified it to
|
558 |
|
|
-- create a clock enable output which essentially has
|
559 |
|
|
-- a duty cycle that varies from zero up to 100%. This
|
560 |
|
|
-- is similar in some ways to a first order sigma-delta
|
561 |
|
|
-- modulator, my friend! It can be used as a DAC, if
|
562 |
|
|
-- the sys_clk_en is high. See dds_pwm_dac for a
|
563 |
|
|
-- similar unit that allows slowing down the output
|
564 |
|
|
-- waveform according to the period between sys_clk_en
|
565 |
|
|
-- pulses.
|
566 |
|
|
--
|
567 |
|
|
-- Description
|
568 |
|
|
-------------------------------------------------------------------------------
|
569 |
|
|
-- This is a simple direct digital synthesizer module. It includes a phase
|
570 |
|
|
-- accumulator which increments in order to produce the desired output
|
571 |
|
|
-- frequency in its most significant bit, which is a squarewave with
|
572 |
|
|
-- some unavoidable jitter.
|
573 |
|
|
--
|
574 |
|
|
-- In this module, the squarewave is not provided as an output, because
|
575 |
|
|
-- this module's purpose is to generate a clock enable signal.
|
576 |
|
|
--
|
577 |
|
|
-- The clock enable output is a pulsed output which, for frequencies below
|
578 |
|
|
-- the Nyquist frequency is high for one sys_clk period, during the sys_clk
|
579 |
|
|
-- period immediately preceding the rising edge of the squarewave output.
|
580 |
|
|
--
|
581 |
|
|
-- A special "trick" is performed inside this module, which is to invert the
|
582 |
|
|
-- pulse output for frequencies above the Nyquist frequency. Since the pulse
|
583 |
|
|
-- train is a perfect 50% duty cycle squarewave at the Nyquist frequency, the
|
584 |
|
|
-- pulse train and its inverse are equivalent at that point... But for
|
585 |
|
|
-- higher frequencies, the squarewave reduces in frequency back down towards
|
586 |
|
|
-- zero Hz. However, since the pulse train is inverted for frequencies above
|
587 |
|
|
-- the Nyquist frequency (Fsys_clk/2), then the output pulse train is high for
|
588 |
|
|
-- a larger and larger fraction of time... essentially forming a nice clock
|
589 |
|
|
-- enable which can be varied from 0% duty cycle, all the way up to N% duty
|
590 |
|
|
-- cycle, where K is given by:
|
591 |
|
|
--
|
592 |
|
|
-- K = max_duty_cycle = 100 * (1-2**(-N)) percent
|
593 |
|
|
--
|
594 |
|
|
-- Where N is the number of bits in the phase accumulator (ACC_BITS)
|
595 |
|
|
--
|
596 |
|
|
-- This can perhaps operate as a form of PWM also... although the fundamental
|
597 |
|
|
-- frequency is not constant, as it is in true PWM.
|
598 |
|
|
--
|
599 |
|
|
--
|
600 |
|
|
-- NOTES:
|
601 |
|
|
-- The accumulator increment word is:
|
602 |
|
|
-- increment = Fout*2^N/Fsys_clk
|
603 |
|
|
--
|
604 |
|
|
-- Where N is the number of bits in the phase accumulator (ACC_BITS)
|
605 |
|
|
--
|
606 |
|
|
-- There will always be jitter with this type of clock source, but the
|
607 |
|
|
-- clock enable output duty cycle can be adjusted in increments as fine
|
608 |
|
|
-- as may be desired, simply by increasing N.
|
609 |
|
|
--
|
610 |
|
|
--
|
611 |
|
|
|
612 |
|
|
|
613 |
|
|
library IEEE;
|
614 |
|
|
use IEEE.STD_LOGIC_1164.ALL;
|
615 |
|
|
use IEEE.NUMERIC_STD.ALL;
|
616 |
|
|
use IEEE.MATH_REAL.ALL;
|
617 |
|
|
|
618 |
|
|
entity dds_clk_en_gen is
|
619 |
|
|
generic (
|
620 |
|
|
ACC_BITS : integer := 16 -- Bit width of DDS phase accumulator
|
621 |
|
|
);
|
622 |
|
|
port (
|
623 |
|
|
|
624 |
|
|
sys_rst_n : in std_logic;
|
625 |
|
|
sys_clk : in std_logic;
|
626 |
|
|
sys_clk_en : in std_logic;
|
627 |
|
|
|
628 |
|
|
-- Frequency setting
|
629 |
|
|
freq_i : in unsigned(ACC_BITS-1 downto 0);
|
630 |
|
|
|
631 |
|
|
-- Output
|
632 |
|
|
clk_en_o : out std_logic
|
633 |
|
|
);
|
634 |
|
|
end dds_clk_en_gen;
|
635 |
|
|
|
636 |
|
|
architecture beh of dds_clk_en_gen is
|
637 |
|
|
|
638 |
|
|
-- Signals
|
639 |
|
|
signal dds_phase : unsigned(ACC_BITS-1 downto 0); -- phase accumulator register
|
640 |
|
|
signal dds_phase_next : unsigned(ACC_BITS-1 downto 0);
|
641 |
|
|
signal pulse_l : std_logic;
|
642 |
|
|
|
643 |
|
|
-----------------------------------------------------------------------------
|
644 |
|
|
begin
|
645 |
|
|
|
646 |
|
|
dds_proc: Process(sys_rst_n,sys_clk)
|
647 |
|
|
begin
|
648 |
|
|
if (sys_rst_n = '0') then
|
649 |
|
|
dds_phase <= (others=>'0');
|
650 |
|
|
elsif (sys_clk'event and sys_clk='1') then
|
651 |
|
|
if (sys_clk_en='1') then
|
652 |
|
|
dds_phase <= dds_phase_next;
|
653 |
|
|
end if;
|
654 |
|
|
end if; -- sys_clk
|
655 |
|
|
end process dds_proc;
|
656 |
|
|
dds_phase_next <= dds_phase + freq_i;
|
657 |
|
|
pulse_l <= '1' when sys_clk_en='1' and dds_phase(dds_phase'length-1)='0' and dds_phase_next(dds_phase_next'length-1)='1' else '0';
|
658 |
|
|
clk_en_o <= pulse_l when freq_i(freq_i'length-1)='0' else not pulse_l;
|
659 |
|
|
|
660 |
|
|
end beh;
|
661 |
|
|
|
662 |
|
|
|
663 |
|
|
-------------------------------------------------------------------------------
|
664 |
|
|
-- Calibrated Direct Digital Synthesizer Clock Enable Generator
|
665 |
|
|
-------------------------------------------------------------------------------
|
666 |
|
|
--
|
667 |
|
|
-- Author: John Clayton
|
668 |
|
|
-- Update: Nov. 11, 2013 Copied code from dds_clk_en_gen, and modified it.
|
669 |
|
|
--
|
670 |
|
|
-- Description
|
671 |
|
|
-------------------------------------------------------------------------------
|
672 |
|
|
-- This is two DDS units tied together. The first unit produces a calibration
|
673 |
|
|
-- clock enable, at a frequency which is very close to a power of two Hz.
|
674 |
|
|
-- It uses the highest power of two which can be achieved using the given
|
675 |
|
|
-- system clock frequency.
|
676 |
|
|
--
|
677 |
|
|
-- The second DDS unit then uses the calibration clock enable for its
|
678 |
|
|
-- clock enable input. This effectively "calibrates" the second unit
|
679 |
|
|
-- so that its input frequency is in Hz.
|
680 |
|
|
--
|
681 |
|
|
-- The input frequency to this module was fixed at 32 bits, but the
|
682 |
|
|
-- most significant bits may be ignored.
|
683 |
|
|
--
|
684 |
|
|
|
685 |
|
|
|
686 |
|
|
library IEEE;
|
687 |
|
|
use IEEE.STD_LOGIC_1164.ALL;
|
688 |
|
|
use IEEE.NUMERIC_STD.ALL;
|
689 |
|
|
use IEEE.MATH_REAL.ALL;
|
690 |
|
|
|
691 |
|
|
library work;
|
692 |
|
|
use work.dds_pack.all;
|
693 |
|
|
use work.convert_pack.all;
|
694 |
|
|
|
695 |
|
|
entity calibrated_clk_en_gen is
|
696 |
|
|
generic (
|
697 |
|
|
SYS_CLK_RATE : real := 50000000.0 -- underlying clock rate
|
698 |
|
|
);
|
699 |
|
|
port (
|
700 |
|
|
|
701 |
|
|
sys_rst_n : in std_logic;
|
702 |
|
|
sys_clk : in std_logic;
|
703 |
|
|
sys_clk_en : in std_logic;
|
704 |
|
|
|
705 |
|
|
-- Frequency setting
|
706 |
|
|
freq_i : in unsigned(31 downto 0);
|
707 |
|
|
|
708 |
|
|
-- Output
|
709 |
|
|
clk_en_o : out std_logic
|
710 |
|
|
);
|
711 |
|
|
end calibrated_clk_en_gen;
|
712 |
|
|
|
713 |
|
|
architecture beh of calibrated_clk_en_gen is
|
714 |
|
|
|
715 |
|
|
-- Constants
|
716 |
|
|
constant LOG2_CAL_BITS : natural := bit_width(SYS_CLK_RATE)-1;
|
717 |
|
|
|
718 |
|
|
-- Signals
|
719 |
|
|
signal cal_clk_en : std_logic;
|
720 |
|
|
|
721 |
|
|
|
722 |
|
|
|
723 |
|
|
-----------------------------------------------------------------------------
|
724 |
|
|
begin
|
725 |
|
|
|
726 |
|
|
-- Calibration clock enable
|
727 |
|
|
cal_clk_gen : dds_constant_clk_en_gen
|
728 |
|
|
generic map(
|
729 |
|
|
OUTPUT_FREQ => real(2**LOG2_CAL_BITS),
|
730 |
|
|
SYS_CLK_RATE => SYS_CLK_RATE,
|
731 |
|
|
ACC_BITS => 30
|
732 |
|
|
)
|
733 |
|
|
port map(
|
734 |
|
|
|
735 |
|
|
sys_rst_n => sys_rst_n,
|
736 |
|
|
sys_clk => sys_clk,
|
737 |
|
|
sys_clk_en => sys_clk_en,
|
738 |
|
|
|
739 |
|
|
-- Output
|
740 |
|
|
clk_en_o => cal_clk_en
|
741 |
|
|
);
|
742 |
|
|
|
743 |
|
|
clk_en_gen : dds_clk_en_gen
|
744 |
|
|
generic map(
|
745 |
|
|
ACC_BITS => LOG2_CAL_BITS
|
746 |
|
|
)
|
747 |
|
|
port map(
|
748 |
|
|
|
749 |
|
|
sys_rst_n => sys_rst_n,
|
750 |
|
|
sys_clk => sys_clk,
|
751 |
|
|
sys_clk_en => cal_clk_en,
|
752 |
|
|
|
753 |
|
|
-- Frequency setting
|
754 |
|
|
freq_i => freq_i(LOG2_CAL_BITS-1 downto 0),
|
755 |
|
|
|
756 |
|
|
-- Output
|
757 |
|
|
clk_en_o => clk_en_o
|
758 |
|
|
);
|
759 |
|
|
|
760 |
|
|
end beh;
|
761 |
|
|
|
762 |
|
|
|
763 |
|
|
-------------------------------------------------------------------------------
|
764 |
|
|
-- Direct Digital Synthesizer PWM DAC
|
765 |
|
|
-------------------------------------------------------------------------------
|
766 |
|
|
--
|
767 |
|
|
-- Author: John Clayton
|
768 |
|
|
-- Update:
|
769 |
|
|
-- Jan. 23, 2015 Copied code from clk_en_gen, and brought pulse_l
|
770 |
|
|
-- logic inside the sys_clk_en enabled process, so
|
771 |
|
|
-- that the pulses are widened according to sys_clk_en.
|
772 |
|
|
--
|
773 |
|
|
-- Description
|
774 |
|
|
-------------------------------------------------------------------------------
|
775 |
|
|
-- This is exactly the same as dds_clk_en_gen, except that it brings the pulse_l
|
776 |
|
|
-- logic inside the clocked process, so that output pulses are no longer 1
|
777 |
|
|
-- sys_clk wide, but are instead lengthened according to sys_clk_en. This makes
|
778 |
|
|
-- the unit useful for generating a PWM output signal, with the smallest pulse
|
779 |
|
|
-- being the period between sys_clk_en pulses.
|
780 |
|
|
--
|
781 |
|
|
-- This is a simple direct digital synthesizer module. It includes a phase
|
782 |
|
|
-- accumulator which increments in order to produce the desired output
|
783 |
|
|
-- frequency in its most significant bit, which is a squarewave with
|
784 |
|
|
-- some unavoidable jitter.
|
785 |
|
|
--
|
786 |
|
|
-- In this module, the squarewave is not provided as an output, because
|
787 |
|
|
-- this module's purpose is to generate a clock enable signal.
|
788 |
|
|
--
|
789 |
|
|
-- The clock enable output is a pulsed output which, for frequencies below
|
790 |
|
|
-- the Nyquist frequency is high for one sys_clk period, during the sys_clk
|
791 |
|
|
-- period immediately preceding the rising edge of the squarewave output.
|
792 |
|
|
--
|
793 |
|
|
-- A special "trick" is performed inside this module, which is to invert the
|
794 |
|
|
-- pulse output for frequencies above the Nyquist frequency. Since the pulse
|
795 |
|
|
-- train is a perfect 50% duty cycle squarewave at the Nyquist frequency, the
|
796 |
|
|
-- pulse train and its inverse are equivalent at that point... But for
|
797 |
|
|
-- higher frequencies, the squarewave reduces in frequency back down towards
|
798 |
|
|
-- zero Hz. However, since the pulse train is inverted for frequencies above
|
799 |
|
|
-- the Nyquist frequency (Fsys_clk/2), then the output pulse train is high for
|
800 |
|
|
-- a larger and larger fraction of time... essentially forming a nice clock
|
801 |
|
|
-- enable which can be varied from 0% duty cycle, all the way up to N% duty
|
802 |
|
|
-- cycle, where K is given by:
|
803 |
|
|
--
|
804 |
|
|
-- K = max_duty_cycle = 100 * (1-2**(-N)) percent
|
805 |
|
|
--
|
806 |
|
|
-- Where N is the number of bits in the phase accumulator (ACC_BITS)
|
807 |
|
|
--
|
808 |
|
|
-- This can perhaps operate as a form of PWM also... although the fundamental
|
809 |
|
|
-- frequency is not constant, as it is in true PWM.
|
810 |
|
|
--
|
811 |
|
|
--
|
812 |
|
|
-- NOTES:
|
813 |
|
|
-- The accumulator increment word is:
|
814 |
|
|
-- increment = Fout*2^N/Fsys_clk
|
815 |
|
|
--
|
816 |
|
|
-- Where N is the number of bits in the phase accumulator (ACC_BITS)
|
817 |
|
|
--
|
818 |
|
|
-- There will always be jitter with this type of clock source, but the
|
819 |
|
|
-- clock enable output duty cycle can be adjusted in increments as fine
|
820 |
|
|
-- as may be desired, simply by increasing N.
|
821 |
|
|
--
|
822 |
|
|
--
|
823 |
|
|
|
824 |
|
|
|
825 |
|
|
library IEEE;
|
826 |
|
|
use IEEE.STD_LOGIC_1164.ALL;
|
827 |
|
|
use IEEE.NUMERIC_STD.ALL;
|
828 |
|
|
use IEEE.MATH_REAL.ALL;
|
829 |
|
|
|
830 |
|
|
entity dds_pwm_dac is
|
831 |
|
|
generic (
|
832 |
|
|
ACC_BITS : integer := 16 -- Bit width of DDS phase accumulator
|
833 |
|
|
);
|
834 |
|
|
port (
|
835 |
|
|
|
836 |
|
|
sys_rst_n : in std_logic;
|
837 |
|
|
sys_clk : in std_logic;
|
838 |
|
|
sys_clk_en : in std_logic;
|
839 |
|
|
|
840 |
|
|
-- Frequency setting
|
841 |
|
|
freq_i : in unsigned(ACC_BITS-1 downto 0);
|
842 |
|
|
|
843 |
|
|
-- Output
|
844 |
|
|
clk_en_o : out std_logic
|
845 |
|
|
);
|
846 |
|
|
end dds_pwm_dac;
|
847 |
|
|
|
848 |
|
|
architecture beh of dds_pwm_dac is
|
849 |
|
|
|
850 |
|
|
-- Signals
|
851 |
|
|
signal dds_phase : unsigned(ACC_BITS-1 downto 0); -- phase accumulator register
|
852 |
|
|
signal dds_phase_next : unsigned(ACC_BITS-1 downto 0);
|
853 |
|
|
signal pulse_l : std_logic;
|
854 |
|
|
|
855 |
|
|
-----------------------------------------------------------------------------
|
856 |
|
|
begin
|
857 |
|
|
|
858 |
|
|
dds_proc: Process(sys_rst_n,sys_clk)
|
859 |
|
|
begin
|
860 |
|
|
if (sys_rst_n = '0') then
|
861 |
|
|
dds_phase <= (others=>'0');
|
862 |
|
|
pulse_l <= '0';
|
863 |
|
|
elsif (sys_clk'event and sys_clk='1') then
|
864 |
|
|
if (sys_clk_en='1') then
|
865 |
|
|
dds_phase <= dds_phase_next;
|
866 |
|
|
if (dds_phase(dds_phase'length-1)='0' and dds_phase_next(dds_phase_next'length-1)='1') then
|
867 |
|
|
pulse_l <= '1';
|
868 |
|
|
else
|
869 |
|
|
pulse_l <= '0';
|
870 |
|
|
end if;
|
871 |
|
|
end if;
|
872 |
|
|
end if; -- sys_clk
|
873 |
|
|
end process dds_proc;
|
874 |
|
|
dds_phase_next <= dds_phase + freq_i;
|
875 |
|
|
clk_en_o <= pulse_l when freq_i(freq_i'length-1)='0' else not pulse_l;
|
876 |
|
|
|
877 |
|
|
end beh;
|
878 |
|
|
|
879 |
|
|
-------------------------------------------------------------------------------
|
880 |
|
|
-- Direct Digital Synthesizer PWM DAC - Synchronously Resettable Version
|
881 |
|
|
-------------------------------------------------------------------------------
|
882 |
|
|
--
|
883 |
|
|
-- Author: John Clayton
|
884 |
|
|
-- Update:
|
885 |
|
|
-- Jan. 23, 2015 Copied code from dds_pwm_dac, and added synchronous
|
886 |
|
|
-- phase load input and phase value inputs
|
887 |
|
|
--
|
888 |
|
|
-- Description
|
889 |
|
|
-------------------------------------------------------------------------------
|
890 |
|
|
-- This is exactly the same as dds_pwm_dac, except that a synchronous phase
|
891 |
|
|
-- load is provided. This was needed when using the DAC to "throttle" pixel
|
892 |
|
|
-- counters driving a display. By resetting the DAC's phase accumulator
|
893 |
|
|
-- during each retrace interval, visible "jitter" was reduced, and made
|
894 |
|
|
-- identical for each line of display pixels.
|
895 |
|
|
--
|
896 |
|
|
-- NOTES:
|
897 |
|
|
-- The accumulator increment word is:
|
898 |
|
|
-- increment = Fout*2^N/Fsys_clk
|
899 |
|
|
--
|
900 |
|
|
-- Where N is the number of bits in the phase accumulator (ACC_BITS)
|
901 |
|
|
--
|
902 |
|
|
-- There will always be jitter with this type of clock source, but the
|
903 |
|
|
-- clock enable output duty cycle can be adjusted in increments as fine
|
904 |
|
|
-- as may be desired, simply by increasing N.
|
905 |
|
|
--
|
906 |
|
|
--
|
907 |
|
|
|
908 |
|
|
|
909 |
|
|
library IEEE;
|
910 |
|
|
use IEEE.STD_LOGIC_1164.ALL;
|
911 |
|
|
use IEEE.NUMERIC_STD.ALL;
|
912 |
|
|
use IEEE.MATH_REAL.ALL;
|
913 |
|
|
|
914 |
|
|
entity dds_pwm_dac_srv is
|
915 |
|
|
generic (
|
916 |
|
|
ACC_BITS : integer := 16 -- Bit width of DDS phase accumulator
|
917 |
|
|
);
|
918 |
|
|
port (
|
919 |
|
|
|
920 |
|
|
sys_rst_n : in std_logic;
|
921 |
|
|
sys_clk : in std_logic;
|
922 |
|
|
sys_clk_en : in std_logic;
|
923 |
|
|
|
924 |
|
|
-- Frequency/Phase settings
|
925 |
|
|
phase_load_i : in std_logic;
|
926 |
|
|
phase_val_i : in unsigned(ACC_BITS-1 downto 0);
|
927 |
|
|
freq_i : in unsigned(ACC_BITS-1 downto 0);
|
928 |
|
|
|
929 |
|
|
-- Output
|
930 |
|
|
clk_en_o : out std_logic
|
931 |
|
|
);
|
932 |
|
|
end dds_pwm_dac_srv;
|
933 |
|
|
|
934 |
|
|
architecture beh of dds_pwm_dac_srv is
|
935 |
|
|
|
936 |
|
|
-- Signals
|
937 |
|
|
signal dds_phase : unsigned(ACC_BITS-1 downto 0); -- phase accumulator register
|
938 |
|
|
signal dds_phase_next : unsigned(ACC_BITS-1 downto 0);
|
939 |
|
|
signal pulse_l : std_logic;
|
940 |
|
|
|
941 |
|
|
-----------------------------------------------------------------------------
|
942 |
|
|
begin
|
943 |
|
|
|
944 |
|
|
dds_proc: Process(sys_rst_n,sys_clk)
|
945 |
|
|
begin
|
946 |
|
|
if (sys_rst_n = '0') then
|
947 |
|
|
dds_phase <= (others=>'0');
|
948 |
|
|
pulse_l <= '0';
|
949 |
|
|
elsif (sys_clk'event and sys_clk='1') then
|
950 |
|
|
if (sys_clk_en='1') then
|
951 |
|
|
if (phase_load_i='1') then
|
952 |
|
|
dds_phase <= phase_val_i;
|
953 |
|
|
pulse_l <= '0';
|
954 |
|
|
else
|
955 |
|
|
dds_phase <= dds_phase_next;
|
956 |
|
|
if (dds_phase(dds_phase'length-1)='0' and dds_phase_next(dds_phase_next'length-1)='1') then
|
957 |
|
|
pulse_l <= '1';
|
958 |
|
|
else
|
959 |
|
|
pulse_l <= '0';
|
960 |
|
|
end if;
|
961 |
|
|
end if; -- phase_zero_i
|
962 |
|
|
end if; -- sys_clk_en
|
963 |
|
|
end if; -- sys_clk
|
964 |
|
|
end process dds_proc;
|
965 |
|
|
dds_phase_next <= dds_phase + freq_i;
|
966 |
|
|
clk_en_o <= pulse_l when freq_i(freq_i'length-1)='0' else not pulse_l;
|
967 |
|
|
|
968 |
|
|
end beh;
|
969 |
|
|
|
970 |
|
|
|