VHDL-"Input is never used warning"
VHDL - "Input is never used warning"
我用 VHDL(针对 Xilinx Spartan-6)编写了一个程序,它在按下一个按钮时递增一个计数器,并在按下另一个按钮时将其重置为零。
但是,我的过程为重置变量抛出错误 WARNING:Xst:647 - Input is never used. This port will be preserved and left unconnected...
- 尽管它既用于过程的敏感性又用作条件(与 button
,但不会被标记!)。
binary_proc : process(CLK_1Hz, button, reset) --include all inputs on sensitivity list
begin
if rising_edge(CLK_1Hz) and button = '1' then
binary <= binary + 1;
else if reset = '1' then
binary <= (others => '0');
end if;
end if;
end process;
但更奇怪的是,我可以通过简单地使用两个 if 语句而不是仅使用 if-else if 语句来解决此问题,如下所示;
binary_proc : process(CLK_1Hz, button, reset) --include all inputs on sensitivity list
begin
if rising_edge(CLK_1Hz) and button = '1' then
binary <= binary + 1;
end if;
if reset = '1' then
binary <= (others => '0');
end if;
end process;
我的问题是:为什么在使用 if-else 语句时重置变量在电路外优化,而在使用两个 if 语句时却没有?是什么原因造成的,如何避免呢?
非常感谢!
注意:程序的完整代码如下,以防有帮助!
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity button_press is
port(
CLK_200MHz : in std_logic;
button : in std_logic;
reset : in std_logic;
LED : out std_logic_vector(3 downto 0) --array of LED's
);
end button_press;
architecture Behavioral of button_press is
signal CLK_1Hz : std_logic; --input clock (think 200 MHz)
signal counter : std_logic_vector(26 downto 0); --counter to turn 200 MHz clock to 1 Hz
signal binary : std_logic_vector(3 downto 0); --binary vector thats mapped to LED's
begin
-----Create 1 Hz clock signal from 200 MHz system clock-------
prescaler : process(CLK_200MHz)
begin
if rising_edge(CLK_200MHz) then
if (counter < 2500000) then --possibly change to number in binary
counter <= counter + 1;
else
CLK_1Hz <= not CLK_1Hz; --toggle 1 Hz clock
counter <= (others => '0'); --reset counter to 0
end if;
end if;
end process;
------ Increment binary number when on rising clock edge when button pressed -------
binary_proc : process(CLK_1Hz, button, reset) --include all inputs on sensitivity list
begin
if rising_edge(CLK_1Hz) and button = '1' then
binary <= binary + 1;
end if;
if reset = '1' then
binary <= (others => '0');
end if;
end process;
LED <= binary; --map binary number to LED's
end Behavioral;
问题是,重置是 not (rising_edge(CLK_1Hz) and button = '1')
的条件,Xilinx XST 工具无法弄清楚如何将其映射到 FPGA 硬件。
VHDL 是一种硬件描述语言(VHDL 的 HDL 部分),所以不要将其视为编写另一个程序(例如在 C 或 Python 中),而是将其视为描述电路.
将 VHDL 代码转换为硬件是一项复杂的任务,Xilinx 希望设计人员使用一些模式,如“XST 硬件描述语言”中所述
Xilinx XST User Guide 的 (HDL) Coding Techniques”。第一个代码部分不遵循任何这些模式,XST 无法将其转换为硬件,因此出现警告。
按照那种编码风格,写法是:
process(CLK_1Hz, reset) is -- Don't include button, since sync. signal
begin
if reset = '1' then
binary <= (others => '0');
elsif rising_edge(CLK_1Hz) then
if button = '1' then
binary <= binary + 1;
end if;
end if;
end process;
顺便说一句。考虑不制作一个额外的时钟 CLK_1Hz
,而是制作一个增量使能信号,因为每个时钟都需要特殊的处理和资源。
我用 VHDL(针对 Xilinx Spartan-6)编写了一个程序,它在按下一个按钮时递增一个计数器,并在按下另一个按钮时将其重置为零。
但是,我的过程为重置变量抛出错误 WARNING:Xst:647 - Input is never used. This port will be preserved and left unconnected...
- 尽管它既用于过程的敏感性又用作条件(与 button
,但不会被标记!)。
binary_proc : process(CLK_1Hz, button, reset) --include all inputs on sensitivity list
begin
if rising_edge(CLK_1Hz) and button = '1' then
binary <= binary + 1;
else if reset = '1' then
binary <= (others => '0');
end if;
end if;
end process;
但更奇怪的是,我可以通过简单地使用两个 if 语句而不是仅使用 if-else if 语句来解决此问题,如下所示;
binary_proc : process(CLK_1Hz, button, reset) --include all inputs on sensitivity list
begin
if rising_edge(CLK_1Hz) and button = '1' then
binary <= binary + 1;
end if;
if reset = '1' then
binary <= (others => '0');
end if;
end process;
我的问题是:为什么在使用 if-else 语句时重置变量在电路外优化,而在使用两个 if 语句时却没有?是什么原因造成的,如何避免呢?
非常感谢!
注意:程序的完整代码如下,以防有帮助!
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity button_press is
port(
CLK_200MHz : in std_logic;
button : in std_logic;
reset : in std_logic;
LED : out std_logic_vector(3 downto 0) --array of LED's
);
end button_press;
architecture Behavioral of button_press is
signal CLK_1Hz : std_logic; --input clock (think 200 MHz)
signal counter : std_logic_vector(26 downto 0); --counter to turn 200 MHz clock to 1 Hz
signal binary : std_logic_vector(3 downto 0); --binary vector thats mapped to LED's
begin
-----Create 1 Hz clock signal from 200 MHz system clock-------
prescaler : process(CLK_200MHz)
begin
if rising_edge(CLK_200MHz) then
if (counter < 2500000) then --possibly change to number in binary
counter <= counter + 1;
else
CLK_1Hz <= not CLK_1Hz; --toggle 1 Hz clock
counter <= (others => '0'); --reset counter to 0
end if;
end if;
end process;
------ Increment binary number when on rising clock edge when button pressed -------
binary_proc : process(CLK_1Hz, button, reset) --include all inputs on sensitivity list
begin
if rising_edge(CLK_1Hz) and button = '1' then
binary <= binary + 1;
end if;
if reset = '1' then
binary <= (others => '0');
end if;
end process;
LED <= binary; --map binary number to LED's
end Behavioral;
问题是,重置是 not (rising_edge(CLK_1Hz) and button = '1')
的条件,Xilinx XST 工具无法弄清楚如何将其映射到 FPGA 硬件。
VHDL 是一种硬件描述语言(VHDL 的 HDL 部分),所以不要将其视为编写另一个程序(例如在 C 或 Python 中),而是将其视为描述电路.
将 VHDL 代码转换为硬件是一项复杂的任务,Xilinx 希望设计人员使用一些模式,如“XST 硬件描述语言”中所述 Xilinx XST User Guide 的 (HDL) Coding Techniques”。第一个代码部分不遵循任何这些模式,XST 无法将其转换为硬件,因此出现警告。
按照那种编码风格,写法是:
process(CLK_1Hz, reset) is -- Don't include button, since sync. signal
begin
if reset = '1' then
binary <= (others => '0');
elsif rising_edge(CLK_1Hz) then
if button = '1' then
binary <= binary + 1;
end if;
end if;
end process;
顺便说一句。考虑不制作一个额外的时钟 CLK_1Hz
,而是制作一个增量使能信号,因为每个时钟都需要特殊的处理和资源。