【问题标题】:How to implement clock divider to universal shift register如何实现时钟分频器到通用移位寄存器
【发布时间】:2014-11-14 01:06:56
【问题描述】:

我正在尝试为 4 位通用移位寄存器制作 VHDL 代码,我想在其中加载 4 位并从 ctrl 中选择移位操作。我不知道如何实现时钟分频器以在 FPGA 上运行输出。

到目前为止,这是我的代码:

library IEEE;
use IEEE.STD_LOGIC_1164.all;

entity shift_register is
  generic(N : integer := 4);
  port(
    clk, reset : in  std_logic;
    ctrl       : in  std_logic_vector(1 downto 0);
    d          : in  std_logic_vector((N-1) downto 0);
    q          : out std_logic_vector((N-1) downto 0)
    );
end shift_register;

architecture Behavioral of shift_register is

  signal r_reg  : std_logic_vector((N-1) downto 0);
  signal r_next : std_logic_vector((N-1) downto 0);
begin
  process(clk, reset)
  begin
    if(reset = '1') then
      r_reg <= (others => '0');
    elsif(clk'event and clk = '1') then
      r_reg <= r_next;
    end if;
  end process;

  with ctrl select
    r_next <=
    r_reg                      when "00",   --do nothing
    r_reg(N-2 downto 0) & d(0) when "01",   --shift left
    d(N-1) & r_reg(N-1 downto 1)when "10",  --shift right
                     d when others;         --load

  q <= r_reg;
end Behavioral;

【问题讨论】:

  • 时钟分频器问题与所示移位寄存器有何关系?您能否更详细地描述您想要实现的目标?
  • 没有时钟分频器的迹象,没有原始时钟频率的指示,也没有目标时钟频率,比率,目标设备/供应商,...
  • @MortenZilmer 我想通过使用 fpga 上的开关来加载一些输入位。 ctrl 将选择位的走向。结果将显示在 fpga 上的 LED 上。所以我只想实现一个每秒移动的时钟。
  • @user2466860:FPGA 上是否已经有clk 输入。我假设是这样,因为ctrld 必须与clk 同步。然后这个clk 可用于派生一个启用信号,该信号每秒断言一个周期,然后此启用可用于进行所需的更新。
  • @MortenZilmer 谢谢。我现在应该如何修改代码?我对 VHDL 编程很陌生,而且我对时钟很不熟悉。

标签: vhdl counter clock fpga shift-register


【解决方案1】:

带有enable 的分频器代码模板每RATIO 个时钟周期断言一个周期:

library ieee;
use ieee.numeric_std.all;

architecture syn of mdl is
  constant RATIO  : natural := 10;
  signal prescale : std_logic_vector(9 downto 0);  -- Scale to fit RATIO - 1
  signal enable   : std_logic;
begin

  process (clk, reset) is
  begin
    if reset = '1' then
      enable   <= '0';
      prescale <= std_logic_vector(to_unsigned(RATIO - 1, prescale'length));
    elsif rising_edge(clk) then
      if unsigned(prescale) = 0 then
        enable   <= '1';
        prescale <= std_logic_vector(to_unsigned(RATIO - 1, prescale'length));
      else
        enable   <= '0';
        prescale <= std_logic_vector(unsigned(prescale) - 1);
      end if;
    end if;
  end process;

end architecture;

【讨论】:

    猜你喜欢
    • 2018-12-12
    • 1970-01-01
    • 2020-11-21
    • 1970-01-01
    • 1970-01-01
    • 2015-12-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多