现在我正在编写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;
答案 0 :(得分:2)
两个版本都无法合成:
rising_edge
条件。通常,第二种实现最接近解决方案。您可以使用-1
类型向signed
计数来改进递减计数器。可以通过MSB '1'
来识别-1。无需为所有零比较n位。
其他问题:
trigger
flag
unisim
未使用。 flag
未使用。