我在CheckSyntax期间遇到以下代码的错误,我试过了。错误说:
"Line 48. parse error, unexpected VARIABLE Line 53. Undefined symbol 'InOutDetector'.
Line 57. InOutDetector: Undefined symbol (last report in this block)".
你能让我知道我该如何解决这个问题?
这是我的代码的图片,因为我无法粘贴它。 https://www.dropbox.com/s/ay8pjq4ojoep6ry/RoomLightController.png?dl=0
entity Room_Light_Controller is
port (
clk, sA, sB: IN STD_LOGIC;
sL: OUT STD_LOGIC
);
end Room_Light_Controller;
architecture Behavioral of Room_Light_Controller is
-- assuming sensors are variables sA and sB, and lights switch is sL
SIGNAL People : INTEGER:=0;
SIGNAL AllowNextCount : BIT:='0';
--unsigned int People=0; -- counter for people inside the room
--char AllowNextCount=0; -- boolean indicating if allowing next count or not
--short int InOutDetector; -- 1 = entering; -1 = exiting
begin
variable InOutDetectorDetector: integer;
process (clk)
begin
if ((sA = '0') and (sB = '1')) then
-- entering
InOutDetector := 1;
end if;
if ((sA = '1') and (sb = '0')) then
-- exiting
InOutDetector := -1;
end if;
if ((sA ='1') and (sB = '1') and (AllowNextCount = '1')) then
-- only when both sensors are touched validate the people counter
People := People+InOutDetector;
-- count once then block counting until the same person has finished entering/exiting
AllowNextCount <= '0';
end if;
if ((sA = '0') and (sB = '0')) then
-- it gets 0;0 only when someone has finished entering/exiting
-- pr at turn on; so now allow to counting again
AllowNextCount <= '1';
end if;
if (People > 0) then
sL <= '1'; -- Turn/keep lights on as long as People greater than 0
else
sL <= '0'; -- otherwise, turn them off
end if;
end process;
end Behavioral;
答案 0 :(得分:1)
在进程中声明变量并将其重命名为(InOutDetector)。您在流程中使用了(InOutDetector)。
然后,如果您想在clk上升沿运行该过程,请完成您的过程,例如以下代码:
process(clk)
variable InOutDetector : integer;
begin
if clk = '1' and clk'event then
-- your code
end if;
end process;
但是,如果您不想使用clk上升沿,只需使用您读取的参数完成灵敏度列表或在流程中检查它(sA,sB,AllowNextCount,People)并从流程中删除clk敏感度清单。
还要注意不完整的if语句。锁存器可能来自不完整的case或if语句。
答案 1 :(得分:1)
除了错误Amir注意到名称不匹配并且变量声明在错误的位置,分配给People
时还有一个错误:
library ieee;
use ieee.std_logic_1164.all;
entity Room_Light_Controller is
port (
clk, sA, sB: in std_logic;
sL: out std_logic
);
end entity Room_Light_Controller;
architecture Behavioral of Room_Light_Controller is
-- assuming sensors are variables sA and sB, and lights switch is sL
signal people: integer := 0;
signal allownextcount: bit := '0';
--unsigned int People=0; -- counter for people inside the room
--char AllowNextCount=0; -- boolean indicating if allowing next count or not
--short int InOutDetector; -- 1 = entering; -1 = exiting
begin
-- variable InOutDetectorDetector: integer;
process (clk)
variable InOutDetector: integer; -- as per Amir
begin
if sA = '0' and sB = '1' then
-- entering
InOutDetector := 1;
end if;
if sA = '1' and sb = '0' then
-- exiting
InOutDetector := -1;
end if;
if sA ='1' and sB = '1' and AllowNextCount = '1' then
-- only when both sensors are touched validate the people counter
People <= People + InOutDetector; -- was :=, signal assignment
-- count once then block counting until the same person has finished entering/exiting
AllowNextCount <= '0';
end if;
if sA = '0' and sB = '0' then
-- it gets 0;0 only when someone has finished entering/exiting
-- pr at turn on; so now allow to counting again
AllowNextCount <= '1';
end if;
if People > 0 then
sL <= '1'; -- Turn/keep lights on as long as People greater than 0
else
sL <= '0'; -- otherwise, turn them off
end if;
end process;
end architecture Behavioral;
People
是一个信号,需要信号分配符号(<=
)而不是变量赋值符号(:=
)。
在两次更改之后,VHDL设计规范进行了分析和阐述。
注意添加了一个context子句,使你的代码成为一个Minimal,Verifiable和Complete示例。
另请参阅帮助中心网页Minimal, Complete, and Verifiable example 最小和可读部分,
..使用一致的命名和缩进,并在需要时包含注释以解释部分代码。
如果要编译此代码,则可能需要约束整数。
为了执行效率,可以使用elsif合并所有独立的if语句。这在小型设计中几乎不是问题,但为sA
和sB
描述的二进制模式是互斥的(对于类型std_logic而言并非详尽无遗)。
您忽略了提供完整的错误消息,这些消息似乎是从XST输出的。从历史上看,推荐的设计流程包括仿真,如果没有其他目的,则可以从VHDL分析中提供更好的语法错误消息。
XST历来假定您正在处理一个没有语法错误的设计描述,并且在提供足够的错误消息方面非常明显。
错误消息前缀(例如ERROR:HDLParsers:1209)可以告诉您如何通过Xilinx的支持站点和/或文档找到问题。