Vhdl 如何使任何脉冲延迟2秒?
我写了一个VHDL代码来产生0.8us的脉冲。我的输入时钟是50Mhz。现在我想给这个脉冲一个2us的延迟Vhdl 如何使任何脉冲延迟2秒?,vhdl,vivado,Vhdl,Vivado,我写了一个VHDL代码来产生0.8us的脉冲。我的输入时钟是50Mhz。现在我想给这个脉冲一个2us的延迟 entity singlepulse is Port ( clk : in STD_LOGIC; Rst : in STD_LOGIC; P_out : out STD_LOGIC); end singlepulse; architecture Behavioral of singlepulse is signal cou
entity singlepulse is
Port ( clk : in STD_LOGIC;
Rst : in STD_LOGIC;
P_out : out STD_LOGIC);
end singlepulse;
architecture Behavioral of singlepulse is
signal count : Integer range 0 to 1000000000;
begin
process(clk, rst)
begin
if (rst = '1') then
P_out <= '0';
count <= 0;
elsif (rising_edge(clk)) then
count <= count + 1;
if (count < 40) then
P_out <= '1';
else
p_out <= '0';
end if;
elsif (falling_edge(clk)) then
if (count <= 40) then
p_out <= '1';
else
p_out <= '0';
end if;
end if;
end process;
end Behavioral;
实体单脉冲为
端口(时钟:在标准逻辑中;
Rst:标准逻辑中;
P_out:输出标准逻辑);
单脉冲结束;
singlepulse的架构是
信号计数:整数范围0到100000000;
开始
过程(时钟、rst)
开始
如果(rst='1'),则
P_out正如在评论中所注意到的,您的代码中有几个问题:
- 拆下下降沿部件
- 您的计数器未重置,因此将达到其最大值并重新生成脉冲
如果在复位释放后需要脉冲2 us,只需在计数器介于100和140之间时提高输出:
architecture Behavioral of singlepulse is
signal count : Integer range 0 to 1000000000;
begin
process(clk, rst)
begin
if (rst = '1') then
p_out <= '0';
count <= 0;
elsif (rising_edge(clk)) then
if (count < 100) then -- Wait 2 us
count <= count + 1;
p_out <= '0';
elsif (count < 140) then -- Pulse of 0.8 us
count <= count + 1;
p_out <= '1';
else -- Stop incrementing counter to avoid new pulse
p_out <= '0';
end if;
end process;
end Behavioral;
singlepulse的架构行为是
信号计数:整数范围0到100000000;
开始
过程(时钟、rst)
开始
如果(rst='1'),则
p_out为什么要使用下降沿(clk)
?如果你知道如何在脉冲持续时间后重置p_out,是什么阻止你使用相同的结构来延迟设置?因为时钟的下降沿o/p变为零,恐怕这样的结构是不可合成的。如果删除整个“elsif(falling_edge(clk))
-branch”会发生什么?在担心延迟2us之前,让我们先正确处理这段代码。(如前所述,只需删除与下降沿(clk)
相关的所有代码)如果模拟此代码,它将输出一个0.8us的单脉冲,然后在模拟时间为20秒时崩溃,因为整数计数将超出范围。(在这样一个整数上设置一个范围并不意味着它将环绕。)如果你想每20秒输出一个0.8us脉冲,那么当它达到100000000时,你需要显式代码将计数设置为零。Hi@Gautitho我们可以使用FSM通过case语句一起生成这些脉冲吗?Hi,我不明白你为什么要说几个脉冲,这个代码只产生一个脉冲(除非重置激活)。当然可以,但是做同样的事情,代码会更复杂。