带使能的VHDL移位寄存器

带使能的VHDL移位寄存器,vhdl,Vhdl,我是VHDL的新手。我正在使用VHDL实现串行输入串行输出72位移位寄存器。当启用信号为高时,我希望移位寄存器移位72次,无论启用继续为高还是低。我已经编写了下面的代码,它只在enable高时工作。有人能帮我在启用高然后不依赖启用来移动数据时移动数据吗 ieee库; 使用ieee.std_logic_1164.all; 实体SR是 端口(时钟、din、rst、启用:在标准逻辑中; sr_out:inout标准逻辑向量(71到0); 结束SR; SR-is的体系结构 信号移位寄存器:标准逻辑向量

我是VHDL的新手。我正在使用VHDL实现串行输入串行输出72位移位寄存器。当启用信号为高时,我希望移位寄存器移位72次,无论启用继续为高还是低。我已经编写了下面的代码,它只在enable高时工作。有人能帮我在启用高然后不依赖启用来移动数据时移动数据吗


ieee库;
使用ieee.std_logic_1164.all;
实体SR是
端口(时钟、din、rst、启用:在标准逻辑中;
sr_out:inout标准逻辑向量(71到0);
结束SR;
SR-is的体系结构
信号移位寄存器:标准逻辑向量(71向下至0);
开始
过程(时钟、rst)
开始
如果(rst='0'),则
shift_reg“0”);
elsif(clk'事件和clk='1'),然后
如果enable='1',则

shift_reg(70向下到0)我想你需要一个RS触发器,它由启动信号设置。它的输出是您的启用信号。启动信号还启动72时钟周期计数器。当计数器翻转(或达到零,取决于其方向)时,复位触发器,导致移位寄存器禁用


编辑:此外,您可以在启动信号中添加一个门,在计数器激活时阻止新的启动脉冲。因此,您可以确保您的数据仅以72位的倍数移位。

您需要一个两态机器来进行移位。这里有一个非常好的方法。我很确定它能满足你的需要或者非常接近

library ieee; 
use ieee.std_logic_1164.all; 

entity SR is
   port(
         clk      : in std_logic;
         din      : in std_logic;
         rst      : in std_logic;
         enable   : in std_logic;
         sr_out   : inout std_logic_vector(71 downto 0)
   ); 
end SR; 

architecture behavioral of SR is 
   signal shift_reg  : std_logic_vector(71 downto 0); 
   signal shift_cnt  : integer range 0 to 72 := 0;

   type T_STATE_TYPE is (IDLE, COUNTING);
   signal current_state : T_STATE_TYPE;

begin

p_shift_counter : process(clk,rst)
begin

   if rst = '1' then
      current_state <= IDLE;
      shift_cnt <= 0;

   elsif rising_edge(clk) then   

      if (current_state = IDLE) then --no enable detected yet
         shift_cnt <= 0;
         if enable = '1' then
            current_state <= COUNTING;

         end if;      

      elsif (current_state  = COUNTING) then --will stay in that state until it finishes counting
         if (shift_cnt < 72) then
            shift_reg(0) <= din;
            for i in 0 to 71 loop shift_reg(i+1) <= shift_reg(i); end loop; --shifting register
            shift_cnt <= shift_cnt + 1;
         else
            current_state <= IDLE; --finished counting
         end if;

      end if;

   end if;

end process;

sr_out <= shift_reg;

end behavioral; 
ieee库;
使用ieee.std_logic_1164.all;
实体SR是
港口(
clk:标准逻辑中;
din:标准逻辑;
rst:标准逻辑中;
启用:在std_逻辑中;
sr_out:inout标准逻辑向量(71到0)
); 
结束SR;
SR-is的体系结构
信号移位寄存器:标准逻辑向量(71向下至0);
信号移位:整数范围0到72:=0;
类型T_状态_类型为(空闲、计数);
信号当前_状态:T_状态_类型;
开始
p_移位计数器:过程(时钟、rst)
开始
如果rst='1',则
当前状态
library ieee; 
use ieee.std_logic_1164.all; 

entity SR is
   port(
         clk      : in std_logic;
         din      : in std_logic;
         rst      : in std_logic;
         enable   : in std_logic;
         sr_out   : inout std_logic_vector(71 downto 0)
   ); 
end SR; 

architecture behavioral of SR is 
   signal shift_reg  : std_logic_vector(71 downto 0); 
   signal shift_cnt  : integer range 0 to 72 := 0;

   type T_STATE_TYPE is (IDLE, COUNTING);
   signal current_state : T_STATE_TYPE;

begin

p_shift_counter : process(clk,rst)
begin

   if rst = '1' then
      current_state <= IDLE;
      shift_cnt <= 0;

   elsif rising_edge(clk) then   

      if (current_state = IDLE) then --no enable detected yet
         shift_cnt <= 0;
         if enable = '1' then
            current_state <= COUNTING;

         end if;      

      elsif (current_state  = COUNTING) then --will stay in that state until it finishes counting
         if (shift_cnt < 72) then
            shift_reg(0) <= din;
            for i in 0 to 71 loop shift_reg(i+1) <= shift_reg(i); end loop; --shifting register
            shift_cnt <= shift_cnt + 1;
         else
            current_state <= IDLE; --finished counting
         end if;

      end if;

   end if;

end process;

sr_out <= shift_reg;

end behavioral;