VHDL中灵活/通用译码器的设计思想

VHDL中灵活/通用译码器的设计思想,vhdl,fpga,xilinx,Vhdl,Fpga,Xilinx,我想创建一个地址解码器,它足够灵活,可以在更改选择器和解码输出信号的位数时使用 因此,与其使用静态(固定输入/输出大小)解码器,不如使用如下所示: 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 ((

我想创建一个地址解码器,它足够灵活,可以在更改选择器和解码输出信号的位数时使用

因此,与其使用静态(固定输入/输出大小)解码器,不如使用如下所示:

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;
实体地址\u解码器是
通用的
(
C_输入_大小:整数:=2
);
港口
(
输入:标准逻辑向量(C_输入_大小-1减至0);
输出:输出标准逻辑向量(2**C\U输入大小)-1至0;
clk:标准逻辑中;
rst:在标准逻辑中
);
端地址译码器;
介绍了地址译码器的结构
开始
过程(clk)
开始
如果上升沿(clk),则
如果(rst='1'),则

输出显然,您希望输入是应该设置的输出位的索引

这样写吧。类似于(假设类型来自数值_std):

输出“0”);--违约

输出(to_integer(input))我总是发现,当您循环每一位时,这种事情更容易遵循,所以类似于:

     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;
如果(rst='1'),则
输出“0”);
其他的
对于0中的i到(2**C\u输入大小)-1生成
开始
如果(i=conv_整数(输入)),则

输出(i)
numeric\u std
提供一个函数,可将向量移位指定的数值。因此,您可以假定将向量
0=>'1',其他=>'0'
左移(输入数字-1)。短而有效(而且效果很好!)。这让我意识到,有时想要在硬件描述中稍微“低一点”(试图定义更接近其硬件实现的逻辑),可能会使您看不到明显的解决方案,这些解决方案会将一些设计负载放在软件上,而不是放在您身上。感谢您的解决方案,Jan。我很高兴您收到了meta消息:-)祝贺您有了这样的洞察力,这在HDL设计界是出人意料的罕见!
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;