質問

セレクターとデコードされた出力信号のビット数を変更するときに使用できるほど柔軟に使用できるアドレスデコーダーを作成したいと思います。

したがって、このようなものになる静的(固定入力/出力サイズ)デコーダーを持つ代わりに:

entity Address_Decoder is
Generic
(
    C_INPUT_SIZE: integer := 2
);
Port
(
    input   : in  STD_LOGIC_VECTOR (C_INPUT_SIZE-1 downto 0);
    output  : out STD_LOGIC_VECTOR ((2**C_INPUT_SIZE)-1 downto 0);
    clk : in  STD_LOGIC;
    rst : in  STD_LOGIC
);
end Address_Decoder;

architecture Behavioral of Address_Decoder is

begin        
        process(clk)
            begin
               if rising_edge(clk) then 
                  if (rst = '1') then
                     output <= "0000";
                  else
                     case <input> is
                        when "00" => <output> <= "0001";
                        when "01" => <output> <= "0010";
                        when "10" => <output> <= "0100";
                        when "11" => <output> <= "1000";
                        when others => <output> <= "0000";
                     end case;
                  end if;
               end if;
            end process;

end Behavioral;

より柔軟/一般的なものを持っています、それは次のようになります:

    entity Address_Decoder is
    Generic
    (
        C_INPUT_SIZE: integer := 2
    );
    Port
    (
        input   : in  STD_LOGIC_VECTOR (C_INPUT_SIZE-1 downto 0);
        output  : out STD_LOGIC_VECTOR ((2**C_INPUT_SIZE)-1 downto 0);
        clk : in  STD_LOGIC;
        rst : in  STD_LOGIC
    );
    end Address_Decoder;

    architecture Behavioral of Address_Decoder is

    begin        

DECODE_PROC:
    process (clk)
    begin

        if(rising_edge(clk)) then
         if ( rst = '1') then
           output <= conv_std_logic_vector(0, output'length);
         else
           case (input) is
             for i in 0 to (2**C_INPUT_SIZE)-1 generate
             begin
                when (i = conv_integer(input)) => output <= conv_std_logic_vector((i*2), output'length);        
             end generate;
            when others => output <= conv_std_logic_vector(0, output'length);
           end case;
         end if;
        end if;
    end process;

    end Behavioral;

このコードは有効ではなく、「いつ」テストケースが定数である必要があり、そのようなケースステートメントの間に生成を使用できないことを知っていますが、それは私が後になっていることを示しています:エンティティ私のニーズに合わせて成長するのに十分賢い。

私はこの問題のエレガントなソリューションをあまり成功させることなく見つけようとしてきたので、どんな提案でもオープンです。

よろしくお願いします、エリック

役に立ちましたか?

解決

どうやら、入力を設定する出力ビットのインデックスにする必要があります。

そのように書いてください。 (numeric_stdからタイプを想定する)のようなもの:

output <= (others => '0'); -- default
output(to_integer(input)) <= '1';

他のヒント

各ビットをループするだけで、この種のものがより簡単に従うことができるので、次のようなものがあります。

     if ( rst = '1') then
       output <= (others=>'0');
     else
       for i in 0 to (2**C_INPUT_SIZE)-1 generate
       begin
         if (i = conv_integer(input)) then
           output(i) <= '1';
         else
           output(i) <= '0';
         end if;
       end generate;
     end if;
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top