触发器在两个信号的边沿触发

发布于 2024-08-01 21:45:53 字数 247 浏览 11 评论 0原文

我需要一个对两个不同信号的边缘做出反应的触发器。 像这样的事情:

if(rising_edge(sig1)) then
    bit <= '0';
elsif(rising_edge(sig2)) then
    bit <= '1';
end if;

这样的触发器是否存在或者我可以使用其他一些技术吗? 我需要它可以在 Xilinx Virtex-5 FPGA 上综合。 谢谢

I need a flip flop that reacts on the edges of two different signals. Something like this:

if(rising_edge(sig1)) then
    bit <= '0';
elsif(rising_edge(sig2)) then
    bit <= '1';
end if;

Does such a flip flop exist or is there some other technique i could use?
I need this to be synthesizable on a Xilinx Virtex-5 FPGA.
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

从来不烧饼 2024-08-08 21:45:53

在这种情况下,我通常要做的是保留两个控制信号的延迟版本,并在每个信号的上升沿生成一个时钟宽度的脉冲。 然后,我将使用这些脉冲来驱动微型 FSM 来生成“位”信号。 下面是一些 VHDL。

--                                         -*-vhdl-*-
--  Finding edges of control signals and using the
-- edges to control the state of an output variable
--

library ieee;
use ieee.std_logic_1164.all;

entity stackoverflow_edges is
  port ( clk  : in std_ulogic;
     rst  : in std_ulogic;
     sig1 : in std_ulogic;
     sig2 : in std_ulogic;
     bito : out std_ulogic );

end entity stackoverflow_edges;

architecture rtl of stackoverflow_edges is

  signal sig1_d1  , sig2_d1   : std_ulogic;
  signal sig1_rise, sig2_rise : std_ulogic;

begin 

  -- Flops to store a delayed version of the control signals
  -- If the contorl signals are not synchronous with clk,
  -- consider using a bank of 2 delays and using those outputs
  -- to generate the edge flags
  delay_regs: process ( clk ) is 
  begin 
    if rising_edge(clk) then
      if rst = '1' then 
        sig1_d1 <= '0';
        sig2_d1 <= '0';
      else
        sig1_d1 <= sig1;
        sig2_d1 <= sig2;
      end if;
    end if;
  end process delay_regs;


  -- Edge flags
  edge_flags: process (sig1, sig1_d1, sig2, sig2_d1) is
  begin
    sig1_rise <= sig1 and not sig1_d1;
    sig2_rise <= sig2 and not sig2_d1;
  end process edge_flags;

  -- Output control bit
  output_ctrl: process (clk) is
  begin 
    if rst = '1' then
      bito <= '0';
    elsif sig1_rise = '1' then
      bito <= '1';
    elsif sig2_rise = '1' then
      bito <= '0';
    end if;
  end process output_ctrl;

end rtl;

我对 verilog 更熟悉,所以仔细检查这个 VHDL(任何评论表示赞赏)。

波形 http://img33.imageshack.us/img33/893/stackoverflowvhdlq.png

此代码假设时钟足够快以捕获所有控制信号脉冲。 如果控制信号与时钟不同步,我会保留延迟控制信号的进一步延迟版本(例如sig_d2),然后从制作标志sig_d1 和 sig_d2 。

What I'd usually do in this case is to keep a delayed version of both the control signals and generate a pulse one clock wide at the rising edge of each signal. I'd then use these pulses to drive a tiny FSM to generate the 'bit' signal. Here's some VHDL below.

--                                         -*-vhdl-*-
--  Finding edges of control signals and using the
-- edges to control the state of an output variable
--

library ieee;
use ieee.std_logic_1164.all;

entity stackoverflow_edges is
  port ( clk  : in std_ulogic;
     rst  : in std_ulogic;
     sig1 : in std_ulogic;
     sig2 : in std_ulogic;
     bito : out std_ulogic );

end entity stackoverflow_edges;

architecture rtl of stackoverflow_edges is

  signal sig1_d1  , sig2_d1   : std_ulogic;
  signal sig1_rise, sig2_rise : std_ulogic;

begin 

  -- Flops to store a delayed version of the control signals
  -- If the contorl signals are not synchronous with clk,
  -- consider using a bank of 2 delays and using those outputs
  -- to generate the edge flags
  delay_regs: process ( clk ) is 
  begin 
    if rising_edge(clk) then
      if rst = '1' then 
        sig1_d1 <= '0';
        sig2_d1 <= '0';
      else
        sig1_d1 <= sig1;
        sig2_d1 <= sig2;
      end if;
    end if;
  end process delay_regs;


  -- Edge flags
  edge_flags: process (sig1, sig1_d1, sig2, sig2_d1) is
  begin
    sig1_rise <= sig1 and not sig1_d1;
    sig2_rise <= sig2 and not sig2_d1;
  end process edge_flags;

  -- Output control bit
  output_ctrl: process (clk) is
  begin 
    if rst = '1' then
      bito <= '0';
    elsif sig1_rise = '1' then
      bito <= '1';
    elsif sig2_rise = '1' then
      bito <= '0';
    end if;
  end process output_ctrl;

end rtl;

I'm a lot more comfortable in verilog, so double check this VHDL (any comments appreciated).

waveforms http://img33.imageshack.us/img33/893/stackoverflowvhdlq.png

This code assumes that the clock is fast enough to capture all the control signal pulses. If the control signals are not synchronous with the clock, I'd keep a further delayed version of the delayed control signal (eg sig_d2) then make the flags from sig_d1 and sig_d2.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文