【问题标题】:VHDL: with-select for multiple valuesVHDL:选择多个值
【发布时间】:2013-03-09 18:39:33
【问题描述】:

我有以下代码(它编码了一个按下按钮的数字):

with buttons select
  tmp <= "000" when x"1",
         "001" when x"2",
         "010" when x"4",  
         "011" when x"8",
         "100" when others;
code <= input(1 downto 0);
error <= input(2);

我试图在不使用tmp 信号的情况下重写它。是否可以?以下不起作用:

with buttons select
  error & code <= "000" when x"1",
                  "001" when x"2",
                  "010" when x"4",  
                  "011" when x"8",
                  "100" when others;

【问题讨论】:

    标签: select vhdl


    【解决方案1】:

    你可以用 case 代替 select:

    my_process_name : process(buttons)
    begin
      case buttons is
        when x"1" =>
          error <= '0';
          code  <= "00";
        when x"2" =>
          error <= '0';
          code  <= "01";
        when x"4" =>
          error <= '0';
          code  <= "10";
        when x"8" =>
          error <= '0';
          code  <= "11";
        when others =>
          error <= '1';
          code  <= "00";
      end case;
    end process;
    

    【讨论】:

    • 您是否有特殊原因不想将其放入进程中?
    • 我只是在学习 VHDL,我一直在寻找最简单、最优雅的解决方案。如果我将组合代码放在一个进程中,会有任何语义差异吗?
    • 已编辑以在流程中显示组合。通常在 process() 的括号内,您会将信号添加到敏感度列表中,即组合逻辑的输入,或者如果您的时钟和重置是连续的。合成通常不需要灵敏度列表,但模拟会告诉模拟器仅在灵敏度列表中的信号发生变化时才查看此过程。如果您只是在架构中使用它,我相信模拟器会在每个滴答声中评估该行。
    【解决方案2】:

    或者你可以把它写成两个单独的 with/when 语句:

    with buttons select
      error <= '0' when x"1",
               '0' when x"2",
               '0' when x"4",  
               '0' when x"8",
               '1' when others;
    with buttons select
      code <= "00" when x"1",
              "01" when x"2",
              "10" when x"4",  
              "11" when x"8",
              "00" when others;
    

    或者:

    error <= '0' when (buttons = X"1" or buttons = X"2" buttons = X"4" buttons = X"8") else '1'; 
    code <= "00" when buttons = X"1" else "01" when buttons = X"2" else "10" when buttons = X"4" else "11" when buttons = X"8" else "00"; 
    

    VHDL 是一种编译语言 - 或综合语言。只要综合工具创建相关的逻辑结构,任何格式都可以。剩下的就是让代码被理解和维护的语义。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-04-30
      • 2011-04-14
      • 2022-01-15
      • 2023-03-08
      • 2017-10-03
      • 2021-01-11
      • 2011-04-05
      相关资源
      最近更新 更多