VHDL 中的案例陈述

发布于 2024-08-27 17:23:34 字数 159 浏览 4 评论 0原文

在VHDL中编程时,可以在case语句中使用变量吗?该变量将被其中一种情况修改

,即

case task is

when 1 =>

when 2 => 

when number =>

这样可以吗?

When programming in VHDL, can you use a variable in a case statement? This variable will modified by one of the cases

i.e.

case task is

when 1 =>

when 2 => 

when number =>

is this OK?

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

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

发布评论

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

评论(1

纵性 2024-09-03 17:23:34

用于模拟或综合?

无论哪种方式,从文档

选项必须是与表达式具有相同离散类型的常量

使用 if 测试 number,可以是:

if task=number then
  ...
else
  case task is
    when 1 => ...
    when 2 => ...
    when others => ...
  end case;
end if;

case task is
  when 1 => ...
  when 2 => ...
  when others =>
    if task=number then
      ...
    else
      ...
    end if;
end case;

您的选择取决于您想要 if task=number 测试的结果还是when ... => 测试有优先权? (例如,假设无论出于何种原因 number=1,您希望 when 1 => 还是 if task=number 最终提供您的结果?)

在简单的情况下,case 语句综合为多路复用器; if 语句综合为比较器和双输入多路复用器。一种会融入另一种。

For simulation or synthesis?

Either way, from the documentation:

The choices must be constants of the same discrete type as the expression.

Use if to test for number, either:

if task=number then
  ...
else
  case task is
    when 1 => ...
    when 2 => ...
    when others => ...
  end case;
end if;

or

case task is
  when 1 => ...
  when 2 => ...
  when others =>
    if task=number then
      ...
    else
      ...
    end if;
end case;

Your choice depends on whether you want the result of the if task=number test or of the when ... => test to have priority? (e.g. assume that for whatever reason number=1, do you want when 1 => or if task=number to ultimately provide your result?)

In the trivial case the case statement synthesizes as a multiplexer; the if statement synthesizes as a comparator and two-input multiplexer. One feeds into the other.

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