libraryieee;
useieee.std_logic_1164.all;
entityyou is定義實體
port(clk,din:in std_logic;系統時鐘和開關里程輸入脈沖
dout:out std_logic );輸出信號
endyou;
architecturertl of you is定義結構體
signalx,y:std_logic;定義兩個中間標準邏輯信號
begin
process(clk) 進程
begin
if clk'event and clk='1' then 判斷是否為上升沿
x<=din; 變量賦值
y<=x;
end if;
dout<=x and (not y); 去抖動
end process;
end rtl;
該模塊的的核心部分在于
if clk'event and clk='1' then
x<=din; y<=x;
end if;
dout<=x and (not y);
這是一個同步整形電路,在進程中,信號不是在改變值之后立即變化的,其他語句使用的還是該信號的舊值(未執行進程時的值),所以假設y=0,那么在時鐘的上升沿:
如果:
din="1"小于一個時鐘寬:則有x=1,y=0(雖然進程中改變了值,但不會立即被使用);
則有dout=x and (not y)=1 and (not 0)=1;
如果:
din="1"超過一個時鐘寬:則有x=1,y=1(前次執行進程后,y的值已經改變為‘1’了);
則有dout=x and (not y)=1 and (not 1)=0;
如果din在時鐘周期內出現抖動,則因為不執行進程,所以輸出無影響,還是被整成一個時鐘寬度,所以不管是長按還是短按你的鍵,有效高電平寬度等于時鐘。
|