VHDL 错误 "Process clocking is too complex."

VHDL error "Process clocking is too complex."

大家好,我最近开始用 VHDL 编码(这里的代码是 T 触发器),我遇到了一个错误 "Process clocking is too complex",这是下面附上的第一个代码,令人惊讶的是我解决方案也是。但我不知道它是如何工作的,没有错误的代码是第二个代码。我用谷歌搜索了半小时的错误,但找不到令人满意的原因。请帮忙。

第一个密码:

LIBRARY ieee;
USE ieee.std_logic_1164.all;

ENTITY t_ff IS
    PORT(t,clk,rst:IN STD_LOGIC;
         q,q_bar:OUT STD_LOGIC);
END t_ff;

ARCHITECTURE t_ff OF t_ff IS
SIGNAL temp: STD_LOGIC;
BEGIN
    PROCESS(clk,rst)
    BEGIN
        IF(clk='1' AND clk'event)THEN
            IF(t='1')THEN temp<= NOT temp;
            END IF;
        ELSIF(rst='1')THEN temp<='0';
        END IF;
        q<= temp;
        q_bar<= NOT temp;
    END PROCESS;
END t_ff;

第二个密码:

LIBRARY ieee;
USE ieee.std_logic_1164.all;

ENTITY t_ff IS
    PORT(t,clk,rst:IN STD_LOGIC;
         q,q_bar:OUT STD_LOGIC);
END t_ff;

ARCHITECTURE t_ff OF t_ff IS
SIGNAL temp: STD_LOGIC;
BEGIN
    PROCESS(clk,rst)
    BEGIN
        IF(rst='1')THEN temp<='0';
        ELSIF(clk='1' AND clk'event)THEN
            IF(t='1')THEN temp<= NOT temp;
            END IF;
        END IF;
        q<= temp;
        q_bar<= NOT temp;
    END PROCESS;
END t_ff;

原因很简单。但首先我们需要更改您的代码:

这两个版本都没有描述 T 触发器的行为;两者都描述了至少 2 个(如果不是 3 个)触发器的行为。这是因为

every signal assignment in a clocked process infers a flip-flop

每个进程中有 3 个信号分配 - tempqq_bar - 所以你将得到 3 个触发器(虽然 1 个是多余的,所以可能是被你的合成器优化掉了)。所以,首先,如果你想保证你只有一个触发器,你需要重写每个过程,以便其中只包含一个信号分配。

重写第一个过程没有意义,因为其他原因是错误的 - 稍后见。第二个过程应该改写成这样:

PROCESS(clk,rst)
BEGIN
    IF (rst='1') THEN temp<='0';
    ELSIF (clk='1' AND clk'event) THEN
        IF (t='1') THEN temp <= NOT temp;
        END IF;
    END IF;
END PROCESS;

q <= temp;
q_bar <= NOT temp;

换句话说,您需要将作业移至进程外的 qq_bar。您的第二个版本的这个新版本描述了具有异步复位的 T 型触发器的行为:

if the reset is asserted then reset the flip-flop; otherwise, if the T input is asserted at the rising edge of the clock, then invert the flip-flop

如果我重写了你的第一个版本,它会描述一些不存在的电子元件的行为,所以它无法被合成。没有这种行为的触发器:

if the T input is asserted at the rising edge of the clock, then invert the flip-flop; otherwise, if the reset is asserted then reset the flip-flop

您可以描述一个带有 同步 复位的 T 型触发器:

at the rising edge of the clock: if the reset is asserted then reset the flip-flop, otherwise, if the T input is asserted at the rising edge of the clock, then invert the flip-flop

像这样

PROCESS(clk)
BEGIN
    IF (clk='1' AND clk'event) THEN
        IF (rst='1') THEN temp<='0';
        ELSIF (t='1') THEN temp <= NOT temp;
        END IF;
    END IF;
END PROCESS;

q <= temp;
q_bar <= NOT temp;

最后,您使用的是一种相当老式的编码风格。我建议使用 rising_edge 函数。你的括号也是多余的。有经验的 VHDL 代码会像这样编写您的第二个版本:

PROCESS(clk,rst)
BEGIN
    IF rst='1' THEN temp<='0';
    ELSIF rising_edge(clk) THEN
        IF t='1' THEN temp<= NOT temp;
        END IF;
    END IF;
END PROCESS;    

q <= temp;
q_bar <= NOT temp;