这是一个通用的分数 M/D 时钟分频器设计,应该可以解决您的问题。几年前我写了这个供我自己使用。根据您的目标设备,您可能希望使用 std_logic 而不是 bit。
基本思想是使用累加器跟踪小数时钟相位。这与实现直接数字合成器 (DDS) 的方式非常相似,但只需要担心时钟。
享受!=)
如果不清楚如何使用它,您将使用 39 的乘数和 50 的除数的参数,如100 * 39/100 = 78
,因此所需的操作数宽度为 6(因为2**6 = 64
)。请注意,因为这是输入时钟速率的一半以上,所以没有同步逻辑可以生成输出时钟信号,因此该模块在该速率下的唯一有效输出将是时钟使能。
另请注意,任何可能的除数值的最坏情况是任何一个周期的 33%/66% 占空比。您对乘数和除数的特定选择可能会更好(我需要做一些数学来判断),但是对于使用有理除法的任何算法,通常情况下,您无法得到比最坏情况更好的选择。您可以使用真正的硬件 PLL 或 DLL 清理此模块的输出,以过滤相位噪声并将占空比纳入您的目标范围。
-- Copyright © 2010 Wesley J. Landaker <wjl@icecavern.net>
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
library ieee;
use ieee.numeric_bit.all;
-- Clock Divider
-- =============
--
-- Fractionally divides the input clock using simultaneous frequency
-- multiplication and division.
--
-- Outputs both a clock enable and a balanced duty-cycle clock. The clock's
-- duty-cycle is as always close to 50% as possible, worst case is 33%/66%.
--
-- Details
-- =======
--
-- Given:
--
-- Fi = input frequency Hz
-- M = multiplier
-- D = divisor
-- Fo = output frequency Hz
--
-- Where:
--
-- M ≤ D
--
-- Then:
--
-- ⎧ M
-- ⎪ Fi·— if M <= D
-- Fo = ⎨ D
-- ⎪
-- ⎩ undefined if M > D
--
--
-- If (M/D) is greater than 0.5, only the clock enable is valid.
-- If (M/D) is greater than 1.0, both outputs are invalid.
entity Clock_Divider is
generic (
operand_width : positive
);
port (
clock : in bit;
reset : in bit;
multiplier : in unsigned(operand_width-1 downto 0);
divisor : in unsigned(operand_width-1 downto 0);
out_enable : buffer bit;
out_clock : buffer bit
);
end entity;
architecture any of Clock_Divider is
signal enable_2x : bit;
begin
-- Divide the clock by accumulating phase using the mulitplier and
-- subtracting when we pass the divisor value.
proc_enable : process is
variable phase : unsigned(operand_width downto 0);
begin
wait until rising_edge(clock);
phase := phase + multiplier;
if phase >= divisor then
phase := phase - divisor;
out_enable <= '1';
else
out_enable <= '0';
end if;
if reset = '1' then
phase := (others => '0');
out_enable <= '0';
end if;
end process;
proc_enable : process is
variable phase : unsigned(operand_width downto 0);
begin
wait until rising_edge(clock);
phase := phase + (multiplier & '0');
if phase >= divisor then
phase := phase - divisor;
enable_2x <= '1';
else
enable_2x <= '0';
end if;
if reset = '1' then
phase := (others => '0');
enable_2x <= '0';
end if;
end process;
proc_out_clock : process is
begin
wait until rising_edge(clock);
if enable_2x = '1' then
out_clock <= not out_clock;
end if;
end process;
end architecture;