【问题标题】:code VHDL one shot timer代码 VHDL 一次性定时器
【发布时间】: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


【解决方案1】:

两个版本都无法合成:

  • 第一个代码在rising_edge 条件之外。
  • 第二个代码具有异步加载条件。
    FPGA 不支持。并非所有 FPGA 都支持。

通常,第二种实现最接近解决方案。您可以通过向-1 计数和使用signed 类型来改进递减计数器。 -1 可以通过 MSB 标识为'1'。无需比较 n 位是否为全零。

其他问题:

  • 敏感度列表错误。
    • 信号trigger 丢失
    • 信号flag 未被读取
  • unisim 未使用。
  • 信号flag 未使用。

【讨论】:

  • 那么,testbench 中的 pluse 信号是怎么回事?当 trigger ='1' 或 trigger ='1' 之后,它应该 ='1'。
  • "您可以通过向 -1 计数来改进递减计数器" 我认为这是一种微优化。您至少需要将count 的位数增加一以确保正范围。
  • 我刚试过,XIlinx 工具允许异步加载。就像异步重置一样,但它也使用 'clr' 旁边的 'set' 引脚。
  • @Oldfart 有趣...改变了我的答案:)。
猜你喜欢
  • 2016-08-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多