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

0

そのためには、2 つのステート マシンが必要です。これを行う方法の非常に良いアイデアを次に示します。私はそれがあなたが必要とすること、またはそれに非常に近いことをしていると確信しています。

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 に答える