状态到 std_logic

发布于 2024-09-27 11:13:31 字数 383 浏览 2 评论 0原文

我已将我的状态定义如下:

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 中,以便我可以连接这些 两个信号?

非常感谢, 抢

I have defined my state as follows:

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

Now I would like to use this state information to form another signal

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

....
data_plus_state <= data & state;

Does anyone know how I can concert state into a std_logic_vector so that I can concatenate these
two signals?

Many thanks,
Rob

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情栀口红 2024-10-04 11:13:32

定义一个将状态转换为 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;

Define a subprogram that convert state to std_logic_vector.

That subprogram contains a case statement, something like:

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;
吃素的狼 2024-10-04 11:13:32

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

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;

干杯

The subprogram and case answer would work very well. If you wanted something in line you could use this.

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;

Cheers

等风来 2024-10-04 11:13:32

看来您想将两个(或更多)信号放入一个信号(或端口)中。

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

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;

It seems you want to put two (or more) signals into one signal (or port).

The way to go here is not concatenating the signals, but rather put them in a record. The advantage is that the semantics (the meaning) of each part of the signal is clearly expressed. This way you don't have to encode (and later decode) every data element.

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;

Then you can put the two signals in a single record signal:

data_plus_state <= (data, state);
-- or:
data_plus_state.data <= data;
data_plus_state.state <= state;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文