【问题标题】:State to std_logic状态到 std_logic
【发布时间】:2011-04-25 22:52:54
【问题描述】:

我的状态定义如下:

type state_type is (s0, s1, s2, s3);
signal state   : state_type;

现在我想用这个状态信息来形成另一个信号

signal data : std_logic_vector(3 downto 0);
signal data_plus_state : std_logic_vector(5 downto 0);

....
data_plus_state <= data & state;

有谁知道我如何将状态协调到 std_logic_vector 中,以便我可以连接这些 两个信号?

非常感谢, 抢

【问题讨论】:

  • 属于 ChipHacker,但 SO 未提供选项。太糟糕了!

标签: vhdl fpga


【解决方案1】:

定义一个将状态转换为 std_logic_vector 的子程序。

该子程序包含一个 case 语句,类似于:

case state is
  when s0 => return <std_logic_vector value for s0>;
  when s1 => return <std_logic_vector value for s1>;
  when s2 => return <std_logic_vector value for s2>;
  when s3 => return <std_logic_vector value for s3>;
end case;

【讨论】:

    【解决方案2】:

    子程序和案例答案会很好地工作。如果你想要一些东西,你可以使用它。

    signal state_slv : std_logic_vector(1 downto 0);
    
    state_slv <= "00" when state = s0 else
                 "01" when state = s1 else
                 "10" when state = s2 else
                 "11";
    
    data_plus_state <= data & state_slv;
    

    干杯

    【讨论】:

      【解决方案3】:

      您似乎想将两个(或多个)信号放入一个信号(或端口)中。

      这里的方法不是连接信号,而是将它们放入记录中。优点是信号各部分的语义(含义)表达清楚。这样您就不必编码(然后再解码)每个数据元素。

      type state_type is (s0, s1, s2, s3);
      signal state   : state_type;
      signal data : std_logic_vector(3 downto 0);
      type data_plus_state_type is record
          data : std_logic_vector(3 downto 0);
          state: state_type;
      end record data_plus_state_type;
      signal data_plus_state : data_plus_state_type;
      

      然后你可以把这两个信号放在一个记录信号中:

      data_plus_state <= (data, state);
      -- or:
      data_plus_state.data <= data;
      data_plus_state.state <= state;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多