我正在尝试用VHDL对下面的电路进行编码,以避免在我的项目中出现亚稳态。

这是我到目前为止写的代码:
library ieee;
use ieee.std_logic_1164.all;
entity Metastability is
port ( clk : in std_logic;
key : in std_logic;
reset : in std_logic;
Led : out std_logic
);
end Metastability ;
architecture rtl of Metastability is
signal metastable : std_logic;
signal stabel : std_logic;
begin
process(clk,reset)
begin
if (reset ='1') then
metastable <= '0';
stabel <= metastable;
Led <= stabel;
else if rising_edge(clk) then
metastable <= key;
stabel <= metastable;
Led <= stabel;
end if;
end if;
end process;
end rtl;但是当我在modelsim中模拟它时,在两个时钟周期过去之前,stabel信号不会改变它的状态,并且一个额外的时钟周期使Led变成'1'。为什么会这样呢?

发布于 2017-11-11 01:15:46
有两个问题:
重置
在重置时,您希望将固定值(在编译时已知)分配给信号。所以你应该改变
重置if (
= '1') then stabel <=亚稳态;…
至
if (reset = '1') then
stabel <= '0';
…否则,在复位后的一个时钟周期结束之前,stabel不会处于定义状态。
错误的电路
您所显示的代码没有描述图片中的电路。相反,它描述了一个具有一个附加寄存器的电路:
key metastable stabel Led
,,,,,,, ,,,,,,, ,,,,,,,
---> | D Q | ------> | D Q | ------> | D Q | --->
| | | | | |
|> | |> | |> |
´´´´´´´ ´´´´´´´ ´´´´´´´您应该从时钟进程中删除对Led信号的赋值,而应进行并发赋值:
process(clk, reset)
begin
…
metastable <= … ;
stabel <= … ;
end process;
Led <= stabel;此外,还有两个小问题:
stable,而不是stabel (但至少您可以使用两个嵌套的if,将单个if与elsif一起使用:if (…= '1')则重置否则,如果为rising_edge(clk),则为…end if;end if;
变成了
if (…= '1')则重置elsif rising_edge(clk),然后是…end if;
https://stackoverflow.com/questions/47227532
复制相似问题