【发布时间】:2018-06-10 05:02:37
【问题描述】:
现在我正在编写 VHDL 代码来制作一次性计时器模块。但我不知道哪种代码在两种代码中是正确的,第一种或第二种。我使用了测试台,我看到了不同。单稳态(单次)的正确代码是什么?
这是第一个代码:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
library UNISIM;
use UNISIM.VComponents.all;
entity oneshot is
port ( clk : in STD_LOGIC;
ce : in STD_LOGIC;
trigger : in STD_LOGIC;
delay : in STD_LOGIC_VECTOR (7 downto 0);
pulse : out STD_LOGIC :='0');
end oneshot;
architecture Behavioral of oneshot is
signal count: INTEGER range 0 to 255; -- count variable
begin
process (clk,delay,trigger)
begin
-- wait for trigger leading edge
if rising_edge(clk) then
if trigger = '1' then
count <= to_integer(unsigned(delay));
end if;
if count > 0 then
pulse <= '1';
count <= count - 1;
else
pulse <= '0';
end if;
end if;
end process;
end Behavioral;
这是第二个:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
library UNISIM;
use UNISIM.VComponents.all;
entity oneshot is
port ( clk : in STD_LOGIC;
ce : in STD_LOGIC;
trigger : in STD_LOGIC:='0';
delay : in STD_LOGIC_VECTOR (7 downto 0);
pulse : out STD_LOGIC :='0');
end oneshot;
architecture Behavioral of oneshot is
signal count: INTEGER range 0 to 255; -- count variable
begin
process (clk,delay,trigger)
begin
-- wait for trigger leading edge
if trigger = '1' then
count <= to_integer(unsigned(delay));
elsif rising_edge(clk) then
if count > 0 then
pulse <= '1';
count <= count - 1;
else
pulse <= '0';
end if;
end if;
end process;
end Behavioral;
【问题讨论】:
-
第一。并且只在敏感列表中包含
clk。另外:count可以是unsigned。 -
您编辑的第一个代码看起来随着它的更新波形有了很大改进。 (您可以提供您的测试台或波形计数。注意 ce 未使用。)理想情况下,您可能希望脉冲在触发为“1”时在时钟的上升沿变高,并在上升沿变低计数为 1 时的时钟以消除一个时钟延迟 - 脉冲是触发器。
-
感谢 @JHBonarious @user1155120 我使用计数器 10 个时钟周期。
-
我在 Matlab/Simulink 中使用 Black Box,所以它需要 ce 端口。
标签: vhdl fpga test-bench