对象已使用但未声明

Object is used but not declared

我知道这是一个相当普遍的问题。无论如何,在浏览论坛后,对于给定的 VHDL 代码,我无法找到关于为什么我会收到以下 CT 错误的满意答案。你能帮帮我吗?

VHDL代码

library IEEE;
use IEEE.std_logic_1164.all;
entity design is
port(clk:IN std_logic;
reset:IN std_logic;
A:IN std_logic;
B:IN std_logic;
Q:OUT std_logic);
end design;

architecture behave of design is
--signal R0,R1,R2,R3,R4:std_logic;
begin
process(clk,reset)
variable R0,R1,R2,R3,R4:std_logic;
begin
if (reset='1') then
R0:='0';
R1:='0';
R2:='0';
R3:='0';
R4:='0';
elsif falling_edge(clk) then
R0:=R4;
R1:=R0 xor A;
R2:=R1 xor B;
R3:=R2;
R4:=R2 xor R3;
end if;
end process;
Q<=R4;       -- ERROR POINTED HERE
end behave;

错误:-

Error (10482): VHDL error at design.vhd(31): object "R4" is used but not declared

是否有我缺少的将变量分配给端口的正确方法?

R4 在您的流程的声明区域中声明为变量。它在你的过程之外是不可见的,所以你的工具给了你你给出的错误。如果在进程中移动 Q<=R4; 行,在 end if; 之后,错误应该消失,因为此时变量仍然可见。

话虽如此,我认为您的代码不会如您所愿。我看到您开始使用 signal 来表示 R1 等。您应该避免使用 variable,直到您很好地理解信号和变量之间的差异。还有其他现有问题可以解决这个问题。

R4 是您在代码中声明的变量。它不能在 endif statement.So 之外使用,这就是为什么你的设备给你一个错误信息。要消除此错误,您可以在 Q<=R4 之外和 endif 语句内再次声明 R4。