我正在使用VHDL和Nexys 2 FPGA在Xilinx webpack工作,并且我正在尝试制作模块化代码。所以我的项目包含3个短文件:main.vhd,Adder_4bit.vhd和constraints.ucf。我的代码编译得很好,但LED 6亮起,没有任何响应开关的任何变化,就像它应该的那样。这是我的文件:
main.vhd
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity main is
Port ( switches : in STD_LOGIC_VECTOR (7 downto 0);
LEDs : out STD_LOGIC_VECTOR (7 downto 0));
end main;
architecture Behavioral of main is
COMPONENT Adder_4bit
PORT(
x : IN std_logic_vector(3 downto 0);
y : IN std_logic_vector(3 downto 0);
cin : IN std_logic;
cout : OUT std_logic;
sum : OUT std_logic_vector(3 downto 0);
gp : OUT std_logic;
gg : OUT std_logic
);
END COMPONENT;
signal zero : STD_LOGIC;
begin
Inst_Adder_4bit: Adder_4bit PORT MAP(
x => switches(7 downto 4),
y => switches(3 downto 0),
cin => zero,
cout => LEDs(7),
sum => LEDs(3 downto 0),
gp => LEDs(6),
gg => LEDs(5)
);
LEDs(4) <= '0';
end Behavioral;
Adder_4bit.vhd
-- 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 primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity Adder_4bit is
Port ( x : in STD_LOGIC_VECTOR (3 downto 0);
y : in STD_LOGIC_VECTOR (3 downto 0);
cin : in STD_LOGIC;
cout : out STD_LOGIC;
sum : out STD_LOGIC_VECTOR (3 downto 0);
gp : out STD_LOGIC;
gg : out STD_LOGIC);
end Adder_4bit;
architecture Behavioral of Adder_4bit is
signal p : STD_LOGIC_VECTOR (3 downto 0);
signal g : STD_LOGIC_VECTOR (3 downto 0);
signal iCarry : STD_LOGIC_VECTOR (4 downto 0);
begin
p <= x or y;
g <= x and y;
iCarry(0) <= cin;
iCarry(1) <= g(0) or (p(0) and iCarry(0));
iCarry(2) <= g(1) or (p(1) and iCarry(1));
iCarry(3) <= g(2) or (p(2) and iCarry(2));
iCarry(4) <= g(3) or (p(3) and iCarry(3));
sum(0) <= x(0) xor y(0) xor iCarry(0);
sum(1) <= x(1) xor y(1) xor iCarry(1);
sum(2) <= x(2) xor y(2) xor iCarry(2);
sum(3) <= x(3) xor y(3) xor iCarry(3);
cout <= iCarry(4);
gp <= p(0) and p(1) and p(2) and p(3);
gg <= g(3) or (g(2) and p(3)) or (g(1) and p(2) and p(3)) or (g(0) and p(1) and p(2) and p(3));
end Behavioral;
最后是constraints.ucf
NET switches(7) LOC = "R17";
NET switches(6) LOC = "N17";
NET switches(5) LOC = "L13";
NET switches(4) LOC = "L14";
NET switches(3) LOC = "K17";
NET switches(2) LOC = "K18";
NET switches(1) LOC = "H18";
NET switches(0) LOC = "G18";
NET LEDs(7) LOC = "R4";
NET LEDs(6) LOC = "F4";
NET LEDs(5) LOC = "P15";
NET LEDs(4) LOC = "E17";
NET LEDs(3) LOC = "K14";
NET LEDs(2) LOC = "K15";
NET LEDs(1) LOC = "J15";
NET LEDs(0) LOC = "J14";
#NET LCD_a0 LOC = "F17";
#NET LCD_a1 LOC = "H17";
#NET LCD_a2 LOC = "C18";
#NET LCD_a3 LOC = "F15";
#NET LCD_A LOC = "L18";
#NET LCD_B LOC = "F18";
#NET LCD_C LOC = "D17";
#NET LCD_D LOC = "D16";
#NET LCD_E LOC = "G14";
#NET LCD_F LOC = "J17";
#NET LCD_G LOC = "H14";
#NET LCD_DP LOC = "C17";
#NET clock LOC = "B8";
#NET "clock" TNM_NET = clock;
#TIMESPEC TS_clk = PERIOD "clock" 4 ns HIGH 50%;
提前致谢。
答案 0 :(得分:0)
我现在无法访问合成器,但我认为问题在于您尚未初始化零值。
当未定义信号时,优化器可能会优化你不想要的东西。
尝试声明零信号不变或将cin接线为'0'。
(我刚刚发表评论,但似乎你需要更多的代表才能做到这一点)
答案 1 :(得分:0)
我找到了问题的答案。事实证明,Xilinx ISE生成了两个位文件,每个VHD文件一个。所以我的项目文件夹中有一个Adder_4bit.bit和一个main.bit文件。在我的代码中,Adder_4bit在main中实例化,因此我需要将main.bit上传到我的FPGA中,但我上传了Adder_4bit.bit文件,这个文件对我来说很有意义,因为我的项目也称为Adder_4bit。
简而言之,请确保上传主位文件而不是组件位文件。