VHDL 解析错误,意外 DIV

VHDL parse error, unexpected DIV

我被要求显示键盘上按下次数最多的数字 这是显示

的唯一错误

ERROR:HDLParsers:164 - "D:/project/compartor.vhd" Line 37. parse error, unexpected DIV

这是第 37 行

if Int_Key = i  then

错误是什么意思?我该如何解决?

这是完整代码:

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use ieee.std_logic_arith.all;
---------------------------------------------------------------

entity compartor is
port
(
Key_out : in  std_logic_vector(3 downto 0);
clk,rst: in std_logic;
Winner: out std_logic_vector (3 downto 0)    
);
end compartor;

architecture Behavioral of compartor is

Type Data is array (0 to 15) of integer;
Signal Counters:Data:=(others=>0);
Signal Max:integer;
Signal MaxPlace:integer;
Signal INT_Key:integer:=conv_integer(Key_out);


begin


process (clk,rst)
begin
if (rst='1') then
Winner<= (others=>'0');

elsif (rising_edge(clk)) then


  for i in 0 to 15 loop
     if Int_Key = i  then   
       Counters(i)<= Counters(i)+1;
     end if;
  end loop;

Max <= Counters(0);
MaxPlace <= 0;
    for i in 0 to 15 loop 
      if (Counters(i) > Max) then 
        Max <= Counters(i);
    MaxPlace <= i;
      end if;
    end loop;

end if;
end process;
Winner<= conv_std_logic_vector (MaxPlace,4);

end Behavioral;

看不到该特定错误消息的原因,但代码还有其他问题。

Winners 输出端口在进程内和进程外都被驱动,因此具有多个驱动,Xilinx 综合工具不接受。

在声明中分配给 INT_Key,如:

Signal INT_Key:integer:=conv_integer(Key_out);

给出 INT_Key 和基于 Key_out 输入端口的初始值,这可能不是你想要的,所以考虑改为:

Signal INT_Key:integer;
...
INT_Key <= conv_integer(Key_out);

请注意,在进程中使用 <= 的信号分配不会使新值可用,直到下一次执行进程,例如在 Max <= Counters(0) 的情况下。这可能是你想要的,但它是 VHDL 初学者的常见陷阱。

即使 VHDL 不区分大小写,但对同一标识符使用不同的大小写也是糟糕的风格,就像您使用 INT_KeyInt_Key.

考虑缩进代码以遵循控制结构;这将为您节省大量调试工作并使代码更具可读性。

最后一个建议,为设计制作一个测试平台,并在尝试在硬件上实现它之前进行模拟 运行。进行这种额外的模拟工作实际上会让您更早完成,而不是更晚。