Я пытаюсь написать код для устройства, которое может сдвигаться вправо, сдвигаться влево, кружиться вправо и кружиться влево.как вы можете видеть на этой картинке. Устройство
, поэтому я написал код для модулей 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 FlipFlop:
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;