2

我是 VHDL 的新手。我正在使用 VHDL 实现串行输入串行输出 72 位移位寄存器。当使能信号为高电平时,我希望移位寄存器移位 72 次,无论使能信号继续为高电平还是低电平。我编写了以下代码,该代码仅在启用高时才有效。任何人都可以在启用高后帮助我转移数据,然后不依赖于启用来转移数据吗?


library ieee; 
use ieee.std_logic_1164.all; 

entity SR is
  port(clk, din, rst, 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); 
begin

process (clk, rst) 
begin 
   if (rst = '0') then
      shift_reg <= (others => '0');
   elsif (clk'event and clk = '1') then
      if enable= '1' then 
         shift_reg(70 downto 0) <= shift_reg(71 downto 1);
         shift_reg(71) <= din;
      end if;
   end if;

end process;
sr_out <= shift_reg;
end behavioral; 

非常感谢!

4

2 回答 2

2

我认为您需要一个由启动信号设置的 RS-FlipFlop。它的输出是您的使能信号。启动信号也启动一个 72 个时钟周期的计数器。当计数器翻转(或达到零,取决于其方向)时,您重置触发器,从而导致禁用移位寄存器。

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

于 2013-06-07T11:34:30.867 回答
0

您需要一台两状态机来执行此操作。这是一个很好的想法。我很确定它可以满足您的需求或非常接近。

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; 
于 2013-06-11T18:07:32.200 回答