title: code VHDL one shot timer
body: <p>Now I'm coding VHDL to make a one-shot timer module. But I don't know which code is right in two kind of code, the first or second. i used the testbench i see the different. What the right code for monostable (one-shot) ?</p>
  
  <p><strong>This is the first code:</strong></p>
  
  <pre><code>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 &lt;= to_integer(unsigned(delay));   
      end if;
      if count &gt; 0 then
          pulse &lt;= '1';
          count &lt;= count - 1;
      else
          pulse &lt;= '0';
      end if;
  end if;
  end process;
  end Behavioral;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/dOJCf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dOJCf.png" alt="testbench imagine of the first code"></a></p>
  
  <p><strong>This is second one:</strong></p>
  
  <pre><code>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 &lt;= to_integer(unsigned(delay));
  elsif rising_edge(clk) then
      if count &gt; 0 then
          pulse &lt;= '1';
          count &lt;= count - 1;
      else
          pulse &lt;= '0';
      end if;
  end if;
  end process;
  end Behavioral;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/HBtqe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HBtqe.png" alt="testbench of the second one"></a></p>