【问题标题】:What is the difference between these 2 vhdl codes这2个vhdl代码有什么区别
【发布时间】:2014-02-18 14:02:02
【问题描述】:

这2个vhdl代码有什么区别?

第一

library IEEE;
use IEEE.Std_Logic_1164.all;

entity mux4 is
port(
   in1, in2, in3, in4 : in std_logic;
   ctrl: in std_logic_vector(1 downto 0);
   sai: out std_logic
   );
end mux4;

architecture mux_bhv of mux4 is
begin
    process(in1, in2, in3, in4, ctrl)
        begin case ctrl is
            when "00" => sai <= in1;
            when "01" => sai <= in2;
            when "10" => sai <= in3;
            when "11" => sai <= in4;
            when others => null;
        end case;
    end process;
end mux_bhv;

第二

library IEEE; 
use IEEE.Std_Logic_1164.all; 

entity mux4x1 is 
    port(w, x, y, z: in std_logic_vector(7 downto 0); 
        s: in std_logic_vector(1 downto 0); 
        m: out std_logic_vector(7 downto 0) 
        ); 
end mux4x1; 

architecture circuito of mux4x1 is 
begin 
    m <= w when s = "00" else 
        x when s = "01" else 
        y when s = "10" else 
        z; 
end circuito; 

【问题讨论】:

  • 我的代码没有被识别,所以我把它们上传到了 pastebin:pastebin.com/mvDVnUNnpastebin.com/GQFh9uBZ
  • 我知道它们都是mux,但是代码之间有区别吗?
  • 您会考虑合成产生的电路差异,还是仿真差异?一个是std_logic 之间的复用器,另一个是std_logic_vector(7 downto 0) 之间的复用器;我认为这不是像您所追求的那样明显的区别...
  • 您怀疑有什么不同,为什么?

标签: vhdl


【解决方案1】:

对于第一个程序:

library IEEE;
use IEEE.Std_Logic_1164.all;

entity mux4 is
port(
in1, in2, in3, in4 : in std_logic;
ctrl: in std_logic_vector(1 downto 0);
sai: out std_logic
);
end mux4;

architecture mux_bhv of mux4 is
begin
process(in1, in2, in3, in4, ctrl)
    begin case ctrl is
        when "00" => sai <= in1;
        when "01" => sai <= in2;
        when "10" => sai <= in3;
        when "11" => sai <= in4;
        when others => null;
    end case;
end process;
end mux_bhv;

您有四个二进制一位输入,一个两位选择线和一个输出。所以,那是你的港口声明。然后在您的架构中: 大小写的使用是为了选择。因此,正如您在输入中声明的那样,选择行是 ctrl。当它为 00 时,选择第一个输入。如果选择 ctrl "01",则传递第二个输入,依此类推..

library IEEE; 
use IEEE.Std_Logic_1164.all; 

entity mux4x1 is 
port(w, x, y, z: in std_logic_vector(7 downto 0); 
    s: in std_logic_vector(1 downto 0); 
    m: out std_logic_vector(7 downto 0) 
    ); 
end mux4x1; 

architecture circuito of mux4x1 is 
begin 
m <= w when s = "00" else 
    x when s = "01" else 
    y when s = "10" else 
    z; 
end circuito; 

同样的想法 4-1 多路复用器,但在这里你的输入和输出是 7 位而不是只有一位。我希望你能得到它^_^。

【讨论】:

    【解决方案2】:

    除了std_logicstd_logic_vector 之外,还有一个细微的差别是在模拟中:当s 为“11”并且s 包含任何非零/一值(即 Z、X、H、L、...)。

    在第一个多路复用器中,当ctrl 包含非零/一个值时,输出sai 不会更新。

    同样,这只是模拟差异。

    【讨论】:

      【解决方案3】:

      如上所述“在第一个多路复用器中,当ctrl 包含非零/一个值时,输出sai 不会更新。”
      由于缺乏分配,大多数软件工具将创建一个中间(并且可能是不希望的)锁存器。第二个代码中没有发生的事情,所有可能的值都被分配了。

      【讨论】:

        猜你喜欢
        • 2016-04-20
        • 2020-01-04
        • 1970-01-01
        • 2014-09-28
        • 1970-01-01
        • 2012-09-27
        • 2021-01-06
        相关资源
        最近更新 更多