FPGA(VHDL) - 接收以太网数据包后LED闪烁

时间:2017-11-04 09:28:01

标签: vhdl

我使用的FPGA板与用于以太网数据包传输的Linux服务器盒相连。收到每10个数据包后,一个LED应闪烁一次,然后该过程将继续。这意味着如果我发送100个数据包,LED应闪烁10次。我已经分享了我试图运行的VHDL源代码,但它没有按照我想要的方式工作。任何帮助或建议都会非常感激。提前谢谢。



---------------------------------------------



library IEEE;

use IEEE.std_logic_1164.all;

use IEEE.std_logic_arith.all;

use IEEE.std_logic_unsigned.all;



---------------------------------------------



entity notification is 

port (clk: in std_logic;

      reset: in std_logic;

      dv: in std_logic;

      LED: out std_logic

	  );

end notification;

	  

architecture behavior of notification is

	  

signal packet_count: std_logic_vector (3 downto 0);

signal q: std_logic;



begin

process(clk)



begin

if reset = '1' then

 packet_count <= "0000";

elsif dv = '1' then

  if packet_count < "1010" then

     packet_count <= packet_count + 1;

     q <= '0';

  else 

     q <= '1';

     packet_count <= (others => '0');

  end if;

end if;



LED <= q;



end process;

end behavior;
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

您的代码包含几个我在下面解释的错误。您可能需要考虑阅读一些更基本的VHDL文献并进行教程,如this one

首先:您的流程不包含任何计时代码。你应该通过使你的过程看起来像这样使它成为时钟同步:

notification: process(clk)
begin
    if rising_edge(clk) then
          --<the code you already had>
    end if;
end process;

如果你想保持重置异步(这可能不是一个好主意,请阅读更多here),你可以将其更改为

notification: process(clk)
begin
    if reset = '1' then
          --<your reset conditions here>
    elsif rising_edge(clk) then
          --<the code you already had>
    end if;
end process;

您的代码的另一个问题是使用ieee.std_logic_arithieee.std_logic_unsigned不推荐使用这些库。与他们的名字不同,它们不是标准的IEEE库,你绝对不应该使用它们。相反,您应该使用ieee.numeric_std.all(更多here

但是,您的代码根本不需要使用ieee.numeric_std。您可以(并且可能应该为了更好的可读性)将您的packet_count声明为integer并将其与整数值进行比较,即

signal packet_count : integer range 0 to 10;
notification: process(clk)
begin
    if rising_edge(clk) then
         -- <all your other stuff>
         if packet_count = 10 then
             -- <whatever you want to do
         end if;
    end if;
end process;

整数曾经是合成工具的问题,但这是多年前的事了。这些天,你可以而且应该使用整数作为计数器之类的东西。