【发布时间】:2016-07-09 06:12:03
【问题描述】:
我的代码有以下简化示例,其中可以模拟 DeltasTest 实体以显示问题。实际设计中的时钟是倒置的,或者不是基于泛型的,而是为低于该泛型的其他几个实体提供数据。
问题在于简单的边缘检测器在行为模拟中不起作用(data_out 只是一个小故障),这是由于反转阶段在时钟上引入了增量周期延迟。有没有标准或其他优雅的方法来解决这个问题?
到目前为止,我最好的解决方案是将data_in 信号分配给另一个信号,使其具有与clk 相同的增量周期延迟。我想过使用一个函数来根据需要根据泛型作为函数的第二个参数来反转时钟,但是时钟在很多地方都使用过,这看起来不是很优雅,我注意到它甚至可以解决问题。紧抓着稻草,我还尝试将时钟反转分配设为transport 分配,但正如预期的那样,这没有任何区别。
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Deltas is
Generic (
CLK_INVERT : boolean := false
);
Port (
clk : in std_logic;
data_in : in std_logic
);
end Deltas;
architecture Behavioral of Deltas is
-- Signals
signal data_reg : std_logic := '0';
signal clk_inverted : std_logic := '0';
signal data_out : std_logic := '0';
begin
ClkInvert : if (CLK_INVERT) generate
clk_inverted <= not clk;
else generate
clk_inverted <= clk;
end generate;
process (clk_inverted)
begin
if (rising_edge(clk_inverted)) then
data_reg <= data_in;
end if;
end process;
process (data_reg, data_in)
begin
if (data_reg /= data_in) then
data_out <= '1';
else
data_out <= '0';
end if;
end process;
-- Other entities use `clk_inverted`. Commented out so that this example compiles
--LowerEntity : entity work.Counter
--port map (
-- clk => clk_inverted
--);
end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity DeltasTest is
end DeltasTest;
architecture Behavioral of DeltasTest is
signal clk : std_logic := '0';
signal data_in : std_logic := '0';
begin
clk <= not clk after 10 ns;
process (clk)
variable count : integer := 0;
begin
if (rising_edge(clk)) then
count := count + 1;
if (count = 4) then
count := 0;
data_in <= not data_in;
end if;
end if;
end process;
uut : entity work.Deltas
Port map (
clk => clk,
data_in => data_in
);
end Behavioral;
【问题讨论】:
-
两个问题:1)为什么不在
Deltas中使用falling_edge(),而不是生成一个带有增量延迟的clk_inverted,然后在此使用rising_edge()? 2) 为什么data_in上的刺激不是基于clk生成的,就像在实际设计中那样,而不仅仅是基于时间?改变这将使边缘检测器工作。如果需要反转时钟,则在 clk 之外的顶层进行此操作,并通过层次结构进行分配。 -
@MortenZilmer 感谢 cmets。 1)我没有使用
falling_edge(),因为时钟极性取决于通用。 2)数据信号实际上是由clk生成的,但这最终没有任何区别,因为我的示例与我的真实代码并不完全相同。我将更新示例以包含您的更改。 -
您可能会在electronics.stackexchange.com找到更多的受众
标签: vhdl simulation