为什么程序看不到变量?
Why the procedure doesn't see the variable?
我正在使用 Xilinx ISE 创建 VHDL 项目。
我正在尝试将值添加到整数变量。
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity vending2_mod is
Port ( button1 : in STD_LOGIC;
button2 : in STD_LOGIC;
button3 : in STD_LOGIC;
button4 : in STD_LOGIC;
coin : in integer;
disp : out string(1 to 16);
prodOut : out integer);
shared variable credits : integer := 0;
procedure addCredits ( c : in integer ) is
begin
credits := credits + c; -- Signal is not defined : 'credits'.
end addCredits;
-- additional code
end vending2_mod;
architecture Behavioral of vending2_mod is
begin
acceptCredit: process (coin)
begin
addCredits(coin);
end process;
end Behavioral;
然而,当我尝试综合 (XST) 项目时,我在将其写为注释的行中遇到错误。 credits
不是一个信号,它是一个变量;是什么导致了错误?
保存没有错误,因为语法似乎是正确的。
Entity-statements must be -passive statements, that is, they must not
assign values to any signals.
- 不要使用共享变量。
- 在仿真中,变量在赋值后立即更新,而信号则相反,信号仅在仿真周期结束时更新。在组合代码中,信号立即取其分配的值。在顺序代码中,信号用于创建触发器,触发器本身不会立即获取其分配的值。
- 最好用signal+clock代替
试试这个:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity vending2_mod is
port(
Clock: in std_logic;
Reset: in std_logic;
coin : in integer;
prod_out : out integer
);
end vending2_mod;
architecture Behavioral of vending2_mod is
signal credits : integer := 0;
begin
process(Clock,Reset)
begin
if Reset='1' then
credits <= 0;
elsif(rising_edge(Clock)) then
credits <= credits + coin;
end if;
end process;
prod_out <= credits;
end Behavioral;
查看详细设计:
不要尝试这个(合成OK,注意:你需要clock
):
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity vending2_mod is
Port (
coin : in integer;
prod_out : out integer);
end vending2_mod;
architecture Behavioral of vending2_mod is
signal credits : integer := 0;
begin
credits <= credits + coin;
prod_out <= credits;
end Behavioral;
查看详细设计:
我正在使用 Xilinx ISE 创建 VHDL 项目。
我正在尝试将值添加到整数变量。
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity vending2_mod is
Port ( button1 : in STD_LOGIC;
button2 : in STD_LOGIC;
button3 : in STD_LOGIC;
button4 : in STD_LOGIC;
coin : in integer;
disp : out string(1 to 16);
prodOut : out integer);
shared variable credits : integer := 0;
procedure addCredits ( c : in integer ) is
begin
credits := credits + c; -- Signal is not defined : 'credits'.
end addCredits;
-- additional code
end vending2_mod;
architecture Behavioral of vending2_mod is
begin
acceptCredit: process (coin)
begin
addCredits(coin);
end process;
end Behavioral;
然而,当我尝试综合 (XST) 项目时,我在将其写为注释的行中遇到错误。 credits
不是一个信号,它是一个变量;是什么导致了错误?
保存没有错误,因为语法似乎是正确的。
Entity-statements must be -passive statements, that is, they must not assign values to any signals.
- 不要使用共享变量。
- 在仿真中,变量在赋值后立即更新,而信号则相反,信号仅在仿真周期结束时更新。在组合代码中,信号立即取其分配的值。在顺序代码中,信号用于创建触发器,触发器本身不会立即获取其分配的值。
- 最好用signal+clock代替
试试这个:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity vending2_mod is
port(
Clock: in std_logic;
Reset: in std_logic;
coin : in integer;
prod_out : out integer
);
end vending2_mod;
architecture Behavioral of vending2_mod is
signal credits : integer := 0;
begin
process(Clock,Reset)
begin
if Reset='1' then
credits <= 0;
elsif(rising_edge(Clock)) then
credits <= credits + coin;
end if;
end process;
prod_out <= credits;
end Behavioral;
查看详细设计:
不要尝试这个(合成OK,注意:你需要clock
):
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity vending2_mod is
Port (
coin : in integer;
prod_out : out integer);
end vending2_mod;
architecture Behavioral of vending2_mod is
signal credits : integer := 0;
begin
credits <= credits + coin;
prod_out <= credits;
end Behavioral;
查看详细设计: