我已經完成了代碼,它可以工作,但是當我嘗試寫測試平臺時,我遇到了一些麻煩。輸入x設置爲8位,x:IN BIT_VECTOR(N -1 DOWNTO 0)。 當我編寫測試臺時,我不輸入位數。VHDL計數器錯誤
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
USE ieee.std_logic_unsigned.all;
ENTITY Count_ones IS
GENERIC (N: INTEGER := 8); -- number of bits
PORT (x: IN BIT_VECTOR (N -1 DOWNTO 0); y: OUT NATURAL RANGE 0 TO N);
END ENTITY ;
architecture Behavioral of Count_ones is
TYPE count is Array (N DOWNTO 1) OF Natural;
signal a : count;
begin
a(0) <= 1 when (x(0) = '1')
else
0;
gen: FOR i IN N-1 DOWNTO 0
GENERATE
a(i+1) <= (a(i)+1) when (x(i)='0')
else
a(i);
END GENERATE;
y <= a(N-1);
end Behavioral;
試驗檯:
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.std_logic_unsigned.all;
ENTITY Count_ones_TB IS
END Count_ones_TB;
ARCHITECTURE behavior OF Count_ones_TB IS
COMPONENT Count_ones
PORT(
x : IN std_logic_vector(7 downto 0);
y : OUT std_logic_vector(0 to 3)
);
END COMPONENT;
--Inputs
signal x : std_logic_vector(7 downto 0) := (others => '0');
--Outputs
signal y : std_logic_vector(0 to 3);
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: Count_ones PORT MAP (
x => x,
y => y
);
stim_proc: process
begin
x <= "00010101";
wait for 100 ns;
x <= "00001001";
wait for 100 ns;
x <= "11111111101"
wait for 100ns;
-- insert stimulus here
wait;
end process;
END;
該錯誤是
實體端口x不與組件端口 實體端口Y的類型std_logic_vector匹配不與部件端口的類型std_logic_vector匹配
請幫助我,我真的不知道如何解決這個問題。
您有三個位置的構造錯誤的字符串文字,使用單引號而不是雙引號。這些字符串值的第三個太長。 'x <=「00010101」; - '00010101';','x <=「00001001」; - 00001001'; '和'x <=「11111101」; - '11111111101'(注意它也缺少終止賦值語句的分號)。 「//」不是註釋分隔符(而「 - 」是)。 – user1155120
我得到了這個---實體端口x與組件端口的類型std_logic_vector不匹配,而實體端口y與組件端口的類型std_logic_vector不匹配。 –
當我嘗試模擬wave時,我嘗試將std_logic_vector更改爲std_logic,但它仍然不起作用。非常感謝。 –