【问题标题】:VHDL Clock Divider: Counter - Duty CycleVHDL 时钟分频器:计数器 - 占空比
【发布时间】:2013-02-24 15:02:55
【问题描述】:

我是 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;
    

【问题讨论】:

    标签: counter vhdl clock frequency


    【解决方案1】:

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

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

    只是一个小评论:最好使用 ieee.numeric_std 库 i.s.o ieee_logic_arithieee.std_logic_unsigned

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

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

    process(CLKin, reset) -- no counter needed
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-06
      • 2021-10-04
      • 2020-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多