VHDL 多路复用器实现?

发布于 2024-10-31 06:43:24 字数 235 浏览 1 评论 0原文

是否可以实现具有多个控制信号的多路复用器?例如,我想做这样的事情:

with (sig1 & sig2) select  
output <= A when "00",  
B when "01",  
C when "10",  
D when "11",  
'0' when others;  

我知道我可以将它们分配给一个新信号并使用它,但这是我想尽可能避免的事情。

Is it possible to implement a mux with multiple control signals? For example, I want to do something like this:

with (sig1 & sig2) select  
output <= A when "00",  
B when "01",  
C when "10",  
D when "11",  
'0' when others;  

I know I could just assign them to a new signal and use that, but that's something I want to avoid if possible.

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

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

发布评论

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

评论(2

青衫负雪 2024-11-07 06:43:24

您需要在编译器上启用 VHDL2008 模式才能使其工作。

另一种选择(也是 2008 年):

muxing: process (sig1, sig2) is
begin  -- process muxing
    case sig1 & sig2 is
        when "00" => output <= '1';
        when "01" => output <= '0';
        when "10" => output <= '0';
        when "11" => output <= '1';
        when others => output <= '0';
    end case;
end process muxing;

如果您的编译器上没有 VHDL-2008 模式,它将失败

Array type case expression must be of a locally static subtype.

并出现类似的抱怨。

如果您的编译器无法兼容 VHDL-2008,则必须通过创建可用于包围 sig1 和 sig1 的类型来解决此问题。 sig2 明确告诉编译器发生了什么:

subtype twobits is bit_vector(0 to 1);

然后:

with twobits'(sig1 & sig2) select  
    output <= '1' when "00",  
    -- etc.

或:

case twobits'(sig1 & sig2) is
     when "00" =>  -- etc.

You need to enable VHDL2008 mode on your compiler to have it work.

An alternative (also 2008):

muxing: process (sig1, sig2) is
begin  -- process muxing
    case sig1 & sig2 is
        when "00" => output <= '1';
        when "01" => output <= '0';
        when "10" => output <= '0';
        when "11" => output <= '1';
        when others => output <= '0';
    end case;
end process muxing;

If you have no VHDL-2008 mode on your compiler it will fail with complaints of

Array type case expression must be of a locally static subtype.

or similar.

If your compiler can't be made to be VHDL-2008 compliant, you have to work around this by creating a type that you can use to surround the sig1 & sig2 to explicitly tell the compiler what's going on:

subtype twobits is bit_vector(0 to 1);

Then:

with twobits'(sig1 & sig2) select  
    output <= '1' when "00",  
    -- etc.

or:

case twobits'(sig1 & sig2) is
     when "00" =>  -- etc.
飘过的浮云 2024-11-07 06:43:24

看看这个也许对你有帮助

entity MUX is
  port ( a, i0, i1 : in bit;
         o : out bit );
end MUX;

architecture behave of MUX is
begin
  process ( a, i0, i1 ) begin
    if  a = '1'  then
      o <= i1;
    else
      o <= i0;
    end if;
end process;
end behave;

See this, maybe it helps you

entity MUX is
  port ( a, i0, i1 : in bit;
         o : out bit );
end MUX;

architecture behave of MUX is
begin
  process ( a, i0, i1 ) begin
    if  a = '1'  then
      o <= i1;
    else
      o <= i0;
    end if;
end process;
end behave;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文