2013-05-29 35 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