【问题标题】:Ideas for a flexible/generic decoder in VHDLVHDL中灵活/通用解码器的想法
【发布时间】:2016-07-20 10:03:50
【问题描述】:

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

因此,不要使用看起来像这样的静态(固定输入/输出大小)解码器:

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;

我知道这段代码无效,并且“何时”测试用例必须是常量,并且我不能在这样的 case 语句之间使用 for-generate,但它显示了我所追求的: 一个足够聪明的实体,可以满足我的需求。

我一直试图为这个问题找到一个优雅的解决方案,但没有取得多大成功,所以,我愿意接受任何建议。

提前致谢, 埃里克

【问题讨论】:

  • numeric_std 提供了一个将向量移动指定数字的函数。因此,您大概可以将向量 0 =&gt; '1', others =&gt; '0' 向左移动(输入数字 - 1)。

标签: vhdl fpga xilinx


【解决方案1】:

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

这样写。类似的东西(假设来自 numeric_std 的类型):

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

【讨论】:

  • 短而有效(而且效果很好!)。这让我意识到有时想要在硬件描述中“降低”一点(尝试定义更接近其硬件实现的逻辑) ),可能会使您对明显的解决方案视而不见,这些解决方案将一些设计负载放在软件而不是您身上。感谢一月的解决方案。
  • 我很高兴您收到了元消息 :-) 恭喜您获得了这种洞察力,这在 HDL 设计领域中非常罕见!
【解决方案2】:

我总是发现,当你循环遍历每一位时,这种事情更容易理解,所以像:

     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;

【讨论】:

    猜你喜欢
    • 2012-07-05
    • 2011-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-31
    • 2015-06-17
    • 2014-12-26
    相关资源
    最近更新 更多