任务要求用VHDL实现一个PISO移位寄存器:
但是之前完全没学过VHDL,所以查资料努力写了个,开始是结果不对,后面又出如下错误。
因为确实没学过,很多不了解,不知道怎么解决,希望能帮我看看代码,然后成功得到结果。
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx leaf cells in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
-- Dflip-flop
entity D_FF is
port (
D : in std_logic;
CLK : in std_logic;
Q : out std_logic
);
end entity D_FF;
architecture D_FF_arch of D_FF is
begin
process (CLK)
begin
if rising_edge(CLK) then
Q <= D;
end if;
end process;
end architecture D_FF_arch;
---piso
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity PISO is
port (
D0, D1, D2, D3 : in std_logic;
SHIFT_LOAD : in std_logic;
CLK : in std_logic;
Q3 : out std_logic
);
end entity PISO;
architecture behavioral of PISO is
signal D_out : STD_LOGIC_VECTOR(3 downto 0);
begin
DFF_3: entity work.D_FF port map (D3, CLK, D_out(3));
DFF_2: entity work.D_FF port map (D2, CLK, D_out(2));
DFF_1: entity work.D_FF port map (D1, CLK, D_out(1));
DFF_0: entity work.D_FF port map (D0, CLK, D_out(0));
process (CLK)
begin
if rising_edge(CLK) then
if SHIFT_LOAD = '0' then
D_out <= D3 & D2 & D1 & D0;
else
D_out <= '0' & D_out(3 downto 1);
end if;
end if;
end process;
Q3 <= D_out(3);
end architecture behavioral;
测试台文件:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity lab1_test is
end lab1_test;
architecture tb of lab1_test is
signal D3, D2, D1, D0, SHIFT_LOAD, CLK : STD_LOGIC := '0';
signal Q3 : STD_LOGIC;
component PISO is
Port ( D3, D2, D1, D0, SHIFT_LOAD, CLK : in STD_LOGIC;
Q3 : out STD_LOGIC);
end component;
begin
dut: PISO
port map (D3, D2, D1, D0, SHIFT_LOAD, CLK, Q3);
CLK_process: process
begin
CLK <= not CLK after 5 ns;
end process;
stimulus: process
begin
wait for 10 ns;
D3 <= '1'; D2 <= '0'; D1 <= '1'; D0 <= '0'; SHIFT_LOAD <= '0'; -- Input data
wait for 10 ns;
SHIFT_LOAD <= '1'; -- Shift data
wait for 10 ns;
D3 <= '0'; D2 <= '0'; D1 <= '1'; D0 <= '1'; SHIFT_LOAD <= '0'; -- Input new data
wait for 10 ns;
SHIFT_LOAD <= '1'; -- Shift data again
wait;
end process;
end Behavioral;