--******************************************************************************
--* @short   Block that generates a pulse (used for steering a front panel
--*          LED) upon rising edge of a signal.
--*
--*          The duration of the pulse is configurable by a generic. Upon a
--*          rising edge in the input signal, a counter is loaded and the LED
--*          switched on. When the counter reaches zero, the LED is switched off.
--*         
--******************************************************************************
--* @author  SAKULIN Hannes  <hsakulin@dsy-srv3.cern.ch>
--* @version $Revision: 1.1 $
--* @date    $Date: 2004/12/16 19:18:09 $
--******************************************************************************
--/
library IEEE;
use IEEE.Std_logic_1164.all;
use IEEE.NUMERIC_STD.all;
 

entity LEDPulser is
  generic (
    length_in_clocks : integer);
  port (
    iSignal   : in std_logic;
    oLEDPulse : out std_logic;
    
    clk       : in std_logic);
end entity LEDPulser;


architecture behavioral of LEDPulser is
  attribute syn_useioff               : boolean;
  attribute syn_useioff of behavioral : architecture is true;

  signal sig_d : std_logic;
begin  -- architecture behavioral

  pulse_LED: process (clk) is
    variable counter : integer := 0;
  begin  -- process pulse_LED
    if clk'event and clk = '1' then
      sig_d <= iSignal;

      -- load counter on rising edge
      if sig_d = '0' and iSignal = '1' then
        counter := length_in_clocks;
      end if;

      -- count down
      if counter > 0 then
        counter := counter - 1;
      end if;

      -- steer LED
      if counter > 0 then
        oLEDPulse <= '1';
      else
        oLEDPulse <= '0';
      end if;
    end if;    
  end process pulse_LED;
  
end architecture behavioral;