首页 文章

某些案例选项的VHDL嵌套案例陈述

提问于
浏览
0

我是VHDL新手并使用case语句,我有类似以下内容:

process(state)
begin
  case state is
    when stop =>
      a <= input;
      b <= output;
    when move =>
      a <= input_1;
      b <= output_1;
  end case;
end process;

其中a,b,输入,输出,input_1和输出1是信号 .

我的问题是我想在一个选项中只有一个嵌套的情况:

例如:

process(state)
begin
  case state is
    when stop =>
      a <= input;  
      b <= output;
    when move =>
      a <= if c='0' then input_1 else input_2;
      b <= if c='0' then output_1 else output_2;
  end case;
end process;

我的问题是,我可以做上面的事情,其中并非所有案例选项都嵌套但只有其中一些是或在这种情况下有任何其他方式,我尝试使用when else但得到一个错误,说这种语法不支持 .

任何帮助表示赞赏

3 回答

  • 1

    我不太清楚你在这里问的是什么:

    我可以做上面这样的事情,并不是所有的案例选项都是嵌套的,但只有其中一些是或者在这种情况下还有其他方式

    但这是你想要做的吗? (注意我已将 c 添加到灵敏度列表中):

    process(state,c)
    begin
      case state is
        when stop =>
          a <= input;  
          b <= output;
        when move =>
          case c is
            when '0' =>
               a <= input_1;
               b <= output_1;
            when '1' =>
               a <= input_2;
               b <= output_2;
            when others => null;
      end case;
    end process;
    
  • 0

    你的问题充满了危险 . 将输出分配给内部信号可能需要inout或buffer或VHDL 2008支持的输出端口模式,这对于合成来说并不通用 . 通常也不支持模式缓冲区 .

    为了解决问题的核心顺序信号分配支持VHDL 2008中支持的时间,但通常不在综合中 .

    案例陈述选择包含顺序陈述 .

    您可以使用if语句:

    library ieee;
    use ieee.std_logic_1164.all;
    
    entity foo is
        port (
            signal input:       in      std_logic;
            signal output:      inout   std_logic;
            signal input_1:     in      std_logic;
            signal input_2:     in      std_logic;
            signal output_1:    inout   std_logic;
            signal output_2:    inout   std_logic
        );
    end entity;
    
    architecture fum of foo is
        signal a, b:    std_logic;
        signal c:       std_logic;
        type some_state is (stop, move);
        signal state: some_state;
    begin
    UNLABELED:
        process(state)
        begin
        case state is
            when stop =>
                a <= input;
                b <= output;
            when move =>
                if c = '0' then
                    a <= input_1;
                    b <= output_1;
                else 
                    a <= input_2;
                    b <= output_2;
                end if;
            end case;
        end process;
    end architecture;
    

    请注意,您对 c 的两个评估已合并为一个 .

    除了在VHDL 2008中作为顺序语句支持的条件信号分配状态之外,还选择了信号赋值语句(同样通常不作为顺序语句由综合支持) .

  • 0

    2008年之前的VHDL没有用于顺序语句的三元运算符(C-like ? : ),所以你不能写 if c='0' then input_1 else input_2 ,但在VHDL-2008中你可以写 input_1 when c='0' else input_2 .

    但是,通过实现一个小功能可以实现紧凑的编码风格:

    function ternary(cond : boolean; res_true, res_false : std_logic) return std_logic is
    begin
      if cond then
        return res_true;
      else
        return res_false;
      end if;
    end function;
    

    因此代码的移动部分可以写成:

    when move =>
      a <= ternary(c='0', input_1, input_2);
      b <= ternary(c='0', output_1, output_2);
    

    你也可以做一个嵌套的情况,如:

    when move =>
      case c is
        when '0' =>
          a <= input_1;
          b <= output_1;
        when others  =>
          a <= input_2;
          b <= output_2;
      end case;
    

    或者像大卫所展示的那样用_2584947做 .

相关问题