VHDL rising_edge 函数改为使用下降沿?
VHDL rising_edge function instead uses falling edge?
一段时间以来,我一直在尝试编写一个模拟切换触发器。我在这里找不到我的代码有什么问题,但由于某种原因,当我模拟它时,输出在时钟的下降沿而不是上升沿切换。有没有我漏掉的错误?
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity TFF is
Port (EN, T, CLK : in std_logic;
Q : out std_logic);
end TFF;
architecture Behavioral of TFF is
signal temp_q : std_logic := '0';
begin
proc1 : process (EN, T, CLK)
begin
if EN = '1' then
if rising_edge(CLK) then
if T = '1' then temp_q <= (not temp_q);
else temp_q <= temp_q; end if;
end if;
else Q <= temp_q; end if;
Q <= temp_q;
end process proc1;
end Behavioral;
它在下降沿切换,因为在 rising_edge 中它使用 temp_q
的旧值(请记住,分配给信号不是立即完成的,它是按计划进行的,并在最后完成过程的),并且因为你在 rising_edge()
if 之外进行了赋值,所以它是在下降沿完成的。
你不应该在 rising_edge()
之外有任何东西。每次时钟边沿发生变化时都会启动此过程,下降沿也会启动。除了敏感度列表中的 CLK 之外,您也不需要任何东西。分配给 Q
也不必在进程中完成 - 它可以同时完成。您还可以将 temp_q <= temp_q;
移动到流程主体的开头,因此它将始终被安排,如果是 T = '0'
则它将被倒置。最后,您应该首先检查 rising_edge,然后检查时钟启用。
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity TFF is
Port (EN, T, CLK : in std_logic;
Q : out std_logic);
end TFF;
architecture Behavioral of TFF is
signal temp_q : std_logic := '0';
begin
Q <= temp_q;
proc1 : process (CLK)
begin
if rising_edge(CLK) then
if EN = '1' then
temp_q <= temp_q;
if T = '1' then
temp_q <= not temp_q;
end if;
end if;
end if;
end process proc1;
end Behavioral;
只要进程被调用,您就会分配 Q <= temp_q
,这意味着敏感度列表中的信号之一会发生变化。这意味着您分别在时钟的上升沿分配 temp_q <= not(temp_q)
或 temp_q <= temp_q
,然后在下降沿将该值分配给 Q,因为这是下一次处理 运行 时。合成时看起来更奇怪,因为它是异步的。
我不是百分百确定你想要实现什么。如果你想要一个完整的同步设计,那么你的 if rising_edge(CLK)
应该是最上面的 IF 语句。此外,灵敏度列表中不需要 T 信号,因为此信号的变化不会直接影响任何输出信号。
一段时间以来,我一直在尝试编写一个模拟切换触发器。我在这里找不到我的代码有什么问题,但由于某种原因,当我模拟它时,输出在时钟的下降沿而不是上升沿切换。有没有我漏掉的错误?
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity TFF is
Port (EN, T, CLK : in std_logic;
Q : out std_logic);
end TFF;
architecture Behavioral of TFF is
signal temp_q : std_logic := '0';
begin
proc1 : process (EN, T, CLK)
begin
if EN = '1' then
if rising_edge(CLK) then
if T = '1' then temp_q <= (not temp_q);
else temp_q <= temp_q; end if;
end if;
else Q <= temp_q; end if;
Q <= temp_q;
end process proc1;
end Behavioral;
它在下降沿切换,因为在 rising_edge 中它使用 temp_q
的旧值(请记住,分配给信号不是立即完成的,它是按计划进行的,并在最后完成过程的),并且因为你在 rising_edge()
if 之外进行了赋值,所以它是在下降沿完成的。
你不应该在 rising_edge()
之外有任何东西。每次时钟边沿发生变化时都会启动此过程,下降沿也会启动。除了敏感度列表中的 CLK 之外,您也不需要任何东西。分配给 Q
也不必在进程中完成 - 它可以同时完成。您还可以将 temp_q <= temp_q;
移动到流程主体的开头,因此它将始终被安排,如果是 T = '0'
则它将被倒置。最后,您应该首先检查 rising_edge,然后检查时钟启用。
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity TFF is
Port (EN, T, CLK : in std_logic;
Q : out std_logic);
end TFF;
architecture Behavioral of TFF is
signal temp_q : std_logic := '0';
begin
Q <= temp_q;
proc1 : process (CLK)
begin
if rising_edge(CLK) then
if EN = '1' then
temp_q <= temp_q;
if T = '1' then
temp_q <= not temp_q;
end if;
end if;
end if;
end process proc1;
end Behavioral;
只要进程被调用,您就会分配 Q <= temp_q
,这意味着敏感度列表中的信号之一会发生变化。这意味着您分别在时钟的上升沿分配 temp_q <= not(temp_q)
或 temp_q <= temp_q
,然后在下降沿将该值分配给 Q,因为这是下一次处理 运行 时。合成时看起来更奇怪,因为它是异步的。
我不是百分百确定你想要实现什么。如果你想要一个完整的同步设计,那么你的 if rising_edge(CLK)
应该是最上面的 IF 语句。此外,灵敏度列表中不需要 T 信号,因为此信号的变化不会直接影响任何输出信号。