为什么我的VHDL测试台会给我'U'作为输出?使用4x1MUX和Dflipflop

时间:2019-03-08 13:25:52

标签: vhdl

我正在尝试为可以向右移动,向左移动,向右转和向左转的设备编写代码。如您在这张照片中看到的。 The Device

所以我为4x1 MUX和DFlipFlop模块编写了代码,并在带有端口映射的主模块中使用了它们。所以当我做一个测试台时,我的输出是'U'。 您可以在下面查看我的代码:

4x1多路复用器:

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;


entity MUX4x1 is
Port ( in1 : in std_logic; -- mux input1
in2 : in std_logic; -- mux input2
in3 : in std_logic; -- mux input3
in4 : in std_logic; -- mux input4
sel : in std_logic_vector(1 downto 0); -- selection line
dataout : out std_logic); -- output data
end MUX4x1;

architecture Behavioral of MUX4x1 is
begin
-- This process for mux logic
process (sel, in1, in2, in3, in4)
begin
case SEL is 
when "00" => dataout <= in1; 
when "01" => dataout <= in2;
when "10" => dataout <= in3;
when "11" => dataout <= in4;
when others => dataout <= '0';
end case;
end process;

end Behavioral;

D触发器:

entity Dflipflop is
port
   (
  clk : in std_logic;

  rst : in std_logic;
  pre : in std_logic;
  ce  : in std_logic;

  d : in std_logic;

  q : out std_logic
   );
end Dflipflop;

architecture Behavioral of Dflipflop is

begin
   process (clk) is
   begin
      if rising_edge(clk) then  
         if (rst='1') then   
            q <= '0';
         elsif (pre='1') then
            q <= '1';
         elsif (ce='1') then
            if (d ='1') then
             q <= '1';
     elsif (d ='0') then 
         q<= '0';
        end if;
     end if;
  end if;
 end process;


end Behavioral;

主模块     库IEEE;     使用IEEE.STD_LOGIC_1164.ALL;

entity Main is
port(
--input: in std_logic_vector(3 downto 0);
s: in std_logic_vector(1 downto 0);
clk: in std_logic;
output0: out std_logic;
output1: out std_logic;
output2: out std_logic;
output3: out std_logic
);
end Main;

architecture Behavioral of Main is


component MUX4x1 is
Port ( 
in1 : in std_logic; -- mux input1
in2 : in std_logic; -- mux input2
in3 : in std_logic; -- mux input3
in4 : in std_logic; -- mux input4
sel : in std_logic_vector(1 downto 0); -- selection line
dataout : out std_logic); -- output data
end component;


component Dflipflop is
port
   (
     clk : in std_logic;

     rst : in std_logic;
     pre : in std_logic;
     ce  : in std_logic;

     d : in std_logic;

      q : out std_logic
   );
end component;

signal temp: std_logic_vector(3 downto 0);
signal A:std_logic_vector(3 downto 0) := "0010";
begin
MUX1: MUX4x1 port map (A(1),'0',A(1),A(3),s,temp(0));
MUX2: MUX4x1 port map (A(2),A(0),A(3),A(1),s,temp(1));
MUX3: MUX4x1 port map (A(3),A(1),A(3),A(1),s,temp(2));
MUX4: MUX4x1 port map (A(0),A(2),A(0),A(2),s,temp(3));
FF1: Dflipflop port map(clk,'0','0','1',temp(0),A(0));
FF2: Dflipflop port map(clk,'0','0','1',temp(1),A(1));
FF3: Dflipflop port map(clk,'0','0','1',temp(2),A(2));
FF4: Dflipflop port map(clk,'0','0','1',temp(3),A(3));
output0<=A(0);
output1<=A(1);
output2<=A(2);
output3<=A(3);
end Behavioral;

并使用此测试平台,我得到的输出为“ U”:

ENTITY TestBench IS
END TestBench;

ARCHITECTURE behavior OF TestBench IS 

-- Component Declaration for the Unit Under Test (UUT)

COMPONENT Main
PORT(
     s : IN  std_logic_vector(1 downto 0);
     clk : IN  std_logic;
     output0 : OUT  std_logic;
     output1 : OUT  std_logic;
     output2 : OUT  std_logic;
     output3 : OUT  std_logic
    );
END COMPONENT;


   --Inputs
   signal s : std_logic_vector(1 downto 0) := (others => '0');
   signal clk : std_logic := '0';

    --Outputs
   signal output0 : std_logic;
   signal output1 : std_logic;
   signal output2 : std_logic;
   signal output3 : std_logic;

   -- Clock period definitions
   constant clk_period : time := 10 ns;

BEGIN

    -- Instantiate the Unit Under Test (UUT)
   uut: Main PORT MAP (
          s => s,
          clk => clk,
          output0 => output0,
          output1 => output1,
          output2 => output2,
          output3 => output3
        );

   -- Clock process definitions
   clk_process :process
   begin
        clk <= '0';
        wait for clk_period/2;
        clk <= '1';
        wait for clk_period/2;
   end process;


   -- Stimulus process
   stim_proc: process
   begin        
      -- hold reset state for 100 ns.
      wait for 100 ns;  

      wait for clk_period*10;

      -- insert stimulus here 

      wait;
   end process;

 END;

0 个答案:

没有答案