我想在VHDL中编写这样的通用时钟分频器:
entity Generic_Clk_Divider is
Generic(
INPUT_FREQ: integer := 100;
OUTPUT_FREQ: integer := 25;
);
Port (
Clk: in std_logic;
Rst: in std_logic;
Generated_Clk: out std_logic
);
end entity;
architecture Behavioral of Generic_Clk_Divider is
signal Cnt: integer := 0;
signal Gen_Clk : std_logic := '0';
constant MaxCnt: integer := (integer (INPUT_FREQ/OUTPUT_FREQ)) - 1;
begin
process(clk, Rst)
begin
if (Rst = '1') then
Cnt <= 0;
elsif rising_edge(Clk) then
Cnt <= Cnt + 1 ;
if (Cnt = MaxCnt) then
Gen_Clk <= not Gen_Clk;
Cnt <= 0;
end if;
end if;
Generated_Clk <= Gen_Clk;
end process;
end architecture;
[如果我在测试台上进行测试,则可以使用,但是如果我将生成的Clk信号与另一个组件(在这种情况下为VGA控制器)一起使用,则无法使用。我的问题是关于2个整数之间的除法,董事会似乎并未意识到这一点。
Integer / Integer,返回一个整数,其余部分被丢弃。因此,对于INPUT / OUTPUT是彼此的整数倍的情况,这很好。但是否则,它将无法正常工作。
例如
200/75 = 2
150/40 = 3
等
这真正起作用的唯一方法是使用实类型,因此您可以找到分数关系,然后使用大得多的计数器值来获取确切的关系。
但是,这实际上并没有帮助,因为强烈不建议使用这种时钟分频器。逻辑生成的时钟使时序分析变得困难,并导致时序问题。使用真实时钟并生成时钟使能更为安全。