Vhdl 如何在通用移位寄存器中实现时钟分频器

Vhdl 如何在通用移位寄存器中实现时钟分频器,vhdl,counter,clock,fpga,shift-register,Vhdl,Counter,Clock,Fpga,Shift Register,我正在尝试为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_lo

我正在尝试为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;
IEEE库;
使用IEEE.STD_LOGIC_1164.all;
实体移位寄存器为
泛型(N:整数=4);
港口(
时钟,复位:在标准逻辑中;
ctrl:在标准逻辑向量中(1到0);
d:在标准逻辑向量中((N-1)降到0);
q:out标准逻辑向量((N-1)向下至0)
);
端移寄存器;
移位寄存器的结构是
信号r_reg:std_逻辑_向量((N-1)向下至0);
信号r_next:标准逻辑向量((N-1)向下至0);
开始
过程(时钟、复位)
开始
如果(重置='1'),则
r_reg“0”);
elsif(clk'事件和clk='1'),然后

r_reg具有
启用功能的除法器代码模板每
比率
时钟周期断言一个周期:

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;
ieee库;
使用ieee.numeric_std.all;
mdl的体系结构syn是
固定比率:自然:=10;
信号预刻度:标准逻辑向量(9到0);--比例匹配比-1
信号启用:std_逻辑;
开始
进程(clk、reset)正在运行
开始
如果重置='1',则

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