2013-05-29 34 views
0

我有一个关于我的VHDL代码的问题。该代码适用于机器人,应该能够检测到矿山。这段代码是这个特定探雷器的代码。 teller_sensor进程不起作用。我知道,因为它将被编程在FPGA芯片上,所以你只能有一个时钟。但我不知道该怎么做才能使这个过程奏效。我希望你们愿意帮助我:)VHDL误解时钟

罗伯托

下面是代码:

LIBRARY IEEE; 
USE IEEE.std_logic_1164.ALL; 
use IEEE.numeric_std.all; 
library ieee; use ieee.numeric_std.all; 

entity metaal_detector is 
port (clk : in std_logic; 
     sensor : in std_logic; 
     reset : in std_logic; 
     metaal : out std_logic 
); 
end entity metaal_detector; 

architecture behavioural of metaal_detector is 
signal count, count_sensor, stand, clock1, sensor1, stand1 : unsigned (10 downto 0); 
signal reset_teller, resets, metaals: std_logic; 

begin 

teller_clk: process (clk) 
begin 
if rising_edge(clk) then 
    if ((reset ='1') or (resets = '1')) then 
    count <= (others => '0'); 
    else 
    count <= count + 1; 
    end if; 
end if; 
end process; 


teller_sensor: process (sensor) 
begin 
if rising_edge(clk) then 
    if ((reset ='1') or (resets = '1')) then 
    count_sensor <= (others => '0'); 
    else 
    if (sensor'event and sensor='1') then 
     count_sensor <= count_sensor + 1; 
    end if; 
    end if; 
end if; 
end process; 


process(clk) 
begin 
if (unsigned(clock1) = 71) then 
    stand <= clock1; 
    reset_teller <= '1'; 
else 
    reset_teller <= '0'; 
    stand <= stand; 
end if; 
end process; 

process(clk) 
begin 
if (unsigned(stand1) < 70) then 
    metaals <= '1'; 
else 
    metaals <= '0'; 
end if; 
end process; 


clock1 <= count; 
sensor1 <= count_sensor; 
stand1 <= stand; 
resets <= reset_teller; 
metaal <= metaals; 

end architecture behavioural; 

回答

1

在过程上指定CLK,而不是传感器。然后在内部采样传感器的状态,也就是说在感兴趣的时钟边缘。

这种方法不是没有理论问题(亚稳态,取样理论),但它可能会让你走上一定程度的功能。

现在没有任何反应,因为它只有在传感器的变化触发进程的同时恰好出现了clk的上升沿时才会发生。在很少见的硬件中(并且在边缘检测器是时钟输入一部分的典型模块中无法实现) - 在模拟中,这可能是不可能的(您将不得不阅读详细的语言和模拟器规则),但无论在任何情况下它会做你需要的吗?

+0

感谢您的回答克里斯。我在灵敏度列表中将传感器切换为时钟。但是,我并不真正理解你的意思,“然后在内部采样传感器的状态,也就是在感兴趣的时钟边缘采样”。你能解释一下吗? – Earless