VHDL - "从不使用输入警告"

时间:2015-10-31 23:39:59

标签: if-statement input vhdl xilinx synthesis

我用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;

1 个答案:

答案 0 :(得分:5)

问题是,重置是以not (rising_edge(CLK_1Hz) and button = '1')为条件的,而Xilinx XST工具无法弄清楚如何将其映射到FPGA硬件。

VHDL是硬件描述语言(VHDL的HDL部分),所以不要把它想象成编写另一个程序(例如在C或Python中),而是将其视为描述电路。

将VHDL代码转换为硬件是一项复杂的任务,Xilinx希望设计人员使用某些模式,如&#34; XST硬件描述语言中所述 (HDL)编码技术&#34;的Xilinx XST User Guide。第一个代码部分不遵循任何这些模式,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,而是改为使用增量使能信号,因为每个时钟都需要特殊的处理和资源。