1

我是 VHDL 的新手。我收到了有关如何从 24 MHz 的输入时钟信号生成 1Hz(50% 占空比)的时钟信号的代码。我有一些问题需要澄清。

  1. 计数器限制是如何选择的?在下面的情况下,12000000。如果我想生成 8Hz 时钟信号,这个限制是多少。
  2. 如果我想将占空比更改为 80%,应该如何调整代码?

    library IEEE;
    use IEEE.STD_LOGIC_1164.ALL;
    use IEEE.STD_LOGIC_ARITH.ALL;
    use IEEE.STD_LOGIC_UNSIGNED.ALL;
    entity clock is
       port ( CLKin: in std_logic;
              reset: in std_logic;
              CLKout: out std_logic);
    end clock;
    architecture arch of clock is
    
      signal counter: integer:=0;
      signal temp : std_logic := '1';
    begin
    process(CLKin,counter,reset)
    begin
       if(reset='0') then counter<=0; temp<='1';
        elsif(CLKin'event and CLKin='1') then counter <=counter+1;
         if (counter = 12000000) then temp <= NOT temp; counter<=0;
         end if;
        end if;
       CLKout <= temp;
    end process;
    end arch;
    
4

1 回答 1

8

您想将 24MHz 的时钟(即 24000000 Hz)分频为 1 Hz。因此,您创建了一个计数器,它将对 CLKin (24 MHz) 的每个上升沿进行计数。在 24000000/2=12000000 计数之后,你在中间。这就是您更改输出信号 ( temp <= not temp) 的电平值的地方。因为您指定它必须是 50% 的占空比。这样做时,您也会从头开始计数。

对于 8MHz,您有一个 (24000000/8)/2 = 1500000 的计数器。

并且只是一个小评论:最好使用ieee.numeric_std库 iso theieee_logic_arith和 theieee.std_logic_unsigned

注意:代码首先分配给一个信号temp。然后将信号temp输出clkout。这背后的原因是在 VHDL 中不允许从输出端口 ( clkout) 读取。你应该在做output <= not output;. 从一个信号,读取是允许的。

还有一点需要注意的是:在过程的敏感度列表中,不需要有counter信号。

process(CLKin, reset) -- no counter needed

而且,另一件事......计算12000000个周期是:0 - >(12000000-1)= 11999999

于 2013-02-24T15:28:31.057 回答