vhdl D-Flip-Flops (DFF) and latches Latches


Example

In all examples:

  • en is the enable signal,
  • d is the input,
  • q is the output,
  • srst is an active high synchronous reset,
  • srstn is an active low synchronous reset,
  • arst is an active high asynchronous reset,
  • arstn is an active low asynchronous reset,
  • sset is an active high synchronous set,
  • ssetn is an active low synchronous set,
  • aset is an active high asynchronous set,
  • asetn is an active low asynchronous set

All signals are of type ieee.std_logic_1164.std_ulogic. The syntax used is the one that leads to correct synthesis results with all logic synthesizers. Please see the Clock edge detection example for a discussion about alternate syntax.

Active high enable

process(en, d)
begin
  if en = '1' then
    q <= d;
  end if;
end process;

Active low enable

process(en, d)
begin
  if en = '0' then
    q <= d;
  end if;
end process;

Active high enable, synchronous active high reset

process(en, d)
begin
  if en = '1' then
    if srst = '1' then
      q <= '0';
    else
      q <= d;
    end if;
  end if;
end process;

Active high enable, asynchronous active high reset

process(en, d, arst)
begin
  if arst = '1' then
    q <= '0';
  elsif en = '1' then
    q <= d;
  end if;
end process;

Active low enable, asynchronous active low reset, synchronous active high set

process(en, d, arstn)
begin
  if arstn = '0' then
    q <= '0';
  elsif en = '0' then
    if sset = '1' then
      q <= '1';
    else
      q <= d;
    end if;
  end if;
end process;

Active high enable, asynchronous active high reset, asynchronous active low set

Note: set has higher priority than reset

process(en, d, arst, asetn)
begin
  if asetn = '0' then
    q <= '1';
  elsif arst = '1' then
    q <= '0';
  elsif en = '1' then
    q <= d;
  end if;
end process;