无法推断Quartus II中的寄存器(VHDL)

时间:2011-11-18 20:38:19

标签: vhdl intel-fpga quartus

这是完整的代码

library ieee;
use ieee.std_logic_1164.all;

entity move_key_detector is
    PORT(
        clk : IN STD_LOGIC;
        done : IN STD_LOGIC;
        hex : IN STD_LOGIC_VECTOR(7 DOWNTO 0);
        up, down : out std_logic
    );
END move_key_detector;

architecture arch of move_key_detector is

    type statetype is (IDLE, RECEIVED_BREAK);
    signal next_state, current_state : statetype :=IDLE;

begin

process (Clk) begin
    if(rising_edge(Clk)) then
        current_state <= next_state;
    end if;
end process;


process(done) begin
next_state <= current_state;
    case current_state is
        when IDLE=>
            if(done = '1') then
                if (hex = "00011101") then up <= '1';
                elsif(hex = "00011011") then down <= '1';
                --check to see if a break code is sent
                elsif (hex = "11110000") then next_state <= RECEIVED_BREAK; 
                end if;
            end if;
        when RECEIVED_BREAK=>
            if(done ='1') then
                if (hex = "00011101") then up <= '0';
                elsif(hex="00011011") then down <= '0';
                end if;
                next_state <= IDLE;
            end if;
        end case;
end process;

错误是:

  

错误(10821):move_key_detector.vhd(31)中的HDL错误:无法推断寄存器为“down”,因为其行为与任何支持的寄存器模型都不匹配

     

Info(10041):move_key_detector.vhd(29)中“down”的推断锁存器

     

错误(10821):move_key_detector.vhd(31)处的HDL错误:无法推断寄存器为“up”,因为其行为与任何支持的寄存器模型不匹配

     

Info(10041):move_key_detector.vhd(29)的“up”推断锁存器

     

错误(10818):无法在move_key_detector.vhd(41)中推断“next_state”的寄存器,因为它没有在时钟边缘之外保持其值

     

错误(10818):无法在move_key_detector.vhd(33)推断出“next_state”的寄存器,因为它没有在时钟边缘之外保持其值

我遇到了这种错误。我按照这个recommendation阅读了HDL手册,我仍然不知道如何解决这个问题。

任何人都可以帮助我吗?非常感谢你!

1 个答案:

答案 0 :(得分:2)

为什么你有第二个过程?看起来它包含了异步代码。

如果您需要该过程以便可以使用if和case构造,则需要将任何可能影响所需输出的内容放入过程敏感性列表中(即:done AND current_state&amp; hex)

您还可能为next_state分配两个不同的值,这在定位FPGA时通常是一件坏事。我建议在case语句中移动“next_state&lt; = current_state”并明确指定case / if语句的所有分支中的所有术语(我猜测你对行为的期望有点,但是你应该得到总体思路):

case current_state is
    when IDLE=>
        if(done = '1') then
            if (hex = "00011101") then 
                up <= '1';
                down <= '0';
                next_state <= current_state;
            elsif(hex = "00011011") then 
                up <= '0';
                down <= '1';
                next_state <= current_state;
            --check to see if a break code is sent
            elsif (hex = "11110000") then 
                up <= '0';
                down <= '0';
                next_state <= RECEIVED_BREAK; 
            ...

如果您打算生成异步逻辑,也可以在进程外使用选定的信号分配。

如果您真的想要推断上/下/下一个状态信号的锁存器,您需要更明确地了解您想要发生的事情,无论是直接在您的代码中还是在您的问题中,我们都可以提供帮助你。