1

我有很大的问题,因为我不了解如何正确地做作业。好吧,我必须做这样的事情:
http
: //tomaszewicz.zpt.tele.pw.edu.pl/files/u1/zad4.gif 我有创建 b1 的代码,但我不知道如何创建第二个并制作它们连接到 b3。

我的代码是:

library ieee;
use ieee.std_logic_1164.all;

entity test is
generic(
n : integer := 4
);
port(
a, b, c, d : in std_logic_vector(n-1 downto 0);
s : in std_logic_vector(1 downto 0);
y : out std_logic_vector(n-1 downto 0)
);
end test;



-- przypisanie sekwencyjne - case
architecture arch_mux5 of test is
begin
pr_case: process(a,b,c,d,s)
begin
case s is
when "00" => y <= a;
when "01" => y <= b;
when "10" => y <= c;
when others => y <= d;
end case;
end process;
end arch_mux5;

architecture arch_mux6 of test is
begin
pr_if: process(a,b,c,d,s)
begin
y <= (others => '0'); -- latch jesli zakomentujemy, dlaczego?
if s = "00" then
y <= a;
end if;
if s = "01" then
y <= b;
end if;
if s = "10" then
y <= c;
end if;
if s = "11" then
y <= d;
end if;
end process;
end arch_mux6;

configuration cfg of test is
for arch_mux5
end for;
end cfg;

mux5 和 mux6 似乎相同,但写入方法不同。

4

2 回答 2

3

您必须实例化这些多路复用器,例如:

entity top is
  generic (
    n: integer:=4
  );
  port (
    a, b, c, d, e, f, g, h: in std_logic_vector(n-1 downto 0);
    s: in std_logic_vector(2 downto 0);
    y: out std_logic_vector(n-1 downto 0)
  );
end entity top;

architecture struct of top is
  signal t1, t2: std_logic_vector(n-1 downto 0);
  component test is
    generic(
      n : integer := 4
    );
    port (
      a, b, c, d : in std_logic_vector(n-1 downto 0);
      s : in std_logic_vector(1 downto 0);
      y : out std_logic_vector(n-1 downto 0)
    );
  end component test;
  component mux2 is
    generic(
      n : integer := 4
    );
    port (
      a, b : in std_logic_vector(n-1 downto 0);
      s : in std_logic;
      y : out std_logic_vector(n-1 downto 0)
    );
  end component test;
begin
  b1: test
    generic_map (
      n => n
    );
    port map (
      a => a,
      b => b,
      c => c,
      d => d,
      s => s(1 downto 0),
      y => t1
    );
  b2: test
    generic_map (
      n => n
    );
    port map (
      e => a,
      f => b,
      g => c,
      h => d,
      s => s(1 downto 0),
      y => t2
    );
  b3: mux2
    generic_map (
      n => n
    );
    port map (
      a => t1,
      b => t2,
      s => s(2),
      y => y
    );
end architecture struct;

当然,您仍然需要为mux2. 我没有测试这段代码(这里没有 VHDL 编译器),但这至少应该引导你进入正确的方向。

于 2011-04-18T21:20:18.923 回答
1

是的,你的老师提供了两种不同的方法来实现相同的多路复用器。这可能只是为了教育目的。您需要为 b1 和 b2 实例化这个多路复用器。

正如@bmk 指出的那样,您仍然需要b3在一个顶层提供三个多路复用器的实现和实例化。

于 2011-04-19T10:06:55.327 回答